$haveFilter = false;
$textSearch = '';
- // Check for "show" shortcode parameter
+ // Check for "show" shortcode parameter (what elements to show on the page)
$settings = array();
$showList = $actionData['request']['show'];
-
if ($showList) {
// Separate options and see if we have any
$whereSep = ' AND ';
}
- // Get category filter data
- $categoryData = false;
+ // Get category data for search pick list and shortcode selection
+ require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
+ $Categories = new GlmDataCategories($this->wpdb, $this->config);
+ $categoryData = $Categories->getListSortedParentChild(false);
+
+ // Get any numeric categories selected in the submitted shortcode
$catSelected = '';
- if ($this->config['settings']['list_show_search_category']) {
+ $cats = array();
+ if (isset($actionData['request']['category'])) {
+
+ $catsRequested = explode(',', $actionData['request']['category']);
+
+ // Check for numeric IDs only
+ while (list($k, $v) = each($catsRequested)) {
+
+ // If it's just numeric
+ if (preg_match('/^[0-9]*$/', trim($v))) {
+
+ // Clean up the category number and add to cats array
+ $cats[] = ($v-0);
+
+ }
+
+ }
+
+ }
- // Get category data for search pick list
- require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
- $Categories = new GlmDataCategories($this->wpdb, $this->config);
- $categoryData = $Categories->getListSortedParentChild();
+ // Get any text categories selected in the submitted shortcode
+ if (isset($actionData['request']['category-name'])) {
+
+ // Break up shortcode categories into an array to make searching easy
+ $catsRequested = explode('|', $actionData['request']['category-name']);
+
+ // Check for numeric or text selection of categories
+ while (list($k, $v) = each($catsRequested)) {
+
+ $vStripped = html_entity_decode(stripslashes(trim($v)));
+
+ reset($categoryData);
+ foreach ($categoryData as $c) {
+
+ $x = html_entity_decode(stripslashes(trim($c['name'])));
+
+ // If this entry matches - apply html entity decode in case string is encoded
+ if ($x == $vStripped) {
+
+ // Update the $cats array with the ID rather than the name and mark as found
+ $cats[] = $c['id'];
+ }
+ }
+
+ }
+
+ }
+
+ // If there's categories specified with the shortcode
+ if (count($cats) > 0) {
+
+ /*
+ * Restrict available categories for selection to those in shortcode or children
+ * Note that the array is already ordered by parent then children then next parent
+ * so $parentSelected
+ */
+ $parentSelected = false;
+ reset($categoryData);
+ while (list($k, $v) = each($categoryData)) {
+
+ // If this is a parent, then clear parent selected
+ if ($v['parent_id'] != $parentSelected) {
+ $parentSelected = false;
+ }
+
+ // If category or parent is selected
+ if ($parentSelected == false && !in_array($k, $cats)) {
+
+ // Drop this category from the list
+ unset($categoryData[$k]);
+
+ // Otherwise, if this is a top-level category that's not dropped, save as currently selected parent
+ } elseif (!$v['parent_id']) {
+ $parentSelected = $k;
+ }
+
+ }
+
+ }
+
+ // If we're doing category search selection Get category filter data
+ if ($this->config['settings']['list_show_search_category']) {
// Add default flag as false to all entries
foreach ($categoryData as $k=>$v) {
$categoryData[$k]['default'] = false;
}
+
+ // Check if a category has been submitted
+ if (isset($_REQUEST['categorySearch'])) {
+ $c = $_REQUEST['categorySearch'] - 0;
+
+ // Since we have one category selected by the user, make that default
+ if ($c && isset($categoryData[$c])) {
+ $categoryData[$c]['default'] = true;
+ $catSelected = $c;
+ }
+
+ }
+
}
- // Check if a category has been submitted
- if (isset($_REQUEST['categorySearch'])) {
- $catSelected = $_REQUEST['categorySearch'] - 0;
- } elseif ($actionData['request']['category']) {
- $catSelected = $actionData['request']['category'];
+
+ if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
+ glmMembersFront::addNotice("<b>Categories Requested:</b> $catSelected", 'Process');
+
}
- // If we have a category ID
- if ($catSelected > 0) {
+ // If we have a category ID or IDs
+ if ($catSelected != '') {
$where .= $whereSep." T.id in (
SELECT DISTINCT(member_info)
)";
$whereSep = ' AND ';
- // Set default to true for the selected category
- $c = explode(',', $catSelected);
- $categoryData[$c[0]]['default'] = true;
-
}
-
// Get amenity filter data
$amenityData = false;
$amenSelected = '';
'alphaSelected' => $alphaSelected
);
- // Return status, suggested view, and data to controller
+ // Return status, suggested view, and data to controller - also return any modified settings
return array(
'status' => $success,
'menuItemRedirect' => false,