示例#1
0
 /**
  * Override default filter values
  *
  * ex: change hub_id to Hub
  *
  * @param  $vals   - incoming values
  * @param  $column - incoming column for which values pertain
  * @return $return - outgoing values
  */
 public static function filtersOverrides($vals, $column)
 {
     $return = [];
     if ($column == 'task_id') {
         $ids = array_map(function ($task) {
             return $task->val;
         }, $vals);
         $tasks = Task::whereIn('id', $ids)->rows();
     }
     foreach ($vals as $val) {
         // Just so I don't have to keep writing $val->val
         $value = $val->val;
         $x = array();
         $x['value'] = $value;
         $x['display'] = $value;
         // Now override at will...
         if ($column == 'assignee_id' || $column == 'liaison_id' || $column == 'user_id') {
             $x['value'] = $value;
             $x['display'] = User::getInstance($value)->get('name');
             if ($value == 0) {
                 $x['display'] = 'No User';
             }
         } elseif ($column == 'hub_id') {
             $x['value'] = $value;
             $x['display'] = Hub::oneOrFail($value)->name;
         } elseif ($column == 'task_id') {
             $x['value'] = $value;
             $x['display'] = $tasks->seek($value)->name;
         } elseif ($column == 'active') {
             $x['value'] = $value;
             $x['display'] = $value ? 'Yes' : 'No';
         }
         $return[] = $x;
     }
     // Get an array of kays for sorting purposes
     // We do this here, as opposed to in the query, because the data could have been modified at this point by the overrides above
     foreach ($return as $key => $row) {
         $display[$key] = $row['display'];
     }
     // Do the sort
     array_multisort($display, SORT_ASC, $return);
     return $return;
 }
示例#2
0
 /**
  * Toggle a task's active status
  *
  * @return void
  */
 public function toggleActiveTask()
 {
     $task = Task::oneOrFail(Request::getInt('id'));
     $task->set('active', $task->active == 0 ? 1 : 0);
     if (!$task->save()) {
         App::abort(500, implode('<br />', $task->getErrors()));
         return;
     }
     // Set the redirect
     App::redirect(Route::url($this->base . $this->start($task)), Lang::txt('COM_TIME_TASKS_ACTIVE_STATUS_CHANGED'), 'passed');
 }
示例#3
0
}
?>
				</select>
			</label>

			<label for="task_id"><?php 
echo Lang::txt('PLG_SUPPORT_TIME_TASK');
?>
:
				<select name="task_id" id="task_id">
					<option value=""><?php 
echo Lang::txt('PLG_SUPPORT_TIME_NO_HUB_SELECTED');
?>
</option>
					<?php 
foreach ($tasks = Task::all()->order('name', 'asc') as $task) {
    ?>
						<option value="<?php 
    echo $task->id;
    ?>
">
							<?php 
    echo $task->name;
    ?>
						</option>
					<?php 
}
?>
					<?php 
