/** * Process the 'post comments to JIRA' form on submission * Checks for validity and then posts the comment to JIRA web service * using REST API * * @author Abhinav Kumar * @return boolean 'true' on success and 'false' otherwise * @throws SWIFT_Exception if class is not loaded */ public function ProcessCommentForm() { if (!$this->GetIsClassLoaded()) { throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED); } $_SWIFT = SWIFT::GetInstance(); $_issueKey = null; $_rawComment = null; $_comment = null; if (array_key_exists('issueKey', $_POST) && $_POST['issueKey'] != '') { $_issueKey = $_POST['issueKey']; } if (array_key_exists('comment', $_POST) && $_POST['comment'] != '') { $_comment = $_rawComment = $_POST['comment']; } if (array_key_exists('visibility', $_POST)) { $_visibility = $_POST['visibility']; } if ($_issueKey && $_comment) { $this->Load->Library('JIRA:JIRABridge', false, false, 'jira'); $_JIRABridge = SWIFT_JIRABridge::GetInstance(); if (!$_JIRABridge || !$_JIRABridge instanceof SWIFT_JIRABridge || !$_JIRABridge->GetIsClassLoaded()) { $this->UserInterface->DisplayAlert($this->Language->Get('jira_error'), $this->Language->Get('connection_error') . $_SWIFT->Settings->Get('bj_jiraurl')); return false; } $_staffDataStore = $_SWIFT->Staff->GetDataStore(); $_issueCreator = $_staffDataStore['grouptitle']; $_staff = $_SWIFT->Staff->GetProperty('fullname') . ' (' . $_issueCreator . ')' . PHP_EOL; $_comment = $_staff . $_comment; $_JIRAIssue = $_JIRABridge->GetIssueBy('issuekey', $_issueKey); if ($_JIRAIssue && $_JIRAIssue instanceof SWIFT_JIRAIssueManager && $_JIRAIssue->GetIsClassLoaded()) { $_JIRAComment = new SWIFT_JIRAComment(); $_JIRAComment->SetBody($_comment); if (isset($_visibility)) { $_visibilityArray = array('type' => 'role', 'value' => $_visibility); $_JIRAComment->SetVisibility($_visibilityArray); } $_commentPosted = $_JIRAIssue->PostComment($_JIRAComment); if ($_commentPosted) { $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_JIRAIssue->GetKayakoTicketId()); // Did the object load up? if (!$_SWIFT_TicketObject || !$_SWIFT_TicketObject instanceof SWIFT_Ticket || !$_SWIFT_TicketObject->GetIsClassLoaded()) { throw new SWIFT_Exception('Ticket Object ' . SWIFT_INVALIDDATA); } $_logText = $this->Language->Get('jira_comment_posted'); SWIFT_TicketAuditLog::AddToLog($_SWIFT_TicketObject, null, SWIFT_TicketAuditLog::ACTION_UPDATETICKETPOST, $_logText, SWIFT_TicketAuditLog::VALUE_NONE, 0, '', 0, ''); SWIFT::Notify(SWIFT::NOTIFICATION_INFO, $this->Language->Get('jira_comment_posted')); } else { SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_comment_notposted')); } } else { SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_noissuefound')); } } $this->Load->Controller('Ticket', APP_TICKETS)->Load->Method('View', $_POST['jira_ticketid'], $_POST['jira_listtype'], $_POST['jira_departmentid'], $_POST['jira_ticketstatusid'], $_POST['jira_tickettypeid']); return true; }
/** * Handle todo export form submit * * @author Atul Atri * @return bool "true" on Success, "false" otherwise * @throws SWIFT_Exception */ public function TodoExportFormSubmit() { $_pId = $_POST['todoproject']; $_todolistId = $_POST['todolist']; $_assigneeId = $_POST['assignee']; $_todo = trim($_POST['todoitem']); $_comment = trim($_POST['todocomment']); $_ticketId = $_POST['todo_ticketid']; $_date = trim($_POST['duedate']); $_fileNames = array(); //if this ticket id is already linked throw exception $_todoId = SWIFT_TodoTicketLink::getTodoInfo($_ticketId); if ($_todoId !== false) { throw new SWIFT_Exception("TIcket id {$_ticketId} is already linked to basecamp todo."); } if (isset($_POST['todo_files'])) { $_fileNames = $_POST['todo_files']; } if ($this->CheckTodoExportForm()) { $this->Load->Library('API:APITodos', false, false); $this->Load->Library('API:APIComments', false, false); $_TodoService = new SWIFT_APITodos(); try { if (!empty($_date)) { $_date = date("c", strtotime($_date)); } $_reponse = $_TodoService->PostTodo($_pId, $_todolistId, $_todo, $_assigneeId, $_date); $_reponseArr = json_decode($_reponse, true); $_newTodoId = $_reponseArr['id']; $this->PostTodoComment($_ticketId, $_pId, $_newTodoId, $_comment, $_fileNames); $this->Load->LoadModel('AuditLog:TicketAuditLog'); $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_ticketId); SWIFT_TicketAuditLog::AddToLog($_SWIFT_TicketObject, null, SWIFT_TicketAuditLog::ACTION_UPDATESTATUS, $this->Language->Get('basecamp_audit_todo_posted'), SWIFT_TicketAuditLog::VALUE_NONE, 0, '', 0, ''); //all well make link in table SWIFT_TodoTicketLink::insertTodo($_ticketId, $_newTodoId, $_pId); //return success message $this->View->TodoPostSuccess($_ticketId, $_pId, $_newTodoId); return true; } catch (Exception $_e) { $_error = $_e->getMessage(); $_SWIFT = SWIFT::GetInstance(); SWIFT::Error($_SWIFT->Language->Get('error'), $_error); } } $this->Load->TodoExportForm($_ticketId, $_pId); return true; }