Return a list of cost objects exported by available APIs, optionally
filtered by client_ids.
public static getCostObjects ( $client_ids = null, $external_only = false ) |
/** * Get the list of Hermes-only deliverables for the requested client. * - c: The client id * - id: The optional deliverable id, if requesting a specific deliverable. */ public function listDeliverables() { global $injector; if (!empty($this->vars->id)) { $params = array('id' => $this->vars->id); return array_values($injector->getInstance('Hermes_Driver')->listDeliverables($params)); } // Only poll Hermes' deliverables if we have a client id since they // are ALWAYS tied to a client. Otherwise, just return the list of // external cost objects. $client_id = !empty($this->vars->c) ? $this->vars->c : null; if (!empty($client_id)) { $objs = array_values($injector->getInstance('Hermes_Driver')->listDeliverables(array('client_id' => $client_id))); foreach ($objs as &$obj) { $obj['id'] = 'hermes:' . $obj['id']; $obj['hours'] = 0; foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $obj['id'])) as $slice) { $obj['hours'] += $slice['hours']; } } return $objs; } $elts = array(); foreach (Hermes::getCostObjects($client_id, true) as $category) { Horde_Array::arraySort($category['objects'], 'name'); foreach ($category['objects'] as $object) { $hours = 0; foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $object['id'])) as $slice) { $hours += $slice['hours']; } $elts[] = array('id' => $object['id'], 'client_id' => false, 'name' => sprintf('%s (%s)', htmlspecialchars(Horde_String::truncate($object['name'], 80)), htmlspecialchars($category['category'])), 'parent' => empty($object['parent']) ? 0 : $object['parent'], 'estimate' => empty($object['estimate']) ? 0 : $object['estimate'], 'active' => true, 'is_external' => true, 'hours' => $hours); } } return array_values($elts); }