[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.resolution.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.resolution.php 3246 2007-02-09 09:10:12Z glen $
  29  //
  30  
  31  require_once (APP_INC_PATH . "class.error_handler.php");
  32  require_once (APP_INC_PATH . "class.misc.php");
  33  
  34  /**
  35   * Class to handle the business logic related to the administration
  36   * of resolutions in the system.
  37   *
  38   * @version 1.0
  39   * @author João Prado Maia <jpm@mysql.com>
  40   */
  41  
  42  class Resolution
  43  {
  44      /**
  45       * Method used to get the title of a specific resolution.
  46       *
  47       * @access  public
  48       * @param   integer $res_id The resolution ID
  49       * @return  string The title of the resolution
  50       */
  51      function getTitle($res_id)
  52      {
  53          $stmt = "SELECT
  54                      res_title
  55                   FROM
  56                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
  57                   WHERE
  58                      res_id=" . Misc::escapeInteger($res_id);
  59          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
  60          if (PEAR::isError($res)) {
  61              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  62              return "";
  63          } else {
  64              return $res;
  65          }
  66      }
  67  
  68  
  69      /**
  70       * Method used to remove resolutions by using the administrative
  71       * interface of the system.
  72       *
  73       * @access  public
  74       * @return  boolean
  75       */
  76      function remove()
  77      {
  78          $items = @implode(", ", Misc::escapeInteger($_POST["items"]));
  79          // gotta fix the issues before removing the resolution
  80          $stmt = "UPDATE
  81                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue
  82                   SET
  83                      iss_res_id=0
  84                   WHERE
  85                      iss_res_id IN ($items)";
  86          $res = $GLOBALS["db_api"]->dbh->query($stmt);
  87          if (PEAR::isError($res)) {
  88              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  89              return false;
  90          } else {
  91              $stmt = "DELETE FROM
  92                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
  93                       WHERE
  94                          res_id IN ($items)";
  95              $res = $GLOBALS["db_api"]->dbh->query($stmt);
  96              if (PEAR::isError($res)) {
  97                  Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  98                  return false;
  99              } else {
 100                  return true;
 101              }
 102          }
 103      }
 104  
 105  
 106      /**
 107       * Method used to update the resolution by using the administrative
 108       * interface of the system.
 109       *
 110       * @access  public
 111       * @return  integer 1 if the update worked, -1 or -2 otherwise
 112       */
 113      function update()
 114      {
 115          if (Validation::isWhitespace($_POST["title"])) {
 116              return -2;
 117          }
 118          $stmt = "UPDATE
 119                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
 120                   SET
 121                      res_title='" . Misc::escapeString($_POST["title"]) . "'
 122                   WHERE
 123                      res_id=" . Misc::escapeInteger($_POST["id"]);
 124          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 125          if (PEAR::isError($res)) {
 126              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 127              return -1;
 128          } else {
 129              return 1;
 130          }
 131      }
 132  
 133  
 134      /**
 135       * Method used to get the details of a specific resolution.
 136       *
 137       * @access  public
 138       * @param   integer $res_id The resolution ID
 139       * @return  array The details of the resolution
 140       */
 141      function getDetails($res_id)
 142      {
 143          $stmt = "SELECT
 144                      *
 145                   FROM
 146                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
 147                   WHERE
 148                      res_id=" . Misc::escapeInteger($res_id);
 149          $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC);
 150          if (PEAR::isError($res)) {
 151              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 152              return "";
 153          } else {
 154              return $res;
 155          }
 156      }
 157  
 158  
 159      /**
 160       * Method used to get the full list of resolutions.
 161       *
 162       * @access  public
 163       * @return  array The list of resolutions
 164       */
 165      function getList()
 166      {
 167          $stmt = "SELECT
 168                      res_id,
 169                      res_title
 170                   FROM
 171                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
 172                   ORDER BY
 173                      res_title ASC";
 174          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 175          if (PEAR::isError($res)) {
 176              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 177              return "";
 178          } else {
 179              return $res;
 180          }
 181      }
 182  
 183  
 184      /**
 185       * Method used to get a list as an associative array of the
 186       * resolutions.
 187       *
 188       * @access  public
 189       * @return  array The list of resolutions
 190       */
 191      function getAssocList()
 192      {
 193          $stmt = "SELECT
 194                      res_id,
 195                      res_title
 196                   FROM
 197                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
 198                   ORDER BY
 199                      res_id ASC";
 200          $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
 201          if (PEAR::isError($res)) {
 202              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 203              return "";
 204          } else {
 205              return $res;
 206          }
 207      }
 208  
 209  
 210      /**
 211       * Method used to add a new resolution by using the administrative
 212       * interface of the system.
 213       *
 214       * @access  public
 215       * @return  integer 1 if the update worked, -1 or -2 otherwise
 216       */
 217      function insert()
 218      {
 219          if (Validation::isWhitespace($_POST["title"])) {
 220              return -2;
 221          }
 222          $stmt = "INSERT INTO
 223                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "resolution
 224                   (
 225                      res_title,
 226                      res_created_date
 227                   ) VALUES (
 228                      '" . Misc::escapeString($_POST["title"]) . "',
 229                      '" . Date_API::getCurrentDateGMT() . "'
 230                   )";
 231          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 232          if (PEAR::isError($res)) {
 233              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 234              return -1;
 235          } else {
 236              return 1;
 237          }
 238      }
 239  }
 240  
 241  // benchmarking the included file (aka setup time)
 242  if (APP_BENCHMARK) {
 243      $GLOBALS['bench']->setMarker('Included Resolution Class');
 244  }


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