コード例 #1
0
ファイル: Yml.php プロジェクト: infrajs/yml
 public static function init()
 {
     $data = Catalog::init();
     Xlsx::runGroups($data, function (&$group, $i, &$parent) {
         $group['data'] = array_filter($group['data'], function (&$pos) {
             //Убираем позиции у которых не указана цена
             //if($pos['Синхронизация']!='Да')return false;
             if (!$pos['Цена']) {
                 return false;
             }
             $pos['Цена'] = preg_replace('/\\s/', '', $pos['Цена']);
             if (!$pos['Цена']) {
                 return false;
             }
             if (strtolower($pos['Маркет']) == 'да') {
                 $pos['Описание'] = strip_tags($pos['Описание']);
                 $pos['Описание'] = preg_replace('/ /', ' ', $pos['Описание']);
                 return true;
             }
         });
         $group['data'] = array_values($group['data']);
     });
     Xlsx::runGroups($data, function (&$group, $i, &$parent) {
         if ($group['childs']) {
             $group['childs'] = array_filter($group['childs'], function (&$g) {
                 if (!$g['data'] && !$g['childs']) {
                     return false;
                 }
                 return true;
             });
             $group['childs'] = array_values($group['childs']);
         }
     }, array(), true);
     Xlsx::runPoss($data, function (&$pos) {
         $conf = Catalog::$conf;
         Xlsx::addFiles($conf['dir'], $pos, array('Производитель', 'article'));
         foreach ($pos['images'] as $k => $v) {
             $src = $pos['images'][$k];
             $p = explode('/', $src);
             foreach ($p as $i => $n) {
                 $p[$i] = urlencode($n);
                 $p[$i] = preg_replace('/\\+/', '%20', $p[$i]);
             }
             $pos['images'][$k] = implode('/', $p);
         }
     });
     return static::parse($data);
 }
コード例 #2
0
ファイル: producers.php プロジェクト: infrajs/catalog
$fd = Catalog::initMark($ans);
if (isset($_GET['lim'])) {
    $lim = $_GET['lim'];
} else {
    $lim = '0,20';
}
$p = explode(',', $lim);
if (sizeof($p) != 2) {
    return Ans::err($ans, 'Is wrong paramter lim');
}
$start = (int) $p[0];
$count = (int) $p[1];
$args = array($start, $count);
$list = Catalog::cache('producers.php', function ($start, $count) {
    $ans = array();
    $data = Catalog::init();
    $prods = array();
    Xlsx::runPoss($data, function &(&$pos) use(&$prods) {
        if (empty($prods[$pos['producer']])) {
            $prods[$pos['producer']] = 0;
        }
        $prods[$pos['producer']]++;
        $r = null;
        return $r;
    });
    arsort($prods, SORT_NUMERIC);
    $prods = array_slice($prods, $start, $count);
    return $prods;
}, $args, isset($_GET['re']));
$ans['menu'] = Load::loadJSON('-catalog/menu.json');
$ans['list'] = $list;
コード例 #3
0
ファイル: Catalog.php プロジェクト: infrajs/catalog
 public static function getGroups($list, $now = false)
 {
     //Groups
     $subgroups = Catalog::cache('getGroups', function () {
         //Микро вставка всё ради того чтобы не пользоваться $data на этом уровне
         //данный кэш один для любой страницы каталога
         $subgroups = array();
         $data = Catalog::init();
         Xlsx::runGroups($data, function &($group) use(&$subgroups) {
             $r = null;
             if (empty($group['childs'])) {
                 return $r;
             }
             $subgroup = array();
             array_walk($group['childs'], function ($g) use(&$subgroup) {
                 $subgroup[] = array('title' => $g['title'], 'name' => $g['name']);
             });
             $subgroups[$group['title']] = $subgroup;
             return $r;
         });
         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 = Catalog::$conf;
         $groupchilds = $subgroups[$conf['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;
 }