From: <nat...@us...> - 2013-01-30 23:10:33
|
Author: nathangray Date: Thu Jan 31 00:10:18 2013 New Revision: 41514 URL: http://svn.stylite.de/viewvc/egroupware?rev=41514&view=rev Log: Implement custom notification messages (with placeholders) generally so all apps can use them Modified: trunk/etemplate/inc/class.bo_tracking.inc.php Modified: trunk/etemplate/inc/class.bo_tracking.inc.php URL: http://svn.stylite.de/viewvc/egroupware/trunk/etemplate/inc/class.bo_tracking.inc.php?rev=41514&r1=41513&r2=41514&view=diff ============================================================================== --- trunk/etemplate/inc/class.bo_tracking.inc.php (original) +++ trunk/etemplate/inc/class.bo_tracking.inc.php Thu Jan 31 00:10:18 2013 @@ -181,6 +181,11 @@ const ONE2N_SEPERATOR = '~|~'; /** + * Config name for custom notification message + */ + const CUSTOM_NOTIFICATION = 'custom_notification'; + + /** * Constructor * * @param string $cf_app=null if set, custom field names get added to $field2history @@ -271,6 +276,7 @@ * - 'link' string of link to view $data * - 'sender' sender of email * - 'skip_notify' array of email addresses that should _not_ be notified + * - CUSTOM_NOTIFICATION string notification body message. Merge print placeholders are allowed. * @param array $data current entry * @param array $old=null old/last state of the entry or null for a new entry * @return mixed @@ -902,6 +908,19 @@ public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null) { $body = ''; + if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old)) + { + $body = $this->get_custom_message($data,$old); + if($html_email) + { + $body = nl2br($body); + } + if($sig = $this->get_signature($data,$old,$receiver)) + { + $body .= ($html_email ? '<br />':'') . "\n$sig"; + } + return $body; + } if ($html_email) { $body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n"; @@ -1065,4 +1084,43 @@ } return $config['signature']; } + + /** + * Get a custom notification message to be used instead of the standard one. + * It can use merge print placeholders to include data. + */ + protected function get_custom_message($data, $old, $merge_class = null) + { + $message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old); + if(!$message) + { + return ''; + } + + // Automatically set merge class from naming conventions + if($merge_class == null) + { + $merge_class = $this->app.'_merge'; + } + if(!isset($data[$this->id_field])) + { + error_log($this->app . ' did not properly implement bo_tracking->id_field. Merge skipped.'); + return $message; + } + elseif(class_exists($merge_class)) + { + $merge = new $merge_class(); + $merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html'); + if($error) + { + error_log($error); + return $message; + } + return $merged_message; + } + else + { + throw new egw_exception_wrong_parameter("Invalid merge class '$merge_class' for {$this->app} custom notification"); + } + } } |