Пример #1
0
 public function getCategories(&$data = [], $parent = NULL)
 {
     $category = Category::find()->where(['parent_id' => $parent, 'type' => 'news'])->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($data, $value->id);
     }
     return $data;
 }
Пример #2
0
 public function getCategories($type, &$data = [], $parent = NULL)
 {
     $post = Post::findOne($this->id);
     $category = Category::find()->where(['parent_id' => $parent, 'type' => $type])->all();
     foreach ($category as $key => $value) {
         if (!empty($post->category_id) && in_array($value->id, explode(',', $post->category_id))) {
             $checked = 1;
         } else {
             $checked = 0;
         }
         $data[] = ['id' => $value->id, 'title' => $this->getIndent($value->indent) . $value->title, 'checked' => $checked];
         unset($category[$key]);
         $this->getCategories($type, $data, $value->id);
     }
     return $data;
 }