/** * Получить публикации выбранного сотрудника с учётом года * @param CPerson $key * @param CTerm $int * @return CArrayList */ public static function getPublicationsByPersonByYear(CPerson $key, CTerm $int) { $publications = new CArrayList(); foreach (CStaffManager::getPublicationsByPerson($key)->getItems() as $person) { foreach (CStaffManager::getPublicationsByYear($int)->getItems() as $year) { $persons = $person->id; $years = $year->id; if ($persons == $years) { $item = CActiveRecordProvider::getById(TABLE_PUBLICATIONS, $person->id); $publication = new CPublication($item); $publications->add($publication->getId(), $publication); self::getCachePublications()->add($publication->getId(), $publication); } } } return $publications; }
public function actionGetDataForChart() { $data = array(); if (array_key_exists("data", $_POST)) { $data = $_POST["data"]; } // определяем, в каких годах искать $years = new CArrayList(); if (array_key_exists("years", $data)) { foreach ($data['years'] as $item) { $year = CTaxonomyManager::getYear($item); if (!is_null($year)) { $years->add($year->getId(), $year); } } } else { $years->add(CUtils::getCurrentYear()->getId(), CUtils::getCurrentYear()); } // по каким показателям показывать $indexes = new CArrayList(); if (array_key_exists("indexes", $data)) { foreach ($data["indexes"] as $item) { foreach (CStaffManager::getPublicationsByType($item)->getItems() as $index) { foreach ($years->getItems() as $year) { if ($index->year == date("Y", strtotime($year->date_start)) or $index->year == date("Y", strtotime($year->date_end))) { $indexes->add($index->getId(), $index); } } } } } else { foreach ($years->getItems() as $year) { foreach (CStaffManager::getPublicationsByYear($year)->getItems() as $index) { $indexes->add($index->getId(), $index); } } } // по каким людям показывать $persons = new CArrayList(); if (array_key_exists("persons", $data)) { foreach ($data["persons"] as $item) { $person = CStaffManager::getPerson($item); if (!is_null($person)) { $persons->add($person->getId(), $person); } } } else { // показывать по всем, у кого показатели есть в указанных годах foreach (CStaffManager::getAllPersons()->getItems() as $person) { foreach ($years->getItems() as $year) { foreach ($person->getPublications($year)->getItems() as $index) { if ($indexes->hasElement($index->getId())) { $persons->add($person->getId(), $person); } } } } } $res = array(); // начинаем собирать инфу по людям // подписи к осям $axis = array(); $i = 0; foreach ($persons->getItems() as $person) { $i++; $axis[] = $person->getName(); //$axis[] = $i; } // все показатели, которые есть у выбранных людей (id всех показателей) // за все годы $resIndexes = array(); foreach ($persons->getItems() as $person) { foreach ($years->getItems() as $year) { foreach ($person->getPublications($year)->getItems() as $index) { if ($indexes->hasElement($index->getId())) { if (!is_null($index->type)) { $resIndexes[$index->type->getValue()] = $index->type->getValue(); } } } } } $indicators = array(); // данные по годам // данные должны возвращаться в том же порядке, в котором у нас идут люди foreach ($resIndexes as $key => $value) { foreach ($years->getItems() as $year) { $data = array(); // собираем данные по каждому человеку foreach ($persons->getItems() as $person) { $indexValue = 0; foreach ($person->getPublications($year)->getItems() as $index) { if (!is_null($index->type)) { if ($index->type->getValue() == $key) { $indexValue = $index->type->weight; } } } $data[] = (double) $indexValue; } $indicator = array("name" => $value . " (" . $year->name . ")", "data" => $data, "stack" => $year->name); $indicators[] = $indicator; } } $res["axis"] = $axis; $res["series"] = $indicators; echo json_encode($res); }