Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if ($this->model === null) {
         throw new InvalidConfigException("Model should be set for WarehousesRemains widget");
     }
     $state = $this->model->getWarehousesState();
     $activeWarehousesIds = Warehouse::activeWarehousesIds();
     $remains = [];
     foreach ($state as $remain) {
         $remains[$remain->warehouse_id] = $remain;
         if (($key = array_search($remain->warehouse_id, $activeWarehousesIds)) !== false) {
             unset($activeWarehousesIds[$key]);
         }
     }
     // if we have new warehouses that not represented in warehouses state
     if (count($activeWarehousesIds) > 0) {
         foreach ($activeWarehousesIds as $id) {
             // create new record with default values
             $remain = new WarehouseProduct();
             $remain->warehouse_id = $id;
             $remain->product_id = $this->model->id;
             $remain->save();
             // add to remains
             $remains[$remain->warehouse_id] = $remain;
         }
         TagDependency::invalidate(Yii::$app->cache, ActiveRecordHelper::getObjectTag($this->model->className(), $this->model->id));
     }
     return $this->render('warehouses-remains', ['model' => $this->model, 'remains' => $remains]);
 }
 /**
  * @inheritdoc
  */
 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     /*
         В parameters должен храниться last_category_id
         Если его нет - используем parameters.category_id
     */
     $category_id = null;
     if (isset($parameters['last_category_id'])) {
         $category_id = $parameters['last_category_id'];
     } elseif (isset($parameters['category_id'])) {
         $category_id = $parameters['category_id'];
     }
     $used_params[] = 'last_category_id';
     $used_params[] = 'category_id';
     if ($category_id === null) {
         return false;
     }
     $category = Category::findById($category_id);
     if (is_object($category) === true) {
         $parentIds = $category->getParentIds();
         foreach ($parentIds as $id) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
         }
         $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
         return $category->getUrlPath($this->include_root_category);
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * Actual run function for all widget classes extending BaseWidget
  *
  * @return mixed
  */
 public function widgetRun()
 {
     $pages = Page::getDb()->cache(function ($db) {
         return Page::find()->where(['parent_id' => $this->parent_id])->orderBy([$this->order_by => $this->order])->limit($this->limit)->all();
     }, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Page::className(), $this->parent_id)]]));
     return $this->render($this->view_file, ['pages' => $pages, 'parent_id' => $this->parent_id, 'more_pages_label' => $this->more_pages_label, 'display_date' => $this->display_date, 'date_format' => $this->date_format]);
 }
Ejemplo n.º 4
0
 /**
  * Returns class name and params of widget for specified wysiwyg record id
  * @param integer $id ID of Wysiwyg record
  * @return array of 'class_name' and 'params'
  */
 public static function getClassNameAndParamsById($id)
 {
     $cacheKey = 'WysiwygClassName:' . $id;
     $data = Yii::$app->cache->get($cacheKey);
     if (is_array($data) === false) {
         $data = self::getDb()->createCommand('select class_name, params from {{%wysiwyg}} where id = :id', [':id' => $id])->queryOne();
         $data['params'] = empty($data['params']) ? [] : Json::decode($data['params']);
         Yii::$app->cache->set($cacheKey, $data, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(self::className(), $id)]]));
     }
     return $data;
 }
Ejemplo n.º 5
0
 /**
  * @param integer $id
  * @return \yii\db\ActiveRecord
  */
 public static function findById($id)
 {
     $cache_key = static::className() . ':' . $id;
     $model = Yii::$app->cache->get($cache_key);
     if (is_object($model) === false) {
         $model = static::findOne($id);
         if (is_object($model)) {
             Yii::$app->cache->set(static::className() . ":" . $id, $model, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $model->id)]]));
         }
     }
     return $model;
 }
