/**
  * Метод обрабатывающий событие перед обновлением Setting-ов
  */
 public static function onSettingsUpdate()
 {
     $cache = new Cache();
     $cache->setLocalPath('settings');
     $cache->clear();
     Message::instance()->success('Setting has successfully saved');
 }
Exemple #2
0
 /**
  * Returns the translation table for a given language.
  *
  *     // Get all defined Spanish messages
  *     $messages = I18n::load('es');
  *
  * @param   string  $lang   language to load
  * @return  array
  */
 public static function load($lang)
 {
     if (isset(I18n::$_cache[$lang])) {
         return I18n::$_cache[$lang];
     }
     // Кешировка данных
     $cache = new Cache();
     $cache->setLocalPath($lang . '_I18n');
     //		$cache->load();
     if ($cache->isValid()) {
         $items = json_decode($cache->getData(), true);
     } else {
         // Возврошает масив где ключи те ж что id таблици
         $entities = EntityModel::all()->keyBy('id')->toArray();
         $translations = (new EntityTranslationModel())->whereLang_id(Lang::instance()->getLang($lang)['id'])->get()->toArray();
         // Новая таблица для трансляций
         $items = [];
         // Заливает масив где ключом становится entities.text а значением entities_translations.text
         foreach ($translations as $trans) {
             $items[$entities[$trans['entity_id']]['text']] = $trans['text'];
         }
         //todo: Cacher@ miacnel
         //			$cache->setData(json_encode($items));
         //			$cache->save();
     }
     // Cache the translation table locally
     return I18n::$_cache[$lang] = $items;
 }
 /**
  * Метод обрабатывающий событие обновления транслиаций
  */
 public static function onEntitiesUpdate()
 {
     // Очишает кеш
     $cache = new Cache();
     foreach (Lang::instance()->getLangs() as $lang) {
         $cache->setLocalPath($lang['iso'] . '_I18n');
         $cache->clear();
     }
 }
 /**
  * Метод обрабатывающий событие обновления материала
  * @param $article \ArticleModel
  */
 public static function onArticleUpdate($article)
 {
     Message::instance()->success('Article was successfully saved');
     $cache = new Cache();
     $cache->setLocalPath($article->slug . '_article');
     $cache->clear();
     //todo:: Можно было бы сразу сгенерировать ключ, если материал вместе с контентом бы шёл
     //        $cache->setData($article);
     //        $cache->save();
 }
 /**
  * Метод обрабатывающий событие обновления материала
  */
 public static function onLanguageUpdate()
 {
     Message::instance()->success('Language was successfully saved');
     // Очишает кеш
     $cache = new Cache();
     $cache->setLocalPath('languages');
     $cache->clear();
     // Добовляет нрвий кеш
     $items = LangModel::where('status', '=', '1')->get();
     $cache->setData($items);
     $cache->save();
 }
 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 #7
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 #9
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 #10
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;
 }