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; }
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; }
protected function categories(&$data = [], $parent = NULL) { $category = Category::find()->where(['parent_id' => $parent, 'type' => $this->type])->orderBy(['type' => SORT_DESC])->all(); foreach ($category as $key => $value) { $data[] = $value; unset($category[$key]); $this->categories($data, $value->id); } return $data; }