Ejemplo n.º 1
0
 /**
  * Initializes widget with configuration stored in corresponding ThemeWidgets record.
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (isset($this->themeWidgetModel) === false && isset($this->themeWidgetModelId) === false) {
         throw new InvalidConfigException("Either themeWidgetModel or themeWidgetModelId must be set.");
     }
     if (isset($this->themeWidgetModelId) === true) {
         $this->themeWidgetModel = ThemeWidgets::findById($this->themeWidgetModelId);
         if ($this->themeWidgetModel === null) {
             throw new InvalidConfigException("Supplied themeWidgetModelId not found.");
         }
     }
     $configuration = Json::decode($this->themeWidgetModel->configuration_json, true);
     if (count($configuration) > 0) {
         Yii::configure($this, $configuration);
     }
     $this->fragmentCacheId = 'BaseWidgetCache:' . $this->themeWidgetModel->id . ':' . $this->partRow['id'];
 }
 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]);
 }