Пример #1
0
 public static function filtering(&$poss, $md)
 {
     if (!sizeof($poss)) {
         return;
     }
     $filters = array();
     //Filter producer
     $key = 'producer';
     if (!empty($md[$key])) {
         $val = $md[$key];
         $title = 'Производитель';
         $filter = array('title' => $title, 'name' => infra_seq_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' && Xlsx::isSpecified($prop)) {
                     return true;
                 }
                 if ($value === 'no' && !Xlsx::isSpecified($prop)) {
                     return true;
                 }
                 if ((string) $value === $prop) {
                     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));
         $filters[] = $filter;
     }
     //Filter Цена
     $key = 'cost';
     if (!empty($md[$key])) {
         $val = $md[$key];
         $option = 'Цена';
         $title = $option;
         $filter = array('title' => $title, 'name' => infra_seq_short(array(Catalog::urlencode($key))));
         $poss = array_filter($poss, function ($pos) use($key, $val, $option) {
             $prop = $pos[$option];
             foreach ($val as $value => $one) {
                 if ($value === 'yes' && Xlsx::isSpecified($prop)) {
                     return true;
                 }
                 if ($value === 'no' && !Xlsx::isSpecified($prop)) {
                     return true;
                 }
                 if ((string) $value === $prop) {
                     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));
         $filters[] = $filter;
     }
     //Filter more
     if (!empty($md['more'])) {
         foreach ($md['more'] as $key => $val) {
             $title = $key;
             $filter = array('title' => $title, 'name' => infra_seq_short(array('more', Catalog::urlencode($key))));
             $poss = array_filter($poss, function ($pos) use($key, $val) {
                 $prop = $pos['more'][$key];
                 foreach ($val as $value => $one) {
                     if ($value === 'yes' && Xlsx::isSpecified($prop)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($prop)) {
                         return true;
                     }
                     if ((string) $value === $prop) {
                         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));
             $filters[] = $filter;
         }
     }
     //Filter group
     $key = 'group';
     if (!empty($md[$key])) {
         $title = 'Группа';
         $val = $md[$key];
         $filter = array('title' => $title, 'name' => infra_seq_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']));
         $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;
 }
Пример #2
0
 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' => infra_seq_short(array('more', Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     if ($value === 'yes' && Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($option)) {
                         return true;
                     }
                     $option = $pos['more'][$prop['posid']];
                     $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 = infra_forFS($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' => infra_seq_short(array(Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     if ($value === 'yes' && Xlsx::isSpecified($prop)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($prop)) {
                         return true;
                     }
                     $option = $pos[$prop['posid']];
                     $titles = $pos[$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 = infra_forFS($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' => infra_seq_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']));
         $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;
 }