Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag(ThemeActiveWidgets::className())]);
 }
 public function actionSaveSorted()
 {
     if (Yii::$app->request->isPost === false || !isset($_POST['ids'])) {
         throw new BadRequestHttpException();
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     $ids = (array) $_POST['ids'];
     $result = ThemeActiveWidgets::sortModels($ids);
     $this->invalidateTags(ThemeActiveWidgets::className(), $ids);
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @param array $attributesRow
  * @return string[] Array of cache tags
  */
 public static function getCacheTags($attributesRow)
 {
     $tags = explode("\n", $attributesRow['cache_tags']);
     $tags[] = ActiveRecordHelper::getObjectTag(ThemeParts::className(), $attributesRow['id']);
     $tags[] = ActiveRecordHelper::getCommonTag(ThemeActiveWidgets::className());
     return $tags;
 }
Ejemplo n.º 4
0
 /**
  * Returns active widgets for current request
  * @return ThemeActiveWidgets[]
  */
 public static function getActiveWidgets()
 {
     if (static::$activeWidgets === null) {
         Yii::beginProfile('Get active widgets');
         $variationIds = ArrayHelper::getColumn(ThemeVariation::getMatchedVariations(), 'id');
         if (count($variationIds) === 0) {
             Yii::trace("Warning! No active widgets because of no matched variations! Check your variations configuration.");
             Yii::endProfile('Get active widgets');
             return [];
         }
         $cacheKey = 'ActiveWidgets:' . implode(',', $variationIds);
         static::$activeWidgets = Yii::$app->cache->get($cacheKey);
         if (static::$activeWidgets === false) {
             static::$activeWidgets = ThemeActiveWidgets::find()->where(['in', 'variation_id', $variationIds])->with('widget')->orderBy(['part_id' => SORT_ASC, 'sort_order' => SORT_ASC])->all();
             Yii::$app->cache->set($cacheKey, static::$activeWidgets, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ThemeActiveWidgets::className()), ActiveRecordHelper::getCommonTag(ThemeWidgets::className())]]));
         }
         Yii::endProfile('Get active widgets');
     }
     return static::$activeWidgets;
 }