/**
  * Пункт меню, к которому привязана задача
  *
  * @return CTerm
  */
 public function getMenu()
 {
     if (is_null($this->_menu)) {
         $this->_menu = CTaxonomyManager::getLegacyTerm($this->menu_name_id, "task_menu_names");
     }
     return $this->_menu;
 }
 private function getValues()
 {
     $values = array();
     if (array_key_exists('source', $this->params)) {
         $source = $this->params['source'];
         if (CUtils::strLeft($source, ".") == "class") {
             $class = CUtils::strRight($source, ".");
             if (array_key_exists('properties', $this->params)) {
                 $object = new $class(array("properties" => $this->params['properties']));
             } else {
                 $object = new $class();
             }
             $sourceParams = $this->params['params'];
             // для совместимости их надо положить в запрос
             foreach ($sourceParams as $key => $value) {
                 $_POST[$key] = $value;
             }
             $values = $object->actionGetViewData();
         } else {
             $taxonomy = CTaxonomyManager::getTaxonomy($this->params['source']);
             $values = $taxonomy->getTermsList();
         }
     } elseif (array_key_exists('values', $this->params)) {
         $values = $this->params['values'];
     }
     return $values;
 }
 /**
  * Специальность
  *
  * @return CTerm
  */
 public function getSpeciality()
 {
     if (is_null($this->_speciality)) {
         $this->_speciality = CTaxonomyManager::getSpeciality($this->getRecord()->getItemValue("speciality_id"));
     }
     return $this->_speciality;
 }
 /**
  * Дисциплина, к которой вопрос привязан
  *
  * @return CTerm
  */
 public function getDiscipline()
 {
     if (is_null($this->_discipline)) {
         $this->_discipline = CTaxonomyManager::getCacheDisciplines()->getItem($this->getRecord()->getItemValue("discipline_id"));
     }
     return $this->_discipline;
 }
 public function actionWizardCompleted()
 {
     $speciality = CTaxonomyManager::getCacheSpecialities()->getItem(CRequest::getInt("speciality_id"));
     $year = CTaxonomyManager::getCacheYears()->getItem(CRequest::getInt("year_id"));
     $protocol = CProtocolManager::getDepProtocol(CRequest::getInt("protocol_id"));
     $signer = CStaffManager::getPersonById(CRequest::getInt("signer_id"));
     $disciplines = new CArrayList();
     foreach (CRequest::getArray("discipline") as $i) {
         $disciplines->add($disciplines->getCount(), CDisciplinesManager::getDiscipline($i));
     }
     // бегаем по циклу столько раз, сколько нам билетов нужно
     for ($i = 1; $i <= CRequest::getInt("count"); $i++) {
         $ticket = CFactory::createSebTicket();
         $ticket->setSpeciality($speciality);
         $ticket->setYear($year);
         $ticket->setProtocol($protocol);
         $ticket->setSigner($signer);
         $ticket->setNumber($i);
         foreach ($disciplines->getItems() as $disc) {
             if ($disc->getQuestions()->getCount() == 0) {
                 break;
             }
             $question = $disc->getQuestions()->getShuffled()->getFirstItem();
             $disc->getQuestions()->removeItem($question->getId());
             $ticket->addQuestion($question);
         }
         $ticket->save();
     }
     $this->redirect("?action=index");
 }
 /**
  * Соберем все года, за которые у выбранных пользователей есть
  * индивидуальные планы
  */
 public function actionSelectYearsByPersonsPlans()
 {
     $bean = self::getStatefullBean();
     $ids = explode(":", $bean->getItem("id"));
     $bean->add("id", new CArrayList($ids));
     $persons = new CArrayList();
     foreach ($ids as $id) {
         $person = CStaffManager::getPerson($id);
         if (!is_null($person)) {
             $persons->add($person->getId(), $person);
         }
     }
     $years = new CArrayList();
     /**
      * @var $person CPerson
      */
     foreach ($persons->getItems() as $person) {
         foreach ($person->getIndPlansByYears()->getItems() as $year_id => $data) {
             $year = CTaxonomyManager::getYear($year_id);
             if (!is_null($year)) {
                 $years->add($year->getId(), $year->getValue());
             }
         }
     }
     if ($years->getCount() == 0) {
         $this->setData("message", "Год не выбран, продолжение невозможно");
         $this->renderView("_flow/dialog.ok.tpl", "", "");
         return true;
     }
     $this->setData("items", $years);
     $this->renderView("_flow/pickList.tpl", get_class($this), "SelectLoadTypesByPersonsPlans");
 }
 public function getType()
 {
     if (is_null($this->_type)) {
         $this->_type = CTaxonomyManager::getLegacyTerm($this->type_book, "izdan_type");
     }
     return $this->_type;
 }
 public function import(CFormModel $source)
 {
     $data = $source->getData();
     $markIds = array();
     $isFirstRow = true;
     foreach ($data as $row) {
         if ($isFirstRow) {
             // это первая строка - в не идентификаторы оценок
             $isFirstRow = false;
             $markIds = $row;
         } else {
             // это все остальные строки - здесь уже студенты
             $student = CStaffManager::getStudent($row[0]);
             if (!is_null($student)) {
                 $isFirstCol = true;
                 foreach ($row as $id => $cell) {
                     if (!$isFirstCol) {
                         if ($cell != "") {
                             // если не пустая, то берем дисциплину
                             $subjectId = $markIds[$id];
                             $subject = CTaxonomyManager::getDiscipline($subjectId);
                             if (!is_null($subject)) {
                                 // если дисциплина есть, то происходит маппинг оценок
                                 $marks = array("2" => "4", "3" => "3", "4" => "2", "5" => "1");
                                 // создаем запись об оценке
                                 $activity = new CStudentActivity();
                                 $activity->subject_id = $subject->getId();
                                 $activity->kadri_id = $source->person;
                                 $activity->student_id = $student->getId();
                                 $activity->date_act = date("Y-m-d", strtotime($source->created));
                                 if (mb_strlen($cell) == 2 || strlen($cell) == 2) {
                                     // это курсовой
                                     $cell = mb_substr($cell, 0, 1);
                                     $activity->study_act_id = 43;
                                     if (array_key_exists($cell, $marks)) {
                                         $activity->study_mark = $marks[$cell];
                                     }
                                 } elseif (array_key_exists($cell, $marks)) {
                                     // это экзамен
                                     $activity->study_act_id = 1;
                                     $activity->study_mark = $marks[$cell];
                                 } else {
                                     // это зачет
                                     $activity->study_act_id = 2;
                                     $activity->study_mark = 5;
                                 }
                                 $activity->save();
                             }
                         }
                     } else {
                         // пропускаем первую ячейку - в ней идентификатор студента
                         $isFirstCol = false;
                     }
                 }
             }
         }
     }
     return true;
 }
 /**
  * Все роли пользователей
  */
 public function actionGetStaffRoles()
 {
     $res = array();
     foreach (CTaxonomyManager::getCacheTypes()->getItems() as $role) {
         $res[$role->getId()] = $role->getValue();
     }
     echo json_encode($res);
 }
 public function actionGetObject($id)
 {
     $taxonomy = CTaxonomyManager::getLegacyTaxonomy($this->taxonomy);
     if (is_null($taxonomy)) {
         return null;
     }
     return $taxonomy->getTerm($id);
 }
