Filter refactoring
This commit is contained in:
@@ -145,94 +145,6 @@ class SubtaskTimeTracking extends Base
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user calendar events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $user_id
|
||||
* @param string $start ISO-8601 format
|
||||
* @param string $end
|
||||
* @return array
|
||||
*/
|
||||
public function getUserCalendarEvents($user_id, $start, $end)
|
||||
{
|
||||
$hook = 'model:subtask-time-tracking:calendar:events';
|
||||
$events = $this->getUserQuery($user_id)
|
||||
->addCondition($this->getCalendarCondition(
|
||||
$this->dateParser->getTimestampFromIsoFormat($start),
|
||||
$this->dateParser->getTimestampFromIsoFormat($end),
|
||||
'start',
|
||||
'end'
|
||||
))
|
||||
->findAll();
|
||||
|
||||
if ($this->hook->exists($hook)) {
|
||||
$events = $this->hook->first($hook, array(
|
||||
'user_id' => $user_id,
|
||||
'events' => $events,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
));
|
||||
}
|
||||
|
||||
return $this->toCalendarEvents($events);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get project calendar events
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id
|
||||
* @param integer $start
|
||||
* @param integer $end
|
||||
* @return array
|
||||
*/
|
||||
public function getProjectCalendarEvents($project_id, $start, $end)
|
||||
{
|
||||
$result = $this
|
||||
->getProjectQuery($project_id)
|
||||
->addCondition($this->getCalendarCondition(
|
||||
$this->dateParser->getTimestampFromIsoFormat($start),
|
||||
$this->dateParser->getTimestampFromIsoFormat($end),
|
||||
'start',
|
||||
'end'
|
||||
))
|
||||
->findAll();
|
||||
|
||||
return $this->toCalendarEvents($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a record set to calendar events
|
||||
*
|
||||
* @access private
|
||||
* @param array $rows
|
||||
* @return array
|
||||
*/
|
||||
private function toCalendarEvents(array $rows)
|
||||
{
|
||||
$events = array();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$user = isset($row['username']) ? ' ('.($row['user_fullname'] ?: $row['username']).')' : '';
|
||||
|
||||
$events[] = array(
|
||||
'id' => $row['id'],
|
||||
'subtask_id' => $row['subtask_id'],
|
||||
'title' => t('#%d', $row['task_id']).' '.$row['subtask_title'].$user,
|
||||
'start' => date('Y-m-d\TH:i:s', $row['start']),
|
||||
'end' => date('Y-m-d\TH:i:s', $row['end'] ?: time()),
|
||||
'backgroundColor' => $this->color->getBackgroundColor($row['color_id']),
|
||||
'borderColor' => $this->color->getBorderColor($row['color_id']),
|
||||
'textColor' => 'black',
|
||||
'url' => $this->helper->url->to('task', 'show', array('task_id' => $row['task_id'], 'project_id' => $row['project_id'])),
|
||||
'editable' => false,
|
||||
);
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a timer is started for this use and subtask
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user