[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/projectmanager/inc/ -> class.soprojectelements.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - ProjectManager - Elements storage object                    *
   4  * http://www.egroupware.org                                                *
   5  * Written and (c) 2005 by Ralf Becker <RalfBecker@outdoor-training.de>     *
   6  * --------------------------------------------                             *
   7  *  This program is free software; you can redistribute it and/or modify it *
   8  *  under the terms of the GNU General Public License as published by the   *
   9  *  Free Software Foundation; either version 2 of the License, or (at your  *
  10  *  option) any later version.                                              *
  11  \**************************************************************************/
  12  
  13  /* $Id: class.soprojectelements.inc.php 21516 2006-05-13 06:07:23Z ralfbecker $ */
  14  
  15  include_once (EGW_INCLUDE_ROOT.'/etemplate/inc/class.so_sql.inc.php');
  16  
  17  /**
  18   * Elements storage object of the projectmanager
  19   *
  20   * Tables: egw_pm_elements, egw_links
  21   *
  22   * A project P is the parent of an other project C, if link_id1=P.pm_id and link_id2=C.pm_id !
  23   *
  24   * @package projectmanager
  25   * @author RalfBecker-AT-outdoor-training.de
  26   * @copyright (c) 2005 by RalfBecker-AT-outdoor-training.de
  27   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
  28   */
  29  class soprojectelements extends so_sql
  30  {
  31      /**
  32       * @var string $links_table table name 'egw_links'
  33       */
  34      var $links_table = 'egw_links';
  35      /**
  36       * @var string $links_join join in the links table
  37       */
  38      var $links_join = ',egw_links WHERE pe_id=link_id';
  39      /**
  40       * @var array $links_extracols extracolumns from the links table
  41       */
  42      var $links_extracols = array(
  43          "CASE WHEN link_app1='projectmanager' AND link_id1=pm_id THEN link_app2 ELSE link_app1 END AS pe_app",
  44          "CASE WHEN link_app1='projectmanager' AND link_id1=pm_id THEN link_id2 ELSE link_id1 END AS pe_app_id",
  45          'link_remark AS pe_remark',
  46      );
  47      /**
  48       * @var int $default_share default share in minutes (on the whole project), used if no planned time AND no pe_share set
  49       */
  50      var $default_share = 240; // minutes
  51  
  52      /**
  53       * Constructor, calls the constructor of the extended class
  54       * 
  55       * It is sufficent to give just the pe_id, as it is unique!
  56       *
  57       * @param int $pm_id pm_id of the project to use, default null
  58       * @param int $pe_id pe_id of the project-element to load, default null
  59       */
  60  	function soprojectelements($pm_id=null,$pe_id=null)
  61      {
  62          $this->so_sql('projectmanager','egw_pm_elements');
  63  
  64          if ((int) $pm_id || (int) $pe_id) 
  65          {
  66              $this->pm_id = (int) $pm_id;
  67              
  68              if ((int) $pe_id)
  69              {
  70                  if ($this->read($pe_id)) $this->pm_id = $this->data['pm_id'];
  71              }
  72          }
  73      }
  74      
  75      /**
  76       * Summarize the information of all elements of a project: min(start-time), sum(time), avg(completion), ...
  77       *
  78       * @param int/array $pm_id=null int project-id, array of project-id's or null to use $this->pm_id
  79       * @param array $filter=array() columname => value pairs to filter, eg. '
  80       * @return array/boolean with summary information (keys as for a single project-element), false on error
  81       */
  82  	function summary($pm_id=null,$filter=array())
  83      {
  84          if (is_null($pm_id)) $pm_id = $this->pm_id;
  85  
  86          if ($this->project->data['pm_id'] != $pm_id)
  87          {
  88              $save_data = $this->project->data;
  89              $this->project->read($pm_id);
  90          }
  91          if ($this->project->data['pm_accounting_type'] == 'status')    // we dont have a times!
  92          {
  93              $share = "CASE WHEN pe_share IS NULL THEN $this->default_share ELSE pe_share END";
  94          }
  95          else
  96          {
  97              $share = "CASE WHEN pe_share IS NULL AND pe_planned_time IS NULL THEN $this->default_share WHEN pe_share IS NULL THEN pe_planned_time ELSE pe_share END";
  98          }
  99          if ($save_data) $this->project->data = $save_data;
 100  
 101          if (!isset($filter['pm_id'])) $filter['pm_id'] = $pm_id;
 102          if (!isset($filter['pe_status'])) $filter[] = "pe_status != 'ignore'";
 103          // fix some special filters: resources, cats
 104          $filter = $this->_fix_filter($filter);
 105  
 106          $this->db->select($this->table_name,array(
 107              "SUM(pe_completion * ($share)) AS pe_sum_completion_shares",
 108              "SUM(CASE WHEN pe_completion IS NULL THEN NULL ELSE ($share) END) AS pe_total_shares",
 109  //            'AVG(pe_completion) AS pe_completion',
 110              'SUM(pe_used_time) AS pe_used_time',
 111              'SUM(pe_planned_time) AS pe_planned_time',
 112              'SUM(pe_used_budget) AS pe_used_budget',
 113              'SUM(pe_planned_budget) AS pe_planned_budget',
 114              'MIN(pe_real_start) AS pe_real_start',
 115              'MIN(pe_planned_start) AS pe_planned_start',
 116              'MAX(pe_real_end) AS pe_real_end',
 117              'MAX(pe_planned_end) AS pe_planned_end',
 118          ),$filter,__LINE__,__FILE__);
 119          
 120          if (!($data = $this->db->row(true)))
 121          {
 122              return false;
 123          }
 124          if ($data['pe_total_shares'])
 125          {
 126              $data['pe_completion'] = round($data['pe_sum_completion_shares'] / $data['pe_total_shares'],1);
 127          }
 128          return $this->db2data($data);
 129      }
 130  
 131      /**
 132       * search elements, reimplemented to use $this->pm_id, if no pm_id given in criteria or filter
 133       *
 134       * @param array/string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!)
 135       * @param boolean $only_keys True returns only keys, False returns all cols
 136       * @param string $order_by fieldnames + {ASC|DESC} separated by colons ','
 137       * @param string/array $extra_cols string or array of strings to be added to the SELECT, eg. "count(*) as num"
 138       * @param string $wildcard appended befor and after each criteria
 139       * @param boolean $empty False=empty criteria are ignored in query, True=empty have to be empty in row
 140       * @param string $op defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together
 141       * @param int/boolean $start if != false, return only maxmatch rows begining with start
 142       * @param array $filter if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards
 143       * @param string/boolean $join=true default join with links-table or string as in so_sql
 144       * @return array of matching rows (the row is an array of the cols) or False
 145       */
 146  	function search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join=true)
 147      {
 148          if ($this->pm_id && (!isset($filter['pm_id']) || !$filter['pm_id']))
 149          {
 150              $filter['pm_id'] = $this->pm_id;
 151          }
 152          if ($join === true)    // add join with links-table and extra-columns
 153          {
 154              $join = $this->links_join;
 155              
 156              if (!$extra_cols)
 157              {
 158                  $extra_cols = $this->links_extracols;
 159              }
 160              else
 161              {
 162                  $extra_cols = array_merge($this->links_extracols,
 163                      is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols));
 164              }            
 165          }
 166          // fix some special filters: resources, cats
 167          $filter = $this->_fix_filter($filter);
 168  
 169          return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join);
 170      }
 171      
 172  	function _fix_filter($filter)
 173      {
 174          // handle search for a single resource in comma-separated pe_resources column
 175          if (isset($filter['pe_resources']))
 176          {
 177              if ($filter['pe_resources'])
 178              {
 179                  $filter[] = $this->db->concat("','",'pe_resources',"','").' LIKE '.$this->db->quote('%,'.$filter['pe_resources'].',%');
 180              }
 181              unset($filter['pe_resources']);
 182          }
 183          // include sub-categories in the search
 184          if ($filter['cat_id'])
 185          {
 186              if (!is_object($GLOBALS['egw']->categories))
 187              {
 188                  $GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories');
 189              }
 190              $filter['cat_id'] = $GLOBALS['egw']->categories->return_all_children($filter['cat_id']);
 191          }
 192          return $filter;
 193      }
 194  
 195      /**
 196       * reads one project-element specified by $keys, reimplemented to use $this->pm_id, if no pm_id given
 197       *
 198       * @param array $keys array with keys in form internalName => value, may be a scalar value if only one key
 199       * @param string/array $extra_cols string or array of strings to be added to the SELECT, eg. "count(*) as num"
 200       * @param string/boolean $join=true default join with links-table or string as in so_sql
 201       * @return array/boolean data if row could be retrived else False
 202      */
 203  	function read($keys,$extra_cols='',$join=true)
 204      {
 205          if ($this->pm_id && !isset($keys['pm_id']))
 206          {
 207              if (!is_array($keys) && (int) $keys) $keys = array('pe_id' => (int) $keys);
 208              $keys['pm_id'] = $this->pm_id;
 209          }
 210          if ($join === true)    // add join with links-table and extra-columns
 211          {
 212              $join = $this->links_join;
 213              
 214              if (!$extra_cols) $extra_cols = $this->links_extracols;
 215          }
 216          return parent::read($keys,$extra_cols,$join);
 217      }
 218  }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7