コード例 #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]);
 }
コード例 #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);
 }
コード例 #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]);
     });
 }
コード例 #4
0
 /**
  * @param string $type
  * @return Category
  */
 public static function findByType($type)
 {
     return Category::findByType($type);
 }
コード例 #5
0
 /**
  * @return Category - associated category
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'categoryId']);
 }
コード例 #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;
 }
コード例 #7
0
ファイル: Category.php プロジェクト: cmsgears/module-core
 /**
  * @return array - list of immediate child categories
  */
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['parentId' => 'id']);
 }