/** * Gets the list of the cost centres * * @return array Returns the list of the cost centres */ private function getNodesList($period, $ccId = null, $query = null) { $nodes = array(); if (!$ccId) { $criteria = null; if ($query) { $criteria = array('name' => array('$like' => array('%' . $query . '%'))); foreach (ProjectEntity::find($criteria) as $item) { /* @var $item ProjectEntity */ if (!isset($nodes[$item->ccId])) { $nodes[$item->ccId] = $this->getCostCenterData($this->getContainer()->analytics->ccs->get($item->ccId), $period); $nodes[$item->ccId]['nodes'] = array(); } $nodes[$item->ccId]['nodes'][] = $this->getProjectData($item, $period); } foreach (CostCentreEntity::find($criteria) as $item) { /* @var $item CostCentreEntity */ if (!isset($nodes[$item->ccId])) { $nodes[$item->ccId] = $this->getCostCenterData($item, $period); $nodes[$item->ccId]['nodes'] = array(); } $projectItems = ProjectEntity::findByCcId($item->ccId); foreach ($projectItems as $projectItem) { $nodes[$item->ccId]['nodes'][] = $this->getProjectData($projectItem, $period); } } } else { foreach (CostCentreEntity::all() as $item) { /* @var $item CostCentreEntity */ $nodes[$item->ccId] = $this->getCostCenterData($item, $period); } } } else { foreach ($this->getContainer()->analytics->ccs->get($ccId)->getProjects() as $item) { $nodes[$item->projectId] = $this->getProjectData($item, $period); } } return array_values($nodes); }
protected function run7($stage) { if ($this->getCountOfAccountTagValues(TagEntity::TAG_ID_COST_CENTRE) && $this->console->confirm('Would you like to remove old cost centres from account_tag_values?')) { $this->console->out("Removing old cost centres"); $this->db->Execute("DELETE FROM account_tag_values WHERE tag_id = ?", array(TagEntity::TAG_ID_COST_CENTRE)); } $this->console->out('Populating cost centres to the dictionary'); foreach (CostCentreEntity::all() as $ccEntity) { /* @var $ccEntity CostCentreEntity */ $this->db->Execute("\n INSERT IGNORE `account_tag_values` (`account_id`, `tag_id`, `value_id`, `value_name`)\n VALUES (?, ?, ?, ?)\n ", [$ccEntity->accountId ?: 0, TagEntity::TAG_ID_COST_CENTRE, $ccEntity->ccId, $ccEntity->name]); } }