public static function getById($lid) { $nextModel = new Lesson(); $nextLesson = Yii::$app->businesslayer->lessons->getById($lid); $nextModel->setAttributes(['lessonId' => $nextLesson['ID'], 'lessonCourseId' => $nextLesson['CourseID'], 'lessonName' => $nextLesson['LessonName'], 'lessonLength' => $nextLesson['LessonLength'], 'lessonNumber' => $nextLesson['LessonNumber'], 'lessonDate' => $nextLesson['LessonDate']]); return $nextModel; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $lesson = Lesson::find($this->input('lesson_id')); $product = $lesson->product; $users = $product->owner()->lists('id')->toArray(); return in_array(Auth::id(), $users); }
public function run() { $faker = Faker::create(); foreach (range(1, 30) as $index) { Lesson::create(['title' => $faker->sentence(5), 'body' => $faker->paragraph(4), 'some_bool' => $faker->boolean()]); } }
public function storeActivity($lessonId) { $this->userOwnsLesson($lessonId); $score = $this->getCorrectAnswerCount(Lesson::findOrFail($lessonId)->lessonWords()->get()); auth()->user()->activities()->create(['lesson_id' => $lessonId, 'content' => 'Finished an exam with a score of ' . $score->correct . '/' . $score->total, 'activity_type' => config()->get('activity_type.EXAM_TAKEN')]); return redirect('results/' . $lessonId); }
public function actionLesson() { if (Yii::$app->request->isAjax && $_POST['id']) { Yii::$app->response->format = Response::FORMAT_JSON; $model = Lesson::getById($_POST['id']); return $model; } }
/** * 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)]); }
public function lesson($id) { $lesson = Lesson::find($id); if (empty($lesson)) { Flash::error('Lesson not found'); return redirect('/'); } return view('site.lessons.show')->with('lesson', $lesson); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $lessonIds = \App\Models\Lesson::lists('id')->toArray(); $tagIds = \App\Models\Tag::lists('id')->toArray(); foreach (range(1, 30) as $index) { DB::table('lesson_tag')->insert(['lesson_id' => $faker->randomElement($lessonIds), 'tag_id' => $faker->randomElement($tagIds)]); } }
public function actionDelete($id) { $item = Lesson::findByPK($id); if (empty($item)) { $this->redirect('/admin/lessons/?course=' . $item->course->getPk()); } $item->delete(); $this->redirect('/admin/lessons/?course=' . $item->course->getPk()); }
public function actionIndex($userId, $schId) { //$models = News::getNews($schId); $model = new StudentlkForm(); $model->userID = $userId; $model->curSchoolID = $schId; $lessons = Lesson::getLessons($schId, $userId); return $this->render('index', ['model' => $model, 'lessons' => $lessons]); }
public function actionSave() { if (!empty($_POST['course'][Course::PK])) { $item = Course::findByPK($_POST['course'][Course::PK]); } else { $item = new Course(); } $item->fill($_POST['course']); $item->save(); if ($item->wasNew() && !empty($_POST['lessonsCount'])) { $lessonsCount = (int) $_POST['lessonsCount']; for ($i = 1; $i <= $lessonsCount; $i++) { $lesson = new Lesson(); $lesson->num = $i; $lesson->title = 'Урок ' . $i; $lesson->course = $item; $lesson->save(); } } $this->redirect('/admin/courses'); }
/** * @inheritdoc */ protected function prepareModels() { $models = []; $pagination = $this->getPagination(); if ($pagination === false) { $models = Lesson::getLessons($this->sid, $this->uid); } else { // $pagination->totalCount = $this->getTotalCount(); // $this->fileObject->seek($pagination->getOffset()); // $limit = $pagination->getLimit(); // for ($count = 0; $count < $limit; ++$count) { // $models[] = $this->fileObject->fgetcsv(); // $this->fileObject->next(); // } } return $models; }
public function getLastLessonId($id) { return Lesson::where('user_id', '=', $id)->latest()->first()->id; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit(Request $request, $id) { if (null !== Session::get('active_tab')) { $active_tab = Session::get('active_tab'); } else { $active_tab = 'links'; } $lesson = Lesson::findOrFail($id); return view('site.lessons.edit')->with('lesson', $lesson)->with('product_id', $lesson->product->id)->with('active_tab', $active_tab); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $lesson = Lesson::with('links')->find($id); return $lesson; }
/** * Handle the command. * * @param StoreUserLessonResultCommand $command * @return void */ public function handle(StoreUserLessonResultCommand $command) { $user = User::find($command->userId); $lesson = Lesson::find($command->lessonId); $user->lessons()->save($lesson, ['score' => $command->score]); }
/** * @param $lessonId * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function getTags($lessonId) { $tags = $lessonId ? Lesson::find($lessonId)->tags : Tag::all(); return $tags; }
/** * Remove the specified Lesson from storage. * * @param int $id * * @return Response */ public function destroy($id) { /** @var Lesson $lesson */ $lesson = Lesson::find($id); if (empty($lesson)) { Flash::error('Lesson not found'); return redirect(route('admin.lessons.index')); } $lesson->delete(); Flash::message('Lesson deleted successfully.'); return redirect(route('admin.lessons.index')); }