Placeholder dialog: Add placeholders for projectmanager, timesheet, tracker

This commit is contained in:
nathan 2021-10-05 16:09:39 -06:00
parent 66cf807cdd
commit a0a89a6b74
3 changed files with 60 additions and 6 deletions

View File

@ -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;

View File

@ -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
{

View File

@ -207,14 +207,59 @@ class timesheet_merge extends Api\Storage\Merge
$i++;
}
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
echo '<tr><td colspan="4"><h3>' . lang('General fields:') . "</h3></td></tr>";
foreach($this->get_common_replacements() as $name => $label)
{
echo '<tr><td>{{'.$name.'}}</td><td colspan="3">'.$label."</td></tr>\n";
echo '<tr><td>{{' . $name . '}}</td><td colspan="3">' . $label . "</td></tr>\n";
}
echo "</table>\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;
}
}