[ 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.datasource.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - ProjectManager - DataSource baseclass                       *
   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.datasource.inc.php 20887 2006-03-28 10:40:50Z ralfbecker $ */
  14  
  15  /**
  16   * constants for the different types of data
  17   *
  18   * or'ed together eg. for egw_pm_eletemts.pe_overwrite
  19   */
  20  /** int percentage completion 0-100 */
  21  define('PM_COMPLETION',1);
  22  /** int seconds planned time */
  23  define('PM_PLANNED_TIME',2);
  24  /** int seconds used time */
  25  define('PM_USED_TIME',4);
  26  /** double planned budget */
  27  define('PM_PLANNED_BUDGET',8);
  28  /** double planned budget */
  29  define('PM_USED_BUDGET',16);
  30  /** int timestamp planned start-date */
  31  define('PM_PLANNED_START',32);
  32  /** int timestamp real start-date */
  33  define('PM_REAL_START',64);        
  34  /** int timestamp planned end-date */
  35  define('PM_PLANNED_END',128);
  36  /** int timestamp real end-date */
  37  define('PM_REAL_END',256);
  38  /** array with (int) user- or (string) resource-ids */
  39  define('PM_RESOURCES',512);
  40  /** string title */
  41  define('PM_TITLE',1024);
  42  /** string details */
  43  define('PM_DETAILS',2048);
  44  /** int pl_id */
  45  define('PM_PRICELIST_ID',4096);
  46  /** double price */
  47  define('PM_UNITPRICE',8192);
  48  /** double planned quantity */
  49  define('PM_PLANNED_QUANTITY',16384);
  50  /** double used quantity */
  51  define('PM_USED_QUANTITY',32768);
  52  /** all data-types or'ed together, need to be changed if new data-types get added */
  53  define('PM_ALL_DATA',65535);
  54  
  55  /**
  56   * DataSource baseclass of the ProjectManager
  57   *
  58   * This is the baseclass of all DataSources, each spezific DataSource extends it and implement 
  59   * an own get method.
  60   *
  61   * The read method of this class sets (if not set by the get method) the planned start- and endtime:
  62   *  - planned start from the end of a start constrain or the project start-time
  63   *  - planned end from the planned time and a start-time
  64   *  - real or planned start and end from each other
  65   *
  66   * @package projectmanager
  67   * @author RalfBecker-AT-outdoor-training.de
  68   * @copyright (c) 2005 by RalfBecker-AT-outdoor-training.de
  69   * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
  70   */
  71  class datasource
  72  {
  73      /**
  74       * @var string $type type of the datasource, eg. name of the supported app
  75       */
  76      var $type;
  77      /**
  78       * @var bolink-object $link instance of the link-class
  79       */
  80      var $link;
  81      /**
  82       * @var object $bo bo-object of the used app
  83       */
  84      var $bo;
  85      /**
  86       * @var int $valid valid data-types of that source (or'ed PM_ constants)
  87       */
  88      var $valid = 0;
  89      /**
  90       * @var array $name2id translated names / array-keys to the numeric ids PM_*
  91       */
  92      var $name2id = array(
  93          'pe_completion'     => PM_COMPLETION,
  94          'pe_planned_time'   => PM_PLANNED_TIME,
  95          'pe_used_time'      => PM_USED_TIME,
  96          'pe_planned_budget' => PM_PLANNED_BUDGET,
  97          'pe_used_budget'    => PM_USED_BUDGET,
  98          'pe_planned_start'  => PM_PLANNED_START,
  99          'pe_real_start'     => PM_REAL_START,
 100          'pe_planned_end'    => PM_PLANNED_END,
 101          'pe_real_end'       => PM_REAL_END,
 102          'pe_title'          => PM_TITLE,
 103          'pe_resources'        => PM_RESOURCES,
 104          'pe_details'        => PM_DETAILS,
 105          'pl_id'                => PM_PRICELIST_ID,
 106          'pe_unitprice'      => PM_UNITPRICE,
 107          'pe_planned_quantity' => PM_PLANNED_QUANTITY,
 108          'pe_used_quantity'  => PM_USED_QUANTITY,        
 109      );
 110      /**
 111       * @var boprojectelements-object $bo_pe pe object to read other pe's (eg. for constraints)
 112       */
 113      var $bo_pe;
 114  
 115      /**
 116       * Constructor
 117       *
 118       * @param string $type=null type of the datasource
 119       */
 120  	function datasource($type=null)
 121      {
 122          $this->type = $type;
 123  
 124          if (!is_object($GLOBALS['egw']->link))
 125          {
 126              $GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink');
 127          }
 128          $this->link =& $GLOBALS['egw']->link;
 129      }
 130      
 131      /**
 132       * get an item from the underlaying app and convert applying data ia a datasource array
 133       *
 134       * A datasource array can contain values for the keys: completiton, {planned|used}_time, {planned|used}_budget,
 135       *    {planned|real}_start, {planned|real}_end and pe_status
 136       * Not set values mean they are not supported by the datasource.
 137       *
 138       * Reimplent this function for spezial datasource types (not read!)
 139       * 
 140       * @param mixed $data_id id as used in the link-class for that app, or complete entry as array
 141       * @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
 142       */
 143  	function get($data_id)
 144      {
 145          if (($title = $this->link->title($this->type,$data_id)))
 146          {
 147              return array(
 148                  'pe_title'  => $title,
 149                  'pe_status' => 'ignore',    // not supported datasources are ignored, as they contain no values, eg. addressbook
 150              );
 151          }
 152          return false;
 153      }
 154      
 155      /**
 156       * read an item from a datasource (via the get methode) and try to set (guess) some not supported values
 157       *
 158       * A datasource array can contain values for the keys: completiton, {planned|used}_time, {planned|used}_budget,
 159       *    {planned|real}_start, {planned|real}_end
 160       * Not set values mean they are not supported by the datasource.
 161       * 
 162       * @param mixed $data_id id as used in the link-class for that app, or complete entry as array
 163       * @param array $pe_data data of the project-element or null, eg. to use the constraints
 164       * @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
 165       */
 166  	function read($data_id,$pe_data=null)
 167      {
 168          $ds = $this->get($data_id);
 169          
 170          //echo "<p>datasource::read($data_id,$pe_data) ds="; _debug_array($ds);
 171          
 172          if ($ds)
 173          {
 174              // setting a not set planned start from a contrains
 175              if ((!$ds['pe_planned_start'] || $ds['ignore_planned_start']) && !is_null($pe_data) && $pe_data['pe_constraints']['start'])
 176              {
 177                  //echo "start-constr."; _debug_array($pe_data['pe_constraints']['start']);
 178                  $start = 0;
 179                  if (!is_object($this->bo_pe))
 180                  {
 181                      $this->bo_pe =& CreateObject('projectmanager.boprojectelements',$pe_data['pm_id']);
 182                  }
 183                  foreach($pe_data['pe_constraints']['start'] as $start_pe_id)
 184                  {
 185                      if ($this->bo_pe->read(array('pm_id'=>$pe_data['pm_id'],'pe_id'=>$start_pe_id)) &&
 186                          $start < $this->bo_pe->data['pe_planned_end'])
 187                      {
 188                          $start = $this->bo_pe->data['pe_planned_end'];
 189                          //echo "startdate from startconstrain with"; _debug_array($this->bo_pe->data);
 190                      }
 191                  }
 192                  if ($start)
 193                  {
 194                      $ds['pe_planned_start'] = $this->project->date_add($start,0,$ds['pe_resources'][0]);
 195                      //echo "<p>$ds[pe_title] set planned start to ".date('D Y-m-d H:i',$ds['pe_planned_start'])."</p>\n";
 196                      unset($ds['ignore_planned_start']);
 197                  }
 198              }
 199              // setting the planned start from the real-start
 200              if (!$ds['pe_planned_start'] && !$ds['ignore_planned_start'] && $ds['pe_real_start'])
 201              {
 202                  $ds['pe_planned_start'] = $ds['pe_real_start'];
 203              }
 204              // setting the planned start from the projects start
 205              if ((!$ds['pe_planned_start'] || $ds['ignore_planned_start']) && $pe_data['pm_id'])
 206              {
 207                  if (!is_object($this->bo_pe))
 208                  {
 209                      $this->bo_pe =& CreateObject('projectmanager.boprojectelements',$pe_data['pm_id']);
 210                  }
 211                  if ($this->bo_pe->pm_id != $pe_data['pm_id'])
 212                  {
 213                      $this->bo_pe->boprojectelements($pe_data['pm_id']);
 214                  }
 215                  if ($this->bo_pe->project->data['pm_planned_start'] || $this->bo_pe->project->data['pm_real_start'])
 216                  {
 217                      $ds['pe_planned_start'] = $this->bo_pe->project->data['pm_planned_start'] ? 
 218                          $this->bo_pe->project->data['pm_planned_start'] : $this->bo_pe->project->data['pm_real_start'];
 219                      unset($ds['ignore_planned_start']);
 220                  }
 221              }
 222              // calculating the planned end-date from the planned time
 223              if ((!$ds['pe_planned_end'] || $ds['ignore_planned_end']) && $ds['pe_planned_time'])
 224              {
 225                  if ($ds['pe_planned_start'] && is_object($this->project))
 226                  {
 227                      $ds['pe_planned_end'] = $this->project->date_add($ds['pe_planned_start'],$ds['pe_planned_time'],$ds['pe_resources'][0]);
 228                      //echo "<p>$ds[pe_title] set planned end to ".date('D Y-m-d H:i',$ds['pe_planned_end'])."</p>\n";
 229                      unset($ds['ignore_planned_end']);
 230                  }
 231              }
 232              // setting real or planned start- or end-date, from each other if not set
 233              foreach(array('start','end') as $name)
 234              {
 235                  if ((!isset($ds['pe_real_'.$name]) || $ds['ignore_real_'.$name]) && isset($ds['pe_planned_'.$name]) /*&&
 236                  // setting the real dates only if the completion is more then 0% (if supported by the datasource)
 237                      (!isset($ds['pe_completion']) || $ds['pe_completion'] > 0)*/)
 238                  {
 239                      $ds['pe_real_'.$name] = $ds['pe_planned_'.$name];
 240                  }
 241                  elseif (!isset($ds['pe_planned_'.$name]) && isset($ds['pe_real_'.$name]))
 242                  {
 243                      $ds['pe_planned_'.$name] = $ds['pe_real_'.$name];
 244                  }
 245              }
 246              // try calculating a (second) completion from the times
 247              if (!empty($ds['pe_used_time']) && (int) $ds['pe_planned_time'] > 0)
 248              {
 249                  $compl_by_time = $ds['pe_used_time'] / $ds['pe_planned_time'];
 250  
 251                  // if no completion is given by the datasource use the calculated one
 252                  if (!isset($ds['pe_completion']))
 253                  {
 254                      $ds['pe_completion'] = $compl_by_time;
 255                  }
 256                  elseif ($compl_by_time < $ds['pe_completion'])
 257                  {
 258                      $ds['warning']['completion_by_time'] = $compl_by_time;
 259                  }
 260              }
 261              // try calculating a (second) completion from the budget
 262              if(!empty($ds['pe_used_budget']) && $ds['pe_planned_budget'] > 0)
 263              {
 264                  $compl_by_budget = $ds['pe_used_budget'] / $ds['pe_planned_budget'];
 265              
 266                  // if no completion is given by the datasource use the calculated one
 267                  if (!isset($ds['pe_completion']))
 268                  {
 269                      $ds['pe_completion'] = $compl_by_budget;
 270                  }
 271                  elseif ($compl_by_budget < $ds['pe_completion'])
 272                  {
 273                      $ds['warning']['completion_by_budget'] = $compl_by_budget;
 274                  }
 275              }
 276              // setting quantity from time, if not given by the ds
 277              foreach(array(
 278                  'pe_planned_time' => 'pe_planned_quantity',
 279                  'pe_used_time'    => 'pe_used_quantity',
 280              ) as $time => $quantity)
 281              {
 282                  if (!isset($ds[$quantity]) && isset($ds[$time]))
 283                  {
 284                      $ds[$quantity] = $ds[$time] / 60.0;    // time is in min, quantity in h
 285                  }
 286              }
 287              // setting the budget from unitprice and quantity
 288              if (isset($ds['pe_unitprice']))
 289              {
 290                  foreach(array(
 291                      'pe_planned_quantity' => 'pe_planned_budget',
 292                      'pe_used_quantity'    => 'pe_used_budget',
 293                  ) as $quantity => $budget)
 294                  {
 295                      if (!isset($ds[$budget]) && isset($ds[$quantity]))
 296                      {
 297                          $ds[$budget] = $ds[$quantity] * $ds['pe_unitprice'];
 298                      }
 299                  }
 300              }
 301                  
 302          }
 303          return $ds;
 304      }
 305      
 306      /**
 307       * reading the not-overwritten values from the element-data
 308       *
 309       * Can be used instead of read, if there's no read-access to the datasource itself
 310       *
 311       * @param array $data element data
 312       * @return array
 313       */
 314  	function element_values($data)
 315      {
 316          $values = array();
 317  
 318          foreach($this->name2id as $name => $id)
 319          {
 320              if (!($data['pe_overwrite'] & $id))
 321              {
 322                  $values[$name] = $data[$name];
 323              }
 324          }
 325          return $values;
 326      }
 327  }


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