/** * Нагрузка по типу (лекция, практика, т.п.) * Параметрам * type_1 - основная * type_2 - дополнительная * type_3 - надбавка * type_4 - почасовка * filials - с учетом выезда * Семестру * 1 - осенний * 2 - весенний * Типу данных * 0 - только бюджет * 1 - только контракт * 2 - сумма бюджета и контракта * * @param $typeAlias * @param array $params * @param int $period * @param int $dataType * @return int */ private function getLoadPlanByType($typeAlias, $params = array(), $period = 1, $dataType = 2) { $result = 0; $defaulParams = array("type_1" => false, "type_2" => false, "type_3" => false, "type_4" => false, "filials" => false); $params = array_merge($defaulParams, $params); // общие условия $condition = array("kadri_id = " . $this->getLoad()->person_id, "year_id = " . $this->getLoad()->year->getId(), "part_id = " . $period); // типы нагрузки $types = array(); if ($params["type_1"]) { $types[] = "1"; } if ($params["type_2"]) { $types[] = "2"; } if ($params["type_3"]) { $types[] = "3"; } if ($params["type_4"]) { $types[] = "4"; } if (count($types) > 0) { $condition[] = "hours_kind_type in (" . implode(", ", $types) . ")"; } else { $condition[] = "hours_kind_type in (0)"; } if ($params["filials"]) { $condition[] = "on_filial in (0, 1)"; } else { $condition[] = "on_filial in (0)"; } // какие столбцы брать и считать ли сумму $query = new CQuery(); if ($dataType == 2) { $query->select("IFNULL(SUM(" . $typeAlias . "), 0) + IFNULL(SUM(" . $typeAlias . "_add), 0) as value"); } elseif ($dataType == 1) { $query->select("IFNULL(SUM(" . $typeAlias . "_add), 0) as value"); } elseif ($dataType == 0) { $query->select("IFNULL(SUM(" . $typeAlias . "), 0) as value"); } $query->from(TABLE_IND_PLAN_PLANNED); $query->condition(implode(" AND ", $condition)); $data = $query->execute()->getFirstItem(); $result = $data["value"]; return $result; }
/** * Количество записей в таблице * * @return int */ public function getItemsCount() { if ($this->_manualAdded) { return $this->getCount(); } else { $query = new CQuery(); if (mb_strpos(mb_strtolower($this->getQuery()->getFields()), "distinct") === false) { $query->select("count(" . $this->getTableAlias() . ".id) as cnt"); } else { $query->select("count(distinct " . $this->getTableAlias() . ".id) as cnt"); } $query->from($this->getQuery()->getTable())->condition($this->getQuery()->getCondition()); foreach ($this->getQuery()->getInnerJoins()->getItems() as $key => $value) { $query->innerJoin($key, $value); } foreach ($this->getQuery()->getLeftJoins() as $key => $value) { $query->leftJoin($key, $value); } $arr = $query->execute(); if ($arr->getCount() > 0) { $item = $arr->getFirstItem(); return $item["cnt"]; } else { return 0; } } }