Ejemplo n.º 6
0
 /**
  * Get measure by id.
  * @param int $id
  * @return Measure
  */
 public static function findById($id)
 {
     $cacheKey = 'Measure: ' . $id;
     $measure = Yii::$app->cache->get($cacheKey);
     if ($measure === false) {
         $measure = self::findOne($id);
         if (is_null($measure)) {
             return null;
         }
         Yii::$app->cache->set($cacheKey, $measure, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(self::className()), ActiveRecordHelper::getObjectTag(self::className(), $id)]]));
     }
     return $measure;
 }
 /**
  * Returns model instance by ID using IdentityMap
  * @param integer $id
  * @return Object
  */
 public static function findById($id)
 {
     if (!isset(static::$identity_map[$id])) {
         static::$identity_map[$id] = Yii::$app->cache->get(static::tableName() . ': ' . $id);
         if (static::$identity_map[$id] === false) {
             static::$identity_map[$id] = static::findOne($id);
             if (is_object(static::$identity_map[$id])) {
                 Yii::$app->cache->set(static::tableName() . ': ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]]));
             }
         }
     }
     return static::$identity_map[$id];
 }
Ejemplo n.º 8
0
 /**
  * @return string
  */
 public function run()
 {
     parent::run();
     if (!$this->product instanceof Product) {
         return '';
     }
     $cacheKey = 'RelatedProduct:' . implode('_', [$this->viewFile, $this->product, json_encode($this->additional)]);
     if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
         return $cache;
     }
     $result = $this->render($this->viewFile, ['model' => $this->product, 'products' => $this->product->relatedProducts, 'additional' => $this->additional]);
     \Yii::$app->cache->set($cacheKey, $result, 0, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $this->product->id), ActiveRecordHelper::getCommonTag(\app\modules\shop\models\RelatedProduct::className())]]));
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Returns model using indentity map and cache
  * @param string $id
  * @return SliderHandler|null
  */
 public static function findBySliderId($id)
 {
     if (!isset(SliderHandler::$identity_map[$id])) {
         $cacheKey = SliderHandler::tableName() . ":{$id}";
         if (false === ($model = Yii::$app->cache->get($cacheKey))) {
             $model = SliderHandler::findById($id);
             if (null !== $model) {
                 Yii::$app->cache->set($cacheKey, $model, 86400, new \yii\caching\TagDependency(['tags' => [ActiveRecordHelper::getObjectTag($model, $model->id)]]));
             }
         }
         static::$identity_map[$id] = $model;
     }
     return static::$identity_map[$id];
 }
Ejemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function getNextPart($full_url, $next_part, &$previous_parts)
 {
     if (mb_strpos($next_part, $this->static_part) === 0) {
         if (count($this->parameters) === 0) {
             $this->parameters = ['static_part' => $this->static_part];
         }
         $cacheTags = [];
         if (isset($this->parameters['last_category_id']) && $this->parameters['last_category_id'] !== null) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $this->parameters['last_category_id']);
         }
         $part = new self(['gathered_part' => $this->static_part, 'rest_part' => mb_substr($next_part, mb_strlen($this->static_part)), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]);
         return $part;
     } else {
         return false;
     }
 }
Ejemplo n.º 11
0
 /**
  * @return array [[DropDownList]]
  */
 public static function getPaymentMethodArray()
 {
     $cacheKey = 'PaymentMethodItems:' . implode(':', []);
     $items = Yii::$app->cache->get($cacheKey);
     if ($items !== false) {
         return $items;
     }
     $data = self::find()->select(['payment_method_id', 'name'])->orderBy('name ASC')->asArray()->all();
     $cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
     foreach ($data as $val) {
         $key = $val['payment_method_id'];
         $items[$key] = $val['name'];
         $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
     }
     Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
     return $items;
 }
Ejemplo n.º 12
0
 /**
  * @return array [[DropDownList]]
  */
 public static function getOrderStatusArray($asHtml = false)
 {
     $cacheKey = 'OrderStatusItems:' . implode(':', [intval($asHtml)]);
     $items = Yii::$app->cache->get($cacheKey);
     if ($items !== false) {
         return $items;
     }
     $data = self::find()->select(['order_status_id', 'name', 'color'])->orderBy('name ASC')->asArray()->all();
     $cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
     foreach ($data as $val) {
         $key = $val['order_status_id'];
         $items[$key] = $asHtml ? Html::badge($val['name'], ['class' => 'btn btn-xs btn-block ' . $val['color']]) : $val['name'];
         $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
     }
     Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
     return $items;
 }
