2006-01-11 06:12:18 +01:00
|
|
|
<?php
|
2007-05-22 15:40:35 +02:00
|
|
|
/**
|
|
|
|
* InfoLog - Datasource for ProjektManager
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package infolog
|
|
|
|
* @subpackage projectmanager
|
2016-04-30 19:05:23 +02:00
|
|
|
* @copyright (c) 2005-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-05-22 15:40:35 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2006-01-11 06:12:18 +01:00
|
|
|
|
2016-06-28 19:06:31 +02:00
|
|
|
use EGroupware\Api;
|
2016-04-30 19:05:23 +02:00
|
|
|
use EGroupware\Api\Link;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
include_once(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.datasource.inc.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataSource for InfoLog
|
|
|
|
*
|
2008-10-07 14:50:14 +02:00
|
|
|
* The InfoLog datasource set's only real start- and endtimes, plus planned and used time and
|
2006-01-11 06:12:18 +01:00
|
|
|
* the responsible user as resources (not always the owner too!).
|
|
|
|
* The read method of the extended datasource class sets the planned start- and endtime:
|
|
|
|
* - planned start from the end of a start constrain
|
|
|
|
* - planned end from the planned time and a start-time
|
|
|
|
* - planned start and end from the "real" values
|
|
|
|
*/
|
2008-10-07 14:50:14 +02:00
|
|
|
class infolog_datasource extends datasource
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
2007-10-05 17:06:27 +02:00
|
|
|
/**
|
2008-10-07 14:50:14 +02:00
|
|
|
* Reference to infolog_bo
|
2007-10-05 17:06:27 +02:00
|
|
|
*
|
2008-10-07 14:50:14 +02:00
|
|
|
* @var infolog_bo
|
2007-10-05 17:06:27 +02:00
|
|
|
*/
|
2008-10-07 14:50:14 +02:00
|
|
|
var $infolog_bo;
|
2007-10-05 17:06:27 +02:00
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2008-10-07 19:16:24 +02:00
|
|
|
function __construct()
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
2008-10-07 19:16:24 +02:00
|
|
|
parent::__construct('infolog');
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2012-06-19 18:51:41 +02:00
|
|
|
$this->valid = PM_COMPLETION|PM_PLANNED_START|PM_PLANNED_END|PM_REAL_END|PM_PLANNED_TIME|PM_REPLANNED_TIME|PM_USED_TIME|PM_RESOURCES|PM_CAT_ID;
|
2007-10-05 17:06:27 +02:00
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
// we use $GLOBALS['infolog_bo'] as an already running instance might be availible there
|
|
|
|
if (!is_object($GLOBALS['infolog_bo']))
|
2007-10-05 17:06:27 +02:00
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$GLOBALS['infolog_bo'] = new infolog_bo();
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->infolog_bo =& $GLOBALS['infolog_bo'];
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
/**
|
|
|
|
* get an entry from the underlaying app (if not given) and convert it into a datasource array
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2006-01-11 06:12:18 +01:00
|
|
|
* @param mixed $data_id id as used in the link-class for that app, or complete entry as array
|
|
|
|
* @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
|
|
|
|
*/
|
|
|
|
function get($data_id)
|
|
|
|
{
|
|
|
|
if (!is_array($data_id))
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$data =& $this->infolog_bo->read((int) $data_id);
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
if (!is_array($data)) return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$data =& $data_id;
|
|
|
|
}
|
2017-01-11 23:48:10 +01:00
|
|
|
$status = null;
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
return array(
|
2008-10-07 14:50:14 +02:00
|
|
|
'pe_title' => $this->infolog_bo->link_title($data),
|
2017-01-11 23:48:10 +01:00
|
|
|
'pe_status' => $data['info_status'],
|
2006-03-17 21:53:26 +01:00
|
|
|
'pe_completion' => $data['info_percent'],
|
|
|
|
'pe_planned_start'=> $data['info_startdate'] ? $data['info_startdate'] : null,
|
|
|
|
'pe_planned_end' => $data['info_enddate'] ? $data['info_enddate'] : null,
|
|
|
|
'pe_real_end' => $data['info_datecompleted'] ? $data['info_datecompleted'] : null,
|
2006-01-11 06:12:18 +01:00
|
|
|
'pe_planned_time' => $data['info_planned_time'],
|
2008-10-07 10:40:46 +02:00
|
|
|
'pe_replanned_time' => $data['info_replanned_time'],
|
2006-01-11 06:12:18 +01:00
|
|
|
'pe_used_time' => $data['info_used_time'],
|
|
|
|
'pe_resources' => count($data['info_responsible']) ? $data['info_responsible'] : array($data['info_owner']),
|
|
|
|
'pe_details' => $data['info_des'] ? nl2br($data['info_des']) : '',
|
2006-02-04 08:49:47 +01:00
|
|
|
'pl_id' => $data['pl_id'],
|
|
|
|
'pe_unitprice' => $data['info_price'],
|
|
|
|
'pe_planned_quantity' => $data['info_planned_time'] / 60,
|
|
|
|
'pe_planned_budget' => $data['info_planned_time'] / 60 * $data['info_price'],
|
|
|
|
'pe_used_quantity' => $data['info_used_time'] / 60,
|
|
|
|
'pe_used_budget' => $data['info_used_time'] / 60 * $data['info_price'],
|
2012-06-19 18:51:41 +02:00
|
|
|
'cat_id' => $data['info_cat'],
|
2006-01-11 06:12:18 +01:00
|
|
|
);
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
/**
|
|
|
|
* Copy the datasource of a projectelement (InfoLog entry) and re-link it with project $target
|
|
|
|
*
|
|
|
|
* @param array $element source project element representing an InfoLog entry, $element['pe_app_id'] = info_id
|
|
|
|
* @param int $target target project id
|
2016-04-30 19:05:23 +02:00
|
|
|
* @param array $extra =null data of target-project, atm not used by the infolog datasource
|
2016-06-28 19:06:31 +02:00
|
|
|
* @param DateInterval[] $date_offsets = Array() - When copying, a list of date fields
|
|
|
|
* and the amount to offset them from the original while copying
|
2006-01-11 06:12:18 +01:00
|
|
|
* @return array/boolean array(info_id,link_id) on success, false otherwise
|
|
|
|
*/
|
2016-06-28 19:06:31 +02:00
|
|
|
function copy($element,$target,$extra=null,$date_offsets = Array())
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
unset($extra); // not used, but required by function signature
|
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
$info =& $this->infolog_bo->read((int) $element['pe_app_id']);
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
if (!is_array($info)) return false;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
// unsetting info_link_id and evtl. info_from
|
|
|
|
if ($info['info_link_id'])
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->infolog_bo->link_id2from($info); // unsets info_from and sets info_link_target
|
2006-01-11 06:12:18 +01:00
|
|
|
unset($info['info_link_id']);
|
2016-12-15 18:24:14 +01:00
|
|
|
unset($info['info_contact']);
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
|
|
|
// we need to unset a view fields, to get a new entry
|
|
|
|
foreach(array('info_id','info_owner','info_modified','info_modifierer') as $key)
|
|
|
|
{
|
|
|
|
unset($info[$key]);
|
|
|
|
}
|
2016-06-28 19:06:31 +02:00
|
|
|
|
|
|
|
// Apply date offsets, if any
|
2016-07-20 21:04:57 +02:00
|
|
|
$map = array(
|
|
|
|
'planned_start' => 'info_startdate',
|
|
|
|
'planned_end' => 'info_enddate',
|
|
|
|
'real_start' => 'info_startdate',
|
|
|
|
'real_end' => 'info_datecompleted'
|
|
|
|
);
|
2016-09-20 17:05:46 +02:00
|
|
|
|
|
|
|
$startdate_original = $info['info_startdate'];
|
2016-06-28 19:06:31 +02:00
|
|
|
foreach($map as $offset_field => $info_field)
|
|
|
|
{
|
|
|
|
if($date_offsets[$offset_field] && $info[$info_field])
|
|
|
|
{
|
2016-09-20 17:05:46 +02:00
|
|
|
// Don't move startdate twice, but prefer later value
|
|
|
|
if($startdate_original && $info_field == 'info_startdate')
|
|
|
|
{
|
|
|
|
$info[$info_field] = $startdate_original;
|
|
|
|
}
|
2016-06-28 19:06:31 +02:00
|
|
|
//error_log($offset_field . ' ' . Api\DateTime::to($info[$info_field]) . ' ' . $date_offsets[$offset_field]->format('%R%a days') . ' ' . date_add(new Api\DateTime($info[$info_field]), $date_offsets[$offset_field]) );
|
|
|
|
|
|
|
|
$info[$info_field] = date_add(new Api\DateTime($info[$info_field]), $date_offsets[$offset_field])->format('ts');
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 22:56:39 +02:00
|
|
|
// Sanity check - not due or ended before it starts
|
|
|
|
if($info['info_startdate'] && $info['info_enddate'] && $info['info_startdate'] > $info['info_enddate'])
|
|
|
|
{
|
|
|
|
unset($info['info_enddate']);
|
|
|
|
}
|
|
|
|
if($info['info_startdate'] && $info['info_datecompleted'] && $info['info_startdate'] > $info['info_datecompleted'])
|
|
|
|
{
|
|
|
|
unset($info['info_datecompleted']);
|
|
|
|
}
|
2016-06-28 19:06:31 +02:00
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
if(!($info['info_id'] = $this->infolog_bo->write($info))) return false;
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
// link the new infolog against the project and setting info_link_id and evtl. info_from
|
2016-12-15 18:24:14 +01:00
|
|
|
$old_link = $info['info_link_id'] ? Link::get_link($info['info_link_id']) : $info['info_link'];
|
2016-04-30 19:05:23 +02:00
|
|
|
$info['info_link_id'] = Link::link('projectmanager',$target,'infolog',$info['info_id'],$element['pe_remark'],0,0,1);
|
2015-07-22 17:37:05 +02:00
|
|
|
if (!$info['info_from'] || $old_link && $info['info_from'] == $old_link['title'])
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
$info['info_from'] = Link::title('projectmanager',$target);
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
|
|
|
if ($info['info_status'] == 'template')
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$info['info_status'] = $this->infolog_bo->activate($info);
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->infolog_bo->write($info);
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
// creating again all links, beside the one to the source-project
|
2016-04-30 19:05:23 +02:00
|
|
|
foreach(Link::get_links('infolog',$element['pe_app_id']) as $link)
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
|
|
|
if ($link['app'] == 'projectmanager' && $link['id'] == $element['pm_id'] || // ignoring the source project
|
2016-04-30 19:05:23 +02:00
|
|
|
$link['app'] == Link::VFS_APPNAME) // ignoring files attachments for now
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-30 19:05:23 +02:00
|
|
|
Link::link('infolog',$info['info_id'],$link['app'],$link['id'],$link['remark']);
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2010-09-07 17:45:47 +02:00
|
|
|
$ret = array($info['info_id'],$info['info_link_id']);
|
|
|
|
|
|
|
|
// if we have a parent set, return our callback to modify the parent id, after all entries are copied
|
|
|
|
if ($info['info_id_parent'])
|
|
|
|
{
|
|
|
|
$ret[] = array($this,'copy_callback'); // callback
|
|
|
|
$ret[] = array($info['info_id'],$info['info_id_parent']); // $param
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
2012-06-19 18:51:41 +02:00
|
|
|
|
2010-09-07 17:45:47 +02:00
|
|
|
/**
|
|
|
|
* Callback called after copying of all datasource, used to:
|
|
|
|
* - fix parent id's
|
|
|
|
*
|
|
|
|
* @param array $param array($info_id,$info_id_parent)
|
|
|
|
* @param array $apps_copied array('infolog' => array($old_info_id => $new_info_id))
|
|
|
|
*/
|
|
|
|
public function copy_callback(array $param, array $apps_copied)
|
|
|
|
{
|
|
|
|
//error_log(__METHOD__."(".array2string($param).', '.array2string($apps_copied).')');
|
|
|
|
list($info_id,$parent_id) = $param;
|
|
|
|
if (isset($apps_copied['infolog'][$parent_id]) && ($info = $this->infolog_bo->read($info_id)))
|
|
|
|
{
|
|
|
|
$info['info_id_parent'] = $apps_copied['infolog'][$parent_id];
|
|
|
|
$this->infolog_bo->write($info,false,true,true,true); // no default and no notification
|
|
|
|
}
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-10-05 17:06:27 +02:00
|
|
|
/**
|
|
|
|
* Delete the datasource of a project element
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return boolean true on success, false on error
|
|
|
|
*/
|
|
|
|
function delete($id)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
if (!is_object($GLOBALS['infolog_bo']))
|
2007-10-05 17:06:27 +02:00
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
include_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.infolog_bo.inc.php');
|
2009-06-08 18:21:14 +02:00
|
|
|
$GLOBALS['infolog_bo'] = new infolog_bo();
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
2007-10-30 17:18:12 +01:00
|
|
|
// dont delete infolog, which are linked to other elements, but their project
|
2016-04-30 19:05:23 +02:00
|
|
|
if (count(Link::get_links('infolog',$id)) > 1)
|
2007-10-30 17:18:12 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
return $this->infolog_bo->delete($id);
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-10-05 17:06:27 +02:00
|
|
|
/**
|
|
|
|
* Change the status of an infolog entry according to the project status
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @param string $status
|
|
|
|
* @return boolean true if status changed, false otherwise
|
|
|
|
*/
|
|
|
|
function change_status($id,$status)
|
|
|
|
{
|
|
|
|
//error_log("datasource_infolog::change_status($id,$status)");
|
2017-01-06 18:43:16 +01:00
|
|
|
if (($info = $this->infolog_bo->read($id)) && (
|
|
|
|
$this->infolog_bo->check_access($info,Acl::EDIT) ||
|
|
|
|
$info['info_status'] == 'deleted' && $this->infolog_bo->check_access($info, infolog_bo::ACL_UNDELETE)
|
|
|
|
))
|
2007-10-05 17:06:27 +02:00
|
|
|
{
|
2017-01-06 18:43:16 +01:00
|
|
|
if ($status == 'active' && in_array($info['info_status'],array('template','nonactive','archive','deleted')))
|
2007-10-05 17:06:27 +02:00
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$status = $this->infolog_bo->activate($info);
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
if($info['info_status'] != $status && isset($this->infolog_bo->status[$info['info_type']][$status]))
|
2007-10-05 17:06:27 +02:00
|
|
|
{
|
|
|
|
//error_log("datasource_infolog::change_status($id,$status) setting status from ".$info['info_status']);
|
|
|
|
$info['info_status'] = $status;
|
2008-10-07 14:50:14 +02:00
|
|
|
return $this->infolog_bo->write($info) !== false;
|
2007-10-05 17:06:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|