protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $users = UserTable::getInstance()->findAllUnlocked();
     foreach ($users as $user) {
         if (false == TimeLogItemTable::getInstance()->updateMissedBookings(time(), $user)) {
             if ($user->Setting->reminder == true && $this->isWorkingDay(date('N'), $user)) {
                 $mailer = $this->getMailer();
                 $mailserver = sfConfig::get('app_system_email');
                 $context = sfContext::createInstance($this->configuration);
                 $this->configuration->loadHelpers('Partial');
                 $i18n = $this->getI18N($user->Setting->culture);
                 $subject = 'TimeHive - ' . $i18n->__('Missing Booking');
                 $body = get_partial('global/missingBookings', array('user' => $user, 'i18n' => $i18n));
                 $message = $mailer->compose($mailserver['from'], $user->email, $subject);
                 $message->setBody($body, 'text/html');
                 try {
                     $mailer->send($message);
                 } catch (Exception $e) {
                     $this->log($e->getMessage());
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->last_items = TimeLogItemTable::getInstance()->getLastTimeItems($this->getUser()->getId(), $request->getParameter('timeitemcount', 10));
     $this->no_bookings_pager = new sfDoctrinePager('MissingTimeItemEntry', 10);
     $this->no_bookings_pager->setQuery(MissingTimeItemEntryTable::getInstance()->getForUserQuery($this->getUser()->getId()));
     $this->no_bookings_pager->setPage($request->getParameter('missing_page', 1));
     $this->no_bookings_pager->init();
     $time_range = $request->getParameter('total_filter_by', 'this_month');
     $this->project_totals = ProjectTable::getInstance()->getTimeTotals($this->getUser()->getId(), $time_range);
 }
示例#3
0
 public function executeProjectTotal(sfWebRequest $request)
 {
     $filter = $this->checkFilter($request);
     $account_id = $this->getUser()->getAttribute('account_id');
     $this->types = TimeItemTypeTable::getInstance()->findByAccountId($account_id);
     $this->user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid'));
     $this->users = UserTable::getInstance()->findByAccountId($account_id);
     if ($this->getUser()->getAttribute('overlord', false) == true) {
         $this->projects = ProjectTable::getInstance()->findByAccountId($account_id);
     } else {
         if (array_key_exists('user', $filter)) {
             $this->user = UserTable::getInstance()->find($filter['user']);
             $this->projects = $this->user->Projects;
         } else {
             $this->projects = $this->user->Projects;
         }
     }
     $this->project_totals = TimeLogItemTable::getInstance()->prepareTotalReport($filter, $this->projects, $this->user, $account_id);
 }
示例#4
0
 public function executeUpdate($request)
 {
     $time_values = $request->getParameter('time', array());
     $user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid'));
     $this->time_values = $time_values;
     for ($i = 1; $i <= 7; $i++) {
         if (!array_key_exists($i, $time_values)) {
             continue;
         }
         $projects = $time_values[$i];
         $booking_timestamp = $request->getParameter('weekstart') + ($i - 1) * 24 * 60 * 60;
         $booking_date = date("Y-m-d", $booking_timestamp);
         if ($booking_timestamp < time()) {
             foreach ($projects as $pid => $project) {
                 $query = new Doctrine_Query();
                 $query->delete('TimeLogItem ti')->where('ti.user_id=? AND ti.project_id=? AND ti.itemdate=?', array($this->getUser()->getAttribute('uid'), $pid, $booking_date))->execute();
                 for ($time_index = 0; $time_index < count($project['time']); $time_index++) {
                     $time_value = $project['time'][$time_index];
                     $time_type = $project['type'][$time_index];
                     $time_comment = $project['comment'][$time_index];
                     if ($time_value != "" && $time_value != 0) {
                         $type_query = new Doctrine_Query();
                         $type = $type_query->from('TimeItemType tit')->where('tit.name=?', array($time_type))->fetchOne();
                         $current_value = new TimeLogItem();
                         $current_value->value = $time_value;
                         $current_value->itemdate = $booking_date;
                         $current_value->user_id = $this->getUser()->getAttribute('uid');
                         $current_value->project_id = $pid;
                         $current_value->type_id = $type->id;
                         $current_value->note = $time_comment;
                         $current_value->save();
                     }
                 }
             }
             TimeLogItemTable::getInstance()->updateMissedBookings($booking_timestamp, $user);
         }
     }
     $this->getUser()->setFlash('saved.success', 1);
     $this->redirect('timesheet/index?year=' . $request->getParameter('year', date('Y')) . '&week=' . $request->getParameter('week', date('W')));
 }