Membership "filter"

By Toledoh - October 12, 2010

Hi Guys.

I'm doing a website for a sports club who have many "teams".

For instance, people are either
1. General Public (no membership)
2. Member of Red Team
3. Member of Blue Team
4. Member of all teams.

I've a number of section; news, event, gallery, blog etc, and for each item within these sections, I want to be able to say that they are for public, for a specific team or teams.

I've created a Category Menu (teams) with
1. All
2. Red
3. Blue

On the accounts table, I've a multi-select pull down "membership";
Section Tablename team
Use this field for option values num
Use this field for option labels name


On each item (within various editors) I have the same option to identify if that event etc is specific to a team etc via a multi-select pull down "membership";
Section Tablename team
Use this field for option values num
Use this field for option labels name


Now... the question. Is there some easy way that I can say something like;

<?php foreach ..... where $CURRENT_USER meets the $record('membership') OR the record is a "public" record ?>...


Does that make sence?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership "filter"

By Jason - October 12, 2010

Hi Tim,

Are referring to controlling what is displayed on the website, or what is displayed inside CMS Builder? If you want to control which groups can view which pieces of information inside CMS Builder, that will take some custom code. If you're interested in that please email consulting@interactivetools.com for a quote.

If you're trying to control what is being displayed on the website, you can do this with the website membership plugin.

First, how do you determine if a record is public? In your example, the "team" section has only 3 values (All, Red, and Blue)
Also, why are the pull downs multi-select? If some one selects "All", it would imply red and blue. I ask because it will affect how we will do the search.

Let me know and I can give you a better example of how to do this.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Membership "filter"

By Toledoh - October 12, 2010

Hi Jason,

I'm talking about what is displayed on the website - and I have the membership plugin installed.

I was thinking that if no option was selected for team, then it was public, but if an option or multiple options were selected it would be visiable only to those options (but I'm open to a "Members Only" checkbox).

There will be more than 2 teams in the end, red and blue are only examples.

Cheers,
Tim
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Membership "filter"

By Chris - October 12, 2010

Hi Tim,

I think the easiest way to do this is to build up a WHERE clause for getRecords. Here's an example:

# team filter must accept records with no teams specified (i.e. a "public record")
$team_filter = "team = ''";

# team filter must also accept records with any single team which is also listed in $CURRENT_USER['team']
foreach (explode("\t", trim($CURRENT_USER['team'])) as $team_num) {
$team_filter .= mysql_escapef(" OR team LIKE ?", "%\t$team_num\t%");
}

list($sampleRecords, $sampleMetaData) = getRecords(array(
'tableName' => 'sample',
'where' => $team_filter,
));


If you need to add extra conditions to the WHERE clause, you can do something like this:

'where' => '(' . $team_filter . ') AND featured = 1',

Does this help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Membership "filter"

By Toledoh - October 12, 2010

Wow - works perfectly! Thanks
Cheers,

Tim (toledoh.com.au)

Re: [chris] Membership "filter"

By Toledoh - October 12, 2010

Hi Chris.

This may be pushing it...?

I've taken the "zickey calendar" and trying to add this filter.

I've attached 2 files, eventsTest.php is straight out of the code generator, with filter added. eventsMembers.php is the zickey calendar, with the same code added to the top, plus line 135 from:

'where' => mysql_escapef("start_date < ? AND IF(end_date != '0000-00-00', end_date >= ?, start_date >= ?)", $next_month_date, $this_month_date, $this_month_date),

to:'where' => '(' . $team_filter . ')' AND mysql_escapef("start_date < ? AND IF(end_date != '0000-00-00', end_date >= ?, start_date >= ?)", $next_month_date, $this_month_date, $this_month_date),

It works with eventsTest.php, but not eventsMembership.php... any ideas?

You can see these at:
http://www.toledoh.com.au/clubsite/eventsTest.php
http://www.toledoh.com.au/clubsite/eventsMember.php

login using red/red at

http://www.toledoh.com.au/clubsite/eventsTest.php
Cheers,

Tim (toledoh.com.au)
Attachments:

eventstest.php 4K

eventsmember.php 11K

Re: [Toledoh] Membership "filter"

By Chris - October 12, 2010

Hi Tim,

Well, I can see a problem with the code you pasted. Does Changing this:

'where' => '(' . $team_filter . ')' AND mysql_escapef("start_date < ? AND IF(end_date != '0000-00-00', end_date >= ?, start_date >= ?)", $next_month_date, $this_month_date, $this_month_date),

...to this:

'where' => '(' . $team_filter . ') AND ' . mysql_escapef("start_date < ? AND IF(end_date != '0000-00-00', end_date >= ?, start_date >= ?)", $next_month_date, $this_month_date, $this_month_date),

...fix anything? Or will I need to take a closer look?
All the best,
Chris

Re: [chris] Membership "filter"

By Toledoh - October 12, 2010

Nope.

If I move that inverted comma, the page doesn't load at all.
Cheers,

Tim (toledoh.com.au)

Re: [chris] Membership "filter"

By Toledoh - October 12, 2010

That did it Chris.... fantastic - thanks!
Cheers,

Tim (toledoh.com.au)