public function download_payment_document($id)
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $data["actions"] = Session::get('actions');
         if (in_array('side_matricularse', $data["actions"]) || in_array('side_aprobar_matriculas_online', $data["actions"])) {
             $enrollment = Enrollment::find($id);
             $path = $enrollment->doc_path . $enrollment->doc_name;
             $headers = array('Content-Type', mime_content_type($path));
             // Llamo a la función para registrar el log de auditoria
             $log_description = "Se descargó la boleta de la Matrícula con id {{$enrollment->id}}";
             Helpers::registerLog(9, $log_description);
             return Response::download($path, basename($enrollment->doc_title), $headers);
         } else {
             // Llamo a la función para registrar el log de auditoria
             $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registrarLog(10, $descripcion_log);
             Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
             return Redirect::to('/dashboard');
         }
     } else {
         return View::make('error/error');
     }
 }
Ejemplo n.º 2
0
 /**
  * @api {get} courses/enrolled/users/:id Get User's course history
  * @apiName Get User's course history
  * @apiGroup Enrollment
  *
  * @apiHeader (Header) {String} X_Authorization Authorization value.
  *
  * @apiParam {Number} idUser Mandatory  Users unique ID.
  *
  * @apiSuccessExample {json} Success-Response:
  *   HTTP/1.1 200 OK
  *   [
  *   {
  *    "membership_id": 1,
  *    "course_id": 26262,
  *    "name": "TurboChef: iSeries",
  *    "manufacturer": "TurboChef",
  *    "type": "3d",
  *    "note": null,
  *    "pak": " iSeries",
  *    "html5": 0,
  *    "safety": -1,
  *    "short_description": null,
  *    "status": "Active to Enroll",
  *    "end_at": "2016-11-29 11:05:07"
  *},
  *{
  *    "id": 103,
  *    "course_id": 45950,
  *    "name": "Scotsman: Prodigy Eclipse Ice Cuber EH222",
  *    "manufacturer": "Scotsman Ice Systems",
  *    "type": "course",
  *    "note": null,
  *    "pak": "Prodigy Eclipse Ice Cuber EH222",
  *    "html5": 1,
  *    "safety": -1,
  *    "short_description": null,
  *    "status": "Enrolled",
  *    "end_at": null,
  *    "enrolled_at": "2015-11-30 12:27:52"
  *}
  *   ]
  */
 public static function getEnrollments($idUser)
 {
     $app = \Slim\Slim::getInstance();
     if (!User::find($idUser)) {
         $app->response->setStatus(400);
         return json_encode("User does not exist");
     }
     $enrollments = User::find($idUser)->enrollment;
     $active_enrollment_ids = Enrollment::where('end_at', '>', date('Y-m-d H:i:s'))->orwhere('end_at', null)->where('user_id', '=', $idUser)->lists('course_id')->toArray();
     $result = [];
     foreach ($enrollments as &$enrollment) {
         if (!is_null($enrollment->end_at)) {
             if (date("Y-m-d H:i:s") > $enrollment->end_at) {
                 $enrollment->status = "expired";
                 continue;
             }
         }
         $course = Enrollment::find($enrollment->id)->course;
         if ($course->type == "membership") {
             if ($enrollment->status == "expired") {
                 continue;
             }
             $membership_courses = Catalog::find($course->id)->course()->where("isPublished", "1");
             foreach ($membership_courses as $key => $value) {
                 if (is_array($active_enrollment_ids) && in_array($value->id, $active_enrollment_ids)) {
                     continue;
                 }
                 $data = array("membership_id" => $enrollment->course_id, "course_id" => $value->id, "name" => $value->name, "manufacturer" => $value->manufacturer, "type" => $value->type, "note" => $value->note, "pak" => trim($value->pak), "html5" => $course->html5, "safety" => $enrollment->isSafety, "short_description" => $value->shortDescription, "status" => "Active to Enroll", "scorm_registration_id" => $enrollment->scorm_registration_id, "end_at" => $enrollment->end_at);
                 array_push($result, $data);
             }
         } else {
             $data = array("id" => $enrollment->id, "course_id" => $course->id, "name" => $course->name, "manufacturer" => $course->manufacturer, "type" => $course->type, "note" => $course->note, "pak" => trim($course->pak), "html5" => $course->html5, "safety" => $enrollment->isSafety, "short_description" => $course->shortDescription, "progress" => $enrollment->progress, "status" => ucfirst($enrollment->status), "end_at" => $enrollment->end_at, "scorm_registration_id" => $enrollment->scorm_registration_id, "enrolled_at" => date($enrollment->created_at));
             array_push($result, $data);
         }
     }
     // Add additional recommend course to user's library
     $paks = array();
     $courses = array();
     foreach ($result as $data) {
         if (!in_array($data['pak'], $paks)) {
             array_push($paks, trim($data['pak']));
         }
         array_push($courses, $data['course_id']);
     }
     foreach ($paks as $key => $value) {
         $ids = Course::where('pak', '=', $value)->lists('id')->toArray();
         foreach ($ids as $id) {
             if (!in_array($id, $courses)) {
                 $course = Course::find($id);
                 $price = Price::where('course_id', $id)->orderBy('length')->first();
                 //priority
                 $data = array("status" => "Recommend to buy", "course_id" => $course->id, "name" => $course->name, "manufacturer" => $course->manufacturer, "type" => $course->type, "note" => $course->note, "pak" => trim($course->pak), "html5" => $course->html5, "short_description" => $course->shortDescription);
                 if ($price) {
                     $data['price'] = $price->price;
                     $data['idSale'] = $price->id;
                 }
                 array_push($result, $data);
             }
         }
     }
     //print_r($paks);
     return json_encode($result);
 }
 /**
  * Sync enrollment.
  *
  * @param  int  $idEnrollment
  * @param  object  enrollments
  * @return int $idEnrollment
  */
 public static function sync()
 {
     $app = \Slim\Slim::getInstance();
     $data = $app->request->post();
     $enrollments = json_decode($data['data']);
     foreach ($enrollments as $key => $enrollment) {
         $server = Enrollment::find($enrollment->id);
         if (!$server) {
             //$app->response->setStatus(400);
             //return "Enrollment does not exist";
         } else {
             if (is_null($server->progress)) {
                 $server->progress = $enrollment->progress;
                 if (property_exists($enrollment, 'safety')) {
                     $server->isSafety = $enrollment->safety;
                 }
                 $server->save();
             } else {
                 //compare
                 //always follow the structure from cilent side
                 $localprogress = json_decode($enrollment->progress);
                 $serverprogress = json_decode($server->progress);
                 foreach ($localprogress as $key => $value) {
                     if (isset($serverprogress->{$key}) && $serverprogress->{$key}) {
                         $localprogress->{$key} = 1;
                     }
                 }
                 if (property_exists($enrollment, 'safety')) {
                     $server->isSafety = $enrollment->safety;
                 }
                 $server->progress = json_encode($localprogress);
                 $server->save();
             }
         }
     }
     //print_r($enrollments);
     return 1;
 }