[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.impact_analysis.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: class.impact_analysis.php 3246 2007-02-09 09:10:12Z glen $
  29  //
  30  
  31  require_once (APP_INC_PATH . "class.misc.php");
  32  require_once (APP_INC_PATH . "class.auth.php");
  33  require_once (APP_INC_PATH . "class.user.php");
  34  require_once (APP_INC_PATH . "class.history.php");
  35  require_once (APP_INC_PATH . "class.date.php");
  36  
  37  /**
  38   * Class to handle the business logic related to the impact analysis section
  39   * of the view issue page. This section allows the developer to give feedback
  40   * on the impacts required to implement a needed feature, or to change an
  41   * existing application.
  42   *
  43   * @version 1.0
  44   * @author João Prado Maia <jpm@mysql.com>
  45   */
  46  
  47  class Impact_Analysis
  48  {
  49      /**
  50       * Method used to insert a new requirement for an existing issue.
  51       *
  52       * @access  public
  53       * @param   integer $issue_id The issue ID
  54       * @return  integer -1 if an error occurred or 1 otherwise
  55       */
  56      function insert($issue_id)
  57      {
  58          $usr_id = Auth::getUserID();
  59          $stmt = "INSERT INTO
  60                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
  61                   (
  62                      isr_iss_id,
  63                      isr_usr_id,
  64                      isr_created_date,
  65                      isr_requirement
  66                   ) VALUES (
  67                      " . Misc::escapeInteger($issue_id) . ",
  68                      $usr_id,
  69                      '" . Date_API::getCurrentDateGMT() . "',
  70                      '" . Misc::escapeString($_POST["new_requirement"]) . "'
  71                   )";
  72          $res = $GLOBALS["db_api"]->dbh->query($stmt);
  73          if (PEAR::isError($res)) {
  74              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  75              return -1;
  76          } else {
  77              Issue::markAsUpdated($issue_id);
  78              // need to save a history entry for this
  79              History::add($issue_id, $usr_id, History::getTypeID('impact_analysis_added'), ev_gettext('New requirement submitted by %1$s', User::getFullName($usr_id)));
  80              return 1;
  81          }
  82      }
  83  
  84  
  85      /**
  86       * Method used to get the full list of requirements and impact analysis for
  87       * a specific issue.
  88       *
  89       * @access  public
  90       * @param   integer $issue_id The issue ID
  91       * @return  array The full list of requirements
  92       */
  93      function getListing($issue_id)
  94      {
  95          $stmt = "SELECT
  96                      isr_id,
  97                      isr_requirement,
  98                      isr_dev_time,
  99                      isr_impact_analysis,
 100                      A.usr_full_name AS submitter_name,
 101                      B.usr_full_name AS handler_name
 102                   FROM
 103                      (
 104                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement,
 105                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user A
 106                      )
 107                   LEFT JOIN
 108                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user B
 109                   ON
 110                      isr_updated_usr_id=B.usr_id
 111                   WHERE
 112                      isr_iss_id=" . Misc::escapeInteger($issue_id) . " AND
 113                      isr_usr_id=A.usr_id";
 114          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 115          if (PEAR::isError($res)) {
 116              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 117              return "";
 118          } else {
 119              if (count($res) == 0) {
 120                  return "";
 121              } else {
 122                  for ($i = 0; $i < count($res); $i++) {
 123                      $res[$i]["isr_requirement"] = Link_Filter::processText(Issue::getProjectID($issue_id), nl2br(htmlspecialchars($res[$i]["isr_requirement"])));
 124                      $res[$i]["isr_impact_analysis"] = Link_Filter::processText(Issue::getProjectID($issue_id), nl2br(htmlspecialchars($res[$i]["isr_impact_analysis"])));
 125                      $res[$i]["formatted_dev_time"] = Misc::getFormattedTime($res[$i]["isr_dev_time"]);
 126                  }
 127                  return $res;
 128              }
 129          }
 130      }
 131  
 132  
 133      /**
 134       * Method used to update an existing requirement with the appropriate
 135       * impact analysis.
 136       *
 137       * @access  public
 138       * @param   integer $isr_id The requirement ID
 139       * @return  integer -1 if an error occurred or 1 otherwise
 140       */
 141      function update($isr_id)
 142      {
 143          $stmt = "SELECT
 144                      isr_iss_id
 145                   FROM
 146                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
 147                   WHERE
 148                      isr_id=" . Misc::escapeInteger($isr_id);
 149          $issue_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
 150  
 151          // we are storing minutes, not hours
 152          $dev_time = $_POST["dev_time"] * 60;
 153          $usr_id = Auth::getUserID();
 154          $stmt = "UPDATE
 155                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
 156                   SET
 157                      isr_updated_usr_id=$usr_id,
 158                      isr_updated_date='" . Date_API::getCurrentDateGMT() . "',
 159                      isr_dev_time=$dev_time,
 160                      isr_impact_analysis='" . Misc::escapeString($_POST["impact_analysis"]) . "'
 161                   WHERE
 162                      isr_id=" . Misc::escapeInteger($isr_id);
 163          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 164          if (PEAR::isError($res)) {
 165              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 166              return -1;
 167          } else {
 168              Issue::markAsUpdated($issue_id);
 169              // need to save a history entry for this
 170              History::add($issue_id, $usr_id, History::getTypeID('impact_analysis_updated'), ev_gettext('Impact analysis submitted by %1$s', User::getFullName($usr_id)));
 171              return 1;
 172          }
 173      }
 174  
 175  
 176      /**
 177       * Method used to remove an existing set of requirements.
 178       *
 179       * @access  public
 180       * @return  integer -1 if an error occurred or 1 otherwise
 181       */
 182      function remove()
 183      {
 184          $items = implode(", ", Misc::escapeInteger($_POST["item"]));
 185          $stmt = "SELECT
 186                      isr_iss_id
 187                   FROM
 188                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
 189                   WHERE
 190                      isr_id IN ($items)";
 191          $issue_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
 192  
 193          $stmt = "DELETE FROM
 194                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
 195                   WHERE
 196                      isr_id IN ($items)";
 197          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 198          if (PEAR::isError($res)) {
 199              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 200              return -1;
 201          } else {
 202              Issue::markAsUpdated($issue_id);
 203              // need to save a history entry for this
 204              History::add($issue_id, Auth::getUserID(), History::getTypeID('impact_analysis_removed'), ev_gettext('Impact analysis removed by %1$s', User::getFullName(Auth::getUserID())));
 205              return 1;
 206          }
 207      }
 208  
 209  
 210      /**
 211       * Method used to remove all of the requirements associated with a set of
 212       * issue IDs.
 213       *
 214       * @access  public
 215       * @param   array $ids The list of issue IDs
 216       * @return  boolean
 217       */
 218      function removeByIssues($ids)
 219      {
 220          $items = implode(", ", Misc::escapeInteger($ids));
 221          $stmt = "DELETE FROM
 222                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_requirement
 223                   WHERE
 224                      isr_iss_id IN ($items)";
 225          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 226          if (PEAR::isError($res)) {
 227              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 228              return false;
 229          } else {
 230              return true;
 231          }
 232      }
 233  }
 234  
 235  // benchmarking the included file (aka setup time)
 236  if (APP_BENCHMARK) {
 237      $GLOBALS['bench']->setMarker('Included Impact_Analysis Class');
 238  }


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7