if (!$tasks->count()) {
    ?>
示例#4
0
 /**
  * Get time of each task
  *
  * @return void
  */
 public static function getTimePerTask()
 {
     $permissions = new Permissions('com_time');
     $hub_id = Request::getInt('hub_id', null);
     $task_id = Request::getInt('task_id', null);
     $start = Request::getCmd('start_date', Date::of(strtotime('today - 1 month'))->format('Y-m-d'));
     $end = Request::getCmd('end_date', Date::format('Y-m-d'));
     $tasks = Task::blank();
     $records = Record::all();
     $records = $records->select('SUM(time)', 'hours')->select($records->getQualifiedFieldName('id'))->select('task_id')->select($tasks->getQualifiedFieldName('name'))->join($tasks->getTableName(), 'task_id', $tasks->getQualifiedFieldName('id'))->where('date', '>=', Date::of($start . ' 00:00:00', Config::get('offset'))->toSql())->where('date', '<=', Date::of($end . ' 23:59:59', Config::get('offset'))->toSql())->order('hours', 'asc')->group('task_id');
     if (isset($task_id) && $task_id > 0) {
         $records->whereEquals('task_id', $task_id);
     } else {
         if (isset($hub_id) && $hub_id > 0) {
             $records->whereRelatedHas('task', function ($task) use($hub_id) {
                 $task->whereEquals('hub_id', $hub_id);
             });
         }
     }
     $summary = array();
     // Loop through and check permissions and grab raw object from rows
     foreach ($records->including('task') as $record) {
         if ($permissions->can('view.report', 'hubs', $record->task->hub_id)) {
             $summary[] = $record->toObject();
         }
     }
     echo json_encode($summary);
     exit;
 }
示例#5
0
								<?php 
echo Lang::txt('COM_TIME_OVERVIEW_TASK');
?>
:
								<span class="task-error error-message"><?php 
echo Lang::txt('COM_TIME_OVERVIEW_PLEASE_SELECT_TASK');
?>
</span>
							</label>
							<select name="task_id" id="task_id" tabindex="2">
								<option value=""><?php 
echo Lang::txt('COM_TIME_RECORDS_NO_HUB_SELECTED');
?>
</option>
								<?php 
foreach ($tasks = Task::all()->ordered() as $task) {
    ?>
									<option value="<?php 
    echo $task->id;
    ?>
">
										<?php 
    echo $task->name;
    ?>
									</option>
								<?php 
}
?>
								<?php 
if (!$tasks->count()) {
    ?>
示例#6
0
}
?>
				</select>
			</div>
			<div class="grouping">
				<label for="task_id"><?php 
echo Lang::txt('PLG_TIME_SUMMARY_TASK_NAME');
?>
: </label>
				<select name="task_id" id="task_id">
					<option value=""><?php 
echo Lang::txt('PLG_TIME_SUMMARY_NO_TASK_SELECTED');
?>
</option>
					<?php 
$tasks = Task::all()->order('name', 'asc');
?>
					<?php 
if ($this->hub_id) {
    $tasks->whereEquals('hub_id', $this->hub_id);
}
?>
					<?php 
foreach ($tasks as $task) {
    ?>
						<?php 
    if ($this->permissions->can('view.report', 'hub', $task->hub_id)) {
        ?>
							<option value="<?php 
        echo $task->id;
        ?>
示例#7
0
 /**
  * Download CSV
  *
  * @return void
  */
 public static function download()
 {
     // Load language
     Lang::load('plg_time_csv', __DIR__);
     $hub_id = Request::getInt('hub_id', null);
     $start = Request::getCmd('start_date', Date::of(strtotime('today - 1 month'))->format('Y-m-d'));
     $end = Request::getCmd('end_date', Date::format('Y-m-d'));
     $records = Record::all()->where('date', '>=', $start)->where('date', '<=', Date::of(strtotime($end . ' + 1 day'))->format('Y-m-d'))->order('date', 'asc');
     if (isset($hub_id) && $hub_id > 0) {
         // @FIXME: is there a better way to do this?
         $records->whereIn('task_id', Task::select('id')->whereEquals('hub_id', $hub_id)->rows()->fieldsByKey('id'));
         $hubname = Hub::oneOrFail($hub_id)->name_normalized;
     }
     $all = true;
     foreach (Request::query() as $key => $value) {
         if (strpos($key, 'fields-') !== false) {
             $all = false;
         }
     }
     $filename = 'time_report';
     $filename .= isset($hubname) ? '_' . $hubname : '';
     $filename .= '_' . Date::of($start)->format('Ymd');
     $filename .= '-' . Date::of($end)->format('Ymd');
     $filename .= '.csv';
     // Set content type headers
     header("Content-type: application/csv");
     header("Content-Disposition: attachment; filename={$filename}");
     header("Pragma: no-cache");
     header("Expires: 0");
     $row = array();
     if ($hub = Request::getInt('fields-hub', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_HUB');
     }
     if ($task = Request::getInt('fields-task', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_TASK');
     }
     if ($user = Request::getInt('fields-user', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_USER');
     }
     if ($date = Request::getInt('fields-date', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_DATE');
     }
     if ($time = Request::getInt('fields-time', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_TIME');
     }
     if ($description = Request::getInt('fields-description', $all)) {
         $row[] = Lang::txt('PLG_TIME_CSV_DESCRIPTION');
     }
     echo implode(',', $row) . "\n";
     $permissions = new Permissions('com_time');
     foreach ($records->including('task.hub', 'user') as $record) {
         if ($permissions->can('view.report', 'hub', $record->task->hub_id)) {
             $output = fopen('php://output', 'w');
             $row = array();
             if ($hub) {
                 $row[] = $record->task->hub->name;
             }
             if ($task) {
                 $row[] = $record->task->name;
             }
             if ($user) {
                 $row[] = $record->user->name;
             }
             if ($date) {
                 $row[] = Date::of($record->date)->toLocal();
             }
             if ($time) {
                 $row[] = $record->time;
             }
             if ($description) {
                 $row[] = $record->description;
             }
             fputcsv($output, $row);
             fclose($output);
         }
     }
     exit;
 }
示例#8
0
 /**
  * Lists all applicable tasks
  *
  * @apiMethod GET
  * @apiUri    /time/indexTasks
  * @apiParameter {
  * 		"name":        "hid",
  * 		"description": "Hub id",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "pactive",
  * 		"description": "Task active status",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "limit",
  * 		"description": "Maximim number of tasks to return",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     1000
  * }
  * @apiParameter {
  * 		"name":        "start",
  * 		"description": "Task index to start at (for pagination)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "orderby",
  * 		"description": "Field by which to order results",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "id"
  * }
  * @apiParameter {
  * 		"name":        "orderdir",
  * 		"description": "Direction by which to order results",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "asc"
  * }
  * @return  void
  */
 public function indexTasksTask()
 {
     // Require authentication and authorization
     $this->requiresAuthentication();
     $this->authorizeOrFail();
     $task = Task::all();
     if ($hub_id = Request::getInt('hid', false)) {
         $task->whereEquals('hub_id', $hub_id);
     }
     if ($active = Request::getInt('pactive', false)) {
         $task->whereEquals('active', $active);
     }
     if ($limit = Request::getInt('limit', 1000)) {
         $task->limit($limit);
     }
     if ($start = Request::getInt('start', 0)) {
         $task->start($start);
     }
     if (($orderby = Request::getCmd('orderby', 'name')) && ($orderdir = Request::getCmd('orderdir', 'asc'))) {
         $task->order($orderby, $orderdir);
     }
     // Create object with tasks property
     $response = new stdClass();
     $response->tasks = $task->rows()->toObject();
     // Return object
     $this->send($response);
 }