| 1 | <?php
|
| 2 |
|
| 3 | /**
|
| 4 | * =======================================
|
| 5 | * ###################################
|
| 6 | * SWIFT Framework
|
| 7 | *
|
| 8 | * @package SWIFT
|
| 9 | * @author Kayako Infotech Ltd.
|
| 10 | * @copyright Copyright (c) 2001-2009, Kayako Infotech Ltd.
|
| 11 | * @license http://www.kayako.com/license
|
| 12 | * @link http://www.kayako.com
|
| 13 | * @filesource
|
| 14 | * ###################################
|
| 15 | * =======================================
|
| 16 | */
|
| 17 |
|
| 18 | /**
|
| 19 | * The Bug View
|
| 20 | * Handles all the bug(s) logged per ticet
|
| 21 | *
|
| 22 | * @author Abhinav Kumar <abhinav.kumar@kayako.com>
|
| 23 | */
|
| 24 | class View_Bug extends SWIFT_View
|
| 25 | {
|
| 26 | /**
|
| 27 | * The constructor
|
| 28 | *
|
| 29 | * @return bool 'TRUE' on success and 'FALSE' otherwise
|
| 30 | */
|
| 31 | public function __construct()
|
| 32 | {
|
| 33 | parent::__construct();
|
| 34 |
|
| 35 | $_SWIFT = SWIFT::GetInstance();
|
| 36 |
|
| 37 | $_SWIFT->Language->Load('staff_ticketsmanage');
|
| 38 | $_SWIFT->Language->Load('tickets_auditlogs');
|
| 39 |
|
| 40 | return true;
|
| 41 | }
|
| 42 |
|
| 43 | /**
|
| 44 | * The destructor
|
| 45 | *
|
| 46 | * @return bool 'TRUE' on success and 'FALSE' otherwise
|
| 47 | */
|
| 48 | public function __destruct()
|
| 49 | {
|
| 50 | return parent::__destruct();
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Renders the 'Export to JIRA' form
|
| 55 | *
|
| 56 | * @param int $_ticketID The current ticket id
|
| 57 | *
|
| 58 | * @return boolean 'TRUE' on success and 'FALSE' otherwise
|
| 59 | * @throws SWIFT_Exception if class is not loaded or $_ticketID is not provided
|
| 60 | */
|
| 61 | public function RenderExportForm($_ticketID)
|
| 62 | {
|
| 63 | $_SWIFT = SWIFT::GetInstance();
|
| 64 |
|
| 65 | if (!$this->GetIsClassLoaded()) {
|
| 66 | throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);
|
| 67 | }
|
| 68 |
|
| 69 | if (empty($_ticketID)) {
|
| 70 | throw new SWIFT_Exception('Ticket ID' . $this->Language->Get('jira_noempty'));
|
| 71 | }
|
| 72 |
|
| 73 | $_ticketID = (int) $_ticketID;
|
| 74 | $_projectsOptionsContainer = array();
|
| 75 | $_issueTypesOptionsContainer = array();
|
| 76 | $_securityLevelsContainer = array();
|
| 77 | $_securityLevelsOptionsContainer = array();
|
| 78 |
|
| 79 |
|
| 80 | //$this->Load->Library('Ticket:Ticket', false, false, APP_TICKETS);
|
| 81 |
|
| 82 | $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_ticketID);
|
| 83 |
|
| 84 | $_ticketPostContainer = $_SWIFT_TicketObject->GetTicketPosts();
|
| 85 |
|
| 86 | $_ticketPosts = array();
|
| 87 |
|
| 88 | foreach ($_ticketPostContainer as $_TicketPost) {
|
| 89 | $_creater = $_TicketPost->GetProperty('fullname');
|
| 90 |
|
| 91 | if ($_TicketPost->GetProperty('creator') == SWIFT_Ticket::CREATOR_STAFF) {
|
| 92 | $_staffDataStore = $_SWIFT->Staff->GetDataStore();
|
| 93 | $_creater = $_staffDataStore['grouptitle'];
|
| 94 | } else if ($_TicketPost->GetProperty('creator') == SWIFT_Ticket::CREATOR_USER) {
|
| 95 | $_creater .= ' (' . $this->Language->Get('jira_user') . ')';
|
| 96 | }
|
| 97 |
|
| 98 | $_postedOn = SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $_TicketPost->GetProperty('dateline'));
|
| 99 |
|
| 100 | $_ticketPosts[] = $_creater . ' - ' . $_postedOn . PHP_EOL . strip_tags(trim($_TicketPost->GetDisplayContents())) . PHP_EOL;
|
| 101 | }
|
| 102 |
|
| 103 | $_ticketPosts = implode(PHP_EOL, $_ticketPosts);
|
| 104 |
|
| 105 | $_ticketPosts = '[' . $_SWIFT_TicketObject->GetProperty('ticketmaskid') . ']: ' . $_SWIFT_TicketObject->GetProperty('subject')
|
| 106 | . PHP_EOL
|
| 107 | . '=================================================='
|
| 108 | . PHP_EOL
|
| 109 | . PHP_EOL
|
| 110 | . $_ticketPosts;
|
| 111 |
|
| 112 | $this->UserInterface->Start(get_class($this), '/JIRA/Bug/ProcessIssueForm', SWIFT_UserInterface::MODE_INSERT, true);
|
| 113 |
|
| 114 | $_buttonText = '<input type="button" name="submitbutton" id="%formid%_submit" class="rebuttonblue" onclick="javascript: $(\'#%formid%\').submit();" value="' . $this->Language->Get('jira_save') . '" onfocus="blur();" />
|
| 115 | <input type="button" name="submitbutton" id="%formid%_cancel" class="rebuttonred" onclick="javascript: $(\'.ui-icon-closethick\').click();" value="' . $this->Language->Get('jira_cancel') . '" onfocus="blur();" />';
|
| 116 |
|
| 117 | $this->UserInterface->OverrideButtonText($_buttonText);
|
| 118 |
|
| 119 | $_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), SWIFT::Get('swiftpath') . SWIFT_APPSDIRECTORY . '/jira/resources/postbugtojira_b.gif', 'general', true, false);
|
| 120 |
|
| 121 | $this->Load->Library('JIRA:JIRABridge', false, false, 'jira');
|
| 122 |
|
| 123 | $_JIRABridge = SWIFT_JIRABridge::GetInstance();
|
| 124 |
|
| 125 | if (!$_JIRABridge || !$_JIRABridge instanceof SWIFT_JIRABridge || !$_JIRABridge->GetIsClassLoaded()) {
|
| 126 | throw new SWIFT_Exception('JIRABridge ' . SWIFT_CLASSNOTLOADED);
|
| 127 | }
|
| 128 |
|
| 129 | $_defaultReporter = $_SWIFT->Settings->Get('bj_username');
|
| 130 | $_defaultProject = $_SWIFT->Settings->Get('bj_defaultproject');
|
| 131 |
|
| 132 | $_projectsContainer = $_JIRABridge->GetProjects();
|
| 133 |
|
| 134 | if ($_projectsContainer == false) {
|
| 135 | SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $_JIRABridge->GetErrorMessage());
|
| 136 | } else if (_is_array($_projectsContainer)) {
|
| 137 | foreach ($_projectsContainer as $_project) {
|
| 138 | $_projectsOptionsContainer[] = array(
|
| 139 | 'title' => $_project['title'],
|
| 140 | 'value' => $_project['value'],
|
| 141 | );
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | $_prioritiesContainer = $_JIRABridge->GetPriorities();
|
| 146 |
|
| 147 | // Check if a default project is configured & load the issue types based on it
|
| 148 | // Use the first entry of the projects drop down otherwise
|
| 149 | if ((empty($_defaultProject) || $_defaultProject == $_SWIFT->Language->Get('bj_noproject')) && _is_array($_projectsOptionsContainer)) {
|
| 150 | $_defaultProject = $_projectsOptionsContainer[0]['value'];
|
| 151 | }
|
| 152 |
|
| 153 | $_issueTypeContainer = $_JIRABridge->GetIssueTypesByProject($_defaultProject);
|
| 154 |
|
| 155 | if (_is_array($_issueTypeContainer)) {
|
| 156 | foreach ($_issueTypeContainer as $_IssueType) {
|
| 157 | // Ignore sub-task issue type as we currently dont support it
|
| 158 | if (strtolower($_IssueType->name) == 'sub-task') {
|
| 159 | continue;
|
| 160 | }
|
| 161 |
|
| 162 | $_issueTypesOption = array(
|
| 163 | 'title' => $_IssueType->name,
|
| 164 | 'value' => $_IssueType->id
|
| 165 | );
|
| 166 |
|
| 167 | $_issueTypesOptionsContainer[] = $_issueTypesOption;
|
| 168 | }
|
| 169 | } else {
|
| 170 | if ($_JIRABridge && $_JIRABridge instanceof SWIFT_JIRABridge && $_JIRABridge->GetIsClassLoaded()) {
|
| 171 | $_JIRABridge->SetErrorMessage($this->Language->Get('jira_issuetypenotfound'));
|
| 172 | }
|
| 173 | }
|
| 174 |
|
| 175 | if (_is_array($_issueTypesOptionsContainer)) {
|
| 176 | $_securityLevelsContainer = $_JIRABridge->GetSecurityLevelsByProject($_defaultProject, $_issueTypesOptionsContainer[0]['value']);
|
| 177 | }
|
| 178 | if (_is_array($_securityLevelsContainer)) {
|
| 179 | foreach ($_securityLevelsContainer as $_securityLevelKey => $_securityLevelValue) {
|
| 180 | $_securityLevelsOptionsContainer[] = array(
|
| 181 | 'title' => isset($_securityLevelValue) ? $_securityLevelValue : 'Untitled',
|
| 182 | 'value' => $_securityLevelKey
|
| 183 | );
|
| 184 | }
|
| 185 | } else {
|
| 186 | $_securityLevelsOptionsContainer[] = array(
|
| 187 | 'title' => $_SWIFT->Language->Get('jira_notapplicable'),
|
| 188 | 'value' => 0
|
| 189 | );
|
| 190 | }
|
| 191 |
|
| 192 | //Add form fields
|
| 193 | $_GeneralTabObject->Hidden('ticketId', $_ticketID);
|
| 194 | $_GeneralTabObject->Text('summary', $this->Language->Get('jira_summary'), $this->Language->Get('jira_summary_desc'), $_SWIFT_TicketObject->GetProperty('subject'), 'text', 60);
|
| 195 | $_GeneralTabObject->Select('project', $this->Language->Get('jira_project'), $this->Language->Get('jira_project_desc'), $_projectsContainer);
|
| 196 | $_GeneralTabObject->Select('issueType', $this->Language->Get('jira_issuetype'), $this->Language->Get('jira_issuetype_desc'), $_issueTypesOptionsContainer);
|
| 197 | $_GeneralTabObject->Select('securityLevel', $this->Language->Get('jira_security_level'), $this->Language->Get('jira_issuetype_desc'), $_securityLevelsOptionsContainer);
|
| 198 | $_GeneralTabObject->Select('priority', $this->Language->Get('jira_priority'), $this->Language->Get('jira_priority_desc'), $_prioritiesContainer);
|
| 199 | $_GeneralTabObject->Hidden('reporter', $_defaultReporter);
|
| 200 | $_GeneralTabObject->Title('<label for="description">' . $this->Language->Get('jira_description') . '</label><br/>' . $this->Language->Get('jira_sensitive'));
|
| 201 | $_GeneralTabObject->TextArea('description', '', $this->Language->Get('jira_description_desc'), $_ticketPosts, 50, 16);
|
| 202 |
|
| 203 | //Add Hidden fields - proves handy for Loading the view after update
|
| 204 | $this->UserInterface->Hidden('jira_ticketid', $_SWIFT_TicketObject->GetTicketID());
|
| 205 | $this->UserInterface->Hidden('jira_listtype', 'inbox');
|
| 206 | $this->UserInterface->Hidden('jira_departmentid', $_SWIFT_TicketObject->GetProperty('departmentid'));
|
| 207 | $this->UserInterface->Hidden('jira_ticketstatusid', $_SWIFT_TicketObject->GetProperty('ticketstatusid'));
|
| 208 | $this->UserInterface->Hidden('jira_tickettypeid', $_SWIFT_TicketObject->GetProperty('tickettypeid'));
|
| 209 |
|
| 210 | $this->UserInterface->End();
|
| 211 |
|
| 212 | return true;
|
| 213 | }
|
| 214 |
|
| 215 | /**
|
| 216 | * Renders Link Issue Form
|
| 217 | *
|
| 218 | * @param int $_ticketID The current ticket id
|
| 219 | *
|
| 220 | * @return boolean 'TRUE' on success and 'FALSE' otherwise
|
| 221 | * @throws SWIFT_Exception if class is not loaded or $_ticketID is not provided
|
| 222 | */
|
| 223 | public function RenderLinkIssueForm($_ticketID)
|
| 224 | {
|
| 225 | $_SWIFT = SWIFT::GetInstance();
|
| 226 |
|
| 227 | if (!$this->GetIsClassLoaded()) {
|
| 228 | throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);
|
| 229 | }
|
| 230 |
|
| 231 | if (empty($_ticketID)) {
|
| 232 | throw new SWIFT_Exception('Ticket ID' . $this->Language->Get('jira_noempty'));
|
| 233 | }
|
| 234 |
|
| 235 | $_ticketID = (int) $_ticketID;
|
| 236 |
|
| 237 | $this->Load->Library('Ticket:Ticket', false, false, APP_TICKETS);
|
| 238 |
|
| 239 | $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_ticketID);
|
| 240 |
|
| 241 | $_ticketPostContainer = $_SWIFT_TicketObject->GetTicketPosts();
|
| 242 |
|
| 243 | $_ticketPosts = array();
|
| 244 |
|
| 245 | foreach ($_ticketPostContainer as $_TicketPost) {
|
| 246 | $_creater = $_TicketPost->GetProperty('fullname');
|
| 247 |
|
| 248 | if ($_TicketPost->GetProperty('creator') == SWIFT_Ticket::CREATOR_STAFF) {
|
| 249 | $_staffDataStore = $_SWIFT->Staff->GetDataStore();
|
| 250 | $_creater = $_staffDataStore['grouptitle'];
|
| 251 | } else if ($_TicketPost->GetProperty('creator') == SWIFT_Ticket::CREATOR_USER) {
|
| 252 | $_creater .= ' (' . $this->Language->Get('jira_user') . ')';
|
| 253 | }
|
| 254 |
|
| 255 | $_postedOn = SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $_TicketPost->GetProperty('dateline'));
|
| 256 |
|
| 257 | $_ticketPosts[] = $_creater . ' - ' . $_postedOn . PHP_EOL . strip_tags(trim($_TicketPost->GetDisplayContents())) . PHP_EOL;
|
| 258 | }
|
| 259 |
|
| 260 | $_ticketPosts = implode(PHP_EOL, $_ticketPosts);
|
| 261 |
|
| 262 | $_ticketPosts = '[' . $_SWIFT_TicketObject->GetProperty('ticketmaskid') . ']: ' . $_SWIFT_TicketObject->GetProperty('subject')
|
| 263 | . PHP_EOL
|
| 264 | . '=================================================='
|
| 265 | . PHP_EOL
|
| 266 | . PHP_EOL
|
| 267 | . $_ticketPosts;
|
| 268 |
|
| 269 | $this->UserInterface->Start(get_class($this), '/JIRA/Bug/ProcessLinkIssueForm', SWIFT_UserInterface::MODE_INSERT, true);
|
| 270 |
|
| 271 | $_buttonText = '<input type="button" name="submitbutton" id="%formid%_submit" class="rebuttonblue" onclick="javascript: $(\'#%formid%\').submit();" value="' . $this->Language->Get('jira_save') . '" onfocus="blur();" />
|
| 272 | <input type="button" name="submitbutton" id="%formid%_cancel" class="rebuttonred" onclick="javascript: $(\'.ui-icon-closethick\').click();" value="' . $this->Language->Get('jira_cancel') . '" onfocus="blur();" />';
|
| 273 |
|
| 274 | $this->UserInterface->OverrideButtonText($_buttonText);
|
| 275 |
|
| 276 | $_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), SWIFT::Get('swiftpath') . '__modules/jira/resources/postbugtojira_b.gif', 'general', true, false);
|
| 277 |
|
| 278 | $this->Load->Library('JIRA:JIRABridge', false, false, 'jira');
|
| 279 |
|
| 280 | $_JIRABridge = SWIFT_JIRABridge::GetInstance();
|
| 281 |
|
| 282 | if (!$_JIRABridge) {
|
| 283 | echo $this->Language->Get('jira_error');
|
| 284 | }
|
| 285 |
|
| 286 | $_defaultReporter = $_SWIFT->Settings->Get('bj_username');
|
| 287 | $_defaultProject = $_SWIFT->Settings->Get('bj_defaultproject');
|
| 288 |
|
| 289 |
|
| 290 | //Add form fields
|
| 291 | $_GeneralTabObject->Hidden('ticketId', $_ticketID);
|
| 292 | $_GeneralTabObject->Hidden('ticketkey', $_SWIFT_TicketObject->GetTicketDisplayID());
|
| 293 | $_GeneralTabObject->Text('jira_issue_id', $this->Language->Get('jira_issue_id'), $this->Language->Get('jira_issue_id_desc'), '', 'text', 60);
|
| 294 | $_GeneralTabObject->Title('<label for="description">' . $this->Language->Get('jira_description') . '</label><br/>' . $this->Language->Get('jira_sensitive'));
|
| 295 | $_GeneralTabObject->TextArea('description', '', $this->Language->Get('jira_description_desc'), $_ticketPosts, 3, 14);
|
| 296 |
|
| 297 | //Add Hidden fields - proves handy for Loading the view after update
|
| 298 | $this->UserInterface->Hidden('jira_ticketid', $_SWIFT_TicketObject->GetTicketID());
|
| 299 | $this->UserInterface->Hidden('jira_listtype', 'inbox');
|
| 300 | $this->UserInterface->Hidden('jira_departmentid', $_SWIFT_TicketObject->GetProperty('departmentid'));
|
| 301 | $this->UserInterface->Hidden('jira_ticketstatusid', $_SWIFT_TicketObject->GetProperty('ticketstatusid'));
|
| 302 | $this->UserInterface->Hidden('jira_tickettypeid', $_SWIFT_TicketObject->GetProperty('tickettypeid'));
|
| 303 |
|
| 304 | $this->UserInterface->End();
|
| 305 |
|
| 306 | return true;
|
| 307 | }
|
| 308 |
|
| 309 | /**
|
| 310 | * Renders the 'Add Comment to JIRA' form
|
| 311 | *
|
| 312 | * @param string $_issueKey The JIRA issue key
|
| 313 | *
|
| 314 | * @return boolean 'TRUE' on success and 'FALSE' otherwise
|
| 315 | * @throws SWIFT_Exception if class is not loaded or $_issueKey is empty
|
| 316 | */
|
| 317 | public function RenderCommentForm($_issueKey)
|
| 318 | {
|
| 319 | if (!$this->GetIsClassLoaded()) {
|
| 320 | throw new SWIFT_Exception(__CLASS__ . ' ' . SWIFT_CLASSNOTLOADED);
|
| 321 | }
|
| 322 |
|
| 323 | if (empty($_issueKey)) {
|
| 324 | throw new SWIFT_Exception('Issue Key' . $this->Language->Get('jira_noempty'));
|
| 325 | }
|
| 326 |
|
| 327 | //$this->UserInterface->Header('Post a JIRA comment');
|
| 328 | $_buttonText = '<input type="button" name="submitbutton" id="%formid%_submit" class="rebuttonblue" onclick="javascript: $(\'#%formid%\').submit();" value="' . $this->Language->Get('jira_post') . '" onfocus="blur();" />
|
| 329 | <input type="button" name="submitbutton" id="%formid%_cancel" class="rebuttonred" onclick="javascript: $(\'.ui-icon-closethick\').click();" value="' . $this->Language->Get('jira_cancel') . '" onfocus="blur();" />';
|
| 330 |
|
| 331 | $this->UserInterface->OverrideButtonText($_buttonText);
|
| 332 |
|
| 333 | $_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), SWIFT::Get('swiftpath') . '__modules/jira/resources/postbugtojira_b.gif', 'general', true, false);
|
| 334 | $this->Load->Library('JIRA:JIRABridge', false, false, 'jira');
|
| 335 |
|
| 336 | $_JIRABridge = SWIFT_JIRABridge::GetInstance();
|
| 337 |
|
| 338 | if (!$_JIRABridge || !$_JIRABridge instanceof SWIFT_JIRABridge || !$_JIRABridge->GetIsClassLoaded()) {
|
| 339 | SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_error'));
|
| 340 | return false;
|
| 341 | }
|
| 342 |
|
| 343 | $_JIRAIssue = $_JIRABridge->GetIssueBy('issuekey', $_issueKey);
|
| 344 |
|
| 345 | if ($_JIRAIssue && $_JIRAIssue instanceof SWIFT_JIRAIssueManager && $_JIRAIssue->GetIsClassLoaded()) {
|
| 346 |
|
| 347 | $this->Load->Library('Ticket:Ticket', false, false, APP_TICKETS);
|
| 348 |
|
| 349 | $_project = $_JIRAIssue->GetProject();
|
| 350 |
|
| 351 | $_RolesContainer = $_JIRABridge->GetProjectRoles($_project);
|
| 352 |
|
| 353 | $_RolesOptionContainer = array();
|
| 354 |
|
| 355 | if ($_RolesContainer && _is_array($_RolesContainer)) {
|
| 356 | foreach ($_RolesContainer as $_Role => $_RoleURL) {
|
| 357 | $_RolesOptionContainer[] = array(
|
| 358 | 'title' => $_Role,
|
| 359 | 'value' => $_Role
|
| 360 | );
|
| 361 | }
|
| 362 | }
|
| 363 |
|
| 364 | $_SWIFT_TicketObject = SWIFT_Ticket::GetObjectOnID($_JIRAIssue->GetKayakoTicketID());
|
| 365 |
|
| 366 | $_GeneralTabObject->Title('<label for="comment">' . $this->Language->Get('jira_comment') . '</label><br/>' . $this->Language->Get('jira_sensitive'));
|
| 367 | $_GeneralTabObject->TextArea('comment', '', '', '', 50, 6);
|
| 368 | $_GeneralTabObject->Select('visibility', $this->Language->Get('jira_comment_visibility'), '', $_RolesOptionContainer);
|
| 369 | $_GeneralTabObject->Hidden('issueKey', $_issueKey);
|
| 370 |
|
| 371 | $this->UserInterface->Hidden('jira_ticketid', $_SWIFT_TicketObject->GetTicketID());
|
| 372 | $this->UserInterface->Hidden('jira_listtype', 'inbox');
|
| 373 | $this->UserInterface->Hidden('jira_departmentid', $_SWIFT_TicketObject->GetProperty('departmentid'));
|
| 374 | $this->UserInterface->Hidden('jira_ticketstatusid', $_SWIFT_TicketObject->GetProperty('ticketstatusid'));
|
| 375 | $this->UserInterface->Hidden('jira_tickettypeid', $_SWIFT_TicketObject->GetProperty('tickettypeid'));
|
| 376 | //$this->UserInterface->End();
|
| 377 | } else {
|
| 378 | SWIFT::Notify(SWIFT::NOTIFICATION_ERROR, $this->Language->Get('jira_noissuefound') . $_issueKey);
|
| 379 | }
|
| 380 |
|
| 381 | return true;
|
| 382 | }
|
| 383 | }
|