コード例 #1
0
ファイル: timev1_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Grabs the records per day this week for the current user
  *
  * @apiMethod GET
  * @apiUri    /time/week
  * @return    void
  */
 public function weekTask()
 {
     // Require authentication and authorization
     $this->requiresAuthentication();
     $this->authorizeOrFail();
     // Get the day of the week
     $today = Date::of(Request::get('today', time()));
     $dateofToday = $today->toSql();
     $dayOfWeek = $today->format('N') - 1;
     // Create object and get records
     $records = Record::whereEquals('user_id', App::get('authn')['user_id'])->where('date', '>=', Date::of(strtotime("{$dateofToday} - {$dayOfWeek}days"))->toSql())->where('date', '<', Date::of(strtotime("{$dateofToday} + " . (7 - $dayOfWeek) . 'days'))->toSql());
     // Restructure response into the format that the calendar plugin expects
     $response = [];
     foreach ($records as $r) {
         $dayOfWeek = Date::of($r->date)->toLocal('N') - 1;
         $response[$dayOfWeek][] = $r->time;
     }
     // Return object
     $this->send($response);
 }