public function actionImport() { $thisYear = new CArrayList(); // импортируем показатели должностей $index = new CRatingIndex(); $index->title = "Должность"; $index->manager_class = "CTaxonomyManager"; $index->manager_method = "getPosts()"; $index->person_method = "getPost()"; $index->year_id = CUtils::getCurrentYear()->getId(); $index->isMultivalue = 0; $index->save(); $thisYear->add($index->getId(), $index); foreach (CActiveRecordProvider::getAllFromTable("spr_dolzhnost")->getItems() as $item) { $post = CTaxonomyManager::getPostById($item->getItemValue("id")); if (!is_null($post)) { $value = new CRatingIndexValue(); $value->index_id = $index->id; $value->fromTaxonomy = 1; $value->title = $post->getId(); $value->value = $item->getItemValue("rate"); $value->save(); } } // показатели размножаем на все года foreach (CTaxonomyManager::getYearsList() as $key => $value) { $year = CTaxonomyManager::getYear($key); if ($year->getId() !== $index->year_id) { $newIndex = new CRatingIndex(); $newIndex->title = $index->title; $newIndex->manager_class = $index->manager_class; $newIndex->manager_method = $index->manager_method; $newIndex->person_method = $index->person_method; $newIndex->year_id = $year->getId(); $newIndex->isMultivalue = $index->isMultivalue; $newIndex->save(); foreach ($index->getIndexValues()->getItems() as $value) { $newValue = new CRatingIndexValue(); $newValue->index_id = $newIndex->getId(); $newValue->fromTaxonomy = $value->fromTaxonomy; $newValue->title = $value->title; $newValue->value = $value->value; $newValue->save(); } } } // звания $index = new CRatingIndex(); $index->title = "Звание"; $index->manager_class = "CTaxonomyManager"; $index->manager_method = "getTitles()"; $index->year_id = CUtils::getCurrentYear()->getId(); $index->isMultivalue = 0; $index->person_method = "getTitle()"; $index->save(); $thisYear->add($index->getId(), $index); foreach (CActiveRecordProvider::getAllFromTable("spr_zvanie")->getItems() as $item) { $post = CTaxonomyManager::getTitle($item->getItemValue("id")); if (!is_null($post)) { $value = new CRatingIndexValue(); $value->index_id = $index->id; $value->fromTaxonomy = 1; $value->title = $post->getId(); $value->value = $item->getItemValue("rate"); $value->save(); } } // показатели размножаем на все года foreach (CTaxonomyManager::getYearsList() as $key => $value) { $year = CTaxonomyManager::getYear($key); if ($year->getId() !== $index->year_id) { $newIndex = new CRatingIndex(); $newIndex->title = $index->title; $newIndex->manager_class = $index->manager_class; $newIndex->manager_method = $index->manager_method; $newIndex->year_id = $year->getId(); $newIndex->isMultivalue = $index->isMultivalue; $newIndex->person_method = $index->person_method; $newIndex->save(); foreach ($index->getIndexValues()->getItems() as $value) { $newValue = new CRatingIndexValue(); $newValue->index_id = $newIndex->getId(); $newValue->fromTaxonomy = $value->fromTaxonomy; $newValue->title = $value->title; $newValue->value = $value->value; $newValue->save(); } } } // научно-методическая работа $taxonomy = new CTaxonomy(); $taxonomy->name = "Виды научно-методической и учебной работы"; $taxonomy->alias = "scientificWork"; $taxonomy->save(); $index = new CRatingIndex(); $index->title = "Научно-методическая и учебная работа"; $index->manager_class = "CTaxonomyManager"; $index->manager_method = 'getTaxonomy("scientificWork")->getTerms()'; $index->year_id = CUtils::getCurrentYear()->getId(); $index->isMultivalue = 1; $index->save(); $thisYear->add($index->getId(), $index); foreach (CActiveRecordProvider::getAllFromTable("spr_nauch_met_uch_rab")->getItems() as $item) { $term = new CTerm(); $term->taxonomy_id = $taxonomy->getId(); $term->name = $item->getItemValue("name"); $term->save(); $value = new CRatingIndexValue(); $value->index_id = $index->id; $value->fromTaxonomy = 1; $value->title = $term->getId(); $value->value = $item->getItemValue("rate"); $value->save(); } // показатели размножаем на все года foreach (CTaxonomyManager::getYearsList() as $key => $value) { $year = CTaxonomyManager::getYear($key); if ($year->getId() !== $index->year_id) { $newIndex = new CRatingIndex(); $newIndex->title = $index->title; $newIndex->manager_class = $index->manager_class; $newIndex->manager_method = $index->manager_method; $newIndex->year_id = $year->getId(); $newIndex->isMultivalue = $index->isMultivalue; $newIndex->save(); foreach ($index->getIndexValues()->getItems() as $value) { $newValue = new CRatingIndexValue(); $newValue->index_id = $newIndex->getId(); $newValue->fromTaxonomy = $value->fromTaxonomy; $newValue->title = $value->title; $newValue->value = $value->value; $newValue->save(); } } } // вычеты $taxonomy = new CTaxonomy(); $taxonomy->name = "Виды вычетов"; $taxonomy->alias = "takeouts"; $taxonomy->save(); $index = new CRatingIndex(); $index->title = "Вычеты"; $index->manager_class = "CTaxonomyManager"; $index->manager_method = 'getTaxonomy("takeouts")->getTerms()'; $index->year_id = CUtils::getCurrentYear()->getId(); $index->isMultivalue = 1; $index->save(); $thisYear->add($index->getId(), $index); foreach (CActiveRecordProvider::getAllFromTable("spr_vichet")->getItems() as $item) { $term = new CTerm(); $term->taxonomy_id = $taxonomy->getId(); $term->name = $item->getItemValue("name"); $term->save(); $value = new CRatingIndexValue(); $value->index_id = $index->id; $value->fromTaxonomy = 1; $value->title = $term->getId(); $value->value = $item->getItemValue("rate"); $value->save(); } // показатели размножаем на все года foreach (CTaxonomyManager::getYearsList() as $key => $value) { $year = CTaxonomyManager::getYear($key); if ($year->getId() !== $index->year_id) { $newIndex = new CRatingIndex(); $newIndex->title = $index->title; $newIndex->manager_class = $index->manager_class; $newIndex->manager_method = $index->manager_method; $newIndex->year_id = $year->getId(); $newIndex->isMultivalue = $index->isMultivalue; $newIndex->save(); foreach ($index->getIndexValues()->getItems() as $value) { $newValue = new CRatingIndexValue(); $newValue->index_id = $newIndex->getId(); $newValue->fromTaxonomy = $value->fromTaxonomy; $newValue->title = $value->title; $newValue->value = $value->value; $newValue->save(); } } } }
public function actionSaveTaxonomy() { $taxonomy = new CTaxonomy(); $taxonomy->setAttributes(CRequest::getArray($taxonomy::getClassName())); $taxonomy->save(); $terms = CRequest::getArray($taxonomy::getClassName()); $terms = explode(chr(13), $terms["terms"]); foreach ($terms as $term) { $t = CFactory::createTerm(); $t->setValue(trim($term)); $t->setTaxonomy($taxonomy); $t->save(); } if ($this->continueEdit()) { $this->redirect("?action=index&id=" . $taxonomy->getId()); } else { $this->redirect("?action=index"); } }