public function actionGetViewData()
 {
     $result = array();
     $query = new CQuery();
     // комиссии по предзащите дипломов. показываем только комиссии этого года
     $query->select("comm.*")->from(TABLE_DIPLOM_PREVIEW_COMISSIONS . " as comm")->condition("comm.date_act between '" . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_start)) . "' and '" . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_end)) . "'");
     foreach ($query->execute()->getItems() as $ar) {
         $comm = new CDiplomPreviewComission(new CActiveRecord($ar));
         $value = $comm->name;
         if (!is_null($comm->secretar)) {
             $value .= " " . $comm->secretar->fio;
         }
         $result[$comm->getId()] = $value;
     }
     return $result;
 }
 public function save()
 {
     $commission = $this->commission;
     $members = array();
     if (array_key_exists("members", $commission)) {
         $members = $commission["members"];
         unset($commission["members"]);
     }
     $commObj = new CDiplomPreviewComission();
     $commObj->setAttributes($commission);
     $commObj->save();
     $this->commission = $commObj;
     foreach (CActiveRecordProvider::getWithCondition(TABLE_DIPLOM_PREVIEW_MEMBERS, "comm_id=" . $commObj->getId())->getItems() as $ar) {
         $ar->remove();
     }
     foreach ($members as $m) {
         if ($m !== 0) {
             $ar = new CActiveRecord(array("comm_id" => $commObj->getId(), "kadri_id" => $m, "id" => null));
             $ar->setTable(TABLE_DIPLOM_PREVIEW_MEMBERS);
             $ar->insert();
         }
     }
 }
 public function actionIndex()
 {
     $set = new CRecordSet(false);
     $query = new CQuery();
     $currentCommission = null;
     $currentGroup = null;
     $isArchive = CRequest::getString("isArchive") == "1";
     $query->select("preview.*")->from(TABLE_DIPLOM_PREVIEWS . " as preview")->order("preview.date_preview desc");
     $set->setQuery($query);
     $commQuery = new CQuery();
     $commQuery->select("comm.*")->from(TABLE_DIPLOM_PREVIEW_COMISSIONS . " as comm")->order("comm.name asc")->innerJoin(TABLE_DIPLOM_PREVIEWS . " as preview", "comm.id = preview.comm_id");
     if (!$isArchive) {
         $commQuery->condition('preview.date_preview between "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_start)) . '" and "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_end)) . '"');
     }
     $groupsQuery = new CQuery();
     $groupsQuery->select("stgroup.*")->from(TABLE_STUDENT_GROUPS . " as stgroup")->order("stgroup.name asc")->innerJoin(TABLE_STUDENTS . " as student", "stgroup.id = student.group_id")->innerJoin(TABLE_DIPLOM_PREVIEWS . " as preview", "student.id =  preview.student_id");
     if (!$isArchive) {
         $groupsQuery->condition('preview.date_preview between "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_start)) . '" and "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_end)) . '"');
     }
     if (CRequest::getString("order") == "student.fio") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->innerJoin(TABLE_STUDENTS . " as student", "preview.student_id=student.id");
         $query->order("student.fio " . $direction);
     } elseif (CRequest::getString("order") == "st_group.name") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->innerJoin(TABLE_STUDENTS . " as student", "preview.student_id=student.id");
         $query->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "student.group_id = st_group.id");
         $query->order("st_group.name " . $direction);
     } elseif (CRequest::getString("order") == "diplom.dipl_name") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->innerJoin(TABLE_DIPLOMS . " as diplom", "diplom.student_id = preview.student_id");
         $query->order("diplom.dipl_name " . $direction);
     } elseif (CRequest::getString("order") == "diplom_percent") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->order("diplom_percent " . $direction);
     } elseif (CRequest::getString("order") == "another_view") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->order("another_view " . $direction);
     } elseif (CRequest::getString("order") == "person.fio") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->innerJoin(TABLE_DIPLOMS . " as diplom", "diplom.student_id = preview.student_id");
         $query->leftJoin(TABLE_PERSON . " as person", "person.id = diplom.recenz_id");
         $query->order("person.fio " . $direction);
     } elseif (CRequest::getString("order") == "date_preview") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->order("date_preview " . $direction);
     } elseif (CRequest::getString("order") == "comm.name") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->innerJoin(TABLE_DIPLOM_PREVIEW_COMISSIONS . " as comm", "preview.comm_id = comm.id");
         $query->order("comm.name " . $direction);
     } elseif (CRequest::getString("order") == "comment") {
         $direction = "asc";
         if (CRequest::getString("direction") != "") {
             $direction = CRequest::getString("direction");
         }
         $query->order("comment " . $direction);
     }
     // фильтр по комисии
     if (!is_null(CRequest::getFilter("commission"))) {
         $query->innerJoin(TABLE_DIPLOM_PREVIEW_COMISSIONS . " as comm", "preview.comm_id = comm.id and comm.id = " . CRequest::getFilter("commission"));
         $currentCommission = CRequest::getFilter("commission");
         // фильтруем еще и группы
         $groupsQuery->innerJoin(TABLE_DIPLOM_PREVIEW_COMISSIONS . " as comm", "preview.comm_id = comm.id and comm.id = " . CRequest::getFilter("commission"));
     }
     // фильтр по группе
     if (!is_null(CRequest::getFilter("group"))) {
         $arr = explode(",", CRequest::getFilter("group"));
         foreach ($arr as $key => $value) {
             $arrs[] = 'st_group.id = ' . $value;
         }
         $currentGroup = CRequest::getFilter("group");
         $query->innerJoin(TABLE_STUDENTS . " as student", "preview.student_id=student.id");
         $query->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "student.group_id = st_group.id and (" . implode(" or ", $arrs) . ")");
         $commQuery->innerJoin(TABLE_STUDENTS . " as student", "preview.student_id = student.id");
         $commQuery->innerJoin(TABLE_STUDENT_GROUPS . " as st_group", "student.group_id = st_group.id and (" . implode(" or ", $arrs) . ")");
     }
     // фильтр по студенту, теме ВКР, рецензенту
     if (!is_null(CRequest::getFilter("student"))) {
         $query->innerJoin(TABLE_STUDENTS . " as student", "preview.student_id=student.id and student.id = " . CRequest::getFilter("student"));
     }
     // фильтр по комментарию
     if (!is_null(CRequest::getFilter("comment"))) {
         $query->condition("preview.id = " . CRequest::getFilter("comment"));
     }
     if (!$isArchive) {
         $query->condition('preview.date_preview between "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_start)) . '" and "' . date("Y-m-d", strtotime(CUtils::getCurrentYear()->date_end)) . '"');
     }
     if ($isArchive) {
         $requestParams = array();
         foreach (CRequest::getGlobalRequestVariables()->getItems() as $key => $value) {
             if ($key != "isArchive") {
                 $requestParams[] = $key . "=" . $value;
             }
         }
         $this->addActionsMenuItem(array(array("title" => "Текущий год", "link" => "?" . implode("&", $requestParams), "icon" => "mimetypes/x-office-calendar.png")));
     } else {
         $requestParams = array();
         foreach (CRequest::getGlobalRequestVariables()->getItems() as $key => $value) {
             $requestParams[] = $key . "=" . $value;
         }
         $requestParams[] = "isArchive=1";
         $this->addActionsMenuItem(array(array("title" => "Архив", "link" => "?" . implode("&", $requestParams), "icon" => "devices/media-floppy.png")));
     }
     $this->addActionsMenuItem(array(array("title" => "Добавить", "link" => "?action=addPreview", "icon" => "actions/list-add.png"), array("title" => "Статистика", "link" => "?action=statistic", "icon" => "mimetypes/x-office-spreadsheet.png")));
     //Предзащиты зимой
     if (CRequest::getInt("winterPreviews") == 1) {
         $query->condition('preview.date_preview between "' . (date("Y") - 1) . "-12-01" . '" and "' . date("Y") . "-02-28" . '"');
     }
     //Предзащиты летом
     if (CRequest::getInt("summerPreviews") == 1) {
         $query->condition('preview.date_preview between "' . date("Y") . "-05-01" . '" and "' . date("Y") . "-06-30" . '"');
     }
     //Прошедшие предзащиту зимой
     if (CRequest::getInt("winterCompletePreviews") == 1) {
         $query->condition('preview.date_preview between "' . (date("Y") - 1) . "-12-01" . '" and "' . date("Y") . "-02-28" . '" and (preview.diplom_percent!=0 and preview.another_view=0)');
     }
     //Прошедшие предзащиту летом
     if (CRequest::getInt("summerCompletePreviews") == 1) {
         $query->condition('preview.date_preview between "' . date("Y") . "-05-01" . '" and "' . date("Y") . "-06-30" . '" and (preview.diplom_percent!=0 and preview.another_view=0)');
     }
     //Не прошедшие предзащиту зимой
     if (CRequest::getInt("winterNotComplete") == 1) {
         $query->condition('preview.date_preview between "' . (date("Y") - 1) . "-12-01" . '" and "' . date("Y") . "-02-28" . '" and (preview.diplom_percent=0 or preview.another_view!=0)');
     }
     //Не прошедшие предзащиту летом
     if (CRequest::getInt("summerNotComplete") == 1) {
         $query->condition('preview.date_preview between "' . date("Y") . "-05-01" . '" and "' . date("Y") . "-06-30" . '" and (preview.diplom_percent=0 or preview.another_view!=0)');
     }
     $previews = new CArrayList();
     foreach ($set->getPaginated()->getItems() as $item) {
         $preview = new CDiplomPreview($item);
         $previews->add($preview->getId(), $preview);
     }
     $commissions = array();
     foreach ($commQuery->execute()->getItems() as $ar) {
         $comm = new CDiplomPreviewComission(new CActiveRecord($ar));
         $secretar = CStaffManager::getPersonById($comm->secretary_id)->fio;
         $commissions[$comm->getId()] = $comm->name . " ({$secretar})";
     }
     $studentGroups = array();
     foreach ($groupsQuery->execute()->getItems() as $ar) {
         $group = new CStudentGroup(new CActiveRecord($ar));
         $studentGroups[$group->getId()] = $group->getName();
     }
     $this->setData("isArchive", $isArchive);
     $this->setData("studentGroups", $studentGroups);
     $this->setData("commissions", $commissions);
     $this->setData("currentCommission", $currentCommission);
     $this->setData("currentGroup", $currentGroup);
     $this->setData("previews", $previews);
     $this->setData("paginator", $set->getPaginator());
     $this->renderView("_diploms/diplom_preview/index.tpl");
 }