Beispiel #1
0
 public static function &get($src)
 {
     $data = xls_make($src);
     xls_processDescr($data);
     xls_processPoss($data);
     Xlsx::runGroups($data, function &(&$gr) {
         unset($gr['parent']);
         $r = null;
         return $r;
     });
     Xlsx::runPoss($data, function &(&$pos) {
         unset($pos['parent']);
         $r = null;
         return $r;
     });
     return $data;
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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;
 }