Re: Website Membership user type / user levels / user permissions and display of data
5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 15, 2018 (RSS)
By Mikey - August 15, 2018 - edited: August 15, 2018
I'm trying to set up an events page to display Church Events to members based on their permission levels, and also filter records based on Date greater than Now.
The code I'm using below works for filter member permission levels, but when I add the AND "(date >= NOW())" nothing seems to happen and it still displays all events even if they are past tense. Anyone have any suggestions on how to get this working and filtering out event records that are past tense.
$paramseventsRecords = array(
'tableName' => 'events',
'perPage' => @$perPage ? $perPage : '6',
'orderBy' => 'date',
'loadUploads' => true,
'allowSearch' => true,
'where' => 'membership_access = "Public"' AND "(date >= NOW())"
);
if(@$CURRENT_USER['membership_user_type'] == 'Congregation')
{ $paramseventsRecords['where'] = 'membership_access = "Public" OR membership_access = "Congregation"' AND "(date >= NOW())";
}
if(@$CURRENT_USER['membership_user_type'] == 'Administration')
{ $paramseventsRecords['where'] = 'membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration"' AND "(date >= NOW())";
}
if(@$CURRENT_USER['membership_user_type'] == 'Leadership' AND "(date >= NOW())")
{ $paramseventsRecords['where'] = 'TRUE';
}
list($eventsRecords, $eventsMetaData) = getRecords($paramseventsRecords);
Thanks, Zick
In response to: [url "https://www.interactivetools.com/forum/forum-posts.php?postNum=2235310#post2235310"]Website Membership user type / user levels / user permissions and display of data[/url], ...
By daniel - August 15, 2018
Hi Zick,
It looks like there are some mismatched quotes in your code; the single quote needs to surround the entire where statement and the double quotes (") should be removed from around the date clause. Try adjusting the code so it follows this general format.
From:
'where' => 'membership_access = "Public"' AND "(date >= NOW())"
To:
'where' => 'membership_access = "Public" AND date >= NOW()'
Additionally, for the statements with multiple membership access levels, I would recommend wrapping those in brackets, such as:
$paramseventsRecords['where'] = '(membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration") AND date >= NOW()';
Let me know if that helps with your issue, or if I can help with anything else.
Thanks,
Technical Lead
interactivetools.com
By Mikey - August 15, 2018
Hey Daniel,
Thanks so much. That did the trick and it's working like a charm.
I wonder if I can trouble with a little more help on one other configuration. It's the same scenario, just a different kind of query of events by month.
I'm trying to add the member's permissions levels to an Events by Month page. So I added the following lines in bold to the 'where', but it is not filter based on the member's permission.
'where' => mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND 'membership_access = "Public"',
$paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation")';
$paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration")';
$paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration" OR membership_access = "Leadership")';
Below is the code I'm working with
$monthNames = Array("Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
$paramseventsRecords = array(
'tableName' => 'events',
'where' => mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND 'membership_access = "Public"',
'orderBy' => 'date',
);
if(@$CURRENT_USER['membership_user_type'] == 'Congregation')
{ $paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation")';
}
if(@$CURRENT_USER['membership_user_type'] == 'Administration')
{ $paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration")';
}
if(@$CURRENT_USER['membership_user_type'] == 'Leadership')
{ $paramseventsRecords['where'] = mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND '(membership_access = "Public" OR membership_access = "Congregation" OR membership_access = "Administration" OR membership_access = "Leadership")';
}
list($eventsRecords, $eventsMetaData) = getRecords($paramseventsRecords);
Thanks Zick
By daniel - August 15, 2018
Hi Zick,
It looks like there is a similar formatting issue here - you'll want to add the "AND..." part inside of the quotes in mysql_escapef(). So for example, something like this:
'where' => mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear) AND 'membership_access = "Public"',
Should look like this:
'where' => mysql_escapef('MONTH(date) = ? AND YEAR(date) = ? AND membership_access = "Public"', $cMonth, $cYear),
I hope this helps!
Technical Lead
interactivetools.com
By Mikey - August 15, 2018
Daniel,
Thanks a ton!!! I got this working now. I really appreciate the help.
Zicky