Hermes::getCostObjectType PHP Method

getCostObjectType() public static method

Return data for costobjects, optionally filtered by client_ids.
public static getCostObjectType ( mixed $client_ids = null ) : array
$client_ids mixed A client id or an array of client ids to filter cost obejcts by.
return array An array of cost objects data.
    public static function getCostObjectType($client_ids = null)
    {
        $elts = array('' => _("--- No Cost Object ---"));
        $counter = 0;
        foreach (self::getCostObjects($client_ids) as $category) {
            Horde_Array::arraySort($category['objects'], 'name');
            $elts['category%' . $counter++] = sprintf('--- %s ---', $category['category']);
            foreach ($category['objects'] as $object) {
                $name = Horde_String::truncate($object['name'], 80);
                $hours = 0.0;
                $filter = array('costobject' => $object['id']);
                if (!empty($GLOBALS['conf']['time']['sum_billable_only'])) {
                    $filter['billable'] = true;
                }
                $result = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($filter, array('hours'));
                foreach ($result as $entry) {
                    if (!empty($entry['hours'])) {
                        $hours += $entry['hours'];
                    }
                }
                /* Show summary of hours versus estimate for this
                 * deliverable. */
                if (empty($object['estimate'])) {
                    $name .= sprintf(_(" (%0.2f hours)"), $hours);
                } else {
                    $name .= sprintf(_(" (%d%%, %0.2f of %0.2f hours)"), (int) ($hours / $object['estimate'] * 100), $hours, $object['estimate']);
                }
                $elts[$object['id']] = $name;
            }
        }
        return $elts;
    }

Usage Example

示例#1
0
 public function __construct(&$vars)
 {
     parent::__construct($vars, _("Search For Time"));
     if ($GLOBALS['registry']->isAdmin(array('permission' => 'hermes:review'))) {
         $type = Hermes::getEmployeesType();
         $this->addVariable(_("Employees"), 'employees', $type[0], false, false, null, array($type[1]));
     }
     $type = $this->getClientsType();
     $cli = $this->addVariable(_("Clients"), 'clients', $type[0], false, false, null, $type[1]);
     $cli->setAction(Horde_Form_Action::factory('submit'));
     $cli->setOption('trackchange', true);
     $type = $this->getJobTypesType();
     $this->addVariable(_("Job Types"), 'jobtypes', $type[0], false, false, null, $type[1]);
     $this->addVariable(_("Cost Objects"), 'costobjects', 'multienum', false, false, null, array(Hermes::getCostObjectType($vars->get('clients'))));
     $this->addVariable(_("Do not include entries before"), 'start', 'monthdayyear', false, false, null, array(date('Y') - 10));
     $this->addVariable(_("Do not include entries after"), 'end', 'monthdayyear', false, false, null, array(date('Y') - 10));
     $states = array('' => '', '1' => _("Yes"), '0' => _("No"));
     $this->addVariable(_("Submitted?"), 'submitted', 'enum', false, false, null, array($states));
     $this->addVariable(_("Exported?"), 'exported', 'enum', false, false, null, array($states));
     $this->addVariable(_("Billable?"), 'billable', 'enum', false, false, null, array($states));
     $this->setButtons(_("Search"));
 }
All Usage Examples Of Hermes::getCostObjectType