/**
  * Returns all db-stored variations in array representation
  *
  * @param bool $force True if you want to refresh static-variable cache
  * @return array
  */
 public static function getAllVariations($force = false)
 {
     if (static::$allVariations === null || $force === true) {
         $cacheKey = 'AllThemeVariations';
         static::$allVariations = Yii::$app->cache->get($cacheKey);
         if (static::$allVariations === false) {
             static::$allVariations = ThemeVariation::find()->orderBy(['exclusive' => SORT_DESC])->asArray()->all();
             Yii::$app->cache->set($cacheKey, static::$allVariations, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ThemeVariation::className())]]));
         }
     }
     return static::$allVariations;
 }
Exemple #2
0
 /**
  * Returns all db-stored theme parts in array representation
  *
  * @param bool $force True if you want to refresh static-variable cache
  * @return array
  */
 public static function getAllParts($force = false)
 {
     if (static::$allParts === null || $force === true) {
         $cacheKey = 'AllThemeParts';
         Yii::beginProfile('Get all theme parts');
         static::$allParts = Yii::$app->cache->get($cacheKey);
         if (static::$allParts === false) {
             static::$allParts = ThemeParts::find()->where(['global_visibility' => 1])->asArray()->all();
             Yii::$app->cache->set($cacheKey, static::$allParts, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ThemeVariation::className())]]));
         }
         Yii::endProfile('Get all theme parts');
     }
     return static::$allParts;
 }
 /**
  * @return array Array of tags(strings)
  */
 public function getCacheTags()
 {
     return [ActiveRecordHelper::getCommonTag(ThemeVariation::className())];
 }
 public function actionActiveWidgets($id)
 {
     $variation = $this->loadModel(ThemeVariation::className(), $id);
     if (isset($_POST['addWidget'], $_POST['partId'])) {
         $part = ThemeParts::findById($_POST['partId']);
         if ($part === null) {
             throw new NotFoundHttpException();
         }
         $widget = ThemeWidgets::findById($_POST['addWidget']);
         if ($widget === null) {
             throw new NotFoundHttpException();
         }
         $binding = new ThemeActiveWidgets();
         $binding->part_id = $part->id;
         $binding->variation_id = $variation->id;
         $binding->widget_id = $widget->id;
         $binding->save();
     }
     $models = ThemeActiveWidgets::find()->where(['variation_id' => $variation->id])->orderBy(['part_id' => SORT_ASC, 'sort_order' => SORT_ASC])->all();
     // Warning! Element of $allParts is not a model! It's an array of db rows
     $allParts = ThemeParts::getAllParts();
     $availableWidgets = ThemeWidgets::find()->joinWith('applying')->all();
     return $this->render('active-widgets', ['variation' => $variation, 'models' => $models, 'availableWidgets' => $availableWidgets, 'allParts' => $allParts]);
 }