Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
Hi,

I've been mucking around for this for awhile, and tried a few different ways.. now i think I am not far off but I need a little bit of a nudge in the right direction..

I have set up a group of ambassadors in a (form) i think!!!

Screen shot 2014-04-28 at 1.33.18 PM.png
Screen shot 2014-04-28 at 1.33.18 PM.png (67.25 KiB) Viewed 1866 times


Screen shot 2014-04-28 at 1.33.35 PM.png
Screen shot 2014-04-28 at 1.33.35 PM.png (68.71 KiB) Viewed 1866 times


Ok so I have 3 checkboxes at the bottom called logged , quoted, completed.. I need to somehow tally these results into a ladder format... ie. name only shown once in ladder, then a column next to it with the tallied up results for logged | quoted | completed.. Similar to the below.

Screen shot 2014-04-28 at 1.55.22 PM.png
Screen shot 2014-04-28 at 1.55.22 PM.png (46.76 KiB) Viewed 1866 times


Ok so far I have setup the backend with the below code:

Code: Select all
<?php require_once( '../admin/cms.php' ); ?>
<cms:template title='Leads' clonable='1'>
<cms:editable type='text' label='Prospect Name' name='prospect' order='1' />
<cms:editable name='name' label='Ambassador Name' desc='Please Select Ambassador' required='1' type='dropdown' opt_values="<cms:pages masterpage='ambassadors/index.php'><cms:show name /> |</cms:pages>" order='2' />
<cms:editable name='image' label='Ambassador Image' width='75' height='75' crop='1' show_preview='1' preview_width='75' type='image' order='3'/>
<cms:editable type='text' label='Account Manager' name='manager' order='4' />
<cms:editable type='text' label='Date Logged' name='date' order='5' />
<cms:editable name="progress" label="Progress" desc="Select one from these" opt_values='logged | contacted | meeting | presentation | quote' type='dropdown' order='6'/>
<cms:editable type='checkbox' opt_values='logged=1' label='Has the lead been logged?' name='logged' order='7' />
<cms:editable type='checkbox' opt_values='quoted=1' label='Has the lead been quoted?' name='quoted' order='8' />
<cms:editable type='checkbox' opt_values='completed=1' label='Has the lead been completed?' name='completed' order='9' />
</cms:template>
<?php COUCH::invoke(); ?>


And the ladder page, has this section:

Code: Select all
<table class="table table-striped">
  <tr>
     <th></th>
    <th>Ambassador</th>
    <th>Leads Logged</th>
    <th>Leads Completed</th>
  </tr>
  <cms:pages masterpage='leads/index.php' custom_field='logged'>
  <tr>
     <td><img src="<cms:show image />" width="50px" alt=""></td>
    <td><cms:show name /></td>
    <td><sms:show logged /></td>
    <td><cms:show completed /></td>
  </tr>
    </cms:pages>
   </table>


Ok so I know the code will do nothing.. I'm guessing I need something like a if and else statement, but I am unsure where or what would work..

