public function actionFindAncestors($id) { $model = TermHierarchy::model()->findByAttributes(array('term_id' => $id)); $parents = array(); while (is_object($model) && $model->parent_id) { $parents[] = $model->parent_id; $model = TermHierarchy::model()->findByAttributes(array('term_id' => $model->parent_id)); } if (count($parents)) { $parents = array_reverse($parents); } $this->result = $parents; }
public function actionBulkCreate(array $names = array(), $parentId = 0, $vocabularyId = 0) { $vocabularyId = CPropertyValue::ensureInteger($vocabularyId); if (!$vocabularyId) { return errorHandler()->log('Missing Vocabulary Id'); } foreach ($names as $catName) { $catName = trim($catName); if ($catName == '') { continue; } $model = new Term('single_save'); $model->v_id = $vocabularyId; $model->name = $catName; $model->alias = Utility::createAlias($model, $model->name); $model->state = Term::STATE_ACTIVE; $model->parentId = $parentId; if (!$model->save()) { $this->result->fail(ERROR_HANDLING_DB, 'save category failed'); } else { if ($model->parentId) { $relation = TermHierarchy::model()->findByAttributes(array('term_id' => $model->id)); if (!is_object($relation)) { $relation = new TermHierarchy(); $relation->term_id = $model->id; } $relation->parent_id = $model->parentId; if (!$relation->save()) { Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR); } } } } }