Hermes::makeExportHours PHP Method

makeExportHours() public static method

Rewrite an hours array into a format useable by Horde_Data::
public static makeExportHours ( array $hours ) : array
$hours array This is an array of the results from $driver->getHours().
return array an array suitable for Horde_Data::
    public static function makeExportHours($hours)
    {
        if (is_null($hours)) {
            return null;
        }
        $clients = Hermes::listClients();
        $namecache = array();
        $results = array();
        for ($i = 0; $i < count($hours); $i++) {
            $timeentry = $hours[$i]->toArray();
            $timeentry['item'] = $timeentry['_type_name'];
            if (isset($clients[$timeentry['client']])) {
                $timeentry['client'] = $clients[$timeentry['client']];
            }
            $emp =& $timeentry['employee'];
            if (isset($namecache[$emp])) {
                $emp = $namecache[$emp];
            } else {
                $ident = $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($emp);
                $fullname = $ident->getValue('fullname');
                if ($fullname) {
                    $namecache[$emp] = $emp = $fullname;
                } else {
                    $namecache[$emp] = $emp;
                }
            }
            $results[] = $timeentry;
        }
        return $results;
    }

Usage Example

Beispiel #1
0
 public function download(Horde_Variables $vars)
 {
     global $notification, $injector;
     switch ($vars->actionID) {
         case 'export':
             // 'export' used from Ajax view
             $ids = split(',', $vars->s);
             if (!is_array($ids)) {
                 $notification->push(_("No time slices were submitted"), 'horde.error');
                 return false;
             }
             try {
                 $hours = $injector->getInstance('Hermes_Driver')->getHours(array('id' => $ids));
             } catch (Hermes_Exception $e) {
                 $notification->push($e->getMessage(), 'horde.error');
                 return false;
             }
             $exportHours = Hermes::makeExportHours($hours);
             $this->_doExport($vars->f, $exportHours);
             if ($vars->m) {
                 $injector->getInstance('Hermes_Driver')->markAs('exported', $hours);
             }
             break;
         case 'search_export':
             // Called from Basic view.
             if (!($searchVars = $GLOBALS['session']->get('hermes', 'search_criteria'))) {
                 $notification->push(_("No time slices were submitted"), 'horde.error');
                 return false;
             }
             $searchForm = new Hermes_Form_Search($searchVars);
             $criteria = $searchForm->getSearchCriteria($searchVars);
             if (is_null($criteria)) {
                 $notification->push(_("No time slices were submitted"), 'horde.error');
                 return false;
             }
             $form = new Hermes_Form_Export($vars);
             $form->validate($vars);
             if (!$form->isValid()) {
                 return false;
             }
             $form->getInfo($vars, $info);
             try {
                 $hours = $injector->getInstance('Hermes_Driver')->getHours($criteria);
             } catch (Hermes_Exception $e) {
                 $notification->push($e, 'horde.error');
                 return false;
             }
             $exportHours = Hermes::makeExportHours($hours);
             $this->_doExport($info['format'], $exportHours);
             if (!empty($info['mark_exported']) && $info['mark_exported'] == 'yes' && $GLOBALS['perms']->hasPermission('hermes:review', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
                 $injector->getInstance('Hermes_Driver')->markAs('exported', $hours);
             }
     }
     $GLOBALS['notification']->push(_("Export complete."), 'horde.success');
     return true;
 }