Example #11
0
 /**
  * Объект таксономии, к которой данный термин привязан.
  * Если это самостоятельный объект словаря, то null
  *
  * @return CTaxonomy
  */
 public function getParentTaxonomy()
 {
     if (is_null($this->_taxonomy)) {
         if ($this->getRecord()->hasItem("taxonomy_id")) {
             $this->_taxonomy = CTaxonomyManager::getTaxonomy($this->getRecord()->getItemValue("taxonomy_id"));
         }
     }
     return $this->_taxonomy;
 }
 public function actionGetQuestionsJSON()
 {
     $arr = array();
     $disc = CTaxonomyManager::getCacheDisciplines()->getItem(CRequest::getInt("id"));
     foreach (CSEBQuestionsManager::getQuestionsByDiscipline($disc)->getItems() as $i) {
         $arr[] = $i->toArrayForJSON();
     }
     echo json_encode($arr);
 }
 public function actionGetObject($id)
 {
     $cache_id = $this->taxonomy . "_item_" . $id;
     if (is_null(CApp::getApp()->cache->get($cache_id))) {
         $taxonomy = CTaxonomyManager::getTaxonomy($this->taxonomy);
         $term = $taxonomy->getTerm($id);
         CApp::getApp()->cache->set($cache_id, $term, 30);
     }
     return CApp::getApp()->cache->get($cache_id);
 }
 public function getPost()
 {
     if (is_null($this->_post)) {
         $term = CTaxonomyManager::getPostById($this->getPostId());
         if (!is_null($term)) {
             $this->_post = $term;
         }
     }
     return $this->_post;
 }
 /**
  * @return CTerm|null
  */
 public function getSpeciality()
 {
     if (is_null($this->_speciality)) {
         $taxonomy = CTaxonomyManager::getLegacyTaxonomy(TAXONOMY_SPECIALITY);
         if (!is_null($taxonomy)) {
             $this->_speciality = $taxonomy->getTerm($this->alias);
         }
     }
     return $this->_speciality;
 }
 /**
  * @return CTerm
  */
 public function getLanguage()
 {
     if (is_null($this->_language)) {
         $tax = CTaxonomyManager::getLegacyTaxonomy("language");
         if (!is_null($tax)) {
             $this->_language = CTaxonomyManager::getLegacyTerm($this->language_id, $tax->getId());
         }
     }
     return $this->_language;
 }
 /**
  * @return array
  */
 private function getWorktypesAlias()
 {
     if (is_null($this->_workTypesAlias)) {
         $this->_workTypesAlias = array();
         foreach (CTaxonomyManager::getLegacyTaxonomy("spravochnik_uch_rab")->getTerms()->getItems() as $term) {
             $this->_workTypesAlias[$term->getId()] = $term->name_hours_kind;
         }
     }
     return $this->_workTypesAlias;
 }
 public function actionIndex()
 {
     $set = new CRecordSet(false);
     $query = new CQuery();
     $query->select("usatu_order.*")->from(TABLE_USATU_ORDERS . " as usatu_order")->order("usatu_order.id desc");
     $set->setQuery($query);
     /**
      * Сортировка приказов в различных направлениях
      */
     $direction = "asc";
     if (CRequest::getString("direction") != "") {
         $direction = CRequest::getString("direction");
     }
     if (CRequest::getString("order") == "date") {
         $query->order("usatu_order.date " . $direction);
     } elseif (CRequest::getString("order") == "number") {
         $query->order("usatu_order.num " . $direction);
     } elseif (CRequest::getString("order") == "type") {
         $query->leftJoin(TABLE_USATU_ORDER_TYPES . " as order_type", "order_type.id = usatu_order.orders_type");
         $query->order("order_type.name " . $direction);
     } elseif (CRequest::getString("order") == "title") {
         $query->order("usatu_order.title " . $direction);
     }
     /**
      * Фильтрация приказов
      */
     $selectedOrder = null;
     if (!is_null(CRequest::getFilter("order"))) {
         $query->condition("usatu_order.id = " . CRequest::getFilter("order"));
         $selectedOrder = CStaffManager::getUsatuOrder(CRequest::getFilter("order"));
     }
     $selectedType = null;
     if (!is_null(CRequest::getFilter("type"))) {
         $query->condition("orders_type = " . CRequest::getFilter("type"));
         $selectedType = CTaxonomyManager::getUsatuOrderType(CRequest::getFilter("type"))->getId();
     }
     /**
      * Выборка приказов
      */
     $orders = new CArrayList();
     foreach ($set->getPaginated()->getItems() as $item) {
         $order = new COrderUsatu($item);
         $orders->add($order->getId(), $order);
     }
     $this->setData("selectedOrder", $selectedOrder);
     $this->setData("selectedType", $selectedType);
     $this->setData("orders", $orders);
     $this->addJSInclude(JQUERY_UI_JS_PATH);
     $this->addCSSInclude(JQUERY_UI_CSS_PATH);
     $this->setData("paginator", $set->getPaginator());
     $this->renderView("_orders_usatu/index.tpl");
 }
 public function getYears()
 {
     $person = CStaffManager::getPerson($this->_bean->getItem("id"));
     $plans = $person->getIndPlansByYears();
     $years = array();
     foreach ($plans->getItems() as $year => $plan) {
         $year = CTaxonomyManager::getYear($year);
         if (!is_null($year)) {
             $years[$year->getId()] = $year->getValue();
         }
     }
     return $years;
 }
 public function actionIndex()
 {
     $persons = new CArrayList();
     if (CRequest::getInt("year") == 0) {
         $year = CUtils::getCurrentYear();
     } else {
         $year = CTaxonomyManager::getYear(CRequest::getInt("year"));
     }
     foreach (CStaffManager::getAllPersons()->getItems() as $person) {
         if ($person->getPublications($year)->getCount() > 0) {
             $persons->add($person->id, $person);
         }
     }
     $this->addActionsMenuItem(array(array("title" => "Назад", "link" => "index.php", "icon" => "actions/edit-undo.png")));
     $this->setData("year", $year);
     $this->setData("persons", $persons);
     $this->renderView("_rating_publications/person/index.tpl");
 }
 public function actionGetDefaultCatalogProperties()
 {
     $properties = array();
     $taxonomy = CTaxonomyManager::getLegacyTaxonomy("person_types");
     /**
      * @var $term CTerm
      */
     foreach ($taxonomy->getTerms()->getItems() as $term) {
         if ($term->getValue() == TYPE_PPS) {
             $properties[] = $term->getId();
         } elseif ($term->getValue() == "учебно-вспомогательный персонал") {
             $properties[] = $term->getId();
         } elseif ($term->getValue() == "аспирант") {
             $properties[] = $term->getId();
         }
     }
     $properties[] = "order";
     return $properties;
 }
