コード例 #1
0
ファイル: ExpenseController.php プロジェクト: nyeholt/relapse
 public function editAction($model = null)
 {
     if ($this->_getParam('clientid')) {
         $this->view->client = $this->clientService->getClient($this->_getParam('clientid'));
     } else {
         $ownerId = za()->getConfig('owning_company');
         $this->view->client = $this->clientService->getClient($ownerId);
     }
     $this->view->locations = $this->expenseService->getExpenseLocations();
     $this->view->users = $this->userService->getUserList();
     $this->view->defaultProjectid = za()->getConfig('default_expense_project');
     $this->view->clients = $this->clientService->getClients();
     $this->view->projects = new ArrayObject();
     // Figure out the stuff for displaying the files
     if ($model == null) {
         if ((int) $this->_getParam('id')) {
             $this->view->model = $this->byId();
             //  $this->dbService->getById((int)$this->_getParam('id'), $modelType);
             $this->view->client = $this->clientService->getClient($this->view->model->clientid);
         } else {
             $this->view->model = new Expense();
         }
         $this->view->files = array();
     } else {
         $this->view->model = $model;
         $this->view->client = $this->clientService->getClient($this->view->model->clientid);
     }
     if ($this->view->client) {
         $this->view->projects = $this->projectService->getProjectsForClient($this->view->client);
         // get the support project at the very least
         if (!$this->view->defaultProjectid) {
             $project = $this->clientService->getClientSupportProject($this->view->client);
             $this->view->defaultProjectid = $project->id;
         }
     }
     $this->view->categories = $this->view->model->constraints['atocategory']->getValues();
     $this->view->expenseTypes = $this->view->model->constraints['expensetype']->getValues();
     $this->view->expenseCategories = $this->view->model->constraints['expensecategory']->getValues();
     if ($this->view->model->id) {
         $this->view->files = $this->expenseService->getExpenseFiles($this->view->model);
         $path = 'Expenses/' . $this->view->model->id;
         $this->view->filePath = $path;
     }
     $this->renderView('expense/edit.php');
 }
コード例 #2
0
ファイル: IssueService.php プロジェクト: nyeholt/relapse
 /**
  * Saves an issue to the database
  *
  * @param array|Issue $params
  */
 public function saveIssue($params, $doNotify = true)
 {
     $issue = null;
     $sendNotification = false;
     if (is_array($params)) {
         $existingId = ifset($params, 'id');
     } else {
         $existingId = $params->id;
     }
     if (!$existingId) {
         $sendNotification = true;
     }
     $oldIssue = null;
     // If there's an existing one, save it in the history
     if ($existingId) {
         $oldIssue = $this->getIssue($existingId);
         $this->versioningService->createVersion($oldIssue);
     }
     // If saving a new one, we want to
     $issue = $this->dbService->saveObject($params, 'Issue');
     // Okay, now check if it's on a project or not
     $project = null;
     if (!$issue->projectid) {
         // Get the project
         $client = $this->clientService->getClient($issue->clientid);
         if (!$client) {
             throw new Exception("No client exists with ID {$issue->clientid}");
         }
         $project = $this->clientService->getClientSupportProject($client);
         if (!$project) {
             throw new Exception("Missing client details for request {$issue->title}");
         }
         $issue->projectid = $project->id;
         $this->dbService->updateObject($issue);
     } else {
         $project = $this->projectService->getProject($issue->projectid);
     }
     // make sure it's assigned to someone
     if (!mb_strlen($issue->userid)) {
         if (!$project) {
             $project = $this->projectService->getProject($issue->projectid);
         }
         $issue->userid = $project->manager;
         $this->dbService->updateObject($issue);
     }
     // Check to see if the assignee has a watch, if not, add one
     $assignedTo = $this->userService->getByName($issue->userid);
     if ($assignedTo) {
         $existing = $this->notificationService->getWatch($assignedTo, $issue->id, 'Issue');
         if (!$existing) {
             $this->notificationService->createWatch($assignedTo, $issue->id, 'Issue');
         }
     }
     $this->log->debug("Saving request, notify {$issue->userid} = " . $sendNotification);
     $this->trackerService->track('create-issue', $issue->id);
     // now send a notification to those users in the
     // group assigned to the project the issue was just saved against.
     if ($sendNotification && $doNotify) {
         // create and assign a task to whoever was assigned to the issue
         // by default
         if ($assignedTo && false) {
             // Create the task
             $task = new Task();
             $task->projectid = $issue->projectid;
             $task->userid = array($assignedTo->username);
             $task->title = 'Respond to request "' . $issue->title . '"';
             $task->description = "Please investigate this request:\r\n\r\n" . $issue->description;
             $task->category = 'Support';
             $task->due = date('Y-m-d H:i:s', strtotime('+2 days'));
             // $task = $this->projectService->saveTask($task, false, true);
             // $this->itemLinkService->linkItems($issue, $task);
         }
         $this->log->debug("Notifying users about new request {$issue->title}");
         $this->notifyOfNewIssue($issue);
         // Add a watch for the current user. Note that it might be null if
         // this issue is created from an email
         $user = za()->getUser();
         if ($user) {
             $this->notificationService->createWatch($user, $issue->id, 'Issue');
         }
     }
     if ($issue->status == Issue::STATUS_CLOSED) {
         // remove notifications
         $subscribers = $this->notificationService->getSubscribers($issue);
         foreach ($subscribers as $username => $item) {
             $user = $this->userService->getUserByField('username', $username);
             if ($user) {
                 $this->notificationService->removeWatch($user, $issue->id, 'Issue');
             }
         }
     }
     // See if the status has changed and notify the creator
     if ($oldIssue != null && $oldIssue->status != $issue->status && $doNotify) {
         try {
             $this->notifyOfUpdatedIssue($oldIssue, $issue);
         } catch (Exception $e) {
             $this->log->warn("Failed to notify of request update");
         }
     }
     return $issue;
 }