[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.stats.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.stats.php 3380 2007-09-26 04:30:54Z balsdorf $
  29  //
  30  
  31  require_once (APP_INC_PATH . "class.error_handler.php");
  32  require_once (APP_INC_PATH . "class.auth.php");
  33  require_once (APP_INC_PATH . "class.release.php");
  34  require_once (APP_INC_PATH . "class.priority.php");
  35  require_once (APP_INC_PATH . "class.misc.php");
  36  require_once (APP_INC_PATH . "class.user.php");
  37  require_once (APP_INC_PATH . "class.project.php");
  38  require_once (APP_INC_PATH . "class.status.php");
  39  
  40  /**
  41   * Class to handle the business logic related to the generation of the
  42   * issue statistics displayed in the main screen of the application.
  43   *
  44   * @version 1.0
  45   * @author João Prado Maia <jpm@mysql.com>
  46   */
  47  
  48  class Stats
  49  {
  50      /**
  51       * Method used to check if the provided array has valid data (e.g. non-zero)
  52       *
  53       * @access  public
  54       * @param   array $data The data to check against
  55       * @return  boolean
  56       */
  57      function hasData($data)
  58      {
  59          foreach ($data as $piece) {
  60              if ($piece) {
  61                  return true;
  62              }
  63          }
  64          return false;
  65      }
  66  
  67  
  68      /**
  69       * Method used to check if the pie charts should be displayed in the main
  70       * screen of the application.
  71       *
  72       * @access  public
  73       * @return  boolean
  74       */
  75      function getPieChart()
  76      {
  77          if (!@file_exists(APP_JPGRAPH_PATH)) {
  78              return false;
  79          } else {
  80              return true;
  81          }
  82      }
  83  
  84  
  85      /**
  86       * Method used to get an associative array of the list of categories and the
  87       * total number of issues associated with each of them.
  88       *
  89       * @access  public
  90       * @param   boolean $hide_closed If closed issues should be hidden.
  91       * @return  array List of categories
  92       */
  93      function getAssocCategory($hide_closed = false)
  94      {
  95          $prj_id = Auth::getCurrentProject();
  96          $list = Category::getAssocList($prj_id);
  97          $stats = array();
  98          foreach ($list as $prc_id => $prc_title) {
  99              $stmt = "SELECT
 100                          COUNT(*) AS total_items
 101                       FROM
 102                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 103                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 104                       WHERE
 105                          iss_sta_id = sta_id AND
 106                          iss_prj_id=$prj_id AND
 107                          iss_prc_id=" . $prc_id;
 108              if ($hide_closed) {
 109                  $stmt .= " AND
 110                          sta_is_closed = 0";
 111              }
 112              $res = (integer) $GLOBALS["db_api"]->dbh->getOne($stmt);
 113              if ($res > 0) {
 114                  $stats[$prc_title] = $res;
 115              }
 116          }
 117          arsort($stats);
 118          return $stats;
 119      }
 120  
 121  
 122      /**
 123       * Method used to get an associative array of the list of releases and the
 124       * total number of issues associated with each of them.
 125       *
 126       * @access  public
 127       * @param   boolean $hide_closed If closed issues should be hidden.
 128       * @return  array List of releases
 129       */
 130      function getAssocRelease($hide_closed = true)
 131      {
 132          $prj_id = Auth::getCurrentProject();
 133          $list = Release::getAssocList($prj_id);
 134          $stats = array();
 135          foreach ($list as $pre_id => $pre_title) {
 136              $stmt = "SELECT
 137                          COUNT(*) AS total_items
 138                       FROM
 139                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 140                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 141                       WHERE
 142                          iss_sta_id = sta_id AND
 143                          iss_prj_id=$prj_id AND
 144                          iss_pre_id=" . $pre_id;
 145              if ($hide_closed) {
 146                  $stmt .= " AND
 147                          sta_is_closed = 0";
 148              }
 149              $res = (integer) $GLOBALS["db_api"]->dbh->getOne($stmt);
 150              if ($res > 0) {
 151                  $stats[$pre_title] = $res;
 152              }
 153          }
 154          arsort($stats);
 155          return $stats;
 156      }
 157  
 158  
 159      /**
 160       * Method used to get an associative array of the list of statuses and the
 161       * total number of issues associated with each of them.
 162       *
 163       * @access  public
 164       * @param   boolean $hide_closed If closed issues should be hidden.
 165       * @return  array List of statuses
 166       */
 167      function getAssocStatus($hide_closed = true)
 168      {
 169          $prj_id = Auth::getCurrentProject();
 170          $list = Status::getAssocStatusList($prj_id);
 171          $stats = array();
 172          foreach ($list as $sta_id => $sta_title) {
 173              $stmt = "SELECT
 174                          COUNT(*) AS total_items
 175                       FROM
 176                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 177                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 178                       WHERE
 179                          iss_sta_id = sta_id AND
 180                          iss_prj_id=$prj_id AND
 181                          iss_sta_id=" . $sta_id;
 182              if ($hide_closed) {
 183                  $stmt .= " AND
 184                          sta_is_closed = 0";
 185              }
 186              $res = (integer) $GLOBALS["db_api"]->dbh->getOne($stmt);
 187              if ($res > 0) {
 188                  $stats[$sta_title] = $res;
 189              }
 190          }
 191          arsort($stats);
 192          return $stats;
 193      }
 194  
 195  
 196      /**
 197       * Method used to get the list of statuses and the total number of issues
 198       * associated with each of them.
 199       *
 200       * @access  public
 201       * @param   boolean $hide_closed If closed issues should be hidden.
 202       * @return  array List of statuses
 203       */
 204      function getStatus($hide_closed = false)
 205      {
 206          $prj_id = Auth::getCurrentProject();
 207          $stmt = "SELECT
 208                      DISTINCT iss_sta_id,
 209                      sta_title,
 210                      COUNT(*) AS total_items
 211                   FROM
 212                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 213                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 214                   WHERE
 215                      iss_sta_id=sta_id AND
 216                      iss_prj_id=$prj_id";
 217              if ($hide_closed) {
 218                  $stmt .= " AND
 219                          sta_is_closed = 0";
 220              }
 221              $stmt .= "
 222                   GROUP BY
 223                      iss_sta_id
 224                   ORDER BY
 225                      total_items DESC";
 226          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 227          if (PEAR::isError($res)) {
 228              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 229              return "";
 230          } else {
 231              return $res;
 232          }
 233      }
 234  
 235  
 236      /**
 237       * Method used to get the list of categories and the total number of issues
 238       * associated with each of them.
 239       *
 240       * @access  public
 241       * @param   boolean $hide_closed If closed issues should be hidden.
 242       * @return  array List of categories
 243       */
 244      function getCategory($hide_closed = false)
 245      {
 246          $prj_id = Auth::getCurrentProject();
 247          $stmt = "SELECT
 248                      DISTINCT iss_prc_id,
 249                      prc_title,
 250                      SUM(IF(sta_is_closed=0, 1, 0)) AS total_open_items,
 251                      SUM(IF(sta_is_closed=1, 1, 0)) AS total_closed_items
 252                   FROM
 253                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 254                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category,
 255                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 256                   WHERE
 257                      iss_prj_id=$prj_id AND
 258                      iss_prc_id=prc_id AND
 259                      iss_sta_id=sta_id";
 260          if ($hide_closed) {
 261              $stmt .= " AND
 262                      sta_is_closed = 0";
 263          }
 264          $stmt .= "
 265                   GROUP BY
 266                      iss_prc_id
 267                   ORDER BY
 268                      total_open_items";
 269          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 270          if (PEAR::isError($res)) {
 271              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 272              return "";
 273          } else {
 274              return $res;
 275          }
 276      }
 277  
 278  
 279      /**
 280       * Method used to get the list of releases and the total number of issues
 281       * associated with each of them.
 282       *
 283       * @access  public
 284       * @param   boolean $hide_closed If closed issues should be hidden.
 285       * @return  array List of releases
 286       */
 287      function getRelease($hide_closed = false)
 288      {
 289          $prj_id = Auth::getCurrentProject();
 290          $stmt = "SELECT
 291                      DISTINCT iss_pre_id,
 292                      pre_title,
 293                      SUM(IF(sta_is_closed=0, 1, 0)) AS total_open_items,
 294                      SUM(IF(sta_is_closed=1, 1, 0)) AS total_closed_items
 295                   FROM
 296                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 297                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release,
 298                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 299                   WHERE
 300                      iss_prj_id=$prj_id AND
 301                      iss_pre_id=pre_id AND
 302                      iss_sta_id=sta_id";
 303          if ($hide_closed) {
 304              $stmt .= " AND
 305                      sta_is_closed = 0";
 306          }
 307          $stmt .= "
 308                   GROUP BY
 309                      iss_pre_id
 310                   ORDER BY
 311                      total_open_items DESC";
 312          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 313          if (PEAR::isError($res)) {
 314              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 315              return "";
 316          } else {
 317              return $res;
 318          }
 319      }
 320  
 321  
 322      /**
 323       * Method used to get an associative array of the list of priorities and the
 324       * total number of issues associated with each of them.
 325       *
 326       * @access  public
 327       * @param   boolean $hide_closed If closed issues should be hidden.
 328       * @return  array List of priorities
 329       */
 330      function getAssocPriority($hide_closed = false)
 331      {
 332          $prj_id = Auth::getCurrentProject();
 333          $list = Priority::getAssocList($prj_id);
 334          $stats = array();
 335          foreach ($list as $pri_id => $pri_title) {
 336              $stmt = "SELECT
 337                          COUNT(*) AS total_items
 338                       FROM
 339                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 340                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 341                       WHERE
 342                          iss_sta_id = sta_id AND
 343                          iss_prj_id=$prj_id AND
 344                          iss_pri_id=" . $pri_id;
 345              if ($hide_closed) {
 346                  $stmt .= " AND
 347                          sta_is_closed = 0";
 348              }
 349              $res = (integer) $GLOBALS["db_api"]->dbh->getOne($stmt);
 350              if ($res > 0) {
 351                  $stats[$pri_title] = $res;
 352              }
 353          }
 354          arsort($stats);
 355          return $stats;
 356      }
 357  
 358  
 359      /**
 360       * Method used to get the list of priorities and the total number of issues
 361       * associated with each of them.
 362       *
 363       * @access  public
 364       * @param   boolean $hide_closed If closed issues should be hidden.
 365       * @return  array List of statuses
 366       */
 367      function getPriority($hide_closed = false)
 368      {
 369          $prj_id = Auth::getCurrentProject();
 370          $stmt = "SELECT
 371                      DISTINCT iss_pri_id,
 372                      pri_title,
 373                      SUM(IF(sta_is_closed=0, 1, 0)) AS total_open_items,
 374                      SUM(IF(sta_is_closed=1, 1, 0)) AS total_closed_items
 375                   FROM
 376                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 377                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority,
 378                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 379                   WHERE
 380                      iss_pri_id=pri_id AND
 381                      iss_sta_id=sta_id AND
 382                      iss_prj_id=$prj_id";
 383          if ($hide_closed) {
 384              $stmt .= " AND
 385                      sta_is_closed = 0";
 386          }
 387          $stmt .= "
 388                   GROUP BY
 389                      iss_pri_id
 390                   ORDER BY
 391                      total_open_items DESC";
 392          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 393          if (PEAR::isError($res)) {
 394              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 395              return "";
 396          } else {
 397              return $res;
 398          }
 399      }
 400  
 401  
 402      /**
 403       * Method used to get an associative array of the list of users and the
 404       * total number of issues associated with each of them.
 405       *
 406       * @access  public
 407       * @param   boolean $hide_closed If closed issues should be hidden.
 408       * @return  array List of users
 409       */
 410      function getAssocUser($hide_closed = false)
 411      {
 412          $prj_id = Auth::getCurrentProject();
 413          $list = Project::getUserAssocList($prj_id, 'stats', User::getRoleID('Customer'));
 414          $stats = array();
 415          foreach ($list as $usr_id => $usr_full_name) {
 416              $stmt = "SELECT
 417                          COUNT(*) AS total_items
 418                       FROM
 419                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 420                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
 421                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 422                       WHERE
 423                          iss_sta_id = sta_id AND
 424                          isu_iss_id=iss_id AND
 425                          iss_prj_id=$prj_id AND
 426                          isu_usr_id=" . $usr_id;
 427              if ($hide_closed) {
 428                  $stmt .= " AND
 429                          sta_is_closed = 0";
 430              }
 431              $res = (integer) $GLOBALS["db_api"]->dbh->getOne($stmt);
 432              if ($res > 0) {
 433                  $stats[$usr_full_name] = $res;
 434              }
 435          }
 436          arsort($stats);
 437          return $stats;
 438      }
 439  
 440  
 441      /**
 442       * Method used to get the list of users and the total number of issues
 443       * associated with each of them.
 444       *
 445       * @access  public
 446       * @param   boolean $hide_closed If closed issues should be hidden.
 447       * @return  array List of users
 448       */
 449      function getUser($hide_closed = false)
 450      {
 451          $prj_id = Auth::getCurrentProject();
 452          $stmt = "SELECT
 453                      DISTINCT isu_usr_id,
 454                      usr_full_name,
 455                      SUM(IF(sta_is_closed=0, 1, 0)) AS total_open_items,
 456                      SUM(IF(sta_is_closed=1, 1, 0)) AS total_closed_items
 457                   FROM
 458                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 459                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,
 460                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user,
 461                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 462                   WHERE
 463                      isu_usr_id=usr_id AND
 464                      isu_iss_id=iss_id AND
 465                      iss_prj_id=$prj_id AND
 466                      iss_sta_id=sta_id";
 467          if ($hide_closed) {
 468              $stmt .= " AND
 469                      sta_is_closed = 0";
 470          }
 471          $stmt .= "
 472                   GROUP BY
 473                      isu_usr_id
 474                   ORDER BY
 475                      total_open_items DESC";
 476          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 477          if (PEAR::isError($res)) {
 478              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 479              return "";
 480          } else {
 481              return $res;
 482          }
 483      }
 484  
 485  
 486      /**
 487       * Method used to get the total number of issues associated with each
 488       * email status.
 489       *
 490       * @access  public
 491       * @return  array List of statuses
 492       */
 493      function getEmailStatus()
 494      {
 495          $prj_id = Auth::getCurrentProject();
 496          $stmt = "SELECT
 497                      IF(sup_iss_id > 0, 'associated', 'unassociated') type,
 498                      COUNT(*) AS total_items
 499                   FROM
 500                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,
 501                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account
 502                   WHERE
 503                      sup_ema_id=ema_id AND
 504                      ema_prj_id=$prj_id AND
 505                      sup_removed=0
 506                   GROUP BY
 507                      type";
 508          $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
 509          if (PEAR::isError($res)) {
 510              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 511              return "";
 512          }
 513          if (empty($res['associated'])) {
 514              $res['associated'] = 0;
 515          }
 516          if (empty($res['unassociated'])) {
 517              $res['unassociated'] = 0;
 518          }
 519          $stmt = "SELECT
 520                      COUNT(*) AS total_items
 521                   FROM
 522                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,
 523                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account
 524                   WHERE
 525                      sup_ema_id=ema_id AND
 526                      ema_prj_id=$prj_id AND
 527                      sup_removed=1";
 528          $res3 = $GLOBALS["db_api"]->dbh->getOne($stmt);
 529          if (PEAR::isError($res3)) {
 530              Error_Handler::logError(array($res3->getMessage(), $res3->getDebugInfo()), __FILE__, __LINE__);
 531              return "";
 532          }
 533          return array(
 534              "pending"    => $res['unassociated'],
 535              "associated" => $res['associated'],
 536              "removed"    => $res3
 537          );
 538      }
 539  }
 540  
 541  // benchmarking the included file (aka setup time)
 542  if (APP_BENCHMARK) {
 543      $GLOBALS['bench']->setMarker('Included Stats Class');
 544  }


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