Example #22
0
 /**
  * Форма обучения, которую студент заканчивает
  *
  * @return CTerm|mixed|null
  */
 public function getSecondaryEducationEndType()
 {
     if (is_null($this->_secondaryEducationEndType)) {
         $this->_secondaryEducationEndType = CTaxonomyManager::getEductionForm($this->education_form_end);
         if (is_null($this->_secondaryEducationEndType)) {
             $corriculum = $this->getCorriculum();
             if (!is_null($corriculum)) {
                 $this->_secondaryEducationEndType = $corriculum->educationForm;
             }
         }
     }
     return $this->_secondaryEducationEndType;
 }
 /**
  * Ищет термин в указанной таксономии. Если не находит - создает
  *
  * @param $taxonomy
  * @param $key
  * @return CTerm
  */
 private function getTerm($taxonomyName, $key)
 {
     if ($taxonomyName == "education_form") {
         $forms = new CArrayList();
         /**
          * Пересортируем формы обучения в другом порядке, чтобы ключом
          * было название
          */
         foreach (CTaxonomyManager::getCacheEducationForms()->getItems() as $form) {
             $forms->add(mb_strtolower($form->getValue()), $form);
         }
         if ($forms->hasElement(mb_strtolower($key))) {
             $term = $forms->getItem(mb_strtolower($key));
         } else {
             $term = new CTerm();
             $term->setTable(TABLE_EDUCATION_FORMS);
             $term->setValue($key);
             $term->save();
             CTaxonomyManager::getCacheEducationForms()->add($term->getId(), $term);
         }
     } elseif ($taxonomyName == "gender") {
         $genders = new CArrayList();
         foreach (CTaxonomyManager::getCacheGenders()->getItems() as $gender) {
             $genders->add(mb_strtoupper($gender->getValue()), $gender);
         }
         if ($genders->hasElement(mb_strtoupper($key))) {
             $term = $genders->getItem(mb_strtoupper($key));
         }
     } else {
         $taxonomy = CTaxonomyManager::getTaxonomy($taxonomyName);
         $term = $taxonomy->getTerm($key);
         if (is_null($term)) {
             $term = new CTerm();
             $term->taxonomy_id = $taxonomy->getId();
             $term->setValue($key);
             $term->save();
             $taxonomy->addTerm($term);
         }
     }
     return $term;
 }