Ejemplo n.º 13
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $n = 0;
     switch ($this->action) {
         case CategoryMovementsButtons::ADD_ACTION:
             $n = $this->add();
             break;
         case CategoryMovementsButtons::MOVE_ACTION:
             $n = $this->move();
             break;
     }
     $tags = [];
     foreach ($this->items as $id) {
         $tags[] = ActiveRecordHelper::getObjectTag(Product::className(), $id);
     }
     TagDependency::invalidate(Yii::$app->cache, $tags);
     Yii::$app->session->setFlash('info', Yii::t('app', 'Items updated: {n}', ['n' => $n]));
 }
Ejemplo n.º 14
0
 /**
  * @return array [[DropDownList]]
  */
 public static function getStoreArray()
 {
     $cacheKey = 'StoreItems:' . implode(':', []);
     $items = Yii::$app->cache->get($cacheKey);
     if ($items !== false) {
         return $items;
     }
     $userModel = \Yii::createObject(['class' => Yii::$app->user->identityClass]);
     $stores_id = $userModel::find()->where(['id' => Yii::$app->user->id])->with('stores')->one();
     $data = self::find()->where(['store_id' => ArrayHelper::getColumn($stores_id->stores, 'store_id')])->orderBy('name ASC')->asArray()->all();
     $cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
     foreach ($data as $val) {
         $key = $val['store_id'];
         $items[$key] = $val['name'];
         $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
     }
     Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
     return $items;
 }
Ejemplo n.º 15
0
 /**
  * Get images by objectId and objectModelId
  * @param integer $objectId
  * @param integer $objectModelId
  * @return Image[]
  */
 public static function getForModel($objectId, $objectModelId)
 {
     if (!isset(self::$identityMap[$objectId][$objectModelId])) {
         $cacheName = 'Images:' . $objectId . ':' . $objectModelId;
         self::$identityMap[$objectId][$objectModelId] = Yii::$app->cache->get($cacheName);
         if (!is_array(self::$identityMap[$objectId][$objectModelId])) {
             if (!isset(self::$identityMap[$objectId])) {
                 self::$identityMap[$objectId] = [];
             }
             self::$identityMap[$objectId][$objectModelId] = static::find()->where(['object_id' => $objectId, 'object_model_id' => $objectModelId])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all();
             $object = Object::findById($objectId);
             if (is_null($object)) {
                 return self::$identityMap[$objectId][$objectModelId];
             }
             Yii::$app->cache->set($cacheName, self::$identityMap[$objectId][$objectModelId], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object->object_class, $objectModelId)]]));
         }
     }
     return self::$identityMap[$objectId][$objectModelId];
 }
Ejemplo n.º 16
0
 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     $used_params[] = 'categories';
     $used_params[] = 'category_group_id';
     $used_params[] = $this->model_category_attribute;
     $attribute_name = $this->model_category_attribute;
     $category_id = $this->model->{$attribute_name};
     /** @var Category $category */
     $category = Category::findById($category_id);
     if (is_object($category) === true) {
         $parentIds = $category->getParentIds();
         foreach ($parentIds as $id) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
         }
         $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
         return $category->getUrlPath($this->include_root_category);
     } else {
         return false;
     }
 }
Ejemplo n.º 17
0
 /**
  * Поиск представления по модели
  *
  * @param Object $model
  * @return string|null Возвращает имя файла или null, если ничего не найдено
  */
 public static function getViewByModel($model = null)
 {
     if (null === $model || !is_object($model)) {
         return null;
     }
     if (null === ($object = Object::getForClass($model::className()))) {
         return null;
     }
     $cacheKey = "View:Object:ModelId" . $object->id . ":" . $model->id;
     $viewObject = Yii::$app->cache->get($cacheKey);
     if ($viewObject === false) {
         $viewObject = static::find()->where(['object_id' => $object->id, 'object_model_id' => $model->id])->one();
     }
     if ($viewObject !== null) {
         Yii::$app->cache->set($cacheKey, $viewObject, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($viewObject, $viewObject->id), \devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object, $object->id), \devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($model, $model->id)]]));
         return View::getViewById($viewObject->view_id);
     } else {
         return null;
     }
 }
