/** * @return TaxonomyTerm[]|array */ protected function getTerms() { if (empty($this->_terms)) { $vocabularies = TaxonomyVocabulary::getModelsArray(); if (isset($vocabularies[$this->vocabularyName])) { $this->_terms = TaxonomyTermHierarchy::getTree($vocabularies[$this->vocabularyName]->id); } } return $this->_terms; }
/** * @return static */ public function getVocabulary() { return $this->hasOne(TaxonomyVocabulary::className(), ['id' => 'vid'])->inverseOf('terms'); }
/** * Find model by ID. * * @param integer|array $id Model ID * * @return TaxonomyVocabulary * * @throws HttpException 404 error if model not found */ protected function findModel($id) { if (is_array($id)) { $model = TaxonomyVocabulary::findAll($id); } else { $model = TaxonomyVocabulary::findOne($id); } if ($model !== null) { return $model; } else { throw new HttpException(404); } }
/** * Creates vocabulary * @param $name * @return TaxonomyVocabulary * @throws \yii\base\ErrorException */ protected function createVocabularyByName($name) { return TaxonomyVocabulary::create($name); }