Overview

Packages

  • Hermes
  • Horde
    • Data
  • Kronolith
  • None

Classes

  • Hermes
  • Hermes_Ajax_Application
  • Hermes_Api
  • Hermes_Driver
  • Hermes_Driver_Sql
  • Hermes_Factory_Driver
  • Hermes_Form_Admin_AddJobType
  • Hermes_Form_Admin_DeleteJobType
  • Hermes_Form_Admin_EditClientStepOne
  • Hermes_Form_Admin_EditClientStepTwo
  • Hermes_Form_Admin_EditJobTypeStepOne
  • Hermes_Form_Admin_EditJobTypeStepTwo
  • Hermes_Form_Deliverable
  • Hermes_Form_Deliverable_ClientSelector
  • Hermes_Form_Export
  • Hermes_Form_JobType_Edit_Step1
  • Hermes_Form_Search
  • Hermes_Form_Time
  • Hermes_Form_Time_Entry
  • Hermes_LoginTasks_SystemTask_Upgrade
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Defines the AJAX interface for Hermes.
  4:  *
  5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Michael J Rubinsky <mrubinsk@horde.org>
 11:  * @package Hermes
 12:  */
 13: class Hermes_Ajax_Application extends Horde_Core_Ajax_Application
 14: {
 15:     /**
 16:      * Determines if notification information is sent in response.
 17:      *
 18:      * @var boolean
 19:      */
 20:     public $notify = true;
 21: 
 22:     /**
 23:      * Fetch a collection of time slices. For now, just allows a search for
 24:      * all of a single employees time. Either submitted or not submitted.
 25:      *
 26:      * @return array
 27:      */
 28:     public function getTimeSlices()
 29:     {
 30:         $params = array('employee' => $this->_vars->e,
 31:                         'submitted' => $this->_vars->s);
 32: 
 33:         try {
 34:             $slices = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($params, array(), $this->_vars->sort, $this->_vars->dir);
 35:         } catch (Hermes_Exception $e) {
 36:             $GLOBALS['notification']->push($e, 'horde.error');
 37:             return array();
 38:         }
 39:         $json = array();
 40:         foreach ($slices as $slice) {
 41:             $json[] = $slice->toJson();
 42:         }
 43: 
 44:         return $json;
 45:     }
 46: 
 47:     /**
 48:      * Enter a time slice
 49:      *
 50:      * @return @array  The new timeslice
 51:      */
 52:     public function enterTime()
 53:     {
 54:         $slice = new Hermes_Slice();
 55:         $slice->readForm();
 56:         $employee = $GLOBALS['registry']->getAuth();
 57:         try {
 58:             $id = $GLOBALS['injector']->getInstance('Hermes_Driver')->enterTime($employee, $slice);
 59:             $new = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours(array('id' => $id));
 60:             $GLOBALS['notification']->push(_("Your time was successfully entered."), 'horde.success');
 61: 
 62:             return current($new)->toJson();
 63:         } catch (Hermes_Exception $e) {
 64:             $GLOBALS['notification']->push($e, 'horde.error');
 65:         }
 66:     }
 67: 
 68:     /**
 69:      * Get a list of client deliverables.
 70:      *
 71:      * @return array
 72:      */
 73:     public function listDeliverables()
 74:     {
 75:         $client = $this->_vars->c;
 76:         return Hermes::getCostObjectType($client);
 77:         return array_values($GLOBALS['injector']
 78:             ->getInstance('Hermes_Driver')
 79:             ->listDeliverables(array('client_id' => $client)));
 80:     }
 81: 
 82:     /**
 83:      * Remove a slice
 84:      */
 85:     public function deleteSlice()
 86:     {
 87:         $sid = array('id' => $this->_vars->id, 'delete' => true);
 88:         try {
 89:             $result = $GLOBALS['injector']->getInstance('Hermes_Driver')->updateTime(array($sid));
 90:             $GLOBALS['notification']->push(_("Your time entry was successfully deleted."), 'horde.success');
 91:             return $result;
 92:         } catch (Hermes_Exception $e) {
 93:             $GLOBALS['notification']->push($e, 'horde.error');
 94:         }
 95:     }
 96: 
 97:     /**
 98:      * Update a slice
 99:      */
100:     public function updateSlice()
101:     {
102:         $slice = new Hermes_Slice();
103:         $slice->readForm();
104:         try {
105:             $GLOBALS['injector']->getInstance('Hermes_Driver')->updateTime(array($slice));
106:         } catch (Hermes_Exception $e) {
107:             $GLOBALS['notification']->push($e, 'horde.error');
108:         }
109:         $new = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours(array('id' => $slice['id']));
110:         $GLOBALS['notification']->push(_("Your time was successfully updated."), 'horde.success');
111:         return current($new)->toJson();
112:     }
113: 
114:     /**
115:      * Mark slices as submitted.
116:      *
117:      */
118:     public function submitSlices()
119:     {
120:         $time = array();
121:         $items = explode(':', $this->_vars->items);
122:         foreach ($items as $id) {
123:             $time[] = array('id' => $id);
124:         }
125:         try {
126:             $GLOBALS['injector']->getInstance('Hermes_Driver')->markAs('submitted', $time);
127:         } catch (Horde_Exception $e) {
128:             $notification->push(sprintf(_("There was an error submitting your time: %s"), $e->getMessage()), 'horde.error');
129:         }
130:         $GLOBALS['notification']->push(_("Your time was successfully submitted."), 'horde.success');
131: 
132:         return true;
133:     }
134: 
135:     /**
136:      * Add a new timer
137:      *
138:      */
139:     public function addTimer()
140:     {
141:         $id = Hermes::newTimer($this->_vars->desc);
142:         return array('id' => $id);
143:     }
144: 
145:     /**
146:      * Stop a timer
147:      */
148:     public function stopTimer()
149:     {
150:         global $prefs;
151: 
152:         if (!$timer = Hermes::getTimer($this->_vars->t)) {
153:             $GLOBALS['notification']->push(_("Invalid timer requested"), 'horde.error');
154:             return false;
155:         }
156:         $results = array();
157:         $tname = $timer['name'];
158:         $elapsed = ((!$timer['paused']) ? time() - $timer['time'] : 0 )+ $timer['elapsed'];
159: 
160:         $tformat = $prefs->getValue('twentyFour') ? 'G:i' : 'g:i a';
161:         $results['h'] = round((float)$elapsed / 3600, 2);
162:         if ($prefs->getValue('add_description')) {
163:             $results['n'] = sprintf(_("Using the \"%s\" stop watch from %s to %s"), $tname, date($tformat, $timer_id), date($tformat, time()));
164:         } else {
165:             $results['n'] = '';
166:         }
167:         $GLOBALS['notification']->push(sprintf(_("The stop watch \"%s\" has been stopped."), $tname), 'horde.success');
168:         Hermes::clearTimer($this->_vars->t);
169: 
170:         return $results;
171:     }
172: 
173:     public function pauseTimer()
174:     {
175:         global $prefs;
176: 
177:         if (!$timer = Hermes::getTimer($this->_vars->t)) {
178:             $GLOBALS['notification']->push(_("Invalid timer requested"), 'horde.error');
179:             return false;
180:         }
181: 
182:         $timer['paused'] = true;
183:         $timer['elapsed'] += time() - $timer['time'];
184:         $timer['time'] = 0;
185:         Hermes::updateTimer($this->_vars->t, $timer);
186: 
187:         return true;
188:     }
189: 
190:     public function startTimer()
191:     {
192:         global $prefs;
193: 
194:         if (!$timer = Hermes::getTimer($this->_vars->t)) {
195:             $GLOBALS['notification']->push(_("Invalid timer requested"), 'horde.error');
196:             return false;
197:         }
198:         $timer['paused'] = false;
199:         $timer['time'] = time();
200:         Hermes::updateTimer($this->_vars->t, $timer);
201: 
202:         return true;
203:     }
204: 
205:     public function listTimers($running_only = false)
206:     {
207:         $timers = $GLOBALS['prefs']->getValue('running_timers');
208:         if (!empty($timers)) {
209:             $timers = @unserialize($timers);
210:         } else {
211:             $timers = array();
212:         }
213:         $return = array();
214:         foreach ($timers as $id => &$timer) {
215:             if ($running_only && $timer['paused']) {
216:                 continue;
217:             }
218:             $elapsed = ((!$timer['paused']) ? time() - $timer['time'] : 0 )+ $timer['elapsed'];
219:             $timer['e'] = round((float)$elapsed / 3600, 2);
220:             $timer['id'] = $id;
221:             $return[] = $timer;
222:         }
223: 
224:         return $return;
225:     }
226: 
227:     public function poll()
228:     {
229:         // Return any elapsed time for timers
230:         return $this->listTimers(true);
231:     }
232: 
233: 
234: }
235: 
API documentation generated by ApiGen