Exemplo n.º 1
0
 public function actionCreate($type = null, $dropDown = false)
 {
     $model = new Category();
     $model->type = $type;
     $avatar = CmgFile::loadFile($model->avatar, 'Avatar');
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'Category') && $model->validate()) {
         if (CategoryService::create($model, $avatar)) {
             return $this->redirect($this->returnUrl);
         }
     }
     return $this->render('@cmsgears/module-core/admin/views/category/create', ['model' => $model, 'avatar' => $avatar, 'dropDown' => $dropDown]);
 }
Exemplo n.º 2
0
 public function actionCreate()
 {
     $model = new Category();
     $model->setScenario("create");
     if ($model->load(Yii::$app->request->post(), "Category") && $model->validate()) {
         if (CategoryService::create($model)) {
             return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST), $model);
         }
     }
     // Generate Errors
     $errors = AjaxUtil::generateErrorMessage($model);
     // Trigger Ajax Failure
     return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
 }
Exemplo n.º 3
0
 /**
  * @return array - Category associated with parent
  */
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['id' => 'categoryId'])->viaTable(CoreTables::TABLE_MODEL_CATEGORY, ['parentId' => 'id'], function ($query) {
         $modelCategory = CoreTables::TABLE_MODEL_CATEGORY;
         $query->onCondition(["{$modelCategory}.parentType" => $this->categoryType]);
     });
 }
Exemplo n.º 4
0
 /**
  * @param string $type
  * @return Category
  */
 public static function findByType($type)
 {
     return Category::findByType($type);
 }
Exemplo n.º 5
0
 /**
  * @return Category - associated category
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'categoryId']);
 }
Exemplo n.º 6
0
 /**
  * @param integer $categoryName - category name
  * @return array - an array having value as key and name as value for given category name.
  */
 public static function getValueNameMapByCategoryName($categoryName)
 {
     $category = Category::findByName($categoryName);
     $options = $category->options;
     $optionsMap = array();
     foreach ($options as $option) {
         $optionsMap[$option->value] = $option->name;
     }
     return $optionsMap;
 }
Exemplo n.º 7
0
 /**
  * @return array - list of immediate child categories
  */
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['parentId' => 'id']);
 }