Ejemplo n.º 18
0
 /**
  * @return array [[DropDownList]]
  */
 public static function getAttributesArray($status = null)
 {
     $cacheKey = 'OrderAttributeItems:' . implode(':', [$status]);
     $items = Yii::$app->cache->get($cacheKey);
     if ($items !== false) {
         return $items;
     }
     $model = new Order();
     $data = self::find()->select(['attribute_name', 'assignment'])->orderBy('attribute_name ASC');
     if ($status != null) {
         $data->where('assignment = :status', [':status' => self::STATUS_USER]);
     }
     $cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
     foreach ($data->asArray()->all() as $val) {
         $key = $val['attribute_name'];
         $items[$key] = $model->getAttributeLabel($key);
         $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $key);
     }
     Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
     return $items;
 }
Ejemplo n.º 19
0
 /**
  * Returns corresponding slides with cache support(not real relation!)
  * @return Slide[]
  */
 public function getSlides($onlyActive = false)
 {
     if ($this->_slides === null) {
         $this->_slides = Yii::$app->cache->get("Slides:" . $this->id);
         if (!is_array($this->_slides)) {
             $this->_slides = Slide::find()->where(['slider_id' => $this->id])->orderBy('sort_order ASC')->all();
             Yii::$app->cache->set("Slides:" . $this->id, $this->_slides, 86400, new \yii\caching\TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Slide::className(), $this->id)]]));
         }
     }
     if ($onlyActive === true) {
         $activeSlides = [];
         foreach ($this->_slides as $slide) {
             if ($slide->active) {
                 $activeSlides[] = $slide;
             }
         }
         return $activeSlides;
     } else {
         return $this->_slides;
     }
 }
Ejemplo n.º 20
0
 /**
  * @inheritdoc
  */
 public function getNextPart($full_url, $next_part, &$previous_parts)
 {
     if (!is_object($this->object)) {
         return false;
     }
     $model_class = $this->object->object_class;
     $next_parts = explode("/", $next_part);
     $slug = $next_parts[0];
     $last_category_id = null;
     foreach ($previous_parts as $part) {
         if (isset($part->parameters['last_category_id'])) {
             $last_category_id = $part->parameters['last_category_id'];
         }
     }
     $model = $model_class::findBySlug($slug, $last_category_id);
     if ($model !== null) {
         $this->parameters['model_id'] = $model->id;
         $part = new self(['gathered_part' => $slug, 'rest_part' => mb_substr($next_part, mb_strlen($slug)), 'parameters' => $this->parameters, 'cacheTags' => [ActiveRecordHelper::getObjectTag($model_class, $this->parameters['model_id'])]]);
         return $part;
     }
     return false;
 }
Ejemplo n.º 21
0
 /**
  * @param ActiveRecord $objectModel
  * @return array|mixed|\yii\db\ActiveRecord[]
  */
 public static function getValuesByObjectModel($objectModel)
 {
     if (!is_object($objectModel) || !$objectModel instanceof ActiveRecord || is_null($objectModel->object)) {
         return [];
     }
     $cacheKey = "RatingValues:{$objectModel->object->id}:{$objectModel->id}";
     $result = Yii::$app->cache->get($cacheKey);
     if (false === $result) {
         $query = static::find();
         $query->select('rating_item_id, value')->from(static::tableName() . ' rv')->where(['rv.object_id' => $objectModel->object->id, 'rv.object_model_id' => $objectModel->id])->join('INNER JOIN', Review::tableName() . ' r', 'r.rating_id = rv.rating_id AND r.status = :status', [':status' => Review::STATUS_APPROVED]);
         $rows = $query->all();
         $result = [];
         foreach ($rows as $row) {
             if (isset($result[$row['rating_item_id']])) {
                 $result[$row['rating_item_id']][] = $row['value'];
             } else {
                 $result[$row['rating_item_id']] = [$row['value']];
             }
         }
         Yii::$app->cache->set($cacheKey, $result, 0, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(static::className(), "{$objectModel->object->id}:{$objectModel->id}")]]));
     }
     return $result;
 }
Ejemplo n.º 22
0
 /**
  * @inheritdoc
  */
 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     if (isset($parameters['properties'])) {
         $used_params[] = 'properties';
         if (isset($parameters['properties'][$this->property_id]) && is_array($parameters['properties'][$this->property_id])) {
             $psv = PropertyStaticValues::findById($parameters['properties'][$this->property_id][0]);
             if (count($this->include_if_value) > 0) {
                 if (!in_array($psv['value'], $this->include_if_value)) {
                     return false;
                 }
             }
             if (is_array($psv)) {
                 $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $psv['id']);
                 return $psv['slug'];
             } else {
                 return false;
             }
         } else {
             return $this->checkIncludeIfValue();
         }
     } else {
         return $this->checkIncludeIfValue();
     }
 }
