[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.release.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.release.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  require_once (APP_INC_PATH . "class.validation.php");
  34  
  35  /**
  36   * Class to handle the business logic related to the administration
  37   * of releases in the system.
  38   *
  39   * @version 1.0
  40   * @author João Prado Maia <jpm@mysql.com>
  41   */
  42  
  43  class Release
  44  {
  45      /**
  46       * Method used to check whether a release is assignable or not.
  47       *
  48       * @access  public
  49       * @param   integer $pre_id The release ID
  50       * @return  boolean
  51       */
  52      function isAssignable($pre_id)
  53      {
  54          $stmt = "SELECT
  55                      COUNT(*)
  56                   FROM
  57                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
  58                   WHERE
  59                      pre_id=" . Misc::escapeInteger($pre_id) . " AND
  60                      pre_status='available'";
  61          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
  62          if (PEAR::isError($res)) {
  63              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  64              return false;
  65          } else {
  66              if ($res == 0) {
  67                  return false;
  68              } else {
  69                  return true;
  70              }
  71          }
  72      }
  73  
  74  
  75      /**
  76       * Method used to get the details of a specific release.
  77       *
  78       * @access  public
  79       * @param   integer $pre_id The release ID
  80       * @return  array The details of the release
  81       */
  82      function getDetails($pre_id)
  83      {
  84          $stmt = "SELECT
  85                      *,
  86                      MONTH(pre_scheduled_date) AS scheduled_month,
  87                      YEAR(pre_scheduled_date) AS scheduled_year
  88                   FROM
  89                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
  90                   WHERE
  91                      pre_id=" . Misc::escapeInteger($pre_id);
  92          $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC);
  93          if (PEAR::isError($res)) {
  94              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  95              return "";
  96          } else {
  97              return $res;
  98          }
  99      }
 100  
 101  
 102      /**
 103       * Method used to get the title of a specific release.
 104       *
 105       * @access  public
 106       * @param   integer $pre_id The release ID
 107       * @return  string The title of the release
 108       */
 109      function getTitle($pre_id)
 110      {
 111          $stmt = "SELECT
 112                      pre_title
 113                   FROM
 114                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 115                   WHERE
 116                      pre_id=" . Misc::escapeInteger($pre_id);
 117          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
 118          if (PEAR::isError($res)) {
 119              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 120              return "";
 121          } else {
 122              return $res;
 123          }
 124      }
 125  
 126  
 127      /**
 128       * Method used to remove all releases associated with a specific
 129       * set of projects.
 130       *
 131       * @access  public
 132       * @param   array $ids The list of projects
 133       * @return  boolean
 134       */
 135      function removeByProjects($ids)
 136      {
 137          $items = @implode(", ", Misc::escapeInteger($ids));
 138          $stmt = "DELETE FROM
 139                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 140                   WHERE
 141                      pre_prj_id IN ($items)";
 142          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 143          if (PEAR::isError($res)) {
 144              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 145              return false;
 146          } else {
 147              return true;
 148          }
 149      }
 150  
 151  
 152      /**
 153       * Method used to remove releases by using the administrative
 154       * interface of the system.
 155       *
 156       * @access  public
 157       * @return  boolean
 158       */
 159      function remove()
 160      {
 161          $items = @implode(", ", Misc::escapeInteger($_POST["items"]));
 162          // gotta fix the issues that are using this release
 163          $stmt = "UPDATE
 164                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue
 165                   SET
 166                      iss_pre_id=0
 167                   WHERE
 168                      iss_pre_id IN ($items)";
 169          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 170          if (PEAR::isError($res)) {
 171              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 172              return false;
 173          } else {
 174              $stmt = "DELETE FROM
 175                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 176                       WHERE
 177                          pre_id IN ($items)";
 178              $res = $GLOBALS["db_api"]->dbh->query($stmt);
 179              if (PEAR::isError($res)) {
 180                  Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 181                  return false;
 182              } else {
 183                  return true;
 184              }
 185          }
 186      }
 187  
 188  
 189      /**
 190       * Method used to update the release by using the administrative
 191       * interface of the system.
 192       *
 193       * @access  public
 194       * @return  integer 1 if the update worked, -1 or -2 otherwise
 195       */
 196      function update()
 197      {
 198          if (Validation::isWhitespace($_POST["title"])) {
 199              return -2;
 200          }
 201          $scheduled_date = $_POST["scheduled_date"]["Year"] . "-" . $_POST["scheduled_date"]["Month"] . "-" . $_POST["scheduled_date"]["Day"];
 202          $stmt = "UPDATE
 203                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 204                   SET
 205                      pre_title='" . Misc::escapeString($_POST["title"]) . "',
 206                      pre_scheduled_date='" . Misc::escapeString($scheduled_date) . "',
 207                      pre_status='" . Misc::escapeString($_POST["status"]) . "'
 208                   WHERE
 209                      pre_prj_id=" . Misc::escapeInteger($_POST["prj_id"]) . " AND
 210                      pre_id=" . Misc::escapeInteger($_POST["id"]);
 211          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 212          if (PEAR::isError($res)) {
 213              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 214              return -1;
 215          } else {
 216              return 1;
 217          }
 218      }
 219  
 220  
 221      /**
 222       * Method used to add a new release by using the administrative
 223       * interface of the system.
 224       *
 225       * @access  public
 226       * @return  integer 1 if the update worked, -1 or -2 otherwise
 227       */
 228      function insert()
 229      {
 230          if (Validation::isWhitespace($_POST["title"])) {
 231              return -2;
 232          }
 233          $scheduled_date = $_POST["scheduled_date"]["Year"] . "-" . $_POST["scheduled_date"]["Month"] . "-" . $_POST["scheduled_date"]["Day"];
 234          $stmt = "INSERT INTO
 235                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 236                   (
 237                      pre_prj_id,
 238                      pre_title,
 239                      pre_scheduled_date,
 240                      pre_status
 241                   ) VALUES (
 242                      " . Misc::escapeInteger($_POST["prj_id"]) . ",
 243                      '" . Misc::escapeString($_POST["title"]) . "',
 244                      '" . Misc::escapeString($scheduled_date) . "',
 245                      '" . Misc::escapeString($_POST["status"]) . "'
 246                   )";
 247          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 248          if (PEAR::isError($res)) {
 249              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 250              return -1;
 251          } else {
 252              return 1;
 253          }
 254      }
 255  
 256  
 257      /**
 258       * Method used to get the list of releases associated with a
 259       * specific project.
 260       *
 261       * @access  public
 262       * @param   integer $prj_id The project ID
 263       * @return  array The list of releases
 264       */
 265      function getList($prj_id)
 266      {
 267          $stmt = "SELECT
 268                      pre_id,
 269                      pre_title,
 270                      pre_scheduled_date,
 271                      pre_status
 272                   FROM
 273                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 274                   WHERE
 275                      pre_prj_id=" . Misc::escapeInteger($prj_id) . "
 276                   ORDER BY
 277                      pre_scheduled_date ASC";
 278          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 279          if (PEAR::isError($res)) {
 280              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 281              return "";
 282          } else {
 283              return $res;
 284          }
 285      }
 286  
 287  
 288      /**
 289       * Method used to get a list as an associative array of the
 290       * releases.
 291       *
 292       * @access  public
 293       * @param   integer $prj_id The project ID
 294       * @param   boolean $show_all_dates If true all releases, not just those with future dates will be returned
 295       * @return  array The list of releases
 296       */
 297      function getAssocList($prj_id, $show_all_dates = false)
 298      {
 299          $stmt = "SELECT
 300                      pre_id,
 301                      pre_title
 302                   FROM
 303                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release
 304                   WHERE
 305                      pre_prj_id=" . Misc::escapeInteger($prj_id) . " AND
 306                      (
 307                        pre_status='available'";
 308          if ($show_all_dates != true) {
 309              $stmt .= " AND
 310                        pre_scheduled_date >= '" . gmdate('Y-m-d') . "'";
 311          }
 312          $stmt .= "
 313                      )
 314                   ORDER BY
 315                      pre_scheduled_date ASC";
 316          $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
 317          if (PEAR::isError($res)) {
 318              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 319              return "";
 320          } else {
 321              return $res;
 322          }
 323      }
 324  }
 325  
 326  // benchmarking the included file (aka setup time)
 327  if (APP_BENCHMARK) {
 328      $GLOBALS['bench']->setMarker('Included Release Class');
 329  }


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