From b195ac76e29c21eaa6ee2643091456d72a66761e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 11 Sep 2008 14:57:20 +0000 Subject: [PATCH] refractured infolog code to create links to custom field link types --- .../inc/class.customfields_widget.inc.php | 68 ++++++++++++++++++- infolog/inc/class.boinfolog.inc.php | 66 +----------------- 2 files changed, 69 insertions(+), 65 deletions(-) diff --git a/etemplate/inc/class.customfields_widget.inc.php b/etemplate/inc/class.customfields_widget.inc.php index a986d6ae0b..8e3267091c 100644 --- a/etemplate/inc/class.customfields_widget.inc.php +++ b/etemplate/inc/class.customfields_widget.inc.php @@ -329,7 +329,7 @@ class customfields_widget if (empty($validation_type)) $validation_type = 1; $field['len'] = implode(',',array($shown, $max, $validation_type, $default)); $input =& etemplate::empty_cell($field['type'],$this->prefix.$lname,array( - 'size' => $field['len'] + 'size' => $field['len'] )); break; case 'url': @@ -420,4 +420,70 @@ class customfields_widget 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); + } + } + } } diff --git a/infolog/inc/class.boinfolog.inc.php b/infolog/inc/class.boinfolog.inc.php index 2d2cd77d82..ea7ecbd591 100644 --- a/infolog/inc/class.boinfolog.inc.php +++ b/infolog/inc/class.boinfolog.inc.php @@ -262,7 +262,7 @@ class boinfolog */ 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) { @@ -275,23 +275,6 @@ class boinfolog 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 * @@ -735,13 +718,12 @@ class boinfolog $values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array(); } // 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 egw_link::notify_update('infolog',$info_id,$values); // 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)) { $this->tracking =& new infolog_tracking($this); @@ -753,50 +735,6 @@ class boinfolog 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 *