Any help would be greatly appreciated, kind of stuck! :(

Thanks for any help!
Hi,

It'd been better to use 'relations' feature to relate the 'ambassadors' with their 'leads'.
Anyways, the following code should do what you want (haven't actually tested the code by executing it so there could be some niggles - but I'm sure you'll get the gist of the solution) -
Code: Select all
<table class="table table-striped">
    <tr>
        <th></th>
        <th>Ambassador</th>
        <th>Leads Logged</th>
        <th>Leads Quoted</th>
        <th>Leads Completed</th>
    </tr>
   
    <!-- loop through the ambassadors -->
    <cms:pages masterpage='ambassadors/index.php'>
   
        <!-- for each ambassador, find all the 'lead' pages that are associated with her -->
        <!-- we'll sum up the checkboxes as we go -->
        <cms:set sum_logged='0' 'global' />
        <cms:set sum_quoted='0' 'global' />
        <cms:set sum_completed='0' 'global' />
       
        <cms:pages masterpage='leads/index.php' custom_field="name==<cms:show name />">
            <cms:if logged >
                <cms:set sum_logged="<cms:add sum_logged '1' />" 'global' />
            </cms:if>
            <cms:if quoted >
                <cms:set sum_quoted="<cms:add sum_quoted '1' />" 'global' />
            </cms:if>
            <cms:if completed >
                <cms:set sum_completed="<cms:add sum_completed '1' />" 'global' />
            </cms:if>
        </cms:pages>
       
        <!-- display the accumulated stats -->
        <tr>
            <td><img src="<cms:show image />" width="50px" alt=""></td>
            <td><cms:show name /></td>
            <td><cms:show sum_logged /></td>
            <td><cms:show sum_quoted /></td>
            <td><cms:show sum_completed /></td>
        </tr>   
    </cms:pages>
</table>

Hope this helps.
Hey KK.. That worked perfectly... thankyou so much!

Is there a way to order the list so the ambassador who has the most logged is at the top of the ladder and the least is at the bottom of the ladder..

I have tried getting this to work using

Code: Select all
orderby='logged'


or

Code: Select all
orderby='sum_logged'


but neither seem to change the layout..

thanks again for the help!
The fields you are trying to sort the ambassador records on do not belong to that template at all (the 'logged' belongs to the leads template while the 'sum_logged' is a calculated variable and is not a field).
So, I am afraid we cannot sort on those.

Anyways, how many ambassador pages do you expect to have?
If they won't be too many, we can try bringing in some raw PHP to do the sorting in memory.

Please let me know.

Thanks.
Hi KK,

I would say there will be max 15-20 ambassadors.. Is that too many to use php memory sorting with??
No, not at all.

Please give me some time. I'll get back with the PHP code.

Thanks.
That's awesome.. Thankyou so much kk
Hi Adam,

Here is a modified version of the code above that uses PHP to sort the records -
Code: Select all
<table class="table table-striped">
    <tr>
        <th></th>
        <th>Ambassador</th>
        <th>Leads Logged</th>
        <th>Leads Quoted</th>
        <th>Leads Completed</th>
    </tr>
   
    <!-- loop through the ambassadors -->
    <cms:php>
        global $my_sorted_rows;
        $my_sorted_rows=array(); // we'll keep the records in this PHP array
    </cms:php>
   
    <cms:pages masterpage='ambassadors/index.php'>
   
        <!-- for each ambassador, find all the 'lead' pages that are associated with her -->
        <!-- we'll sum up the checkboxes as we go -->
        <cms:set sum_logged='0' 'global' />
        <cms:set sum_quoted='0' 'global' />
        <cms:set sum_completed='0' 'global' />
       
        <cms:pages masterpage='leads/index.php' custom_field="name==<cms:show name />">
            <cms:if logged >
                <cms:set sum_logged="<cms:add sum_logged '1' />" 'global' />
            </cms:if>
            <cms:if quoted >
                <cms:set sum_quoted="<cms:add sum_quoted '1' />" 'global' />
            </cms:if>
            <cms:if completed >
                <cms:set sum_completed="<cms:add sum_completed '1' />" 'global' />
            </cms:if>
        </cms:pages>
       
        <!-- capture the accumulated stats -->
        <cms:capture into='my_buffer' scope='global'>
            <tr>
                <td><img src="<cms:show image />" width="50px" alt=""></td>
                <td><cms:show name /></td>
                <td><cms:show sum_logged /></td>
                <td><cms:show sum_quoted /></td>
                <td><cms:show sum_completed /></td>
            </tr>   
        </cms:capture>
       
        <cms:php>
            global $CTX, $my_sorted_rows;
           
            $my_sorted_rows[$CTX->get('k_count')]['k']=$CTX->get('sum_logged');
            $my_sorted_rows[$CTX->get('k_count')]['v']=$CTX->get('my_buffer');
        </cms:php>
   
    </cms:pages>
   
    <!-- now sort the rows found and finally display them -->
    <cms:php>
        global $my_sorted_rows;
       
        usort( $my_sorted_rows, "my_custom_sort" );
        function my_custom_sort( $a, $b ){
          return $a['k']<$b['k'];
        }
           
        foreach( $my_sorted_rows as $row ){
            echo $row['v'];
        }
    </cms:php> 
</table>

Hope this helps.
this is awesome.. you have helped me out of a jam..
thankyou so much!
You are welcome :)
10 posts Page 1 of 1