Example #24
0
 public function save()
 {
     parent::save();
     if (!CTaxonomyManager::getCacheTaxonomy()->hasElement($this->getId())) {
         CTaxonomyManager::getCacheTaxonomy()->add($this->getId(), $this);
         CTaxonomyManager::getCacheTaxonomy()->add($this->getAlias(), $this);
     }
 }
 public function actionDelete()
 {
     $year = CTaxonomyManager::getTimeInterval(CRequest::getInt("id"));
     $year->remove();
     $this->redirect("index.php?action=index");
 }
 public function actionGetStatisticReport()
 {
     $commission = CSABManager::getCommission(CRequest::getInt("id"));
     $marks = array();
     $marks[0] = "";
     foreach (CTaxonomyManager::getMarksList() as $id => $mark) {
         if (in_array(mb_strtolower($mark), array("отлично", "хорошо", "удовлетворительно", "неудовлетворительно"))) {
             $marks[$id] = $mark;
         }
     }
     $marks[] = "оценка не указана";
     $report = array();
     /**
      * Добавляем оценки в список
      */
     $row = array();
     foreach ($marks as $mark) {
         $row[] = $mark;
     }
     $report["Оценка"] = $row;
     /**
      * Добавляем оценки по дням
      */
     foreach ($commission->diploms->getItems() as $diplom) {
         $row = array();
         foreach ($marks as $id => $mark) {
             $row[$id] = array("Бюджет" => 0, "Контракт" => 0, "Не указана" => 0);
         }
         $row[0] = array("Бюджет" => 0, "Контракт" => 0, "Не указана" => 0);
         if (array_key_exists(date("d.m.Y", strtotime($diplom->date_act)), $report)) {
             $row = $report[date("d.m.Y", strtotime($diplom->date_act))];
         }
         /**
          * Добавляем оценку в соответствующую колонку
          */
         if (is_null($diplom->mark)) {
             $key = array_search("оценка не указана", $marks);
         } else {
             $key = array_search($diplom->mark->getValue(), $marks);
         }
         /**
          * Статистика по форме обучения
          */
         $student = $diplom->student;
         $byForm = $row[$key];
         if (!is_null($student)) {
             if ($student->getMoneyForm() == "") {
                 $byForm["Не указана"] += 1;
             } else {
                 $byForm[$student->getMoneyForm()] += 1;
             }
         }
         $row[$key] = $byForm;
         $report[date("d.m.Y", strtotime($diplom->date_act))] = $row;
     }
     /**
      * Посчитаем по дням
      * Лучше отдельно, так нагляднее
      */
     foreach ($commission->diploms->getItems() as $diplom) {
         $byForm = $report[date("d.m.Y", strtotime($diplom->date_act))][0];
         $student = $diplom->student;
         if (!is_null($student)) {
             if ($student->getMoneyForm() == "") {
                 $byForm["Не указана"] += 1;
             } else {
                 $byForm[$student->getMoneyForm()] += 1;
             }
         }
         $report[date("d.m.Y", strtotime($diplom->date_act))][0] = $byForm;
     }
     /**
      * Посчитаем всего.
      * Тоже отдельно для наглядности
      */
     $row = array();
     foreach ($marks as $id => $mark) {
         $row[$id] = array("Бюджет" => 0, "Контракт" => 0, "Не указана" => 0);
     }
     foreach ($commission->diploms->getItems() as $diplom) {
         if (is_null($diplom->mark)) {
             $key = array_search("оценка не указана", $marks);
         } else {
             $key = array_search($diplom->mark->getValue(), $marks);
         }
         $byMark = $row[$key];
         $student = $diplom->student;
         if (!is_null($student)) {
             if ($student->getMoneyForm() == "") {
                 $byMark["Не указана"] += 1;
             } else {
                 $byMark[$student->getMoneyForm()] += 1;
             }
         }
         $row[$key] = $byMark;
         /**
          * Полнейшее всего
          */
         $byMark = $row[0];
         $student = $diplom->student;
         if (!is_null($student)) {
             if ($student->getMoneyForm() == "") {
                 $byMark["Не указана"] += 1;
             } else {
                 $byMark[$student->getMoneyForm()] += 1;
             }
         }
         $row[0] = $byMark;
     }
     $report["Всего"] = $row;
     /**
      * Слегка пересортируем элементы массива
      */
     $this->setData("report", $report);
     $this->renderView("_state_attestation/subform.report.statistic.tpl");
 }
 public function actionGetObject($id)
 {
     return CTaxonomyManager::getTerm($id);
 }
 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();
             }
         }
     }
 }
 /**
  * Список дисциплин для указанной специальности, по
  * которым есть вопросы
  *
  * @static
  * @param CTerm $speciality
  * @return CArrayList
  */
 public static function getDisciplinesBySpeciality(CTerm $speciality)
 {
     if (!self::getCacheDisciplinesBySpeciality()->hasElement($speciality->getId())) {
         $res = new CArrayList();
         $q = new CQuery();
         $q->select("distinct(discipline_id)")->from(TABLE_SEB_QUESTIONS)->condition("speciality_id=" . $speciality->getId());
         foreach ($q->execute()->getItems() as $ar) {
             $disc = CTaxonomyManager::getCacheDisciplines()->getItem($ar["discipline_id"]);
             if (!is_null($disc)) {
                 $res->add($disc->getId(), $disc);
             }
         }
         self::getCacheDisciplinesBySpeciality()->add($speciality->getId(), $res);
     }
     return self::getCacheDisciplinesBySpeciality()->getItem($speciality->getId());
 }
 public function actionIndex()
 {
     $set = new CRecordSet(false);
     $query = new CQuery();
     $query->select("activity.*")->from(TABLE_STUDENTS_ACTIVITY . " as activity");
     // сортировки по столбцам
     if (CRequest::getString("order") == "") {
         $query->order("activity.id desc");
     } elseif (CRequest::getString("order") == "date_act") {
         if (CRequest::getString("direction") == "") {
             $query->order("activity.date_act desc");
         } else {
             $query->order("activity.id " . CRequest::getString("direction"));
         }
     } elseif (CRequest::getString("order") == "subject_id") {
         $query->leftJoin(TABLE_DISCIPLINES . " as discipline", "activity.subject_id = discipline.id");
         if (CRequest::getString("direction") == "") {
             $query->order("discipline.name asc");
         } else {
             $query->order("discipline.name " . CRequest::getString("direction"));
         }
     } elseif (CRequest::getString("order") == "kadri_id") {
         $query->leftJoin(TABLE_PERSON . " as person", "activity.kadri_id = person.id");
         if (CRequest::getString("direction") == "") {
             $query->order("person.fio asc");
         } else {
             $query->order("person.fio " . CRequest::getString("direction"));
         }
     } elseif (CRequest::getString("order") == "student_id") {
         $query->leftJoin(TABLE_STUDENTS . " as student_f", "student_f.id = activity.student_id");
         if (CRequest::getString("direction") == "") {
             $query->order("student_f.fio asc");
         } else {
             $query->order("student_f.fio " . CRequest::getString("direction"));
         }
     } else {
         $query = new CQuery();
         $query->select("activity.*")->from(TABLE_STUDENTS_ACTIVITY)->order("activity.id desc");
     }
     // запросы для получения списка групп и списка преподавателей
     $personQuery = new CQuery();
     $personQuery->select("distinct(person.id) as id, person.fio as name")->from(TABLE_STUDENTS_ACTIVITY . " as activity")->innerJoin(TABLE_PERSON . " as person", "activity.kadri_id = person.id")->order("person.fio asc");
     $groupQuery = new CQuery();
     $groupQuery->select("distinct(st_group.id) as id, st_group.name as name")->from(TABLE_STUDENTS_ACTIVITY . " as activity")->innerJoin(TABLE_STUDENTS . " as student", "student.id = activity.student_id")->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "st_group.id = student.group_id")->order("st_group.name asc");
     $disciplineQuery = new CQuery();
     $disciplineQuery->select("distinct(subject.id) as id, subject.name as name")->from(TABLE_STUDENTS_ACTIVITY . " as activity")->innerJoin(TABLE_DISCIPLINES . " as subject", "activity.subject_id = subject.id")->order("subject.name asc");
     // фильтры
     $selectedPerson = null;
     $selectedGroup = null;
     $selectedDiscipline = null;
     $selectedStudent = null;
     $selectedControl = null;
     if (CRequest::getString("filter") !== "") {
         $filters = explode("_", CRequest::getString("filter"));
         foreach ($filters as $filter) {
             $f = explode(":", $filter);
             if (count($f) > 1) {
                 $key = $f[0];
                 $value = $f[1];
                 if ($key == "person") {
                     if ($value != 0) {
                         $selectedPerson = $value;
                         $query->condition("kadri_id=" . $value);
                     }
                 } elseif ($key == "group") {
                     if ($value != 0) {
                         $selectedGroup = $value;
                         $query->innerJoin(TABLE_STUDENTS . " as student", "activity.student_id = student.id");
                         $query->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "student.group_id = st_group.id AND st_group.id=" . $value);
                     }
                 } elseif ($key == "discipline") {
                     if ($value != 0) {
                         $selectedDiscipline = $value;
                         $query->innerJoin(TABLE_DISCIPLINES . " as subject", "subject.id = activity.subject_id AND subject.id=" . $value);
                     }
                 } elseif ($key == "student") {
                     if ($value != 0) {
                         $selectedStudent = CStaffManager::getStudent($value);
                         $query->innerJoin(TABLE_STUDENTS . " as student", "activity.student_id = student.id AND student.id=" . $value);
                     }
                 } elseif ($key == "control") {
                     if ($value != 0) {
                         $selectedControl = CTaxonomyManager::getControlType($value);
                         $query->innerJoin(TABLE_STUDENTS_CONTROL_TYPES . " as control", "activity.study_act_id = control.id AND control.id=" . $value);
                     }
                 }
             }
         }
         /**
          * Дополняем фильтры по преподавателям, группам и дисциплинам
          */
         if (!is_null($selectedPerson)) {
             $groupQuery->innerJoin(TABLE_PERSON . " as person", "person.id = activity.kadri_id AND person.id=" . $selectedPerson);
             $disciplineQuery->innerJoin(TABLE_PERSON . " as person", "person.id = activity.kadri_id AND person.id=" . $selectedPerson);
         }
         if (!is_null($selectedGroup)) {
             $personQuery->innerJoin(TABLE_STUDENTS . " as student", "student.id = activity.student_id");
             $personQuery->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "st_group.id = student.group_id and st_group.id=" . $selectedGroup);
             $disciplineQuery->innerJoin(TABLE_STUDENTS . " as student", "student.id = activity.student_id");
             $disciplineQuery->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "st_group.id = student.group_id and st_group.id=" . $selectedGroup);
         }
         if (!is_null($selectedDiscipline)) {
             $personQuery->innerJoin(TABLE_DISCIPLINES . " as subject", "subject.id = activity.subject_id AND subject.id=" . $selectedDiscipline);
             $groupQuery->innerJoin(TABLE_DISCIPLINES . " as subject", "subject.id = activity.subject_id AND subject.id=" . $selectedDiscipline);
         }
         if (!is_null($selectedStudent)) {
             $personQuery->innerJoin(TABLE_STUDENTS . " as student_s", "student_s.id = activity.student_id AND student_s.id=" . $selectedStudent->getId());
             $groupQuery->innerJoin(TABLE_STUDENTS . " as student_s", "student_s.id = activity.student_id AND student_s.id=" . $selectedStudent->getId());
             $disciplineQuery->innerJoin(TABLE_STUDENTS . " as student_s", "student_s.id = activity.student_id AND student_s.id=" . $selectedStudent->getId());
         }
         if (!is_null($selectedControl)) {
             $personQuery->innerJoin(TABLE_STUDENTS_CONTROL_TYPES . " as control", "activity.study_act_id = control.id AND control.id=" . $selectedControl->getId());
             $groupQuery->innerJoin(TABLE_STUDENTS_CONTROL_TYPES . " as control", "activity.study_act_id = control.id AND control.id=" . $selectedControl->getId());
             $disciplineQuery->innerJoin(TABLE_STUDENTS_CONTROL_TYPES . " as control", "activity.study_act_id = control.id AND control.id=" . $selectedControl->getId());
         }
     }
     /**
      * Ограничения по уровню доступа
      */
     if (CSession::getCurrentUser()->getLevelForCurrentTask() == ACCESS_LEVEL_READ_OWN_ONLY) {
         $query->condition("activity.kadri_id=" . CSession::getCurrentPerson()->getId());
     } elseif (CSession::getCurrentUser()->getLevelForCurrentTask() == ACCESS_LEVEL_WRITE_OWN_ONLY) {
         $query->condition("activity.kadri_id=" . CSession::getCurrentPerson()->getId());
     }
     $set->setQuery($query);
     // ищем преподавателей, у которых есть оценки в списке
     $persons = array();
     foreach ($personQuery->execute()->getItems() as $item) {
         $persons[$item["id"]] = $item["name"];
     }
     // ищем группы, из которых студенты есть в списке
     $groups = array();
     foreach ($groupQuery->execute()->getItems() as $item) {
         $groups[$item["id"]] = $item["name"];
     }
     // ищем дисциплины, по которым ставились оценки
     $disciplines = array();
     foreach ($disciplineQuery->execute()->getItems() as $item) {
         $disciplines[$item["id"]] = $item["name"];
     }
     // остальные данные
     $items = new CArrayList();
     foreach ($set->getPaginated()->getItems() as $item) {
         $a = new CStudentActivity($item);
         $items->add($a->getId(), $a);
     }
     /**
      * Формируем меню
      */
     $this->addActionsMenuItem(array(array("title" => "Добавить", "link" => "?action=add", "icon" => "actions/list-add.png"), array("title" => "Групповое добавление", "link" => "index.php?action=addGroup", "icon" => "actions/mail-reply-all.png"), array("title" => "Групповые операции", "link" => "#", "icon" => "actions/address-book-new.png", "child" => array(array("title" => "Удалить выбранные", "link" => "index.php", "action" => "removeGroup", "icon" => "actions/edit-clear.png", "form" => "#gradebookForm"))), array("title" => "Мои журналы", "link" => "index.php?action=myGradebooks", "icon" => "actions/format-justify-fill.png")));
     $this->setData("persons", $persons);
     $this->setData("selectedPerson", $selectedPerson);
     $this->setData("groups", $groups);
     $this->setData("selectedGroup", $selectedGroup);
     $this->setData("disciplines", $disciplines);
     $this->setData("selectedDiscipline", $selectedDiscipline);
     $this->setData("selectedStudent", $selectedStudent);
     $this->setData("selectedControl", $selectedControl);
     $this->setData("records", $items);
     $this->setData("paginator", $set->getPaginator());
     $this->renderView("_gradebook/index.tpl");
 }