コード例 #1
0
ファイル: tasks.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Merge task
  *
  * @return void
  */
 public function mergeTask()
 {
     $ids = (array) Request::getVar('ids');
     if (!($primary = Request::getInt('primary'))) {
         // Set the redirect
         App::redirect(Route::url($this->base . $this->start(Task::blank())), Lang::txt('COM_TIME_TASKS_MERGE_NO_PRIMARY'), 'error');
         return;
     }
     // Loop through the tasks given
     foreach ($ids as $id) {
         // Leave the primary task alone
         if ($id == $primary) {
             continue;
         }
         // Get all the records for the given task and update their task id
         $task = Task::oneOrFail((int) $id);
         foreach ($task->records as $record) {
             $record->set('task_id', $primary)->save();
         }
         $task->destroy();
     }
     // Set the redirect
     App::redirect(Route::url($this->base . $this->start($task)), Lang::txt('COM_TIME_TASKS_MERGE_SUCCESSFUL'), 'passed');
 }
コード例 #2
0
ファイル: summary.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * 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;
 }