Ejemplo n.º 23
0
 /**
  * Get children menu items with selected depth
  * @param int $parentId
  * @param null|integer $depth
  * @return array
  */
 public static function getMenuItems($parentId = 0, $depth = null, $fetchModels = false)
 {
     if ($depth === 0) {
         return [];
     }
     $cacheKey = 'CategoryMenuItems:' . implode(':', [$parentId, null === $depth ? 'null' : intval($depth), intval($fetchModels)]);
     $items = Yii::$app->cache->get($cacheKey);
     if ($items !== false) {
         return $items;
     }
     $items = [];
     $categories = static::find()->select(['id', 'name', 'category_group_id'])->where(['parent_id' => $parentId, 'active' => 1])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->with('images')->all();
     $cache_tags = [ActiveRecordHelper::getCommonTag(static::className())];
     /** @var Category $category */
     foreach ($categories as $category) {
         $items[] = ['label' => $category->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $category->category_group_id, 'last_category_id' => $category->id]), 'id' => $category->id, 'model' => $fetchModels ? $category : null, 'items' => static::getMenuItems($category->id, null === $depth ? null : $depth - 1)];
         $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $category->id);
     }
     $cache_tags[] = ActiveRecordHelper::getObjectTag(static::className(), $parentId);
     Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => $cache_tags]));
     return $items;
 }
Ejemplo n.º 24
0
 public function getCacheTags()
 {
     $tags = [ActiveRecordHelper::getObjectTag(self::className(), $this->id)];
     $category = $this->getMainCategory();
     $tags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category->id);
     $categoryParentsIds = $category->getParentIds();
     foreach ($categoryParentsIds as $id) {
         $tags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
     }
     return $tags;
 }
Ejemplo n.º 25
0
 /**
  * Product page view
  *
  * @param null $model_id
  * @return string
  * @throws NotFoundHttpException
  * @throws ServerErrorHttpException
  */
 public function actionShow($model_id = null)
 {
     if (null === ($object = Object::getForClass(Product::className()))) {
         throw new ServerErrorHttpException('Object not found.');
     }
     $cacheKey = 'Product:' . $model_id;
     if (false === ($product = Yii::$app->cache->get($cacheKey))) {
         if (null === ($product = Product::findById($model_id))) {
             throw new NotFoundHttpException();
         }
         Yii::$app->cache->set($cacheKey, $product, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $model_id)]]));
     }
     $request = Yii::$app->request;
     $values_by_property_id = $request->get('properties', []);
     if (!is_array($values_by_property_id)) {
         $values_by_property_id = [$values_by_property_id];
     }
     $selected_category_id = $request->get('last_category_id');
     $selected_category_ids = $request->get('categories', []);
     if (!is_array($selected_category_ids)) {
         $selected_category_ids = [$selected_category_ids];
     }
     $category_group_id = intval($request->get('category_group_id', 0));
     // trigger that we are to show product to user!
     // wow! such product! very events!
     $specialEvent = new ProductPageShowed(['product_id' => $product->id]);
     EventTriggeringHelper::triggerSpecialEvent($specialEvent);
     if (!empty($product->meta_description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => ContentBlockHelper::compileContentString($product->meta_description, Product::className() . ":{$product->id}:meta_description", new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className()), ActiveRecordHelper::getCommonTag(Product::className())]]))], 'meta_description');
     }
     $selected_category = $selected_category_id > 0 ? Category::findById($selected_category_id) : null;
     $this->view->title = $product->title;
     $this->view->blocks['h1'] = $product->h1;
     $this->view->blocks['announce'] = $product->announce;
     $this->view->blocks['content'] = $product->content;
     $this->view->blocks['title'] = $product->title;
     return $this->render($this->computeViewFile($product, 'show'), ['model' => $product, 'category_group_id' => $category_group_id, 'values_by_property_id' => $values_by_property_id, 'selected_category_id' => $selected_category_id, 'selected_category' => $selected_category, 'selected_category_ids' => $selected_category_ids, 'object' => $object, 'breadcrumbs' => $this->buildBreadcrumbsArray($selected_category, $product)]);
 }
