From a0a89a6b74d624f353d486316b3a071e57c8ef2f Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 5 Oct 2021 16:09:39 -0600 Subject: [PATCH] Placeholder dialog: Add placeholders for projectmanager, timesheet, tracker --- api/src/Etemplate/Widget/Placeholder.php | 9 ++++ api/src/Storage/Merge.php | 8 ++-- timesheet/inc/class.timesheet_merge.inc.php | 49 ++++++++++++++++++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/api/src/Etemplate/Widget/Placeholder.php b/api/src/Etemplate/Widget/Placeholder.php index 8c9014b065..a31d88c49d 100644 --- a/api/src/Etemplate/Widget/Placeholder.php +++ b/api/src/Etemplate/Widget/Placeholder.php @@ -93,6 +93,15 @@ class Placeholder extends Etemplate\Widget { $list = array_intersect_key($list, $group); } + // Remove if empty + foreach($list as $p_group => $p_list) + { + if(count($p_list) == 0) + { + unset($list[$p_group]); + } + } + if($list) { $placeholders[$appname] = $list; diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 0dab015a3c..4a407e89ae 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -968,10 +968,10 @@ abstract class Merge } if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true))); // some general replacements: current user, date and time - if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))) + if(strpos($content, '$$user/') !== false && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id'))) { - $replacements += $this->contact_replacements($user,'user', false, $content); - $replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group')); + $replacements += $this->contact_replacements($user, 'user', false, $content); + $replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'account_primary_group')); } $replacements['$$date$$'] = Api\DateTime::to('now',true); $replacements['$$datetime$$'] = Api\DateTime::to('now'); @@ -2828,7 +2828,7 @@ abstract class Merge * Here we adjust the group name, and add the group to the end of the placeholder list * @param array $placeholder_list Our placeholder list * @param string $base_name Name of the entry (eg: Contact, custom field name) - * @param array $add_placeholder_groups Placeholder list from the other app + * @param array $add_placeholder_groups Placeholder list from the other app. Placeholders should include any needed prefix */ protected function add_linked_placeholders(&$placeholder_list, $base_name, $add_placeholder_groups) : void { diff --git a/timesheet/inc/class.timesheet_merge.inc.php b/timesheet/inc/class.timesheet_merge.inc.php index 2a7070ac95..89a11149bc 100644 --- a/timesheet/inc/class.timesheet_merge.inc.php +++ b/timesheet/inc/class.timesheet_merge.inc.php @@ -207,14 +207,59 @@ class timesheet_merge extends Api\Storage\Merge $i++; } - echo '

'.lang('General fields:')."

"; + echo '

' . lang('General fields:') . "

"; foreach($this->get_common_replacements() as $name => $label) { - echo '{{'.$name.'}}'.$label."\n"; + echo '{{' . $name . '}}' . $label . "\n"; } echo "\n"; echo $GLOBALS['egw']->framework->footer(); } + + /** + * Get a list of placeholders provided. + * + * Placeholders are grouped logically. Group key should have a user-friendly translation. + */ + public function get_placeholder_list($prefix = '') + { + $placeholders = array( + 'timesheet' => [], + lang('Project') => [] + ) + parent::get_placeholder_list($prefix); + + $fields = array('ts_id' => lang('Timesheet ID')) + $this->bo->field2label + array( + 'ts_total' => lang('total'), + 'ts_created' => lang('Created'), + 'ts_modified' => lang('Modified'), + ); + $group = 'timesheet'; + foreach($fields as $name => $label) + { + if(in_array($name, array('custom'))) + { + // dont show them + continue; + } + $marker = $this->prefix($prefix, $name, '{'); + if(!array_filter($placeholders, function ($a) use ($marker) + { + return array_key_exists($marker, $a); + })) + { + $placeholders[$group][] = [ + 'value' => $marker, + 'label' => $label + ]; + } + } + + // Add project placeholders + $pm_merge = new projectmanager_merge(); + $this->add_linked_placeholders($placeholders, lang('Project'), $pm_merge->get_placeholder_list('ts_project')); + + return $placeholders; + } }