Try to find & set pm_id from selected project when adding a new timesheet entry

This commit is contained in:
nathangray 2016-08-18 14:04:18 -06:00
parent d47b9f1f66
commit 134572a0d9

View File

@ -88,6 +88,10 @@ class timesheet_ui extends timesheet_bo
'ts_project' => $_REQUEST['ts_project'],
'ts_title_blur' => $_REQUEST['ts_project'],
);
if(!is_numeric($_REQUEST['ts_project']))
{
$this->data['pm_id'] = $this->find_pm_id($_REQUEST['ts_project']);
}
}
$matches = null;
$referer = preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? $matches[1] :
@ -442,6 +446,10 @@ class timesheet_ui extends timesheet_bo
{
$content['ts_viewtype'] = $readonlys['tabs']['notes'] = true;
$content['ts_description_short'] = $content['ts_description'];
if(!$content['pm_id'] && $this->pm_integration != 'full' && $content['ts_project'])
{
$etpl->setElementAttribute('pm_id','blur',$content['ts_project']);
}
}
if (!$this->customfields) $readonlys['tabs']['customfields'] = true; // suppress tab if there are not customfields
if (!$this->data['ts_id']) $readonlys['tabs']['history'] = true; //suppress history for the first loading without ID
@ -1243,4 +1251,26 @@ class timesheet_ui extends timesheet_bo
$etpl = new Etemplate('timesheet.editstatus');
$etpl->exec('timesheet.timesheet_ui.editstatus',$content,$sel_options,array(),$preserv);
}
/**
* Try to find a PM ID from project title
*
* @param string $project
*/
protected function find_pm_id($project)
{
list($pm_number, $pm_title) = explode(': ', $project, 2);
if(!$pm_number || !$pm_title)
{
return false;
}
$pm = new projectmanager_bo();
$pm_ids = $pm->search(array('pm_number' => $pm_number, 'pm_title' => $pm_title));
if($pm_ids && count($pm_ids) >= 1)
{
return $pm_ids[0]['pm_id'];
}
return false;
}
}