コード例 #1
0
ファイル: filters.php プロジェクト: infrajs/catalog
        $block['row'] = array();
        if ($param['option']['nocount']) {
            $row = array('title' => 'Не указано', 'filter' => $param['nofilter']);
            $row['checked'] = !!$mymd['no'];
            if ($row['checked']) {
                $row['add'] = $add . $paramid . '.no=';
            } else {
                $row['add'] = $add . $paramid . '.no=1';
            }
            $block['row'][] = $row;
        }
        if ($block['type'] == 'string') {
            foreach ($param['option']['values'] as $value) {
                $row = array('title' => $value['title'], 'filter' => $value['filter']);
                $row['checked'] = !!$mymd[$value['id']];
                $valueid = Sequence::short(array(Catalog::urlencode($value['id'])));
                if ($row['checked']) {
                    $row['add'] = $add . $paramid . '.' . $valueid . '=';
                } else {
                    $row['add'] = $add . $paramid . '.' . $valueid . '=1';
                }
                $block['row'][] = $row;
            }
        }
        if ($conf['filteroneitem'] || sizeof($block['row']) > 1) {
            $ans['template'][] = $block;
        }
    }
    return $ans;
}, $args, isset($_GET['re']));
$ans = array_merge($ans, $res);
コード例 #2
0
ファイル: Catalog.php プロジェクト: infrajs/catalog
 public static function filtering(&$poss, $md)
 {
     if (!sizeof($poss)) {
         return;
     }
     $params = Catalog::getParams();
     $filters = array();
     foreach ($params as $prop) {
         if ($prop['more']) {
             if (empty($md['more'])) {
                 continue;
             }
             //Filter more
             if (empty($md['more'][$prop['mdid']])) {
                 continue;
             }
             //Filter more
             $valtitles = array();
             $val = $md['more'][$prop['mdid']];
             foreach ($val as $value => $one) {
                 $valtitles[$value] = $value;
             }
             $filter = array('title' => $prop['title'], 'name' => Sequence::short(array('more', Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     $option = $pos['more'][$prop['posid']];
                     if ($value === 'yes' && Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($option)) {
                         return true;
                     }
                     $titles = $pos['more'][$prop['posname']];
                     if ($prop['separator']) {
                         $option = explode($prop['separator'], $option);
                         $titles = explode($prop['separator'], $titles);
                     } else {
                         $option = array($option);
                         $titles = array($titles);
                     }
                     foreach ($option as $k => $opt) {
                         $id = Path::encode($opt);
                         if (strcasecmp($value, $id) == 0) {
                             $valtitles[$value] = $titles[$k];
                             return true;
                         }
                     }
                 }
                 return false;
             });
             if ($val['no']) {
                 unset($val['no']);
                 $val['Не указано'] = 1;
             }
             if ($val['yes']) {
                 unset($val['yes']);
                 $val['Указано'] = 1;
             }
             $filter['value'] = implode(', ', array_values($valtitles));
             $filters[] = $filter;
         } else {
             if (empty($md[$prop['mdid']])) {
                 continue;
             }
             $valtitles = array();
             $val = $md[$prop['mdid']];
             foreach ($val as $value => $one) {
                 $valtitles[$value] = $value;
             }
             $filter = array('title' => $prop['title'], 'name' => Sequence::short(array(Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     $option = $pos[$prop['posid']];
                     $titles = $pos[$prop['posname']];
                     if ($value === 'yes' && Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($prop['separator']) {
                         $option = explode($prop['separator'], $option);
                         $titles = explode($prop['separator'], $titles);
                     } else {
                         $option = array($option);
                         $titles = array($titles);
                     }
                     foreach ($option as $k => $opt) {
                         $id = Path::encode($opt);
                         if (strcasecmp($value, $id) == 0) {
                             $valtitles[$value] = $titles[$k];
                             return true;
                         }
                     }
                 }
                 return false;
             });
             if ($val['no']) {
                 unset($val['no']);
                 $val['Не указано'] = 1;
             }
             if ($val['yes']) {
                 unset($val['yes']);
                 $val['Указано'] = 1;
             }
             $filter['value'] = implode(', ', array_values($valtitles));
             $filters[] = $filter;
         }
     }
     //Filter group
     $key = 'group';
     if (!empty($md[$key])) {
         $title = 'Группа';
         $val = $md[$key];
         $filter = array('title' => $title, 'name' => Sequence::short(array(Catalog::urlencode($key))));
         $poss = array_filter($poss, function ($pos) use($key, $val) {
             $prop = $pos[$key];
             foreach ($val as $value => $one) {
                 if ($value === 'yes') {
                     return true;
                 }
                 foreach ($pos['path'] as $path) {
                     if ((string) $value === $path) {
                         return true;
                     }
                 }
             }
             return false;
         });
         if ($val['no']) {
             unset($val['no']);
             $val['Не указано'] = 1;
         }
         if ($val['yes']) {
             unset($val['yes']);
             $val['Указано'] = 1;
         }
         $filter['value'] = implode(', ', array_keys($val));
         if ($md['search']) {
             $filters[] = $filter;
         }
     }
     //Filter search
     if (!empty($md['search'])) {
         $v = preg_split("/\\s+/", mb_strtolower($md['search']));
         foreach ($v as $i => $s) {
             $v[$i] = preg_replace("/ы\$/", "", $s);
         }
         $poss = array_filter($poss, function ($pos) use($v) {
             return Catalog::searchTest($pos, $v);
         });
         $filters[] = array('title' => 'Поиск', 'name' => 'search', 'value' => $md['search']);
     }
     //Extend::filtering($poss, $md, $filters);
     return $filters;
 }