Example #1
0
 /**
  * @return string[] Array of cache tags
  */
 public function getCacheTags()
 {
     $tags = explode("\n", $this->themeWidgetModel->cache_tags);
     $tags[] = ActiveRecordHelper::getObjectTag(ThemeWidgets::className(), $this->themeWidgetModel->id);
     return $tags;
 }
 public function actionRemoveApplying($id, $part_id)
 {
     $model = $this->loadModel(ThemeWidgets::className(), $id);
     /** @var ThemeParts $themePart */
     $themePart = ThemeParts::findOne($part_id);
     if ($themePart === null) {
         throw new NotFoundHttpException();
     }
     $model->unlink('applicableParts', $themePart);
     return $this->redirect(['edit-widget', 'id' => $model->id]);
 }
 /**
  * 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;
 }