2010-02-12 21:18:45 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Calendar - history and notifications
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @package calendar
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2011-08-04 16:00:15 +02:00
|
|
|
* @version $Id$
|
2010-02-12 21:18:45 +01:00
|
|
|
*/
|
|
|
|
|
2016-05-01 19:47:59 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2010-02-12 21:18:45 +01:00
|
|
|
/**
|
|
|
|
* Calendar - tracking object
|
|
|
|
*/
|
2016-05-01 19:47:59 +02:00
|
|
|
class calendar_tracking extends Api\Storage\Tracking
|
2010-02-12 21:18:45 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Application we are tracking (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $app = 'calendar';
|
|
|
|
/**
|
|
|
|
* Name of the id-field, used as id in the history log (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $id_field = 'id';
|
|
|
|
/**
|
|
|
|
* Name of the field with the creator id, if the creator of an entry should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $creator_field = 'creator';
|
|
|
|
/**
|
|
|
|
* Name of the field with the id(s) of assinged users, if they should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $assigned_field;
|
|
|
|
/**
|
|
|
|
* Translate field-name to 2-char history status
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $field2history = array(
|
|
|
|
'owner' => 'owner',
|
|
|
|
'category' => 'category',
|
|
|
|
'priority' => 'priority',
|
|
|
|
'public' => 'public',
|
|
|
|
'title' => 'title',
|
|
|
|
'description' => 'description',
|
|
|
|
'location' => 'location',
|
|
|
|
'reference' => 'reference',
|
|
|
|
'non_blocking' => 'non_blocking',
|
|
|
|
'special' => 'special',
|
|
|
|
'recurrence' => 'recurrence',
|
2016-04-26 18:41:22 +02:00
|
|
|
'recur_enddate' => 'recur_enddate',
|
2010-02-12 21:18:45 +01:00
|
|
|
'tz_id' => 'tz_id',
|
|
|
|
|
|
|
|
'start' => 'start',
|
|
|
|
'end' => 'end',
|
2015-05-26 20:34:03 +02:00
|
|
|
'deleted' => 'deleted',
|
2011-04-20 08:22:29 +02:00
|
|
|
|
2010-02-12 21:18:45 +01:00
|
|
|
'participants' => array('user_id', 'status', 'role', 'recur'),
|
|
|
|
'participants-c' => array('user_id', 'status', 'quantity', 'role', 'recur'),
|
2011-08-04 16:00:15 +02:00
|
|
|
'participants-r' => array('user_id', 'status', 'quantity', 'role', 'recur'),
|
2011-04-20 08:22:29 +02:00
|
|
|
|
2010-02-12 21:18:45 +01:00
|
|
|
// Custom fields added in constructor
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2011-08-04 16:00:15 +02:00
|
|
|
* Translate field name to label
|
|
|
|
*/
|
2010-02-12 21:18:45 +01:00
|
|
|
public $field2label = array(
|
|
|
|
'owner' => 'owner',
|
|
|
|
'category' => 'category',
|
|
|
|
'priority' => 'priority',
|
|
|
|
'public' => 'public',
|
|
|
|
'title' => 'title',
|
|
|
|
'description' => 'description',
|
|
|
|
'location' => 'location',
|
|
|
|
'reference' => 'reference',
|
|
|
|
'non_blocking' => 'non blocking',
|
|
|
|
'special' => 'special',
|
2011-08-04 16:00:15 +02:00
|
|
|
'recurrence'=> 'recurrence',
|
2016-04-26 18:41:22 +02:00
|
|
|
'recur_enddate' => 'recurrence enddate',
|
2011-08-04 16:00:15 +02:00
|
|
|
'tz_id' => 'timezone',
|
2010-02-12 21:18:45 +01:00
|
|
|
|
|
|
|
'start' => 'start',
|
|
|
|
'end' => 'end',
|
2015-05-26 20:34:03 +02:00
|
|
|
'deleted' => 'deleted',
|
2011-04-20 08:22:29 +02:00
|
|
|
|
2010-02-12 21:18:45 +01:00
|
|
|
'participants' => 'Participants: User, Status, Role',
|
2011-08-04 16:00:15 +02:00
|
|
|
'participants-c'=> 'Participants: User, Status, Quantity, Role',
|
|
|
|
'participants-r'=> 'Participants: Resource, Status, Quantity',
|
2010-02-12 21:18:45 +01:00
|
|
|
|
|
|
|
// Custom fields added in constructor
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should the user (passed to the track method or current user if not passed) be used as sender or get_config('sender')
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $prefer_user_as_sender = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param calendar_bo &$calendar_bo
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2011-04-20 08:22:29 +02:00
|
|
|
parent::__construct('calendar'); // adds custom fields
|
2010-02-12 21:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-04 16:00:15 +02:00
|
|
|
* Tracks the changes in one entry $data, by comparing it with the last version in $old
|
|
|
|
* Overrides parent to reformat participants into a format parent can handle
|
|
|
|
*/
|
2021-04-06 15:32:21 +02:00
|
|
|
public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null, $skip_notification = false)
|
2011-08-04 16:00:15 +02:00
|
|
|
{
|
2011-04-20 08:22:29 +02:00
|
|
|
// Don't try to track dates on recurring events.
|
2010-02-12 21:18:45 +01:00
|
|
|
// It won't change for the base event, and any change to the time creates an exception
|
2024-02-08 10:24:39 +01:00
|
|
|
if(!empty($data['recur_type']))
|
2011-08-04 16:00:15 +02:00
|
|
|
{
|
2010-02-12 21:18:45 +01:00
|
|
|
unset($data['start']); unset($data['end']);
|
|
|
|
unset($old['start']); unset($old['end']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do some magic with the participants and recurrance.
|
|
|
|
* If this is one of a recurring event, append the recur_date to the participant field so we can
|
2011-04-20 08:22:29 +02:00
|
|
|
* filter by it later.
|
2010-02-12 21:18:45 +01:00
|
|
|
*/
|
2011-08-04 16:00:15 +02:00
|
|
|
if(is_array($data['participants']))
|
|
|
|
{
|
2010-02-12 21:18:45 +01:00
|
|
|
$participants = $data['participants'];
|
|
|
|
$data['participants'] = array();
|
2015-09-22 19:26:36 +02:00
|
|
|
$data = array_merge($data, $this->alter_participants($participants));
|
2010-02-12 21:18:45 +01:00
|
|
|
}
|
2015-06-25 22:32:22 +02:00
|
|
|
// if clients eg. CalDAV do NOT set participants, they are left untouched
|
|
|
|
// therefore we should not track them, as all updates then show up as all participants removed
|
|
|
|
elseif(!isset($data['participants']))
|
|
|
|
{
|
|
|
|
unset($old['participants']);
|
|
|
|
}
|
2023-06-09 18:27:28 +02:00
|
|
|
if(isset($old['participants']) && is_array($old['participants']))
|
2011-08-04 16:00:15 +02:00
|
|
|
{
|
2010-02-12 21:18:45 +01:00
|
|
|
$participants = $old['participants'];
|
|
|
|
$old['participants'] = array();
|
2015-09-22 19:26:36 +02:00
|
|
|
$old = array_merge($old, $this->alter_participants($participants));
|
2010-02-12 21:18:45 +01:00
|
|
|
}
|
2018-11-27 19:01:11 +01:00
|
|
|
// Make sure dates are timestamps
|
|
|
|
foreach(array('start','end') as $date)
|
|
|
|
{
|
|
|
|
if(is_object($data[$date]) && is_a($data[$date], 'DateTime'))
|
|
|
|
{
|
|
|
|
$data[$date] = $data[$date]->format('ts');
|
|
|
|
}
|
|
|
|
}
|
2021-04-06 15:32:21 +02:00
|
|
|
parent::track($data,$old,$user,$deleted, $changed_fields, $skip_notification);
|
2010-02-12 21:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-04 16:00:15 +02:00
|
|
|
* Overrides parent because calendar_boupdates handles the notifications
|
|
|
|
*/
|
2021-04-06 15:32:21 +02:00
|
|
|
public function do_notifications($data,$old,$deleted=null, &$email_notified = null)
|
2011-08-04 16:00:15 +02:00
|
|
|
{
|
2015-06-25 22:32:22 +02:00
|
|
|
unset($data, $old, $deleted); // unused, but required by function signature
|
2010-02-12 21:18:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-22 19:26:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute changes between new and old data
|
|
|
|
*
|
|
|
|
* Can be used to check if saving the data is really necessary or user just pressed save
|
|
|
|
* Overridden to handle various participants options
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param array $old = null
|
|
|
|
* @return array of keys with different values in $data and $old
|
|
|
|
*/
|
|
|
|
public function changed_fields(array $data,array $old=null)
|
|
|
|
{
|
|
|
|
if(is_array($data['participants']))
|
|
|
|
{
|
|
|
|
$participants = $data['participants'];
|
|
|
|
$data['participants'] = array();
|
|
|
|
$data = array_merge($data, $this->alter_participants($participants));
|
|
|
|
}
|
|
|
|
if(is_array($old['participants']))
|
|
|
|
{
|
|
|
|
$participants = $old['participants'];
|
|
|
|
$old['participants'] = array();
|
|
|
|
$old = array_merge($old, $this->alter_participants($participants));
|
|
|
|
}
|
|
|
|
return parent::changed_fields($data,$old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do some magic with the participants and recurrance.
|
|
|
|
* If this is one of a recurring event, append the recur_date to the participant field so we can
|
|
|
|
* filter by it later.
|
|
|
|
*/
|
|
|
|
protected function alter_participants($participants)
|
|
|
|
{
|
|
|
|
$data = array();
|
|
|
|
foreach($participants as $uid => $status)
|
|
|
|
{
|
|
|
|
$quantity = $role = $user_type = $user_id = null;
|
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
|
|
|
calendar_so::split_user($uid, $user_type, $user_id);
|
|
|
|
$field = is_numeric($uid) ? 'participants' : 'participants-'.$user_type;
|
|
|
|
$data[$field][] = array(
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'status' => $status,
|
|
|
|
'quantity' => $quantity,
|
|
|
|
'role' => $role,
|
2023-06-09 18:27:28 +02:00
|
|
|
'recur' => $data['recur_date'] ?? 0,
|
2015-09-22 19:26:36 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2023-06-09 18:27:28 +02:00
|
|
|
}
|