Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
I was looking for a way to minify the following code cause it has a lot of constantly repeating regions (especially the <cms:pages masterpage='feedback.php' count_only='1.. part).

Code: Select all
<cms:show yesterday /> - <cms:date format='Y-m-d' />: 
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=yesterday /><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=yesterday /><br />
<cms:show two_days_ago /> - <cms:show yesterday />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=two_days_ago stop_before=yesterday/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=two_days_ago stop_before=yesterday/><br />
<cms:show three_days_ago /> - <cms:show two_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=three_days_ago stop_before=two_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=three_days_ago stop_before=two_days_ago/><br />
<cms:show four_days_ago /> - <cms:show three_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=four_days_ago stop_before=three_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=four_days_ago stop_before=three_days_ago/><br />
<cms:show five_days_ago /> - <cms:show four_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=five_days_ago stop_before=four_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=five_days_ago stop_before=four_days_ago/><br />
<cms:show six_days_ago /> - <cms:show five_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=six_days_ago stop_before=five_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=six_days_ago stop_before=five_days_ago/><br />
<cms:show seven_days_ago /> - <cms:show six_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=seven_days_ago stop_before=six_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=seven_days_ago stop_before=six_days_ago/><br />
<cms:show eight_days_ago /> - <cms:show seven_days_ago />:
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=eight_days_ago stop_before=seven_days_ago/><br />
<cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=eight_days_ago stop_before=seven_days_ago/><br />
There is a way, certainly. Why do you need it minified if it works okay as is?
Okay, I took this as a mind game without your answer. ;)
Here is one of possible solutions. Amount of days is variable (8 in my sample).

Code: Select all
<cms:repeat count='7' startcount='0' >

    <cms:capture into='one_day'>
        <cms:date "<cms:show k_count /> day ago" format='Y-m-d' />
    </cms:capture>

    <cms:capture into='one_day_ago'>
        <cms:date "<cms:add k_count '1' /> day ago" format='Y-m-d' />
    </cms:capture>


    <cms:show one_day_ago /> - <cms:show one_day />:
    <cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Satisfied' start_on=one_day_ago stop_before=one_day /><br />
    <cms:pages masterpage='feedback.php' count_only='1' custom_field='status=Not so much' start_on=one_day_ago stop_before=one_day /><br />

</cms:repeat>
In my previous sample I minified the code, but not the amount of SQL queries to database via cms:pages tag.
If somehow the speed gets slow over large amount of pages, I am posting here another sample.

Idea is to run cms:pages only once, put data into array and output count of array values.
Solution is based on concept Multi-value variables viewtopic.php?f=5&t=10892#p27841

We can check if it really looks like expected via:
Code: Select all
<h3>Test output of array:</h3>
<cms:show feedback as_json='1' />
<br>


Now, the json can be printed as follows

2018-01-23:
-- satisfied: 3
-- not so good: 2
2018-01-22:
-- satisfied: 3
-- not so good: 0

via following code:
Code: Select all
<cms:each feedback>
    <cms:if "<cms:is_array item />">
        <cms:show key />:<br>
       
        <cms:each item>
            <cms:if "<cms:is_array item />">
                -- <cms:show key />: <cms:array_count item /><br>
            </cms:if>   
        </cms:each>

    </cms:if>   
</cms:each>   


Hope it helps

P.S. To limit fetched pages to only last 7 days, modify cms:pages part to
<cms:pages masterpage='feedback.php' limit='1000000' start_on="<cms:date '1 week ago' format='Y-m-d' />" >
trendoman wrote: Idea is to run cms:pages only once, put data into array and output count of array values.
Solution is based on concept Multi-value variables viewtopic.php?f=5&t=10892#p27841


This is exactly the kind of thing I needed, thank you! Will try it out!
Does this work with 1.4.7 too?
For now, if anyone is willing to try out this feature, please download Couch from GitHub -
https://github.com/CouchCMS/CouchCMS
6 posts Page 1 of 1