/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $lesson = Lesson::find($id); if (!$lesson) { return $this->respondNotFound('Lesson does not exist.'); } return $this->respond(['data' => $this->lessonTransformer->transform($lesson)]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $lesson = Lesson::find($id); if (!$lesson) { return $this->respondNotFound('Lesson Not Exist'); /*return Response::json([ 'error' => [ 'message' => 'Lesson not found' ] ],404);*/ } return $this->respond(['data' => $this->lessonTransformer->transform($lesson)]); }
/** * 查询用户详细信息 * @method userDetailInfo * @param number $id 用户ID * @return Json 包含用户详情, 订单信息, 登录信息 */ public function show($id) { //通过用户ID查询详细信息, 且包含订单信息(usertype=1的为学生) $teacherInfo = StudentUser::where('uid', $id)->with('orders')->first(); /** * 对查出来的结果添加 teacher_uid 和 teacher_nickname 两个字段 * 以便在表格显示时, 显示出课程中教师相关的信息 */ foreach ($teacherInfo['orders'] as $order) { /** * 通过课程lid查询用户信息 */ $user = Lesson::find($order->lid)->user()->select('uid as teacher_uid', 'nickname as teacher_nickname')->first(); /** * 给 $teacherInfo 数组添加教师信息 */ $order->teacher_uid = $user->teacher_uid; $order->teacher_nickname = $user->teacher_nickname; } /** * 用户登录信息 * 因表结构中只有用户最后一次登录的数据, 只能提供这个 * @var string */ $loginInfo = $teacherInfo->lastlogin; /** * 用户投诉历史 * 因没有相关数据表结构, 暂时无法提供这个数据. */ /** * 将用户详情, 订单信息, 登录信息组合为同一个数组 */ $data['teacherInfo'] = $teacherInfo; $data['loginInfo'] = $loginInfo; //以Json形式返回 return view('teacherdetail')->with('data', $data); }
function testFind() { $name = "John Doe"; $password = "******"; $email = "*****@*****.**"; $signed_in = 0; $test_user = new User($name, $password, $email, $signed_in); $test_user->save(); $course_title = "Literature"; $subject = "English"; $course_description = "Deconstructing English literature."; $user_id = $test_user->getId(); $test_course = new Course($course_title, $subject, $course_description, $user_id); $test_course->save(); $unit_title = "Into the Wild"; $unit_description = "The life and death of Chris McCandless."; $course_id = $test_course->getId(); $test_unit = new Unit($unit_title, $unit_description, $course_id); $test_unit->save(); $lesson_title = "Into the Wild: Chapter 1"; $objective = "Students will read and discuss Chapter 1"; $materials = "Books, discussion packets, pencils"; $body = "Lorem ipsum etc etc blah blah blah blah..."; $unit_id = $test_unit->getId(); $test_lesson = new Lesson($lesson_title, $objective, $materials, $body, $unit_id); $test_lesson->save(); $lesson_title2 = "The Catcher in the Rye: Chapter 3"; $objective2 = "Students will read and discuss Chapter 3"; $materials2 = "Books, essay prompts, pens"; $body2 = "Blah blah blah etc etc lorem ipsum..."; $test_lesson2 = new Lesson($lesson_title2, $objective2, $materials2, $body, $unit_id); $test_lesson2->save(); $result = Lesson::find($test_lesson->getId()); $this->assertEquals($test_lesson, $result); }
$course_id = $unit->getCourseId(); $course = Course::find($course_id); $user_id = $course->getUserId(); return $app['twig']->render("edit_lesson.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'course' => $course, 'user' => User::find($user_id))); }); $app->patch("/show_lesson_edit/edit_lesson/{id}", function ($id) use($app) { $lesson = Lesson::find($id); $new_title = $_POST['new_title']; $new_objective = $_POST['new_objective']; $new_materials = $_POST['new_materials']; $new_body = $_POST['new_body']; $lesson->updateLesson($new_title, $new_objective, $new_materials, $new_body); $unit_id = $lesson->getUnitId(); $unit = Unit::find($unit_id); $course_id = $unit->getCourseId(); $course = Course::find($course_id); $user_id = $course->getUserId(); return $app['twig']->render("lesson.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'course' => $course, 'user' => User::find($user_id))); }); //Delete a lesson $app->get("/delete_lesson/{unit_id}/{lesson_id}", function ($unit_id, $lesson_id) use($app) { $lesson = Lesson::find($lesson_id); $unit_id = $lesson->getUnitId(); $unit = Unit::find($unit_id); $course_id = $unit->getCourseId(); $course = Course::find($course_id); $user_id = $course->getUserId(); $lesson->delete(); return $app['twig']->render("unit.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'lessons' => $unit->getLessons(), 'course' => $course, 'user' => User::find($user_id))); }); return $app;
function getLessons() { $returned_lessons = $GLOBALS['DB']->query("SELECT * FROM lessons WHERE unit_id = {$this->getId()};"); $unit_lessons = array(); foreach ($returned_lessons as $lesson) { $lesson_id = $lesson['id']; $found_lesson = Lesson::find($lesson_id); array_push($unit_lessons, $found_lesson); } return $unit_lessons; }