public function execute($contextObject)
 {
     $result = 0;
     if (!is_null($contextObject->terms)) {
         $terms = array();
         foreach ($contextObject->terms->getItems() as $term) {
             $terms[] = $term->number;
         }
     }
     $termSectionsData = new CArrayList();
     foreach ($contextObject->terms->getItems() as $term) {
         $query = new CQuery();
         $query->select("sum(if(term.alias = 'lecture', l.value, 0)) as lecture")->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());
         $items = $query->execute();
         if ($items->getCount() > 0) {
             $termSectionsData->add($term->getId(), $items);
         }
     }
     foreach ($termSectionsData->getItems() as $termId => $termData) {
         if (CBaseManager::getWorkPlanTerm($termId)->number == $terms[0]) {
             $result = 0;
             foreach ($termData as $row) {
                 $result += $row["lecture"];
             }
         }
     }
     return $result;
 }
 public function actionDelete()
 {
     $object = CBaseManager::getWorkPlanTerm(CRequest::getInt("id"));
     $plan = $object->plan_id;
     $object->remove();
     $this->redirect("workplanterms.php?action=index&plan_id=" . $plan);
 }
 public function actionDelete()
 {
     $object = CBaseManager::getWorkPlanTerm(CRequest::getInt("id"));
     $plan = $object->plan;
     $object->remove();
     $order = 1;
     foreach ($plan->terms as $term) {
         $term->ordering = $order++;
         $term->save();
     }
     $this->redirect("workplanterms.php?action=index&plan_id=" . $plan->getId());
 }
 public function execute($contextObject)
 {
     $result = array();
     if (!is_null($contextObject->terms)) {
         $terms = array();
         foreach ($contextObject->terms->getItems() as $term) {
             $terms[] = $term->number;
         }
     }
     $termSectionsData = new CArrayList();
     foreach ($contextObject->terms->getItems() as $term) {
         $query = new CQuery();
         $select = array();
         $select[] = "section.sectionIndex";
         $select[] = "section.name";
         $select[] = "sum(if(term.alias in ('lecture', 'practice', 'labwork'), 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(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());
         $items = $query->execute();
         if ($items->getCount() > 0) {
             $termSectionsData->add($term->getId(), $items);
         }
     }
     foreach ($termSectionsData->getItems() as $termId => $termData) {
         if (CBaseManager::getWorkPlanTerm($termId)->number == $terms[1]) {
             foreach ($termData as $row) {
                 $dataRow = array();
                 $dataRow[0] = $row["sectionIndex"];
                 $dataRow[1] = $row["name"];
                 $dataRow[2] = $row["total"];
                 $dataRow[3] = $row["lecture"];
                 $dataRow[4] = $row["practice"];
                 $dataRow[5] = $row["labwork"];
                 $dataRow[6] = $row["selfedu"];
                 $result[] = $dataRow;
             }
         }
     }
     return $result;
 }
 public function actionGetObject($id)
 {
     return CBaseManager::getWorkPlanTerm($id);
 }