コード例 #1
0
 public function actionPlay($id)
 {
     $model = $this->findModel($id);
     $course = Course::findOneById($model->course_id);
     $root = Course::findOneById($course->root);
     $userPlayModel = new UserPlay();
     if (!$userPlayModel->isLearn(Yii::$app->user->id, $model->course_id)) {
         $userPlayModel->addData(Yii::$app->user->id, $model->course_id);
     }
     $learnPoint = $userPlayModel->findOneLearnModel(Yii::$app->user->id, $model->course_id)->learn_point;
     $model->play_count += 1;
     if ($model->save()) {
         //获取附件
         $resourceModel = new Resource();
         $attachments = $resourceModel->getAttachments($model->course_id);
         return $this->render('play', ['url' => $model->url, 'course' => $course, 'root' => $root, 'learnPoint' => $learnPoint, 'id' => $model->id, 'attachments' => $attachments]);
     }
 }