Ejemplo n.º 1
0
 public function run()
 {
     $this->bindedAddons = ArrayHelper::map($this->bindedAddons, 'id', function (Addon $item) {
         return $item;
     }, function (Addon $item) {
         return AddonCategory::findById($item->addon_category_id)->name;
     });
     return $this->render('addons-list-widget', ['object_id' => $this->object_id, 'object_model_id' => $this->object_model_id, 'bindedAddons' => $this->bindedAddons]);
 }
Ejemplo n.º 2
0
 public function run()
 {
     $object = app\models\Object::getForClass($this->model->className());
     /** @var \app\modules\shop\models\AddonCategory $addonCategories */
     $addonCategories = app\components\Helper::getModelMap(AddonCategory::className(), 'id', 'name');
     /** @var app\modules\shop\models\Addon $bindedAddons */
     $bindedAddons = $this->model->bindedAddons;
     $addAddonModel = new AddAddonModel();
     return $this->render('addons-widget', ['object' => $object, 'addonCategories' => $addonCategories, 'bindedAddons' => $bindedAddons, 'model' => $this->model, 'form' => $this->form, 'addAddonModel' => $addAddonModel]);
 }
Ejemplo n.º 3
0
 public static function availableAddons($id)
 {
     $cacheKey = 'Addons4' . $id;
     $addons = Yii::$app->cache->get($cacheKey);
     if ($addons === false) {
         $addons = Addon::findAll(['addon_category_id' => $id]);
         Yii::$app->cache->set($cacheKey, $addons, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Addon::className()), ActiveRecordHelper::getCommonTag(AddonCategory::className())]]));
     }
     return $addons;
 }
Ejemplo n.º 4
0
 /**
  * Add or edit existing Addon model
  * @param string|int $addon_category_id
  * @param null|string $id
  * @return string|\yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionEditAddon($addon_category_id = null, $id = null)
 {
     if ($addon_category_id === null && $id === null) {
         if (isset($_POST['addon_category_id'])) {
             $addon_category_id = intval($_POST['addon_category_id']);
         }
     }
     $addonCategory = $this->loadModel(AddonCategory::className(), $addon_category_id);
     /** @var Addon $model */
     $model = $this->loadModel(Addon::className(), $id, true);
     if ($id === null) {
         $model->loadDefaultValues();
         $model->addon_category_id = $addon_category_id;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             return $this->redirectUser($model->id, true, 'view-category', 'edit-addon', ['addon_category_id' => $addon_category_id]);
         }
     }
     return $this->render('edit-addon', ['model' => $model, 'addonCategory' => $addonCategory]);
 }