/**
  * Копирование показателей из одного года в другой
  *
  * @return bool
  */
 public function actionCopyIndexes()
 {
     $indexes = $_GET['indexes'];
     $year = $_GET['year'];
     $year = CTaxonomyManager::getYear($year);
     if (is_null($year)) {
         return false;
     }
     foreach ($indexes as $index) {
         $index = CRatingManager::getRatingIndex($index);
         if (!is_null($index)) {
             if ($index->year->getId() !== $year->getId()) {
                 $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->person_method = $index->person_method;
                 $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->evaluate_method = $value->evaluate_method;
                     $newValue->evaluate_code = $value->evaluate_code;
                     $newValue->save();
                 }
             }
         }
     }
 }
 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();
             }
         }
     }
 }