public function actionIndex()
 {
     $set = new CRecordSet();
     $query = new CQuery();
     $set->setQuery($query);
     $query->select("t.*")->from(TABLE_EXAMINATION_QUESTIONS . " as t")->order("t.id asc")->condition("plan_id=" . CRequest::getInt("plan_id") . " AND type=" . CRequest::getInt("type"));
     $objects = new CArrayList();
     foreach ($set->getItems() as $ar) {
         $object = new CExamQuestion($ar);
         $objects->add($object->getId(), $object);
     }
     $this->setData("objects", $objects);
     $this->setData("paginator", $set->getPaginator());
     /**
      * Генерация меню 
      */
     $this->addActionsMenuItem(array("title" => "Добавить", "link" => "workplanexamquestions.php?action=add&id=" . CRequest::getInt("plan_id") . "&type=" . CRequest::getInt("type"), "icon" => "actions/list-add.png"));
     $this->addActionsMenuItem(array("title" => "Групповое добавление", "link" => "workplanexamquestions.php?action=addGroup&id=" . CRequest::getInt("plan_id") . "&type=" . CRequest::getInt("type"), "icon" => "actions/list-add.png"));
     /**
      * Отображение представления
      */
     $this->renderView("_corriculum/_workplan/examQuestions/index.tpl");
 }
 /**
  * Структура дисциплины.
  * Здесь идут жестокие sql-запросы, но так оно
  * работает намного быстрее
  */
 public function actionStructure()
 {
     $plan = CWorkPlanManager::getWorkplan(CRequest::getInt("plan_id"));
     $this->addActionsMenuItem(array("title" => "Обновить", "link" => "workplancontent.php?action=structure&plan_id=" . CRequest::getInt("plan_id"), "icon" => "actions/view-refresh.png"));
     $terms = array();
     $terms[] = "term.name";
     $termIds = array();
     foreach ($plan->terms->getItems() as $term) {
         $termIds[] = $term->getId();
         $terms[] = "sum(if(l.term_id = " . $term->getId() . ", l.value, 0)) as t_" . $term->getId();
     }
     if (count($termIds) > 0) {
         $terms[] = "sum(if(l.term_id in (" . join(", ", $termIds) . "), l.value, 0)) as t_sum";
     }
     /**
      * Определим нагрузку по каждому виду в каждом семестре
      */
     $query = new CQuery();
     $query->select(join(", ", $terms))->from(TABLE_WORK_PLAN_CONTENT_LOADS . " as l")->innerJoin(TABLE_TAXONOMY_TERMS . " as term", "term.id = l.load_type_id")->innerJoin(TABLE_WORK_PLAN_CONTENT_SECTIONS . " as section", "l.section_id = section.id")->innerJoin(TABLE_WORK_PLAN_CONTENT_CATEGORIES . " as category", "section.category_id = category.id")->condition("category.plan_id = " . $plan->getId())->group("l.load_type_id")->order("l.ordering asc");
     $objects = $query->execute();
     $this->setData("objects", $objects);
     $this->setData("terms", $plan->terms);
     /**
      * Теперь определим разделы дисциплины и нагрузку по
      * ним в каждом семестре.
      */
     $termSectionsData = new CArrayList();
     foreach ($plan->terms->getItems() as $term) {
         $query = new CQuery();
         $select = array();
         $select[] = "section.sectionIndex";
         $select[] = "section.name";
         $select[] = "sum(if(term.alias in ('lecture', 'practice', 'labwork', 'ksr'), l.value, 0)) + sum(ifnull(selfedu.question_hours, 0)) as total";
         $select[] = "sum(if(term.alias = 'lecture', l.value, 0)) as lecture";
         $select[] = "sum(if(term.alias = 'practice', l.value, 0)) as practice";
         $select[] = "sum(if(term.alias = 'labwork', l.value, 0)) as labwork";
         $select[] = "sum(if(term.alias = 'ksr', l.value, 0)) as ksr";
         $select[] = "sum(ifnull(selfedu.question_hours, 0)) as selfedu";
         $query->select(join(", ", $select))->from(TABLE_WORK_PLAN_CONTENT_SECTIONS . " as section")->innerJoin(TABLE_WORK_PLAN_CONTENT_LOADS . " as l", "l.section_id = section.id")->innerJoin(TABLE_TAXONOMY_TERMS . " as term", "term.id = l.load_type_id")->leftJoin(TABLE_WORK_PLAN_SELFEDUCATION . " as selfedu", "selfedu.load_id = l.id")->group("l.section_id")->condition("l.term_id = " . $term->getId())->order("section.sectionIndex");
         $items = $query->execute();
         if ($items->getCount() > 0) {
             $termSectionsData->add($term->getId(), $items);
         }
     }
     $this->setData("termSectionsData", $termSectionsData);
     /**
      * Виды контроля
      */
     $set = new CRecordSet();
     $queryControlTypes = new CQuery();
     $set->setQuery($queryControlTypes);
     $queryControlTypes->select("l.*")->from(TABLE_WORK_PLAN_TYPES_CONTROL . " as l")->innerJoin(TABLE_TAXONOMY_TERMS . " as term", "term.id = l.control_id")->innerJoin(TABLE_WORK_PLAN_CONTENT_SECTIONS . " as section", "l.section_id = section.id")->innerJoin(TABLE_WORK_PLAN_CONTENT_CATEGORIES . " as category", "section.category_id = category.id")->condition("category.plan_id = " . $plan->getId())->order("section.sectionIndex asc");
     $controlTypes = new CArrayList();
     foreach ($set->getItems() as $ar) {
         $controlType = new CWorkPlanControlTypes($ar);
         $controlTypes->add($controlType->getId(), $controlType);
     }
     $this->setData("controlTypes", $controlTypes);
     /**
      * Описание и количество баллов по видам учебной деятельности
      */
     $setMarks = new CRecordSet();
     $queryMarks = new CQuery();
     $setMarks->setQuery($queryMarks);
     $queryMarks->select("control.*")->from(TABLE_WORK_PLAN_TYPES_CONTROL . " as control")->innerJoin(TABLE_WORK_PLAN_MARKS_STUDY_ACTIVITY . " as activity", "activity.activity_id = control.id")->innerJoin(TABLE_TAXONOMY_TERMS . " as term", "term.id = control.type_study_activity_id")->innerJoin(TABLE_WORK_PLAN_CONTENT_SECTIONS . " as section", "control.section_id = section.id")->innerJoin(TABLE_WORK_PLAN_CONTENT_CATEGORIES . " as category", "section.category_id = category.id")->condition("category.plan_id = " . $plan->getId())->order("activity.ordering asc");
     $marks = new CArrayList();
     foreach ($setMarks->getItems() as $ar) {
         $mark = new CWorkPlanControlTypes($ar);
         $marks->add($mark->getId(), $mark);
     }
     $this->setData("marks", $marks);
     $this->renderView("_corriculum/_workplan/content/structure.tpl");
 }