コード例 #1
0
ファイル: ClientService.php プロジェクト: nyeholt/relapse
 /**
  * Save a contact against a given client object
  * 
  *
  * @param array|Contact $params 
  * @return Contact
  */
 public function saveContact($params)
 {
     $contact = null;
     try {
         $this->dbService->beginTransaction();
         // Get an existing one
         $contact = $this->dbService->saveObject($params, 'Contact');
         // check for a user object to also update
         if ($contact->id) {
             $user = $this->userService->getUserByField('contactid', $contact->id);
             if ($user) {
                 $params = array('firstname' => $contact->firstname, 'lastname' => $contact->lastname, 'email' => $contact->email);
                 $this->userService->updateUser($user, $params);
             }
         }
         $this->trackerService->track('update-contact', $contact->id, null, null, print_r($params, true));
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->dbService->rollback();
         $this->log->err("Failed creating contact for params " . print_r($params, true) . ": " . $e->getMessage());
         $contact = null;
         throw $e;
     }
     return $contact;
 }
コード例 #2
0
ファイル: ItemLinkService.php プロジェクト: nyeholt/relapse
 /**
  * Deletes an item 
  */
 public function deleteItem($item)
 {
     try {
         $this->dbService->beginTransaction();
         $this->dbService->delete('itemlink', 'toid = ' . $item->id . ' OR fromid = ' . $item->id);
         $this->dbService->commit();
     } catch (Exception $e) {
         $this->log->error("Failed deleting item " . get_class($item) . ' #' . $item->id);
         $this->dbService->rollback();
     }
 }
コード例 #3
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;
     }
 }
コード例 #4
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;
     }
 }