2006-01-11 06:12:18 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DataSource for the Calendar
|
|
|
|
*
|
2008-06-07 19:45:33 +02:00
|
|
|
* @link http://www.egroupware.org
|
2006-01-11 06:12:18 +01:00
|
|
|
* @package calendar
|
|
|
|
* @author RalfBecker-AT-outdoor-training.de
|
2008-06-07 19:45:33 +02:00
|
|
|
* @copyright (c) 2005-8 by RalfBecker-AT-outdoor-training.de
|
2006-01-11 06:12:18 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-06-07 19:45:33 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.datasource.inc.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataSource for the Calendar
|
2006-01-11 06:12:18 +01:00
|
|
|
*/
|
2008-06-07 19:45:33 +02:00
|
|
|
class calendar_datasource extends datasource
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2008-06-07 19:45:33 +02:00
|
|
|
function __construct()
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
|
|
|
$this->datasource('calendar');
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2012-06-19 18:51:41 +02:00
|
|
|
$this->valid = PM_PLANNED_START|PM_PLANNED_END|PM_PLANNED_TIME|PM_RESOURCES|PM_CAT_ID;
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +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-06-07 19:45:33 +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)
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
// we use $cal as an already running instance is availible there
|
|
|
|
if (!is_object($GLOBALS['calendar_bo']))
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$GLOBALS['calendar_bo'] = new calendar_bo();
|
2006-01-11 06:12:18 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
$cal = $GLOBALS['calendar_bo'];
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
if (!is_array($data_id))
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
if (!(int) $data_id || !($data = $cal->read((int) $data_id)))
|
2006-01-11 06:12:18 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$data =& $data_id;
|
|
|
|
}
|
|
|
|
$ds = array(
|
2008-06-07 19:45:33 +02:00
|
|
|
'pe_title' => $cal->link_title($data),
|
|
|
|
'pe_planned_start' => $cal->date2ts($data['start']),
|
|
|
|
'pe_planned_end' => $cal->date2ts($data['end']),
|
2006-01-11 06:12:18 +01:00
|
|
|
'pe_resources' => array(),
|
|
|
|
'pe_details' => $data['description'] ? nl2br($data['description']) : '',
|
|
|
|
);
|
2012-06-19 18:51:41 +02:00
|
|
|
// return first global category, as PM only supports one
|
|
|
|
foreach($data['category'] ? explode(',', $data['category']) : array() as $cat_id)
|
|
|
|
{
|
|
|
|
if (categories::is_global($cat_id))
|
|
|
|
{
|
|
|
|
$ds['cat_id'] = $cat_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-04-08 08:20:48 +02:00
|
|
|
// calculation of the time
|
2006-01-11 06:12:18 +01:00
|
|
|
$ds['pe_planned_time'] = (int) (($ds['pe_planned_end'] - $ds['pe_planned_start'])/60); // time is in minutes
|
|
|
|
|
2006-04-08 08:20:48 +02:00
|
|
|
// if the event spans multiple days, we have to substract the nights (24h - daily working time specified in PM)
|
|
|
|
if (date('Y-m-d',$ds['pe_planned_end']) != date('Y-m-d',$ds['pe_planned_start']))
|
|
|
|
{
|
|
|
|
foreach(array('start','end') as $name)
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$$name = $cal->date2array($ds['pe_planned_'.$name]);
|
2006-04-08 08:20:48 +02:00
|
|
|
${$name}['hour'] = 12;
|
|
|
|
${$name}['minute'] = ${$name}['second'] = 0;
|
|
|
|
unset(${$name}['raw']);
|
2008-06-07 19:45:33 +02:00
|
|
|
$$name = $cal->date2ts($$name);
|
2006-04-08 08:20:48 +02:00
|
|
|
}
|
|
|
|
$nights = round(($end - $start) / DAY_s);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2006-04-08 08:20:48 +02:00
|
|
|
if (!is_array($this->pm_config))
|
|
|
|
{
|
|
|
|
$c =& CreateObject('phpgwapi.config','projectmanager');
|
|
|
|
$c->read_repository();
|
|
|
|
$this->pm_config = $c->config_data;
|
|
|
|
unset($c);
|
|
|
|
if (!$this->pm_config['hours_per_workday']) $this->pm_config['hours_per_workday'] = 8;
|
|
|
|
}
|
|
|
|
$ds['pe_planned_time'] -= $nights * 60 * (24 - $this->pm_config['hours_per_workday']);
|
|
|
|
}
|
2006-01-11 06:12:18 +01:00
|
|
|
foreach($data['participants'] as $uid => $status)
|
|
|
|
{
|
|
|
|
if ($status != 'R' && is_numeric($uid)) // only users for now
|
|
|
|
{
|
|
|
|
$ds['pe_resources'][] = $uid;
|
|
|
|
}
|
|
|
|
}
|
2006-04-08 08:20:48 +02:00
|
|
|
// if we have multiple participants we have to multiply the time by the number of participants to get the total time
|
|
|
|
$ds['pe_planned_time'] *= count($ds['pe_resources']);
|
|
|
|
|
2006-01-11 06:12:18 +01:00
|
|
|
/*
|
2008-06-07 19:45:33 +02:00
|
|
|
// ToDO: this does not change automatically after the event is over,
|
2006-01-11 06:12:18 +01:00
|
|
|
// maybe we need a flag for that in egw_pm_elements
|
|
|
|
if ($data['end']['raw'] <= time()+$GLOBALS['egw']->datetime->tz_offset)
|
|
|
|
{
|
|
|
|
$ds['pe_used_time'] = $ds['pe_planned_time'];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "datasource_calendar($data_id) data="; _debug_array($data);
|
|
|
|
echo "datasource="; _debug_array($ds);
|
|
|
|
}
|
|
|
|
return $ds;
|
|
|
|
}
|
|
|
|
}
|