コード例 #1
0
ファイル: ProjectService.php プロジェクト: nyeholt/relapse
 /**
  * As above, this goes through and sets all timesheet entries 
  * that have been locked against a given timesheet to being
  * unlocked
  *
  * @param Timesheet $timesheet
  */
 public function unlockTimesheet(Timesheet $timesheet)
 {
     try {
         $this->dbService->beginTransaction();
         $this->dbService->update('timesheetrecord', array('timesheetid' => 0), 'timesheetid=' . (int) $timesheet->id);
         $timesheet->locked = 0;
         $this->saveTimesheet($timesheet);
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->dbService->rollback();
         throw $e;
     }
 }
コード例 #2
0
ファイル: ExpenseService.php プロジェクト: nyeholt/relapse
 /**
  * Marks all expenses in an expense report as paid
  */
 public function markPaidExpenses(ExpenseReport $report)
 {
     try {
         $this->dbService->beginTransaction();
         $this->dbService->update('expense', array('paiddate' => $report->paiddate), 'expensereportid=' . (int) $report->id);
         $this->dbService->update('expense', array('paiddate' => $report->paiddate), 'userreportid=' . (int) $report->id);
         // Get all the expenses affected, and notify the user involved that it's been paid
         // If a username is set on the report, it's based around user expenses,
         // so just get those
         $expenses = array();
         if (mb_strlen($report->username)) {
             $expenses = $this->getExpenses(array('userreportid=' => $report->id));
         } else {
             $expenses = $this->getExpenses(array('expensereportid=' => $report->id));
         }
         // Keep a map of user -> expenses for that user to limit the number
         // of emails to send
         $userExpenseMap = new ArrayObject();
         foreach ($expenses as $expense) {
             /* @var $expense Expense */
             $user = $this->userService->getUserByField('username', $expense->username);
             $userExpenses = ifset($userExpenseMap, $user->username, array());
             $userExpenses[] = $expense;
             $userExpenseMap[$user->username] = $userExpenses;
         }
         foreach ($userExpenseMap as $username => $expenses) {
             // create the email for this user and send it away
             $msg = new TemplatedMessage('expense-paid.php', array('expenses' => $expenses));
             $this->notificationService->notifyUser('Expenses Paid', $username, $msg);
             $this->log->debug("Sent email to {$username}");
         }
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->dbService->rollback();
         throw $e;
     }
 }