public function editAction(Request $request, $courseId, $lessonId) { $liveCourse = $this->getCourseService()->tryManageCourse($courseId); $liveLesson = $this->getCourseService()->getCourseLesson($liveCourse['id'], $lessonId); if ($request->getMethod() == 'POST') { $editLiveLesson = $request->request->all(); $liveLesson['type'] = 'live'; $liveLesson['title'] = $editLiveLesson['title']; $liveLesson['summary'] = $editLiveLesson['summary']; $liveLesson['courseId'] = $liveCourse['id']; $liveLesson['startTime'] = empty($editLiveLesson['startTime']) ? $liveLesson['startTime'] : strtotime($editLiveLesson['startTime']); $liveLesson['free'] = empty($editLiveLesson['free']) ? 0 : $editLiveLesson['free']; $liveLesson['length'] = empty($editLiveLesson['timeLength']) ? $liveLesson['length'] : $editLiveLesson['timeLength']; $speakerId = current($liveCourse['teacherIds']); $speaker = $speakerId ? $this->getUserService()->getUser($speakerId) : null; $speaker = $speaker ? $speaker['nickname'] : '老师'; $liveParams = array('liveId' => $liveLesson['mediaId'], 'provider' => $liveLesson['liveProvider'], 'summary' => $editLiveLesson['summary'], 'title' => $editLiveLesson['title'], 'speaker' => $speaker, 'authUrl' => $this->generateUrl('live_auth', array(), true), 'jumpUrl' => $this->generateUrl('live_jump', array('id' => $liveLesson['courseId']), true)); if (array_key_exists('startTime', $editLiveLesson)) { $liveParams['startTime'] = strtotime($editLiveLesson['startTime']); } if (array_key_exists('startTime', $editLiveLesson) && array_key_exists('timeLength', $editLiveLesson)) { $liveParams['endTime'] = strtotime($editLiveLesson['startTime']) + $editLiveLesson['timeLength'] * 60 . ''; } $client = new EdusohoLiveClient(); $live = $client->updateLive($liveParams); $liveLesson = $this->getCourseService()->updateLesson($courseId, $lessonId, $liveLesson); return $this->render('TopxiaWebBundle:CourseLessonManage:list-item.html.twig', array('course' => $liveCourse, 'lesson' => $liveLesson)); } return $this->render('TopxiaWebBundle:LiveCourseLessonManage:live-lesson-modal.html.twig', array('liveCourse' => $liveCourse, 'liveLesson' => $liveLesson)); }
public function liveCourseSettingAction(Request $request) { $courseSetting = $this->getSettingService()->get('course', array()); $liveCourseSetting = $this->getSettingService()->get('live-course', array()); $client = new EdusohoLiveClient(); $capacity = $client->getCapacity(); $default = array('live_course_enabled' => '0'); $this->getSettingService()->set('course', $courseSetting); $this->getSettingService()->set('live-course', $liveCourseSetting); $setting = array_merge($default, $liveCourseSetting); if ($request->getMethod() == 'POST') { $liveCourseSetting = $request->request->all(); $liveCourseSetting['live_student_capacity'] = empty($capacity['capacity']) ? 0 : $capacity['capacity']; $setting = array_merge($courseSetting, $liveCourseSetting); $this->getSettingService()->set('live-course', $liveCourseSetting); $this->getSettingService()->set('course', $setting); $hiddenMenus = $this->getSettingService()->get('menu_hiddens', array()); if ($liveCourseSetting['live_course_enabled']) { unset($hiddenMenus['admin_live_course_add']); unset($hiddenMenus['admin_live_course']); } else { $hiddenMenus['admin_live_course_add'] = true; $hiddenMenus['admin_live_course'] = true; } $this->getSettingService()->set('menu_hiddens', $hiddenMenus); $this->getLogService()->info('system', 'update_settings', "更新课程设置", $setting); $this->setFlashMessage('success', '课程设置已保存!'); } $setting['live_student_capacity'] = empty($capacity['capacity']) ? 0 : $capacity['capacity']; return $this->render('TopxiaAdminBundle:System:live-course-setting.html.twig', array('courseSetting' => $setting, 'capacity' => $capacity)); }
public function getMaxOnlineAction(Request $request) { $conditions = $request->query->all(); if (!empty($conditions['courseId']) && !empty($conditions['lessonId'])) { $lesson = $this->getCourseService()->getCourseLesson($conditions['courseId'], $conditions['lessonId']); $client = new EdusohoLiveClient(); if ($lesson['type'] == 'live') { $result = $client->getMaxOnline($lesson['mediaId']); $lesson = $this->getCourseService()->setCourseLessonMaxOnlineNum($lesson['id'], $result['onLineNum']); } } return $this->createJsonResponse($lesson); }
public function entryReplay($lessonId, $courseLessonReplayId) { $lesson = $this->getLessonDao()->getLesson($lessonId); list($course, $member) = $this->tryTakeCourse($lesson['courseId']); $courseLessonReplay = $this->getCourseLessonReplayDao()->getCourseLessonReplay($courseLessonReplayId); $user = $this->getCurrentUser(); $args = array('liveId' => $lesson["mediaId"], 'replayId' => $courseLessonReplay["replayId"], 'provider' => $lesson["liveProvider"], 'user' => $user['email'], 'nickname' => $user['nickname']); $client = new EdusohoLiveClient(); $result = $client->entryReplay($args); return $result; }
public function createAction(Request $request) { $user = $this->getUserService()->getCurrentUser(); $userProfile = $this->getUserService()->getUserProfile($user['id']); $isLive = $request->query->get('flag'); $type = $isLive == "isLive" ? 'live' : 'normal'; if ($type == 'live') { $courseSetting = $this->setting('course', array()); if (!empty($courseSetting['live_course_enabled'])) { $client = new EdusohoLiveClient(); $capacity = $client->getCapacity(); } else { $capacity = array(); } if (empty($courseSetting['live_course_enabled'])) { return $this->createMessageResponse('info', '请前往后台开启直播,尝试创建!'); } if (empty($capacity['capacity']) && !empty($courseSetting['live_course_enabled'])) { return $this->createMessageResponse('info', '请联系EduSoho官方购买直播教室,然后才能开启直播功能!'); } } if (false === $this->get('security.context')->isGranted('ROLE_TEACHER')) { throw $this->createAccessDeniedException(); } if ($request->getMethod() == 'POST') { $course = $request->request->all(); $course = $this->getCourseService()->createCourse($course); return $this->redirect($this->generateUrl('course_manage', array('id' => $course['id']))); } return $this->render('TopxiaWebBundle:Course:create.html.twig', array('userProfile' => $userProfile, 'type' => $type)); }
public function getLiveCourse() { $user = $this->controller->getUserByToken($this->request); if (!$user->isLogin()) { return $this->createErrorResponse('not_login', "您尚未登录!"); } $courseId = $this->getParam("courseId", 0); $lessonId = $this->getParam("lessonId", 0); $lesson = $this->controller->getCourseService()->getCourseLesson($courseId, $lessonId); $now = time(); $params = array(); $params['email'] = 'live-' . $user['id'] . '@edusoho.net'; $params['nickname'] = $user['nickname']; $params['sign'] = "c{$lesson['courseId']}u{$user['id']}t{$now}"; $params['sign'] .= 's' . $this->makeSign($params['sign']); $params['liveId'] = $lesson['mediaId']; $params['provider'] = $lesson["liveProvider"]; $params['role'] = 'student'; $params['user'] = $params['email']; $client = new EdusohoLiveClient(); if (isset($lesson['replayStatus']) && $lesson['replayStatus'] == 'generated') { $result = $client->entryReplay($params, 'root'); } else { $result = $client->getRoomUrl($params, 'root'); } return array('data' => array('lesson' => $lesson, 'result' => $result)); }
public function courseSettingAction(Request $request) { $courseSetting = $this->getSettingService()->get('course', array()); $client = new EdusohoLiveClient(); $capacity = $client->getCapacity(); $default = array('welcome_message_enabled' => '0', 'welcome_message_body' => '{{nickname}},欢迎加入课程{{course}}', 'buy_fill_userinfo' => '0', 'teacher_modify_price' => '1', 'teacher_search_order' => '0', 'teacher_manage_student' => '0', 'teacher_export_student' => '0', 'student_download_media' => '0', 'free_course_nologin_view' => '1', 'relatedCourses' => '0', 'coursesPrice' => '0', 'allowAnonymousPreview' => '1', 'live_course_enabled' => '0', 'userinfoFields' => array(), "userinfoFieldNameArray" => array(), "copy_enabled" => '0'); $this->getSettingService()->set('course', $courseSetting); $courseSetting = array_merge($default, $courseSetting); if ($request->getMethod() == 'POST') { $courseSetting = $request->request->all(); if (!isset($courseSetting['userinfoFields'])) { $courseSetting['userinfoFields'] = array(); } if (!isset($courseSetting['userinfoFieldNameArray'])) { $courseSetting['userinfoFieldNameArray'] = array(); } $courseSetting['live_student_capacity'] = empty($capacity['capacity']) ? 0 : $capacity['capacity']; $this->getSettingService()->set('course', $courseSetting); $this->getLogService()->info('system', 'update_settings', "更新课程设置", $courseSetting); $this->setFlashMessage('success', '课程设置已保存!'); } $courseSetting['live_student_capacity'] = empty($capacity['capacity']) ? 0 : $capacity['capacity']; $userFields = $this->getUserFieldService()->getAllFieldsOrderBySeqAndEnabled(); if ($courseSetting['userinfoFieldNameArray']) { foreach ($userFields as $key => $fieldValue) { if (!in_array($fieldValue['fieldName'], $courseSetting['userinfoFieldNameArray'])) { $courseSetting['userinfoFieldNameArray'][] = $fieldValue['fieldName']; } } } return $this->render('TopxiaAdminBundle:System:course-setting.html.twig', array('courseSetting' => $courseSetting, 'capacity' => $capacity, 'userFields' => $userFields, 'capacity' => $capacity)); }
public function deleteAction(Request $request, $courseId, $lessonId) { $course = $this->getCourseService()->tryManageCourse($courseId); $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId); if ($course['type'] == 'live') { $client = new EdusohoLiveClient(); if ($lesson['type'] == 'live') { $result = $client->deleteLive($lesson['mediaId'], $lesson['liveProvider']); } $this->getCourseService()->deleteCourseLessonReplayByLessonId($lessonId); } $this->getCourseService()->deleteLesson($course['id'], $lessonId); $this->getCourseMaterialService()->deleteMaterialsByLessonId($lessonId); if ($this->isPluginInstalled('Homework')) { //如果安装了作业插件那么也删除作业和练习 $homework = $this->getHomeworkService()->getHomeworkByLessonId($lessonId); if (!empty($homework)) { $this->getHomeworkService()->removeHomework($homework['id']); } $this->getExerciseService()->deleteExercisesByLessonId($lesson['id']); } return $this->createJsonResponse(true); }
public function replayCreateAction(Request $request, $courseId, $lessonId) { $course = $this->getCourseService()->tryManageCourse($courseId); $resultList = $this->getCourseService()->generateLessonReplay($courseId, $lessonId); if (array_key_exists("error", $resultList)) { return $this->createJsonResponse($resultList); } $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId); $lesson["isEnd"] = intval(time() - $lesson["endTime"]) > 0; $client = new EdusohoLiveClient(); if ($lesson['type'] == 'live') { $result = $client->getMaxOnline($lesson['mediaId']); $this->getCourseService()->setCourseLessonMaxOnlineNum($lesson['id'], $result['onLineNum']); } return $this->render('TopxiaWebBundle:LiveCourseReplayManage:list-item.html.twig', array('course' => $this->getCourseService()->getCourse($courseId), 'lesson' => $lesson)); }
public function entryAction(Request $request, $courseId, $lessonId) { $user = $this->getCurrentUser(); if (!$user->isLogin()) { return $this->createMessageResponse('info', '你好像忘了登录哦?', null, 3000, $this->generateUrl('login')); } $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId); if (empty($lesson)) { return $this->createMessageResponse('info', '课时不存在!'); } if (empty($lesson['mediaId'])) { return $this->createMessageResponse('info', '直播教室不存在!'); } if ($lesson['startTime'] - time() > 7200) { return $this->createMessageResponse('info', '直播还没开始!'); } if ($lesson['endTime'] < time()) { return $this->createMessageResponse('info', '直播已结束!'); } $params = array('liveId' => $lesson['mediaId'], 'provider' => $lesson['liveProvider'], 'user' => $user['email'], 'nickname' => $user['nickname']); if ($this->getCourseService()->isCourseTeacher($courseId, $user['id'])) { $params['role'] = 'teacher'; } else { if ($this->getCourseService()->isCourseStudent($courseId, $user['id'])) { $params['role'] = 'student'; } else { return $this->createMessageResponse('info', '您不是课程学员,不能参加直播!'); } } if ($this->setting("developer.cloud_api_failover", 0)) { $client = new EdusohoLiveClient(); $result = $client->entryLive($params); if (empty($result) || isset($result['error'])) { return $this->createMessageResponse('info', $result['errorMsg']); } } return $this->render("TopxiaWebBundle:LiveCourse:classroom.html.twig", array('courseId' => $courseId, 'lessonId' => $lessonId, 'lesson' => $lesson, 'url' => $this->generateUrl('live_classroom_url', array('courseId' => $courseId, 'lessonId' => $lessonId)))); }