forked from extern/egroupware
Add ability to create calendar entries from infolog entries, using new base so other apps can be added (hopefully) easily later
This commit is contained in:
parent
d4cda9a91a
commit
332427277d
@ -661,6 +661,62 @@ class calendar_hooks
|
||||
public static function config_validate() {
|
||||
$GLOBALS['egw_info']['server']['found_validation_hook'] = True;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from a different app entry to this application
|
||||
*
|
||||
* @see phpgwapi/inc/class.transmogrify.inc.php
|
||||
*/
|
||||
public static function convert($data) {
|
||||
$mapping['infolog'] = array(
|
||||
'info_owner' => 'owner',
|
||||
'info_cat' => 'category',
|
||||
'info_priority' => 'priority',
|
||||
'info_access' => 'public',
|
||||
'info_subject' => 'title',
|
||||
'info_des' => 'description',
|
||||
'info_location' => 'location',
|
||||
'info_startdate' => 'start',
|
||||
'info_datecompleted' => 'end',
|
||||
);
|
||||
|
||||
// Check for support
|
||||
if(!$data['from']) return array_keys($mapping); // Get list of supported apps
|
||||
if(!in_array($data['from'], array_keys($mapping))) return false;
|
||||
|
||||
transmogrify::check($data['to'], $data['from'], $data['data'], $mapping[$data['from']]);
|
||||
|
||||
foreach($mapping[$data['from']] as $from => $to)
|
||||
{
|
||||
$result[$to] = $data['data'][$from];
|
||||
}
|
||||
|
||||
// Add user to participants, or it won't show up
|
||||
$result['participants'][calendar_so::combine_user('u',$result['owner'])] = calendar_so::combine_status(NO_RESPONSE);
|
||||
|
||||
switch($data['from'])
|
||||
{
|
||||
case 'infolog':
|
||||
$result['public'] = $result['public'] != 'private';
|
||||
// Add responsible as participant
|
||||
foreach($data['data']['info_responsible'] as $responsible) {
|
||||
$result['participants'][calendar_so::combine_user('u',$responsible)] = calendar_so::combine_status('U');
|
||||
}
|
||||
// Add linked contact as participant
|
||||
if($data['data']['info_link']['app'] == 'addressbook')
|
||||
{
|
||||
$result['participants'][calendar_so::combine_user('c',$data['data']['info_link']['id'])] = calendar_so::combine_status('U');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($result)
|
||||
{
|
||||
$bo = new calendar_boupdate();
|
||||
$id = $bo->save($result);
|
||||
}
|
||||
return $id ? $id : $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Not part of the class, since config hooks are still using the old style
|
||||
|
@ -44,6 +44,7 @@ $setup_info['calendar']['hooks']['search_link'] = 'calendar_hooks::search_link';
|
||||
$setup_info['calendar']['hooks']['config_validate'] = 'calendar_hooks::config_validate';
|
||||
$setup_info['calendar']['hooks']['timesheet_set'] = 'calendar.calendar_bo.timesheet_set';
|
||||
$setup_info['calendar']['hooks']['export_limit'] = 'calendar_hooks::getAppExportLimit';
|
||||
$setup_info['calendar']['hooks']['convert'] = 'calendar_hooks::convert';
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['calendar']['depends'][] = array(
|
||||
|
@ -945,6 +945,15 @@ class infolog_ui
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
if ($GLOBALS['egw_info']['user']['apps']['calendar'])
|
||||
{
|
||||
$actions['calendar'] = array( // interactive add for a single event
|
||||
'icon' => 'calendar/navbar',
|
||||
'caption' => 'Calendar',
|
||||
'group' => $group,
|
||||
'allowOnMultiple' => false,
|
||||
);
|
||||
}
|
||||
if ($GLOBALS['egw_info']['user']['apps']['timesheet'])
|
||||
{
|
||||
$actions['timesheet'] = array( // interactive add for a single event
|
||||
@ -1094,6 +1103,18 @@ class infolog_ui
|
||||
}
|
||||
switch($action)
|
||||
{
|
||||
case 'calendar':
|
||||
$action_msg = lang('copied to %1', lang('calendar'));
|
||||
$cal_id = transmogrify::convert($entry, 'calendar', 'infolog', $id);
|
||||
if($cal_id)
|
||||
{
|
||||
$success++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$failed++;
|
||||
}
|
||||
break;
|
||||
case 'close':
|
||||
$action_msg = lang('closed');
|
||||
$this->close($id, '', false, $skip_notifications);
|
||||
|
124
phpgwapi/inc/class.transmogrify.inc.php
Normal file
124
phpgwapi/inc/class.transmogrify.inc.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Base clase for changing or copying one record type (eg Infolog) into another (eg Calendar)
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Nathan Gray
|
||||
* @package phpgwapi
|
||||
* @copyright (c) 2011 Nathan Gray
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transmogrify: to completely alter the form of
|
||||
* For changing an entry from one application (in array form) into another.
|
||||
*
|
||||
* Uses hooks so other apps can specify how the conversion process is to happen from other applications,
|
||||
* so this class is mostly support functions. In the future, it may support customization of the
|
||||
* field mapping between applications but right now mappings between different fields are provided by the destination
|
||||
* application.
|
||||
*
|
||||
* Hook parameters:
|
||||
* 'location' => 'convert', // Required by hook system
|
||||
* 'from' => Original application. If omitted, hook function should return a list of supported applications.
|
||||
* 'data' => Data from original application. If omitted, return false.
|
||||
* The hook should return the ID for the newly created entry.
|
||||
*
|
||||
* For ease of use & reduction of duplication, hook functions can call transmogrify::check() as a 'parent' function.
|
||||
*/
|
||||
class transmogrify
|
||||
{
|
||||
|
||||
/**
|
||||
* Checks to see if the conversion can happen
|
||||
*
|
||||
* @param from String appname
|
||||
* @param to String appname
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isSupported($from, $to)
|
||||
{
|
||||
$args = array(
|
||||
'location' => 'convert'
|
||||
);
|
||||
return $GLOBALS['egw']->hooks->hook_exists('convert', $to) > 0 && in_array($from, $GLOBALS['egw']->hooks->single('convert',$to));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of applications that the given application can convert to
|
||||
*
|
||||
* @param from String appname
|
||||
*
|
||||
* @return array of appnames
|
||||
*/
|
||||
public static function getList($from)
|
||||
{
|
||||
return $GLOBALS['egw']->hooks->single('convert', $from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert data from the specified record into another, as best as possible.
|
||||
*
|
||||
* @param data Array to be changed
|
||||
* @param to String appname
|
||||
* @param from String appname Defaults to current app.
|
||||
* @param from_id Entry ID. If provided, a link will be created between entries.
|
||||
*
|
||||
* @return Array of data as 'to' app structures it, ready to be saved
|
||||
*/
|
||||
public static function convert(Array $data, $to, $from = null, $from_id = null)
|
||||
{
|
||||
if($from == null) $from = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||
|
||||
if(!self::isSupported($from, $to))
|
||||
{
|
||||
throw new egw_exception_wrong_parameter("$to does not know how to convert from $from");
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
// Check for hook
|
||||
// TODO: Maybe add in preference for conversion
|
||||
if($GLOBALS['egw']->hooks->hook_exists('convert',$to))
|
||||
{
|
||||
$args = array(
|
||||
'location' => 'convert',
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'data' => $data
|
||||
);
|
||||
$id = $GLOBALS['egw']->hooks->single($args, $to);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Automagic conversion based on data types or names
|
||||
throw new egw_exception_wrong_parameter("$to does not know how to convert from $from");
|
||||
}
|
||||
|
||||
// Try to link
|
||||
if($id && $from_id)
|
||||
{
|
||||
egw_link::link($from, $from_id, $to, $id);
|
||||
}
|
||||
|
||||
// Try to edit
|
||||
egw_framework::set_onload("if(egw.open) { egw.open('$id', '$to', 'edit');}");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 'Parent' function for hook functions
|
||||
* Put here to reduce duplication
|
||||
*/
|
||||
public static function check($to, $from, Array &$data, Array &$mapping)
|
||||
{
|
||||
if(!$from) return; // Get list of supported apps
|
||||
if(!$data) return false;
|
||||
|
||||
// If we have some common stuff, it can go here
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user