mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 08:23:12 +01:00
* Addressbook/InfoLog/Filemanager/Tracker: added or fixed formatting of certain custom field types using a single shared method
This commit is contained in:
parent
eeb292ecbd
commit
91573fd113
@ -277,24 +277,9 @@ class addressbook_tracking extends bo_tracking
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($this->contacts->customfields)
|
||||
{
|
||||
foreach($this->contacts->customfields as $name => $custom)
|
||||
{
|
||||
if (!$header_done)
|
||||
{
|
||||
$details['custom'] = array(
|
||||
'value' => lang('Custom fields').':',
|
||||
'type' => 'reply',
|
||||
);
|
||||
$header_done = true;
|
||||
}
|
||||
$details['#'.$name] = array(
|
||||
'label' => $custom['label'],
|
||||
'value' => $custom['type'] == 'select' ? $custom['values'][$data['#'.$name]] : $data['#'.$name],
|
||||
);
|
||||
}
|
||||
}
|
||||
// add custom fields for given type
|
||||
$details += $this->get_customfields($data, $data['tid']);
|
||||
|
||||
return $details;
|
||||
}
|
||||
}
|
||||
|
@ -246,42 +246,11 @@ abstract class bo_merge
|
||||
}
|
||||
if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
|
||||
}
|
||||
// set custom fields
|
||||
// set custom fields, should probably go to a general method all apps can use
|
||||
foreach($this->contacts->customfields as $name => $field)
|
||||
{
|
||||
$name = '#'.$name;
|
||||
$value = (string)$contact[$name];
|
||||
switch($field['type'])
|
||||
{
|
||||
case 'select-account':
|
||||
if ($value) $value = common::grab_owner_name($value);
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
if (count($field['values']) == 1 && isset($field['values']['@']))
|
||||
{
|
||||
$field['values'] = customfields_widget::_get_options_from_file($field['values']['@']);
|
||||
}
|
||||
$values = array();
|
||||
foreach($field['rows'] > 1 ? explode(',',$value) : (array) $value as $value)
|
||||
{
|
||||
$values[] = $field['values'][$value];
|
||||
}
|
||||
$value = implode(', ',$values);
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
case 'date-time':
|
||||
if ($value)
|
||||
{
|
||||
$format = $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
|
||||
$date = array_combine(preg_split('/[\\/. :-]/',$format),preg_split('/[\\/. :-]/',$value));
|
||||
$value = common::dateformatorder($date['Y'],$date['m'],$date['d'],true);
|
||||
if (isset($date['H'])) $value .= ' '.common::formattime($date['H'],$date['i']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value;
|
||||
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = customfields_widget::format_customfield($field, (string)$contact[$name]);
|
||||
}
|
||||
|
||||
// Add in extra cat field
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare - abstract base class for tracking (history log, notifications, ...)
|
||||
* EGroupware - abstract base class for tracking (history log, notifications, ...)
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package etemplate
|
||||
* @subpackage api
|
||||
* @copyright (c) 2007-10 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2007-12 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @version $Id$
|
||||
*/
|
||||
@ -210,6 +210,8 @@ abstract class bo_tracking
|
||||
/**
|
||||
* Get the details of an entry
|
||||
*
|
||||
* You can/should call $this->get_customfields() to add custom fields.
|
||||
*
|
||||
* @param array|object $data
|
||||
* @param int|string $receiver nummeric account_id or email address
|
||||
* @return array of details as array with values for keys 'label','value','type'
|
||||
@ -219,6 +221,43 @@ abstract class bo_tracking
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom fields of an entry of an entry
|
||||
*
|
||||
* @param array|object $data
|
||||
* @param string $only_type2=null if given only return fields of type2 == $only_type2
|
||||
* @return array of details as array with values for keys 'label','value','type'
|
||||
*/
|
||||
function get_customfields($data, $only_type2=null)
|
||||
{
|
||||
$details = array();
|
||||
|
||||
if (($cfs = config::get_customfields($this->app, $all_private_too=false, $only_type2)))
|
||||
{
|
||||
$header_done = false;
|
||||
foreach($cfs as $name => $field)
|
||||
{
|
||||
if (in_array($field['type'], customfields_widget::$non_printable_fields)) continue;
|
||||
|
||||
if (!$header_done)
|
||||
{
|
||||
$details['custom'] = array(
|
||||
'value' => lang('Custom fields').':',
|
||||
'type' => 'reply',
|
||||
);
|
||||
$header_done = true;
|
||||
}
|
||||
//error_log(__METHOD__."() $name: data['#$name']=".array2string($data['#'.$name]).", field[values]=".array2string($field['values']));
|
||||
$details['#'.$name] = array(
|
||||
'label' => $field['label'],
|
||||
'value' => customfields_widget::format_customfield($field, $data['#'.$name]),
|
||||
);
|
||||
//error_log("--> details['#$name']=".array2string($details['#'.$name]));
|
||||
}
|
||||
}
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a config value, which can depend on $data and $old
|
||||
*
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare eTemplate Widget for custom fields
|
||||
* EGroupware eTemplate Widget for custom fields
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
@ -514,7 +514,7 @@ class customfields_widget
|
||||
* @param string $file file name inside the eGW server root, either relative to it or absolute
|
||||
* @return array in case of an error we return a single option with the message
|
||||
*/
|
||||
function _get_options_from_file($file)
|
||||
public static function _get_options_from_file($file)
|
||||
{
|
||||
if (!($path = realpath($file{0} == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
|
||||
substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
|
||||
@ -593,4 +593,89 @@ class customfields_widget
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Non printable custom fields eg. UI elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $non_printable_fields = array('button');
|
||||
|
||||
/**
|
||||
* Format a single custom field value as string
|
||||
*
|
||||
* @param array $field field defintion incl. type
|
||||
* @param string $value field value
|
||||
* @return string formatted value
|
||||
*/
|
||||
public static function format_customfield(array $field, $value)
|
||||
{
|
||||
switch($field['type'])
|
||||
{
|
||||
case 'select-account':
|
||||
if ($value)
|
||||
{
|
||||
$values = array();
|
||||
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
|
||||
{
|
||||
$values[] = common::grab_owner_name($value);
|
||||
}
|
||||
$value = implode(', ',$values);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
$value = $value ? 'X' : '';
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
case 'radio':
|
||||
if (count($field['values']) == 1 && isset($field['values']['@']))
|
||||
{
|
||||
$field['values'] = customfields_widget::_get_options_from_file($field['values']['@']);
|
||||
}
|
||||
$values = array();
|
||||
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
|
||||
{
|
||||
$values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value;
|
||||
}
|
||||
$value = implode(', ', $values);
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
case 'date-time':
|
||||
if ($value)
|
||||
{
|
||||
$format = $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
|
||||
$date = array_combine(preg_split('/[\\/. :-]/',$format), preg_split('/[\\/. :-]/',$value));
|
||||
$value = common::dateformatorder($date['Y'], $date['m'], $date['d'],true);
|
||||
if (isset($date['H'])) $value .= ' '.common::formattime($date['H'], $date['i']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'htmlarea': // ToDo: EMail probably has a nicer html2text method
|
||||
if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
|
||||
break;
|
||||
|
||||
case 'ajax_select': // ToDo: returns unchanged value for now
|
||||
break;
|
||||
|
||||
default:
|
||||
// handling for several link types
|
||||
if ($value && in_array($field['type'], self::get_customfield_link_types()))
|
||||
{
|
||||
if ($field['type'] == 'link-entry' || strpos($value, ':') !== false)
|
||||
{
|
||||
list($app, $value) = explode(':', $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$app = $field['type'];
|
||||
}
|
||||
if ($value) $value = egw_link::title($app, $value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -187,15 +187,13 @@ class infolog_tracking extends bo_tracking
|
||||
/**
|
||||
* Get the details of an entry
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $datetime_format of user to notify, eg. 'Y-m-d H:i'
|
||||
* @param int $tz_offset_s offset in sec to be add to server-time to get the user-time of the user to notify
|
||||
* @param array|object $data
|
||||
* @param int|string $receiver nummeric account_id or email address
|
||||
* @return array of details as array with values for keys 'label','value','type'
|
||||
*/
|
||||
function get_details($data)
|
||||
function get_details($data,$receiver=null)
|
||||
{
|
||||
//error_log(__METHOD__.__LINE__.' Data:'.array2string($data));
|
||||
$header_done = false;
|
||||
$responsible = array();
|
||||
if ($data['info_responsible'])
|
||||
{
|
||||
@ -245,30 +243,9 @@ class infolog_tracking extends bo_tracking
|
||||
'value' => $data['info_des'],
|
||||
'type' => 'multiline',
|
||||
);
|
||||
// should be moved to bo_tracking because auf the different custom field types
|
||||
if ($this->infolog->customfields)
|
||||
{
|
||||
foreach($this->infolog->customfields as $name => $field)
|
||||
{
|
||||
if ($field['type2'] && !in_array($data['info_type'],explode(',',$field['type2']))) continue; // different type
|
||||
// add custom fields for given type
|
||||
$details += $this->get_customfields($data, $data['info_type']);
|
||||
|
||||
if (!$header_done)
|
||||
{
|
||||
$details['custom'] = array(
|
||||
'value' => lang('Custom fields').':',
|
||||
'type' => 'reply',
|
||||
);
|
||||
$header_done = true;
|
||||
}
|
||||
//error_log(__METHOD__."() $name: data['#$name']=".array2string($data['#'.$name]).", field[values]=".array2string($field['values']));
|
||||
$details['#'.$name] = array(
|
||||
'label' => $field['label'],
|
||||
'value' => is_array($field['values']) && $field['values'] && isset($data['#'.$name]) &&
|
||||
array_key_exists((string)$data['#'.$name],$field['values']) ? $field['values'][$data['#'.$name]] : $data['#'.$name],
|
||||
);
|
||||
//error_log("--> details['#$name']=".array2string($details['#'.$name]));
|
||||
}
|
||||
}
|
||||
return $details;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user