Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
The situation:
  • I have (extended) users signing up for hours on a rota.
  • It is possible for more than on user to sign up to an hour.
  • It would be useful to highlight the hours the user has already signed up for.
So my 'hours' template includes a field 'people':
Code: Select all
<cms:editable name='people' label = 'People who have signed up' type='relation'  masterpage='users/index.php'/>

And when I have a logged in user with a k_user_id, I'd like to do something like
Code: Select all
<cms:if people *contains* k_user_id >
<cms:set divclass="signedup">
</cms:if>

What's the Couch way of doing *contains* in this context?
What's the Couch way of doing *contains* in this context?

The "2. Enhanced cms:pages tag" section at viewtopic.php?f=5&t=8581 shows various example queries for this.
Hi, KK

Thanks - so I can use cms:pages, limit by the name matching the current page name, and the relationship matching the current user ID, and count the result, and if that's 1 then I've got what I need.

I think I'll define a cms:func for that!
Hmm. This doesn't seem to be working as I expected.

Before limiting by page name, here's what I think should be a count of all pages where the current user is in the 'people' relationship:
Code: Select all
<cms:set mine="<cms:pages masterpage='hours.php' custom_field="people=<cms:show k_user_id />" count_only='1' />" />

This returns 0 for all users, even though I have allocated users to hours. I haven't even tried limiting it to the current 'hours' page yet!

(To save looking back up the thread, the relation is defined like this:
Code: Select all
<cms:editable name='people' label = 'People who have signed up' type='relation'  masterpage='users/index.php'/>
)

Am I missing something here?



To add to the above, I've created a separate page like this:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>

<cms:show k_user_id />

<cms:pages masterpage='hours.php'  custom_field="people=daldred"  >
    <a href="<cms:show k_page_link />"><h3><cms:show k_page_title /></h3></a>
</cms:pages>

<cms:pages masterpage='hours.php'  custom_field="people=87"  >
    <a href="<cms:show k_page_link />"><h3><cms:show k_page_title /></h3></a>
</cms:pages>

<?php COUCH::invoke(); ?>


This outputs only '87', which confirms my 'k_user_id'. Neither of the cms:pages calls is producing any output - the custom_field filter doesn't seem to be working as I expect it to.
Using ID with the query requires a slightly different syntax -
Code: Select all
<cms:pages masterpage='hours.php' custom_field="people=id(87)"  >
    ...
</cms:pages>

Please check if this works.
Thanks, KK - yes, that works nicely.

For the record, here's the working code, to set a variable to be used to apply a class to the entry if it's related to the current user:

Code: Select all
<cms:func 'set_user_class' masterpage='' currentpageid='' userclass='is_mine'>
  <cms:set my_number = "<cms:pages masterpage='hours.php'
                             id="<cms:show currentpageid />"
                             show_future_entries='1'
                             count_only='1'
                             custom_field="people=id(<cms:show k_user_id />)"
                           />"
  />
  <cms:if my_number ne '0' >
        <cms:show userclass />
  </cms:if>
</cms:func>

use example: apply a class to a link something like this:
Code: Select all
<a class="button <cms:call 'set_user_class' 'hours.php' "<cms:show k_page_id />"/> href="....">
6 posts Page 1 of 1
cron