public function actionAddFocus() { $courseId = Yii::$app->request->post('courseId'); $userId = Yii::$app->user->id; if (UserCourse::isFocus($userId, $courseId)) { echo true; return; } else { if (UserCourse::addData($userId, $courseId, UserCourse::TYPE_FOCUS)) { echo true; return; } } echo false; }
public function actionLearn() { $courseId = Yii::$app->request->get('cid'); $model = $this->findModelByCoursId($courseId); $categoryModel = Category::findOneById($model->category); $isLearn = false; if (UserCourse::isLearn(Yii::$app->user->id, $courseId)) { $isLearn = true; } else { UserCourse::addData(Yii::$app->user->id, $courseId, UserCourse::TYPE_LEARN); $model->learner_count += 1; $model->save(); $isLearn = true; } $learnPersent = UserPlay::getLearnPercent(Yii::$app->user->id, $courseId) * 100; $learnTimeToal = Common::transTime(UserCourse::findOneLearnModel(Yii::$app->user->id, $courseId)->learn_time_total); return $this->render('learn', ['course' => $model, 'categoryModel' => $categoryModel, 'isLearn' => $isLearn, 'learnPersent' => $learnPersent, 'learnTimeToal' => $learnTimeToal]); }