Esempio n. 1
0
/**
 * filter the search with pigeonholes
 * @param $pParamHash['pigeonholes']['filter'] - a pigeonhole or an array of pigeonhole content_id
 **/
function pigeonholes_content_list_sql(&$pObject, $pParamHash = NULL)
{
    global $gBitSystem;
    $ret = array();
    if (!empty($pParamHash['pigeonholes']['no_filter'])) {
        $pParamHash['pigeonholes']['filter'] = array();
    } else {
        if (!empty($pParamHash['pigeonholes']['filter'])) {
            $pParamHash['liberty_categories'] = $pParamHash['pigeonholes']['filter'];
        }
        if (!empty($pParamHash['liberty_categories'])) {
            if (!is_array($pParamHash['liberty_categories'])) {
                $pParamHash['liberty_categories'] = array($pParamHash['liberty_categories']);
            }
            // if we want to allow items in subcategories, we get those and include them in the query
            if (!empty($pParamHash['pigeonholes']['sub_holes'])) {
                $pigeonholes = new Pigeonholes();
                $contentIds = array();
                foreach ($pParamHash['liberty_categories'] as $pigeonhole) {
                    $pigeons = $pigeonholes->getSubPigeonholes($pigeonhole);
                    $contentIds = array_merge($contentIds, array_keys($pigeons));
                }
                $contentIds = array_unique(array_merge($pParamHash['liberty_categories'], $contentIds));
            } else {
                $contentIds = $pParamHash['liberty_categories'];
            }
            $ret['join_sql'] = "INNER JOIN `" . BIT_DB_PREFIX . "pigeonhole_members` pm ON (lc.`content_id`=pm.`content_id`)";
            $ret['where_sql'] = 'AND pm.`parent_id` IN (' . implode(',', array_fill(0, count($contentIds), '?')) . ')';
            $ret['bind_vars'] = $pParamHash['pigeonholes']['filter'] = $contentIds;
        }
        if (!empty($pParamHash['pigeonholes']['root_filter'])) {
            $pParamHash['liberty_root_categories'] = $pParamHash['pigeonholes']['root_filter'];
        }
        if (!empty($pParamHash['liberty_root_categories'])) {
            if (!is_array($pParamHash['liberty_root_categories'])) {
                $pParamHash['liberty_root_categories'] = array($pParamHash['liberty_root_categories']);
            }
            // if we want to allow items in subcategories, we get those and include them in the query
            if (!empty($pParamHash['pigeonholes']['root_sub_holes'])) {
                $pigeonholes = new Pigeonholes();
                $contentIds = array();
                foreach ($pParamHash['liberty_root_categories'] as $pigeonhole) {
                    $pigeons = $pigeonholes->getSubPigeonholes($pigeonhole);
                    $contentIds = array_merge($contentIds, array_keys($pigeons));
                }
                $contentIds = array_unique(array_merge($pParamHash['liberty_root_categories'], $contentIds));
            } else {
                $contentIds = $pParamHash['liberty_root_categories'];
            }
            $ret['join_sql'] = "INNER JOIN `" . BIT_DB_PREFIX . "pigeonhole_members` rpm ON (rlc.`content_id`=rpm.`content_id`)";
            $ret['where_sql'] = 'AND rpm.`parent_id` IN (' . implode(',', array_fill(0, count($contentIds), '?')) . ')';
            $ret['bind_vars'] = $pParamHash['pigeonholes']['filter'] = $contentIds;
        }
    }
    return $ret;
}