/** * View a single client * */ public function viewAction() { $this->view->client = $this->byId(); $this->view->title = $this->view->client->title; $this->view->existingWatch = $this->notificationService->getWatch(za()->getUser(), $this->view->client); if ($this->_getParam('_ajax')) { $this->renderRawView('client/ajaxView.php'); } else { $this->renderView('client/view.php'); } }
/** * Called to redirect after saving a model object * */ protected function onModelSaved($model) { $project = $this->projectService->getProject((int) $this->_getParam('projectid')); // after saving a task, we should probably notify the user about it hey? if (!$this->_getParam('id')) { $message = new TemplatedMessage('new-task.php', array('model' => $model)); $this->notificationService->notifyUser('New task', $model->userid, $message); // Create a watch for the creator $this->notificationService->createWatch(za()->getUser(), $model->id, 'Task'); } // Check to see if the assignee has a watch, if not, add one foreach ($model->userid as $username) { $assignedTo = $this->userService->getByName($username); if ($assignedTo) { $existing = $this->notificationService->getWatch($assignedTo, $model->id, 'Task'); if (!$existing) { $this->notificationService->createWatch($assignedTo, $model->id, 'Task'); } } } if ($this->_getParam('_ajax')) { echo $this->ajaxResponse("Saved " . $model->title); } else { $this->redirect('task', 'edit', array('id' => $model->id)); } }
/** * view a note thread * */ public function viewthreadAction() { $id = $this->_getParam('toid'); $type = $this->_getParam('totype'); if (!$id || !$type) { return; } $this->view->notes = $this->notificationService->getNotesFor($type, $id, 'created asc'); if (!count($this->view->notes)) { $this->flash("No notes found in thread"); $this->redirect('index'); return; } $this->view->itemtype = $type; $this->view->itemid = $id; $this->view->existing = $this->notificationService->getWatch(za()->getUser(), $id, $type); $this->renderView('note/thread-view.php'); }
/** * 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; }
/** * View a project. * */ public function viewAction() { $__start = getmicrotime(); $project = $this->projectService->getProject((int) $this->_getParam('id')); if ($project == null) { $this->flash("Project not found"); $this->renderView('error.php'); return; } $this->view->hideHeader = false; $totalCount = $this->projectService->getTaskCount(array('projectid =' => $project->id, 'complete=' => 0)); $this->view->taskPagerName = 'ptasks'; $currentPage = ifset($this->_getAllParams(), $this->view->taskPagerName, 1); $this->view->totalTasks = $totalCount; $this->view->taskListSize = za()->getConfig('project_task_list_size'); $this->view->displayedTasks = $this->projectService->getTasks(array('projectid =' => $project->id, 'complete=' => 0), 'due asc', $currentPage, za()->getConfig('project_task_list_size')); $totalCompleted = $this->projectService->getTaskCount(array('projectid =' => $project->id, 'complete=' => 1)); $this->view->completedPagerName = 'ctasks'; $currentPage = ifset($this->_getAllParams(), $this->view->completedPagerName, 1); $this->view->totalCompleted = $totalCompleted; $this->view->completedTasks = $this->projectService->getTasks(array('projectid =' => $project->id, 'complete=' => 1), 'due asc', $currentPage, za()->getConfig('project_task_list_size')); $this->view->projectStatusReports = $this->projectService->getStatusReports($project); $this->view->project = $project; $this->view->title = $project->title; $group = $this->groupService->getGroup($project->ownerid); if ($group == null) { $this->log->warn("Invalid project owner {$project->ownerid}"); } else { } $this->view->groupusers = $project->getUsers(); $this->view->users = $this->userService->getUserList(); $this->view->group = $group; $this->view->existingWatch = $this->notificationService->getWatch(za()->getUser(), $project); $this->view->projectuser = za()->getUser(); if ($this->_getParam('projectuser')) { if ($this->_getParam('projectuser') == 'all') { $this->view->projectuser = null; } else { $this->view->projectuser = $this->userService->getUser($this->_getParam('projectuser')); } } if ($this->view->projectuser && !isset($this->view->groupusers[$this->view->projectuser->id])) { $this->view->projectuser = null; } $where = array('projectid =' => $project->id); $new = $this->issueService->getIssues(array('projectid =' => $project->id, 'status =' => Issue::STATUS_NEW)); if (count($new)) { $this->view->newIssues = true; } else { $this->view->newIssues = false; } $this->view->issues = $this->issueService->getIssues($where); za()->recordStat('projectcontroller::setupview', getmicrotime() - $__start); $__start = getmicrotime(); if ($this->_getParam('_ajax')) { $this->renderRawView('project/ajaxView.php'); } else { $this->renderView('project/view.php'); } za()->recordStat('projectcontroller::viewrendered', getmicrotime() - $__start); }
/** * Override the edit action to supply some selectable relationships * * @param MappedObject $model */ public function prepareForEdit($model = null) { if ($this->view->model == null) { $this->flash("Invalid request specified"); $this->redirect('error'); return; } $this->view->issueHistory = $this->issueService->getIssueHistory($this->view->model); $pid = (int) $this->_getParam('projectid'); $cid = (int) $this->_getParam('clientid'); if ($this->view->model->projectid) { $pid = $this->view->model->projectid; } if ($this->view->model->clientid) { $cid = $this->view->model->clientid; } // Which one? if ($pid) { $this->view->project = $this->projectService->getProject($pid); $this->view->client = $this->clientService->getClient($this->view->project->clientid); // figure out the releases available for this project $this->view->releases = $this->issueService->getProjectReleases($this->view->project); } else { if ($cid) { $this->view->client = $this->clientService->getClient($cid); $this->view->releases = array(); } } if ($this->view->client != null) { $this->view->categories = $this->issueService->getIssueCategoriesForCompany($this->view->client); } else { $this->view->categories = array(); } // if it's a new issue, and it's a normal user set it to be private by default // User can always specify a different one though if (!$this->view->model->id && za()->getUser()->hasRole(User::ROLE_USER)) { $this->view->model->isprivate = true; } $this->view->users = $this->userService->getUserList(); $this->view->severities = $this->view->model->constraints['severity']->getValues(); $this->view->types = $this->view->model->constraints['issuetype']->getValues(); $this->view->statuses = $this->view->model->constraints['status']->getValues(); if ($this->view->model->id) { $this->view->notes = $this->notificationService->getNotesFor($this->view->model); $this->view->existingWatch = $this->notificationService->getWatch(za()->getUser(), $this->view->model->id, 'Issue'); $this->view->userStatuses = $this->view->model->getUserStatuses(); $clientUsers = $this->userService->getUsersForClient($this->view->model->clientid); foreach ($this->view->users as $user) { $clientUsers->append($user); } $this->view->allUsers = $clientUsers; $this->view->subscribers = $this->notificationService->getSubscribers($this->view->model->id, 'Issue'); $this->view->project = $this->projectService->getProject($this->view->model->projectid); $this->view->client = $this->clientService->getClient($this->view->model->clientid); $this->view->files = $this->issueService->getIssueFiles($this->view->model); $path = 'Clients/' . $this->view->client->title . '/Issues/' . $this->view->model->id; $this->view->filePath = $path; // Get all the features for this project $this->view->projectFeatures = $this->featureService->getFeatures(array('projectid=' => $this->view->model->projectid)); $this->view->projectTasks = $this->projectService->getTasks(array('projectid=' => $this->view->project->id), 'title asc'); $this->view->linkedTasks = $this->itemLinkService->getLinkedItems($this->view->model, 'from', 'Task'); $this->view->linkedToFeatures = $this->itemLinkService->getLinkedItems($this->view->model, 'from', 'Feature'); $this->view->linkedFromFeatures = $this->itemLinkService->getLinkedItems($this->view->model, 'to', 'Feature'); } $this->view->clients = $this->clientService->getClients(); if ($this->view->client) { $this->view->projects = $this->projectService->getProjectsForClient($this->view->client->id); } }