Ejemplo n.º 1
0
 public function getCategories(&$data = [], $parent = NULL)
 {
     $category = Category::find()->where(['parent_id' => $parent, 'type' => 'forum'])->all();
     foreach ($category as $key => $value) {
         $data[] = ['id' => $value->id, 'slug' => $value->slug, 'title' => $this->getIndent($value->indent) . $value->title];
         unset($category[$key]);
         $this->getCategories($data, $value->id);
     }
     return $data;
 }
Ejemplo n.º 2
0
 public function getCategories($type = NULL, &$data = [], $parent = NULL)
 {
     $category = Category::find()->where(['parent_id' => $parent, 'type' => $type])->andWhere(['NOT IN', 'id', !$this->isNewRecord ? $this->id : 0])->all();
     foreach ($category as $key => $value) {
         $data[$value->id] = $this->getIndent($value->indent) . $value->title;
         unset($category[$key]);
         $this->getCategories($type, $data, $value->id);
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function getCategory()
 {
     $post = Post::findOne($this->id);
     foreach (explode(',', $post->category_id) as $value) {
         $category = Category::findOne($value);
         if (!empty($category)) {
             $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)];
         }
     }
     return $data;
 }
Ejemplo n.º 4
0
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }