<?php namespace itlife\catalog; use itlife\files\Xlsx; infra_cache_no(); $orig_val = infra_toutf(strip_tags($_GET['val'])); $orig_art = infra_toutf(strip_tags($_GET['art'])); $val = infra_strtolower($orig_val); $art = infra_strtolower($orig_art); $args = array($val, $art); $ans = array(); $pos = Catalog::cache('position', function ($val, $art) { $data = Catalog::init(); // список всей продукции return Xlsx::runPoss($data, function (&$pos, $i, &$group) use(&$val, &$art) { if (mb_strtolower($pos['producer']) !== $val) { return; } if (mb_strtolower($pos['article']) !== $art) { return; } return $pos; }); }, $args, isset($_GET['re'])); if (isset($_GET['seo'])) { if (!$pos) { return infra_err($ans, 'Position not found'); } $link = $_GET['seo']; $link = $link . '/' . $pos['producer'] . '/' . $pos['article'];
public static function getGroups($list, $now = false) { //Groups $subgroups = Catalog::cache('search.php subgroups', function () { //Микров вставка всё ради того чтобы не пользоваться $data на этом уровне //данный кэш один для любой страницы каталога $subgroups = array(); $data = Catalog::init(); Xlsx::runGroups($data, function ($group) use(&$subgroups) { if (empty($group['childs'])) { return; } $subgroup = array(); array_walk($group['childs'], function ($g) use(&$subgroup) { $subgroup[] = array('title' => $g['title'], 'name' => $g['name']); }); $subgroups[$group['title']] = $subgroup; }); return $subgroups; }); $groups = array(); foreach ($list as &$pos) { $path = $pos['path']; foreach ($list as &$pos) { foreach ($pos['path'] as $v) { if (!isset($groups[$v])) { $groups[$v] = array('pos' => $pos, 'count' => 0); } $groups[$v]['count']++; } $rpath = array(); foreach ($path as $k => $p) { if ($pos['path'][$k] == $p) { $rpath[$k] = $p; } else { break; } } $path = $rpath; } break; } if (!sizeof($path)) { $conf = infra_config(); $groupchilds = $subgroups[$conf['catalog']['title']]; } else { $g = $path[sizeof($path) - 1]; if (isset($subgroups[$g])) { $groupchilds = $subgroups[$g]; } else { if (!$now || $now != $g) { $groupchilds = array(array("name" => $g, "title" => $g)); } else { $groupchilds = false; } } } $childs = array(); if ($groupchilds) { foreach ($groupchilds as $g) { if (!$groups[$g['title']]) { continue; } $pos = Catalog::getPos($groups[$g['title']]['pos']); $pos = array('article' => $pos['article'], 'producer' => $pos['producer'], 'images' => $pos['images']); $childs[] = array_merge($g, array('pos' => $pos, 'count' => $groups[$g['title']]['count'])); } } return $childs; }