public function downloadAction(Request $request, $courseId, $materialId) { list($course, $member) = $this->getCourseService()->tryTakeCourse($courseId); if ($member && !$this->getCourseService()->isMemberNonExpired($course, $member)) { return $this->redirect($this->generateUrl('course_materials', array('id' => $courseId))); } if ($member && $member['levelId'] > 0) { if ($this->getVipService()->checkUserInMemberLevel($member['userId'], $course['vipLevelId']) != 'ok') { return $this->redirect($this->generateUrl('course_show', array('id' => $id))); } } $material = $this->getMaterialService()->getMaterial($courseId, $materialId); if (empty($material)) { throw $this->createNotFoundException(); } $file = $this->getUploadFileService()->getFile($material['fileId']); if (empty($file)) { throw $this->createNotFoundException(); } if ($file['storage'] == 'cloud') { $factory = new CloudClientFactory(); $client = $factory->createClient(); $client->download($client->getBucket(), $file['hashId'], 3600, $file['filename']); } else { return $this->createPrivateFileDownloadResponse($request, $file); } }
public function fileUrlAction(Request $request) { $id = $request->query->get('id'); $file = $this->getUploadFileService()->getFile($id); if (empty($file)) { throw $this->createNotFoundException(); } if ($file['targetType'] != 'question') { throw $this->createNotFoundException('targetType类型不正确'); } if ($file['storage'] != 'cloud') { throw $this->createNotFoundException('storage类型不正确'); } if ($file['convertStatus'] == 'waiting') { return $this->createJsonResponse(array('status' => 'waiting', 'message' => '音频正在转码中,请稍后再访问.')); } if ($file['convertStatus'] == 'error') { return $this->createJsonResponse(array('status' => 'waiting', 'message' => '音频转码失败,请重新上传此音频.')); } $factory = new CloudClientFactory(); $client = $factory->createClient(); $result = $client->generateFileUrl($client->getBucket(), $file['metas2']['shd']['key'], 3600); $result['status'] = 'ok'; return $this->createJsonResponse($result); }
public function showAction(Request $request, $id, $fileId) { $course = $this->getCourseService()->tryManageCourse($id); $file = $this->getUploadFileService()->getFile($fileId); if (empty($file)) { throw $this->createNotFoundException(); } if ($id != $file["targetId"]) { throw $this->createNotFoundException(); } if ($file['targetType'] == 'courselesson') { return $this->forward('TopxiaWebBundle:CourseLesson:file', array('fileId' => $file['id'], 'isDownload' => true)); } else { if ($file['targetType'] == 'coursematerial' || $file['targetType'] == 'materiallib') { if ($file['storage'] == 'cloud') { $factory = new CloudClientFactory(); $client = $factory->createClient(); $client->download($client->getBucket(), $file['hashId'], 3600, $file['filename']); } else { return $this->createPrivateFileDownloadResponse($request, $file); } } } throw $this->createNotFoundException(); }
private function getCloudClient() { if (empty($this->cloudClient)) { $factory = new CloudClientFactory(); $this->cloudClient = $factory->createClient(); } return $this->cloudClient; }
public function billAction(Request $request) { $factory = new CloudClientFactory(); $client = $factory->createClient(); $result = $client->getBills($client->getBucket()); if (!empty($result['error'])) { return $this->createMessageResponse('error', '获取账单信息失败,云视频参数配置不正确,或网络通讯失败。', '获取账单信息失败'); } return $this->render('TopxiaAdminBundle:Cloud:bill.html.twig', array('money' => $result['money'], 'bills' => $result['bills'])); }
public function operationAnalysisDashbordBlockAction(Request $request) { $todayTimeStart = strtotime(date("Y-m-d", time())); $todayTimeEnd = strtotime(date("Y-m-d", time() + 24 * 3600)); $yesterdayTimeStart = strtotime(date("Y-m-d", time() - 24 * 3600)); $yesterdayTimeEnd = strtotime(date("Y-m-d", time())); $todayRegisterNum = $this->getUserService()->searchUserCount(array("startTime" => $todayTimeStart, "endTime" => $todayTimeEnd)); $yesterdayRegisterNum = $this->getUserService()->searchUserCount(array("startTime" => $yesterdayTimeStart, "endTime" => $yesterdayTimeEnd)); $todayLoginNum = $this->getLogService()->analysisLoginNumByTime(strtotime(date("Y-m-d", time())), strtotime(date("Y-m-d", time() + 24 * 3600))); $yesterdayLoginNum = $this->getLogService()->analysisLoginNumByTime(strtotime(date("Y-m-d", time() - 24 * 3600)), strtotime(date("Y-m-d", time()))); $todayCourseNum = $this->getCourseService()->searchCourseCount(array("startTime" => $todayTimeStart, "endTime" => $todayTimeEnd)); $yesterdayCourseNum = $this->getCourseService()->searchCourseCount(array("startTime" => $yesterdayTimeStart, "endTime" => $yesterdayTimeEnd)); $todayLessonNum = $this->getCourseService()->searchLessonCount(array("startTime" => $todayTimeStart, "endTime" => $todayTimeEnd)); $yesterdayLessonNum = $this->getCourseService()->searchLessonCount(array("startTime" => $yesterdayTimeStart, "endTime" => $yesterdayTimeEnd)); $todayJoinLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $todayTimeStart, "paidEndTime" => $todayTimeEnd, "status" => "paid")); $yesterdayJoinLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $yesterdayTimeStart, "paidEndTime" => $yesterdayTimeEnd, "status" => "paid")); $todayBuyLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $todayTimeStart, "paidEndTime" => $todayTimeEnd, "status" => "paid", "amount" => "0.00")); $yesterdayBuyLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $yesterdayTimeStart, "paidEndTime" => $yesterdayTimeEnd, "status" => "paid", "amount" => "0.00")); $todayFinishedLessonNum = $this->getCourseService()->searchLearnCount(array("startTime" => $todayTimeStart, "endTime" => $todayTimeEnd, "status" => "finished")); $yesterdayFinishedLessonNum = $this->getCourseService()->searchLearnCount(array("startTime" => $yesterdayTimeStart, "endTime" => $yesterdayTimeEnd, "status" => "finished")); $todayAllVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time())), 'endTime' => strtotime(date("Y-m-d", time() + 24 * 3600)), "fileType" => 'video')); $yesterdayAllVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time() - 24 * 3600)), 'endTime' => strtotime(date("Y-m-d", time())), "fileType" => 'video')); $todayCloudVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time())), 'endTime' => strtotime(date("Y-m-d", time() + 24 * 3600)), "fileType" => 'video', 'fileStorage' => 'cloud')); $yesterdayCloudVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time() - 24 * 3600)), 'endTime' => strtotime(date("Y-m-d", time())), "fileType" => 'video', 'fileStorage' => 'cloud')); $todayLocalVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time())), 'endTime' => strtotime(date("Y-m-d", time() + 24 * 3600)), "fileType" => 'video', 'fileStorage' => 'local')); $yesterdayLocalVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time() - 24 * 3600)), 'endTime' => strtotime(date("Y-m-d", time())), "fileType" => 'video', 'fileStorage' => 'local')); $todayNetVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time())), 'endTime' => strtotime(date("Y-m-d", time() + 24 * 3600)), "fileType" => 'video', 'fileStorage' => 'net')); $yesterdayNetVideoViewedNum = $this->getCourseService()->searchAnalysisLessonViewCount(array('startTime' => strtotime(date("Y-m-d", time() - 24 * 3600)), 'endTime' => strtotime(date("Y-m-d", time())), "fileType" => 'video', 'fileStorage' => 'net')); $todayExitLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $todayTimeStart, "paidEndTime" => $todayTimeEnd, "statusPaid" => "paid", "statusCreated" => "created")); $yesterdayExitLessonNum = $this->getOrderService()->searchOrderCount(array("paidStartTime" => $yesterdayTimeStart, "paidEndTime" => $yesterdayTimeEnd, "statusPaid" => "paid", "statusCreated" => "created")); $todayIncome = $this->getOrderService()->analysisAmount(array("paidStartTime" => strtotime(date("Y-m-d", time())), "paidEndTime" => strtotime(date("Y-m-d", time() + 24 * 3600)), "status" => "paid")) + 0.0; $yesterdayIncome = $this->getOrderService()->analysisAmount(array("paidStartTime" => strtotime(date("Y-m-d", time() - 24 * 3600)), "paidEndTime" => strtotime(date("Y-m-d", time())), "status" => "paid")) + 0.0; $todayCourseIncome = $this->getOrderService()->analysisAmount(array("paidStartTime" => strtotime(date("Y-m-d", time())), "paidEndTime" => strtotime(date("Y-m-d", time() + 24 * 3600)), "status" => "paid", "targetType" => "course")) + 0.0; $yesterdayCourseIncome = $this->getOrderService()->analysisAmount(array("paidStartTime" => strtotime(date("Y-m-d", time() - 24 * 3600)), "paidEndTime" => strtotime(date("Y-m-d", time())), "status" => "paid", "targetType" => "course")) + 0.0; $storageSetting = $this->getSettingService()->get('storage'); if (!empty($storageSetting['cloud_access_key']) and !empty($storageSetting['cloud_secret_key'])) { $factory = new CloudClientFactory(); $client = $factory->createClient($storageSetting); $keyCheckResult = $client->checkKey(); } else { $keyCheckResult = array('error' => 'error'); } return $this->render('TopxiaAdminBundle:Default:operation-analysis-dashbord.html.twig', array('todayRegisterNum' => $todayRegisterNum, 'yesterdayRegisterNum' => $yesterdayRegisterNum, 'todayLoginNum' => $todayLoginNum, 'yesterdayLoginNum' => $yesterdayLoginNum, 'todayCourseNum' => $todayCourseNum, 'yesterdayCourseNum' => $yesterdayCourseNum, 'todayLessonNum' => $todayLessonNum, 'yesterdayLessonNum' => $yesterdayLessonNum, 'todayJoinLessonNum' => $todayJoinLessonNum, 'yesterdayJoinLessonNum' => $yesterdayJoinLessonNum, 'todayBuyLessonNum' => $todayBuyLessonNum, 'yesterdayBuyLessonNum' => $yesterdayBuyLessonNum, 'todayFinishedLessonNum' => $todayFinishedLessonNum, 'yesterdayFinishedLessonNum' => $yesterdayFinishedLessonNum, 'todayAllVideoViewedNum' => $todayAllVideoViewedNum, 'yesterdayAllVideoViewedNum' => $yesterdayAllVideoViewedNum, 'todayCloudVideoViewedNum' => $todayCloudVideoViewedNum, 'yesterdayCloudVideoViewedNum' => $yesterdayCloudVideoViewedNum, 'todayLocalVideoViewedNum' => $todayLocalVideoViewedNum, 'yesterdayLocalVideoViewedNum' => $yesterdayLocalVideoViewedNum, 'todayNetVideoViewedNum' => $todayNetVideoViewedNum, 'yesterdayNetVideoViewedNum' => $yesterdayNetVideoViewedNum, 'todayIncome' => $todayIncome, 'yesterdayIncome' => $yesterdayIncome, 'todayCourseIncome' => $todayCourseIncome, 'yesterdayCourseIncome' => $yesterdayCourseIncome, 'todayExitLessonNum' => $todayExitLessonNum, 'yesterdayExitLessonNum' => $yesterdayExitLessonNum, 'keyCheckResult' => $keyCheckResult)); }
protected function getPlayUrl($id, $mode = '') { $file = $this->getUploadFileService()->getFile($id); if (empty($file)) { throw $this->createNotFoundException(); } if (!in_array($file["type"], array("audio", "video"))) { throw $this->createAccessDeniedException(); } if ($file['storage'] == 'cloud') { $factory = new CloudClientFactory(); $client = $factory->createClient(); if (!empty($file['metas2']) && !empty($file['metas2']['sd']['key'])) { if (isset($file['convertParams']['convertor']) && $file['convertParams']['convertor'] == 'HLSEncryptedVideo') { $token = $this->makeToken('hls.playlist', $file['id'], $mode); if ($this->setting("developer.balloon_player")) { $returnJson = true; } $params = array('id' => $file['id'], 'token' => $token['token']); if (isset($returnJson)) { $params['returnJson'] = $returnJson; } return $this->generateUrl('hls_playlist', $params, true); } else { $result = $client->generateHLSQualitiyListUrl($file['metas2'], 3600); } } else { if (!empty($file['metas']) && !empty($file['metas']['hd']['key'])) { $key = $file['metas']['hd']['key']; } else { $key = $file['hashId']; } if ($key) { $result = $client->generateFileUrl($client->getBucket(), $key, 3600); } } return $result['url']; } else { $token = $this->makeToken('local.media', $file['id']); return $this->generateUrl('player_local_media', array('id' => $id, 'token' => $token['token'])); } }
protected function convertCourse($courseId, $siteUrl, $output) { $output->writeln("* 正在转码课程 #{$courseId}"); $lessons = $this->getCourseService()->getCourseLessons($courseId); foreach ($lessons as $lesson) { if ($lesson['type'] != 'video') { continue; } if ($lesson['mediaSource'] != 'self') { continue; } $file = $this->getUploadFileService()->getFile($lesson['mediaId']); if (empty($file)) { continue; } if ($file['storage'] != 'cloud') { continue; } if (!empty($file['metas2'])) { continue; } $factory = new CloudClientFactory(); $client = $factory->createClient(); $commands = array_keys($client->getVideoConvertCommands()); $convertKey = substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 12); $callbackUrl = $siteUrl . $this->getContainer()->get('router')->generate('uploadfile_cloud_convert_callback', array('key' => $convertKey)); $result = $client->convertVideo($client->getBucket(), $file['hashId'], implode(';', $commands), $callbackUrl); if (empty($result['persistentId'])) { $output->writeln("\t[ERROR] 转码请求失败。(课时:{$lesson['title']} #{$lesson['id']}) " . json_encode($result)); } else { $convertHash = "{$result['persistentId']}:{$convertKey}"; $this->getUploadFileService()->setFileConverting($file['id'], $convertHash); $output->writeln("\t[OK] 转码请求成功。(课时:{$lesson['title']} #{$lesson['id']}) "); } } }
public function lessonAction(Request $request, $courseId, $lessonId) { $token = $this->getUserToken($request); $user = $this->getCurrentUser(); if (!$user->isLogin()) { return $this->createErrorResponse($request, 'not_login', '您尚未登录,不能查看课时!'); } $course = $this->getCourseService()->getCourse($courseId); $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId); $json = array(); $json['number'] = $lesson['number']; $chapter = empty($lesson['chapterId']) ? null : $this->getCourseService()->getChapter($course['id'], $lesson['chapterId']); if ($chapter['type'] == 'unit') { $unit = $chapter; $json['unitNumber'] = $unit['number']; $chapter = $this->getCourseService()->getChapter($course['id'], $unit['parentId']); $json['chapterNumber'] = empty($chapter) ? 0 : $chapter['number']; } else { $json['chapterNumber'] = empty($chapter) ? 0 : $chapter['number']; $json['unitNumber'] = 0; } $json['title'] = $lesson['title']; $json['summary'] = $lesson['summary']; $json['type'] = $lesson['type']; $json['content'] = $this->convertAbsoluteUrl($this->container->get('request'), $lesson['content']); $json['status'] = $lesson['status']; if ($lesson['length'] > 0 and in_array($lesson['type'], array('audio', 'video'))) { $json['length'] = $this->container->get('topxia.twig.web_extension')->durationFilter($lesson['length']); } else { $json['length'] = 0; } $json['quizNum'] = $lesson['quizNum']; $json['materialNum'] = $lesson['materialNum']; $json['mediaId'] = $lesson['mediaId']; $json['mediaSource'] = $lesson['mediaSource']; if ($json['mediaSource'] == 'self') { $file = $this->getUploadFileService()->getFile($lesson['mediaId']); if (!empty($file)) { if ($file['storage'] == 'cloud') { $factory = new CloudClientFactory(); $client = $factory->createClient(); $json['mediaConvertStatus'] = $file['convertStatus']; if (!empty($file['metas2']) && !empty($file['metas2']['hd']['key'])) { if (isset($file['convertParams']['convertor']) && $file['convertParams']['convertor'] == 'HLSEncryptedVideo') { $token = $this->getTokenService()->makeToken('hlsvideo.view', array('data' => $lesson['id'], 'times' => 1, 'duration' => 3600)); $hlsKeyUrl = $this->generateUrl('course_lesson_hlskeyurl', array('courseId' => $lesson['courseId'], 'lessonId' => $lesson['id'], 'token' => $token['token']), true); $url = $client->generateHLSEncryptedListUrl($file['convertParams'], $file['metas2'], $hlsKeyUrl, 3600); } else { $url = $client->generateHLSQualitiyListUrl($file['metas2'], 3600); } $json['mediaUri'] = $url['url']; } else { if (!empty($file['metas']) && !empty($file['metas']['hd']['key'])) { $key = $file['metas']['hd']['key']; } else { if ($file['type'] == 'video') { $key = null; } else { $key = $file['hashId']; } } if ($key) { $url = $client->generateFileUrl($client->getBucket(), $key, 3600); $json['mediaUri'] = $url['url']; } else { $json['mediaUri'] = ''; } } } else { $json['mediaUri'] = $this->generateUrl('mapi_course_lesson_media', array('courseId' => $course['id'], 'lessonId' => $lesson['id'], 'token' => empty($token) ? '' : $token['token']), true); } } else { $json['mediaUri'] = ''; } } else { if ($json['mediaSource'] == 'youku') { $matched = preg_match('/\\/sid\\/(.*?)\\/v\\.swf/s', $lesson['mediaUri'], $matches); if ($matched) { $json['mediaUri'] = "http://player.youku.com/embed/{$matches[1]}"; } else { $json['mediaUri'] = ''; } } else { if ($json['mediaSource'] == 'tudou') { $matched = preg_match('/\\/v\\/(.*?)\\/v\\.swf/s', $lesson['mediaUri'], $matches); if ($matched) { $json['mediaUri'] = "http://www.tudou.com/programs/view/html5embed.action?code={$matches[1]}"; } else { $json['mediaUri'] = ''; } } else { $json['mediaUri'] = $lesson['mediaUri']; } } } $this->getCourseService()->startLearnLesson($courseId, $lessonId); return $this->createJson($request, $json); }
private function getDocumentLesson($lesson) { $file = $this->getUploadFileService()->getFile($lesson['mediaId']); if (empty($file)) { return $this->createErrorResponse('not_document', '文档还在转换中,还不能查看,请稍等。!'); } if ($file['convertStatus'] != 'success') { if ($file['convertStatus'] == 'error') { return $this->createErrorResponse('not_document', '文档转换失败,请联系管理员!'); } else { return $this->createErrorResponse('not_document', '文档还在转换中,还不能查看,请稍等!'); } } $factory = new CloudClientFactory(); $client = $factory->createClient(); $metas2 = $file['metas2']; $url = $client->generateFileUrl($client->getBucket(), $metas2['pdf']['key'], 3600); $pdfUri = $url['url']; $url = $client->generateFileUrl($client->getBucket(), $metas2['swf']['key'], 3600); $swfUri = $url['url']; $content = $lesson['content']; $content = $this->controller->convertAbsoluteUrl($this->request, $content); $render = $this->controller->render('TopxiaMobileBundleV2:Course:document.html.twig', array('pdfUri' => $pdfUri, 'swfUri' => $swfUri, 'title' => $lesson['title'])); $lesson['content'] = $render->getContent(); return $lesson; }
public function fileAction(Request $request, $fileId, $isDownload = false) { $file = $this->getUploadFileService()->getFile($fileId); if (empty($file)) { throw $this->createNotFoundException(); } if ($file['storage'] == 'cloud') { if ($isDownload) { $key = $file['hashId']; } else { if (!empty($file['metas']) && !empty($file['metas']['hd']['key'])) { $key = $file['metas']['hd']['key']; } else { $key = $file['hashId']; } } if (empty($key)) { throw $this->createNotFoundException(); } $factory = new CloudClientFactory(); $client = $factory->createClient(); if ($isDownload) { $client->download($client->getBucket(), $key, 3600, $file['filename']); } else { $client->download($client->getBucket(), $key); } } return $this->createLocalMediaResponse($request, $file, $isDownload); }
public function storageAction(Request $request) { $storageSetting = $this->getSettingService()->get('storage', array()); $default = array('upload_mode' => 'local', 'cloud_access_key' => '', 'cloud_secret_key' => '', 'cloud_bucket' => '', 'cloud_api_server' => '', 'video_quality' => 'low', 'video_audio_quality' => 'low', 'video_watermark' => 0, 'video_watermark_image' => '', 'video_watermark_position' => 'topright', 'video_fingerprint' => 0); $storageSetting = array_merge($default, $storageSetting); if ($request->getMethod() == 'POST') { $storageSetting = $request->request->all(); $this->getSettingService()->set('storage', $storageSetting); if (!empty($storageSetting['cloud_access_key']) or !empty($storageSetting['cloud_secret_key'])) { if (!empty($storageSetting['cloud_access_key']) and !empty($storageSetting['cloud_secret_key'])) { $factory = new CloudClientFactory(); $client = $factory->createClient($storageSetting); $keyCheckResult = $client->checkKey(); } else { $keyCheckResult = array('error' => 'error'); } } else { $keyCheckResult = array('status' => 'ok'); } $cop = $this->getAppService()->checkAppCop(); if ($cop && isset($cop['cop']) && $cop['cop'] == 1) { $this->getSettingService()->set('_app_cop', 1); } else { $this->getSettingService()->set('_app_cop', 0); } PluginUtil::refresh(); $this->getLogService()->info('system', 'update_settings', "更新云平台设置", $storageSetting); if (!empty($keyCheckResult['status']) && $keyCheckResult['status'] == 'ok') { $this->setFlashMessage('success', '云平台设置已保存!'); } else { $this->setFlashMessage('danger', 'AccessKey或者SecretKey设置不正确,会影响到系统正常的运行,请修改设置。'); } } return $this->render('TopxiaAdminBundle:System:storage.html.twig', array('storageSetting' => $storageSetting)); }