public function __construct()
 {
     self::$_current = Router::getCurrentRoute()->getActionVariable('page') ?: 'home';
     $cache = new Cache();
     $cache->setLocalPath(self::$_current . '_menus');
     $cache->load();
     if ($cache->isValid()) {
         $this->_items = unserialize(base64_decode($cache->getData()));
     } else {
         $items = MenuModel::all();
         if (empty($items)) {
             throw new HttpException(404);
         }
         if (!empty($items)) {
             foreach ($items as $i) {
                 $class = static::MENU_NAMESPACE . $i->type;
                 $tmp = new $class();
                 $tmp->init($i);
                 $this->_items[$tmp->getPosition()] = $tmp;
             }
         }
         $cache->setData(base64_encode(serialize($this->_items)));
         $cache->save();
     }
 }
Exemple #2
0
 public function __construct()
 {
     $cache = new Cache();
     $cache->setLocalPath('languages');
     $cache->load();
     if ($cache->isValid()) {
         $items = json_decode($cache->getData());
     } else {
         $items = LangModel::where('status', '=', '1')->get();
         $cache->setData($items);
         $cache->save();
     }
     // Устанавливает язык по умолчанию
     if (class_exists('Setting')) {
         $primaryLangIso = strtolower(Setting::instance()->getSettingVal('language.primary_language'));
     } else {
         $primaryLangIso = strtolower(static::DEFAULT_LANGUAGE);
     }
     if (!empty($items)) {
         foreach ($items as $i) {
             $iso = strtolower($i->iso);
             $this->_langs[$iso] = array('id' => $i->id, 'name' => $i->name, 'iso' => $iso);
             if ($primaryLangIso == $i->iso) {
                 $this->_primaryLang = $this->_langs[$iso];
             }
         }
     }
     $this->_currentLang = $this->_primaryLang;
 }
 public function __construct()
 {
     $slug = Router::getCurrentRoute()->getActionVariable('page') ?: 'home';
     $cache = new Cache();
     $cache->setLocalPath($slug . '_widgets');
     $cache->load();
     if ($cache->isValid()) {
         $items = json_decode($cache->getData());
     } else {
         $article = ArticleModel::where('slug', '=', $slug)->first();
         if (empty($article)) {
             throw new HttpException(404);
         }
         //            $items = $items->widgets()->whereStatus(1)->orderBy('sort')->get();
         $data = $article->ancestorsAndSelf()->whereStatus(1)->get();
         $items = [];
         foreach ($data as $item) {
             // todo: надо добавить и "articles_hast_not_widgets"
             //                array_merge($items, json_decode($item->widgets()->whereStatus(1)->orderBy('sort')->get()->keyBy('id')));
             $items += $item->widgets()->whereStatus(1)->orderBy('sort')->get()->getDictionary();
         }
         // Загрузка толкп тех виджетов которие принедлежат именно этому
         $items += $article->onlySelfWidgets()->whereStatus(1)->get()->getDictionary();
         $cache->setData(json_encode($items));
         $cache->save();
     }
     if (!empty($items)) {
         foreach ($items as $i) {
             $class = static::WIDGET_NAMESPACE . $i->type;
             $tmp = new $class();
             $tmp->init($i);
             // todo: в админке проверять чтобы Sorting биль уникалним
             $this->_items[$tmp->getPosition()][$tmp->getSorting()] = $tmp;
             $this->_widgets[$i->type] = $tmp;
         }
     }
 }
Exemple #4
0
 /**
  * Конструктор
  */
 protected function __construct()
 {
     // Кешировка данных
     $cache = new Cache();
     $cache->setLocalPath('settings');
     $cache->load();
     if ($cache->isValid()) {
         $this->_items = json_decode($cache->getData(), true);
     } else {
         $data = \SettingsModel::all();
         if (!empty($data)) {
             foreach ($data as $i) {
                 $this->_items[$i->group][$i->name] = array('id' => $i->id, 'name' => $i->name, 'value' => $i->value, 'title' => $i->title, 'desc' => $i->desc);
             }
         }
         $cache->setData(json_encode($this->_items));
         $cache->save();
     }
 }
Exemple #5
0
 public function getModelFromSlug($slug)
 {
     $cache = new Cache();
     $cache->setLocalPath($slug . '_article');
     $cache->load();
     if ($cache->isValid()) {
         $model = new ModelWrapper($cache->getData());
     } else {
         $model = ArticleModel::where('slug', '=', $slug)->with('contents')->first();
         if (empty($model)) {
             throw new HttpException(404);
         }
         $cache->setData($model);
         $cache->save();
     }
     return $model;
 }