Ejemplo n.º 26
0
 /**
  * Returns Events model by name using identity map by classname and cache
  * @param string $name Event name to find
  * @return Events|null
  */
 public static function findByName($name = null)
 {
     if (empty($name)) {
         return null;
     }
     foreach (static::$identity_map_by_classname as $class_name => $model) {
         if ($model->event_name === $name) {
             return $model;
         }
     }
     $cacheKey = "Event:byName:{$name}";
     $model = Yii::$app->cache->get($cacheKey);
     if ($model === false) {
         $model = self::find()->where(['event_name' => $name])->one();
         if ($model !== null) {
             Yii::$app->cache->set($cacheKey, $model, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(static::className(), $model->event_class_name)]]));
         }
     }
     static::$identity_map_by_classname[$model->event_class_name] = $model;
     return $model;
 }
Ejemplo n.º 27
0
 private function invalidateTags($className, $ids)
 {
     $tags = [ActiveRecordHelper::getCommonTag($className)];
     foreach ($ids as $id) {
         $tags[] = ActiveRecordHelper::getObjectTag($className, $id);
     }
     \yii\caching\TagDependency::invalidate(Yii::$app->cache, $tags);
 }
Ejemplo n.º 28
0
 /**
  * Returns model instance by name using IdentityMap
  * @param string $name
  * @return Extensions|null
  */
 public static function findByName($name)
 {
     if (!isset(static::$identity_map_by_package_name[$name])) {
         static::$identity_map_by_package_name[$name] = Yii::$app->cache->get(static::tableName() . ':name:' . $name);
         if (static::$identity_map_by_package_name[$name] === false) {
             static::$identity_map_by_package_name[$name] = static::find()->where(['name' => $name])->one();
             if (is_object(static::$identity_map_by_package_name[$name]) === true) {
                 $id = static::$identity_map_by_package_name[$name]->id;
                 Yii::$app->cache->set(static::tableName() . ':' . $id, static::$identity_map_by_package_name[$name], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]]));
                 Yii::$app->cache->set(static::tableName() . ':name:' . $name, static::$identity_map_by_package_name[$name], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]]));
             }
         }
         if (is_object(static::$identity_map_by_package_name[$name]) === true) {
             $id = static::$identity_map_by_package_name[$name]->id;
             static::$identity_map[$id] = static::$identity_map_by_package_name[$name];
         }
     }
     return static::$identity_map_by_package_name[$name];
 }
Ejemplo n.º 29
0
 /**
  * Returns active prefiltered page as array for specified URL (exact match).
  * Used by ObjectRule
  * @param $url
  * @return null|array
  */
 public static function getActiveByUrl($url)
 {
     $cacheKey = "12PrefilteredPage:{$url}";
     $model = Yii::$app->cache->get($cacheKey);
     if ($model === false) {
         $model = static::find()->where(['slug' => $url, 'active' => 1])->asArray()->one();
         $dependency = new TagDependency(['tags' => ActiveRecordHelper::getCommonTag(static::className())]);
         if ($model !== null) {
             $dependency = new TagDependency(['tags' => ActiveRecordHelper::getObjectTag(static::className(), $model['id'])]);
         }
         Yii::$app->cache->set($cacheKey, $model, 86400, $dependency);
     }
     return $model;
 }
Ejemplo n.º 30
0
 /**
  * @param string $class_name
  * @return null|\app\models\Object
  */
 public static function getForClass($class_name)
 {
     if (isset(static::$ids_for_class_name[$class_name])) {
         $id = static::$ids_for_class_name[$class_name];
         return Object::findById($id);
     } else {
         $object = Yii::$app->cache->get('ObjectByClassName: ' . $class_name);
         if ($object === false) {
             $object = Object::find()->where(['object_class' => $class_name])->one();
             if ($object !== null) {
                 Yii::$app->cache->set('ObjectByClassName: ' . $class_name, $object, 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag($object, $object->id)]]));
             }
         }
         if (is_object($object)) {
             static::$identity_map[$object->id] = $object;
             static::$ids_for_class_name[$class_name] = $object->id;
             return static::$identity_map[$object->id];
         }
     }
     return null;
 }