mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 09:09:04 +01:00
refractured infolog code to create links to custom field link types
This commit is contained in:
parent
043fda48a4
commit
b195ac76e2
@ -420,4 +420,70 @@ class customfields_widget
|
|||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the customfield types containing links
|
||||||
|
*
|
||||||
|
* @return array with customefield types as values
|
||||||
|
*/
|
||||||
|
public static function get_customfield_link_types()
|
||||||
|
{
|
||||||
|
static $link_types;
|
||||||
|
|
||||||
|
if (is_null($link_types))
|
||||||
|
{
|
||||||
|
$link_types = array_keys(egw_link::app_list());
|
||||||
|
$link_types[] = 'link-entry';
|
||||||
|
}
|
||||||
|
return $link_types;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there are links in the custom fields and update them
|
||||||
|
*
|
||||||
|
* This function have to be called manually by an application, if cf's linking
|
||||||
|
* to other entries should be stored as links too (beside as cf's).
|
||||||
|
*
|
||||||
|
* @param string $own_app own appname
|
||||||
|
* @param array $values new values including the custom fields
|
||||||
|
* @param array $old=null old values before the update, if existing
|
||||||
|
* @param string $id_name='id' name/key of the (link-)id in $values
|
||||||
|
*/
|
||||||
|
public static function update_customfield_links($own_app,array $values,array $old=null,$id_name='id')
|
||||||
|
{
|
||||||
|
$link_types = self::get_customfield_link_types();
|
||||||
|
|
||||||
|
foreach(config::get_customfields($own_app) as $name => $data)
|
||||||
|
{
|
||||||
|
if (!in_array($data['type'],$link_types)) continue;
|
||||||
|
|
||||||
|
// do we have a different old value --> delete that link
|
||||||
|
if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
|
||||||
|
{
|
||||||
|
if ($data['type'] == 'link-entry')
|
||||||
|
{
|
||||||
|
list($app,$id) = explode(':',$old['#'.$name]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$app = $data['type'];
|
||||||
|
$id = $old['#'.$name];
|
||||||
|
}
|
||||||
|
egw_link::unlink(false,$own_app,$values[$id_name],'',$app,$id);
|
||||||
|
}
|
||||||
|
if ($data['type'] == 'link-entry')
|
||||||
|
{
|
||||||
|
list($app,$id) = explode(':',$values['#'.$name]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$app = $data['type'];
|
||||||
|
$id = $values['#'.$name];
|
||||||
|
}
|
||||||
|
if ($id) // create new link, does nothing for already existing links
|
||||||
|
{
|
||||||
|
egw_link::link($own_app,$values[$id_name],$app,$id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ class boinfolog
|
|||||||
*/
|
*/
|
||||||
function has_customfields($type,$links=false)
|
function has_customfields($type,$links=false)
|
||||||
{
|
{
|
||||||
if ($links) $link_types = $this->get_customfield_link_types();
|
if ($links) $link_types = customfields_widget::get_customfield_link_types();
|
||||||
|
|
||||||
foreach($this->customfields as $name => $field)
|
foreach($this->customfields as $name => $field)
|
||||||
{
|
{
|
||||||
@ -275,23 +275,6 @@ class boinfolog
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the customfield types containing links
|
|
||||||
*
|
|
||||||
* @return array with customefield types as values
|
|
||||||
*/
|
|
||||||
function get_customfield_link_types()
|
|
||||||
{
|
|
||||||
static $link_types;
|
|
||||||
|
|
||||||
if (is_null($link_types))
|
|
||||||
{
|
|
||||||
$link_types = array_keys(egw_link::app_list());
|
|
||||||
$link_types[] = 'link-entry';
|
|
||||||
}
|
|
||||||
return $link_types;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check's if user has the requiered rights on entry $info_id
|
* check's if user has the requiered rights on entry $info_id
|
||||||
*
|
*
|
||||||
@ -735,13 +718,12 @@ class boinfolog
|
|||||||
$values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array();
|
$values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array();
|
||||||
}
|
}
|
||||||
// create (and remove) links in custom fields
|
// create (and remove) links in custom fields
|
||||||
$this->update_customfield_links($values,$old);
|
customfields_widget::update_customfield_links('infolog',$values,$old,'info_id');
|
||||||
|
|
||||||
// notify the link-class about the update, as other apps may be subscribt to it
|
// notify the link-class about the update, as other apps may be subscribt to it
|
||||||
egw_link::notify_update('infolog',$info_id,$values);
|
egw_link::notify_update('infolog',$info_id,$values);
|
||||||
|
|
||||||
// send email notifications and do the history logging
|
// send email notifications and do the history logging
|
||||||
require_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.infolog_tracking.inc.php');
|
|
||||||
if (!is_object($this->tracking))
|
if (!is_object($this->tracking))
|
||||||
{
|
{
|
||||||
$this->tracking =& new infolog_tracking($this);
|
$this->tracking =& new infolog_tracking($this);
|
||||||
@ -753,50 +735,6 @@ class boinfolog
|
|||||||
return $info_id;
|
return $info_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if there are links in the custom fields and update them
|
|
||||||
*
|
|
||||||
* @param array $values new values including the custom fields
|
|
||||||
* @param array $old=null old values before the update, if existing
|
|
||||||
*/
|
|
||||||
function update_customfield_links($values,$old=null)
|
|
||||||
{
|
|
||||||
$link_types = $this->get_customfield_link_types();
|
|
||||||
|
|
||||||
foreach($this->customfields as $name => $data)
|
|
||||||
{
|
|
||||||
if (!in_array($data['type'],$link_types)) continue;
|
|
||||||
|
|
||||||
// do we have a different old value --> delete that link
|
|
||||||
if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
|
|
||||||
{
|
|
||||||
if ($data['type'] == 'link-entry')
|
|
||||||
{
|
|
||||||
list($app,$id) = explode(':',$old['#'.$name]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$app = $data['type'];
|
|
||||||
$id = $old['#'.$name];
|
|
||||||
}
|
|
||||||
egw_link::unlink(false,'infolog',$values['info_id'],'',$app,$id);
|
|
||||||
}
|
|
||||||
if ($data['type'] == 'link-entry')
|
|
||||||
{
|
|
||||||
list($app,$id) = explode(':',$values['#'.$name]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$app = $data['type'];
|
|
||||||
$id = $values['#'.$name];
|
|
||||||
}
|
|
||||||
if ($id) // create new link, does nothing for already existing links
|
|
||||||
{
|
|
||||||
egw_link::link('infolog',$values['info_id'],$app,$id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the number of children / subs
|
* Query the number of children / subs
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user