public static function createDefault(IUser $user)
 {
     $categoryItems = [['name' => 'Transport', 'type' => Category::TYPE_OUTCOME], ['name' => 'Food & Drinks', 'type' => Category::TYPE_OUTCOME], ['name' => 'Shopping', 'type' => Category::TYPE_OUTCOME], ['name' => 'Other', 'type' => Category::TYPE_OUTCOME], ['name' => 'Salary', 'type' => Category::TYPE_INCOME]];
     $categories = [];
     foreach ($categoryItems as $categoryItem) {
         $category = new Category();
         $category->name = $categoryItem['name'];
         $category->type = $categoryItem['type'];
         $category->setUser($user);
         if ($category->save()) {
             $categories[] = $category;
         }
     }
     return $categories;
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Category::className(), ['user_id' => 'id']);
 }
 public function actionIndex()
 {
     $categories = Category::find()->active()->forUsersInSameGroup($this->_user)->expand(Yii::$app->request->getQueryParams())->asArray()->all();
     return ['status' => true, 'data' => $categories];
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }