Пример #1
0
 /**
  * @api {get} /managers/:id/bin Get Items in Manager's Content Bin 
  * @apiName Get Items in Manager's Content Bin
  * @apiDescription As a manager, any content I purchased will be shown in my bin.  When an item reaches its expiration date, change the date to read 'EXPIRED'. Keep listing 'EXPIRED' items in this way for 30 days.
  * @apiGroup Manager
  * @apiHeader (Header) {String} X_Authorization Authorization value.
  * @apiParam {Number} id Users unique ID.
  *
  * @apiSuccessExample {json} Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "id": 14,
  *       "quantity": 1,
  *       "expiration_dt": "2015-11-30 00:00:00",
  *       "created_at": "2015-11-19 14:12:30",
  *       "updated_at": "2015-11-19 14:12:30",
  *       "course_id": 45950,
  *       "course_name": "Scotsman: Prodigy Eclipse Ice Cuber EH222",
  *       "course_type": "course",
  *       "restrictions":{
  *           "prerequisite":[],
  *           "expiration":""
  *       }
  *     }
  *
  */
 public static function getBin($idUser)
 {
     GroupController::isAdmin($idUser);
     $bins = Manager_Bin::where('user_id', '=', $idUser)->get();
     $result = [];
     foreach ($bins as &$bin) {
         unset($bin->user_id);
         unset($bin->company_id);
         $course = Price::find($bin->course_sale_id)->course;
         unset($bin->course_sale_id);
         $bin['course_id'] = $course->id;
         $bin['course_name'] = $course->name;
         $bin['course_type'] = $course->type;
         $expired_dt = new DateTime($bin['expiration_dt']);
         $now = new DateTime();
         $diff = $now->diff($expired_dt, false);
         //var_dump($diff);
         $restrictions = [];
         //echo $diff->format("%R%a");
         if ($diff->format("%R%a") >= 0) {
             $pre = CourseController::getCoursePrerequisites($course->id);
             if ($pre) {
                 $restrictions['prerequisite'] = $pre;
             }
         } else {
             if ($diff->format("%R%a") > -30) {
                 $bin['expiration_dt'] = "EXPIRED";
                 $restrictions['expiration'] = 'This content has expired. You cannot assign or transfer this content.  You may renew this content for 30 days after the expiration at the renewal price.';
             } else {
                 continue;
             }
         }
         $bin['restrictions'] = $restrictions;
         array_push($result, $bin);
     }
     return json_encode($result);
 }