public function addFile($targetType, $targetId, array $fileInfo = array(), UploadedFile $originalFile = null) { if (!ArrayToolkit::requireds($fileInfo, array('filename', 'key', 'size'))) { throw $this->createServiceException('参数缺失,添加用户文件失败!'); } $uploadFile = array(); $uploadFile['targetId'] = $targetId; $uploadFile['targetType'] = $targetType; $uploadFile['hashId'] = $fileInfo['key']; $uploadFile['filename'] = $fileInfo['filename']; $uploadFile['ext'] = pathinfo($uploadFile['filename'], PATHINFO_EXTENSION); $uploadFile['size'] = (int) $fileInfo['size']; $uploadFile['etag'] = empty($fileInfo['etag']) ? '' : $fileInfo['etag']; $uploadFile['length'] = empty($fileInfo['length']) ? 0 : intval($fileInfo['length']); $uploadFile['metas'] = $this->encodeMetas(empty($fileInfo['metas']) ? array() : $fileInfo['metas']); $uploadFile['metas2'] = $this->encodeMetas(empty($fileInfo['metas2']) ? array() : $fileInfo['metas2']); if (empty($fileInfo['convertHash'])) { $uploadFile['convertHash'] = "ch-{$uploadFile['hashId']}"; $uploadFile['convertStatus'] = 'none'; $uploadFile['convertParams'] = ''; } else { $uploadFile['convertHash'] = "{$fileInfo['convertHash']}"; $uploadFile['convertStatus'] = 'waiting'; $uploadFile['convertParams'] = $fileInfo['convertParams']; } $uploadFile['type'] = FileToolkit::getFileTypeByMimeType($fileInfo['mimeType']); $uploadFile['canDownload'] = empty($uploadFile['canDownload']) ? 0 : 1; $uploadFile['storage'] = 'cloud'; $uploadFile['createdUserId'] = $this->getCurrentUser()->id; $uploadFile['updatedUserId'] = $uploadFile['createdUserId']; $uploadFile['updatedTime'] = $uploadFile['createdTime'] = time(); return $uploadFile; }
public function listAction(Request $request, $classroomId) { $classroom = $this->getClassroomService()->getClassroom($classroomId); $headTeacher = $this->getClassroomService()->findClassroomMembersByRole($classroomId, 'headTeacher', 0, 1); $assistants = $this->getClassroomService()->findClassroomMembersByRole($classroomId, 'assistant', 0, PHP_INT_MAX); $studentAssistants = $this->getClassroomService()->findClassroomMembersByRole($classroomId, 'studentAssistant', 0, PHP_INT_MAX); $members = $this->getClassroomService()->findClassroomMembersByRole($classroomId, 'teacher', 0, PHP_INT_MAX); $members = array_merge($headTeacher, $members, $assistants, $studentAssistants); $members = ArrayToolkit::index($members, 'userId'); $teacherIds = ArrayToolkit::column($members, 'userId'); $teachers = $this->getUserService()->findUsersByIds($teacherIds); $teachers = $this->sort($teachers, $members); $profiles = $this->getUserService()->findUserProfilesByIds($teacherIds); $user = $this->getCurrentUser(); $myfollowings = $this->getUserService()->filterFollowingIds($user['id'], $teacherIds); $member = $user ? $this->getClassroomService()->getClassroomMember($classroom['id'], $user['id']) : null; $layout = 'ClassroomBundle:Classroom:layout.html.twig'; if ($member && !$member['locked']) { $layout = 'ClassroomBundle:Classroom:join-layout.html.twig'; } if (!$classroom) { $classroomDescription = array(); } else { $classroomDescription = $classroom['about']; $classroomDescription = strip_tags($classroomDescription, ''); $classroomDescription = preg_replace("/ /", "", $classroomDescription); } return $this->render('ClassroomBundle:Classroom\\Teacher:list.html.twig', array('layout' => $layout, 'canLook' => $this->getClassroomService()->canLookClassroom($classroom['id']), 'classroom' => $classroom, 'teachers' => $teachers, 'profiles' => $profiles, 'member' => $member, 'members' => $members, 'Myfollowings' => $myfollowings, 'classroomDescription' => $classroomDescription)); }
/** * 获取一个分类下的课程成员列表 * * 可传入的参数: * categoryId 选填 分类ID * count 必需 学员数量,取值不能超过100 * * @param array $arguments 参数 * @return array 课程成员列表 */ public function getData(array $arguments) { $this->checkCount($arguments); if (empty($arguments['categoryId'])) { $conditions = array('status' => 'published'); } else { $conditions = array('status' => 'published', 'categoryId' => $arguments['categoryId']); } $courses = $this->getCourseService()->searchCourses($conditions, 'latest', 0, 1000); $courseIds = ArrayToolkit::column($courses, 'id'); $conditions = array('courseIds' => $courseIds, 'unique' => true, 'role' => 'student'); $members = $this->getCourseService()->searchMembers($conditions, array('createdTime', 'DESC'), 0, $arguments['count']); $courseIds = ArrayToolkit::column($members, 'courseId'); $userIds = ArrayToolkit::column($members, 'userId'); $users = $this->getUserService()->findUsersByIds($userIds); $users = ArrayToolkit::index($users, 'id'); $this->unsetUserPasswords($users); $courses = $this->getCourseService()->findCoursesByIds($courseIds); $courses = ArrayToolkit::index($courses, 'id'); foreach ($members as &$member) { $member['course'] = $courses[$member["courseId"]]; $member['user'] = $users[$member["userId"]]; } return $members; }
public function createOrder($info) { $connection = ServiceKernel::instance()->getConnection(); try { $connection->beginTransaction(); $user = $this->getCurrentUser(); if (!$user->isLogin()) { throw $this->createServiceException('用户未登录,不能创建订单'); } if (!ArrayToolkit::requireds($info, array('targetId', 'payment'))) { throw $this->createServiceException('订单数据缺失,创建课程订单失败。'); } // 获得锁 $user = $this->getUserService()->getUser($user['id'], true); if ($this->getClassroomService()->isClassroomStudent($info['targetId'], $user['id'])) { throw $this->createServiceException('已经是班级学员,创建订单失败。'); } $classroom = $this->getClassroomService()->getClassroom($info['targetId']); if (empty($classroom)) { throw $this->createServiceException('班级不存在,创建课程订单失败。'); } if ($classroom['private'] == 1) { throw $this->createServiceException('该班级是封闭班级,学员不能自行加入!'); } $order = array(); $order['userId'] = $user['id']; $order['title'] = "购买班级《{$classroom['title']}》"; $order['targetType'] = 'classroom'; $order['targetId'] = $classroom['id']; $order['payment'] = $info['payment']; $order['amount'] = empty($info['amount']) ? 0 : $info['amount']; $order['priceType'] = $info['priceType']; $order['totalPrice'] = $info["totalPrice"]; $order['coinRate'] = $info['coinRate']; $order['coinAmount'] = $info['coinAmount']; $order['snPrefix'] = 'CR'; if (!empty($info['note'])) { $order['data'] = array('note' => $info['note']); } if (!empty($info['coupon'])) { $order['coupon'] = $info['coupon']; $order['couponDiscount'] = $info['couponDiscount']; } $order = $this->getOrderService()->createOrder($order); if (empty($order)) { throw $this->createServiceException('创建订单失败!'); } // 免费班级,就直接将订单置为已购买 if (intval($order['amount'] * 100) == 0 && intval($order['coinAmount'] * 100) == 0 && empty($order['coupon'])) { list($success, $order) = $this->getOrderService()->payOrder(array('sn' => $order['sn'], 'status' => 'success', 'amount' => $order['amount'], 'paidTime' => time())); $info = array('orderId' => $order['id'], 'remark' => empty($order['data']['note']) ? '' : $order['data']['note']); $this->getClassroomService()->becomeStudent($order['targetId'], $order['userId'], $info); } $connection->commit(); return $order; } catch (\Exception $e) { $connection->rollBack(); throw $e; } }
public function showAction(Request $request, $id) { $buyer = $this->getCurrentUser(); $ex = $request->query->all(); $myexchangeid = $ex['ex']; $applyid = $ex[applyid]; $exchange = $this->getExchangeService()->getExchange($id); $condition = array('exchangeId' => $exchange['id'], 'userId' => $buyer['id']); $buyerapplys = $this->getApplyService()->searchApplys($condition, 'latest', 0, 10); $buyerapplyIds = ArrayToolkit::column($buyerapplys, 'id'); $sellerId = $exchange['userId']; $seller = $this->getUserService()->getUser($sellerId); if (empty($exchange)) { throw $this->createNotFoundException("宝贝不存在"); } $conditions = array('exchangeId' => $exchange['id']); $paginator = new Paginator($this->get('request'), $this->getApplyService()->searchApplyCount($conditions), 5); $applys = $this->getApplyService()->searchApplys($conditions, 'latest', $paginator->getOffsetCount(), $paginator->getPerPageCount()); $applysIds = ArrayToolkit::column($applys, 'id'); // dump($applysIds); // die; $flag = 0; if (!empty($applysIds)) { foreach ($buyerapplyIds as $val) { if (in_array($val, $applysIds)) { $flag = 1; break; } } } $userIds = ArrayToolkit::column($applys, 'userId'); $users = $this->getUserService()->findUsersByIds($userIds); return $this->render("TopxiaWebBundle:Exchange:show.html.twig", array('flag' => $flag, 'seller' => $seller, 'applyid' => $applyid, 'myexchangeid' => $myexchangeid, 'exchange' => $exchange, 'applys' => $applys, 'users' => $users, 'paginator' => $paginator)); }
public function exploreAction(Request $request) { if (!$this->setting('course.live_course_enabled')) { return $this->createMessageResponse('info', '直播频道已关闭'); } $recenntLessonsCondition = array('status' => 'published', 'endTimeGreaterThan' => time()); $paginator = new Paginator($this->get('request'), $this->getCourseService()->searchLessonCount($recenntLessonsCondition), 30); $recentlessons = $this->getCourseService()->searchLessons($recenntLessonsCondition, array('startTime', 'ASC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); $courses = $this->getCourseService()->findCoursesByIds(ArrayToolkit::column($recentlessons, 'courseId')); $recentCourses = array(); foreach ($recentlessons as $lesson) { $course = $courses[$lesson['courseId']]; if ($course['status'] != 'published') { continue; } $course['lesson'] = $lesson; $recentCourses[] = $course; } $liveCourses = $this->getCourseService()->searchCourses(array('status' => 'published', 'type' => 'live'), 'lastest', 0, 10); $userIds = array(); foreach ($liveCourses as $course) { $userIds = array_merge($userIds, $course['teacherIds']); } $users = $this->getUserService()->findUsersByIds($userIds); $default = $this->getSettingService()->get('default', array()); return $this->render('TopxiaWebBundle:LiveCourse:index.html.twig', array('recentCourses' => $recentCourses, 'liveCourses' => $liveCourses, 'users' => $users, 'paginator' => $paginator, 'default' => $default)); }
/** * 获取最热话题 * * 可传入的参数: * * count 必需 话题数量,取值不能超过100 * * @param array $arguments 参数 * @return array 最热话题 */ public function getData(array $arguments) { $groupSetting = $this->getSettingService()->get('group', array()); $time = 7 * 24 * 60 * 60; if (isset($groupSetting['threadTime_range'])) { $time = $groupSetting['threadTime_range'] * 24 * 60 * 60; } $hotThreads = $this->getThreadService()->searchThreads(array('createdTime' => time() - $time, 'status' => 'open'), array(array('isStick', 'DESC'), array('postNum', 'DESC'), array('createdTime', 'DESC')), 0, $arguments['count']); $ownerIds = ArrayToolkit::column($hotThreads, 'userId'); $groupIds = ArrayToolkit::column($hotThreads, 'groupId'); $userIds = ArrayToolkit::column($hotThreads, 'lastPostMemberId'); $lastPostMembers = $this->getUserService()->findUsersByIds($userIds); $owners = $this->getUserService()->findUsersByIds($ownerIds); $groups = $this->getGroupService()->getGroupsByids($groupIds); foreach ($hotThreads as $key => $thread) { if ($thread['userId'] == $owners[$thread['userId']]['id']) { $hotThreads[$key]['user'] = $owners[$thread['userId']]; } if ($thread['lastPostMemberId'] > 0 && $thread['lastPostMemberId'] == $lastPostMembers[$thread['lastPostMemberId']]['id']) { $hotThreads[$key]['lastPostMember'] = $lastPostMembers[$thread['lastPostMemberId']]; } if ($thread['groupId'] == $groups[$thread['groupId']]['id']) { $hotThreads[$key]['group'] = $groups[$thread['groupId']]; } } return $hotThreads; }
public function becomeStudentAndCreateOrder($userId, $courseId, $data) { if (!ArrayToolkit::requireds($data, array("price", "remark"))) { throw $this->createServiceException("参数不对!"); } $user = $this->getUserService()->getUser($userId); if (empty($user)) { throw $this->createNotFoundException("用户{$user['nickname']}不存在"); } $course = $this->getCourseService()->getCourse($courseId); if (empty($course)) { throw $this->createNotFoundException("课程{$course['title']}不存在"); } if ($this->getCourseService()->isCourseStudent($course['id'], $user['id'])) { throw $this->createNotFoundException("用户已经是学员,不能添加!"); } $orderTitle = "购买课程《{$course['title']}》"; if (isset($data["isAdminAdded"]) && $data["isAdminAdded"] == 1) { $orderTitle = $orderTitle . "(管理员添加)"; } $order = $this->getOrderService()->createOrder(array('userId' => $user['id'], 'title' => $orderTitle, 'targetType' => 'course', 'targetId' => $course['id'], 'amount' => $data['price'], 'totalPrice' => $data['price'], 'payment' => 'none', 'snPrefix' => 'C')); $this->getOrderService()->payOrder(array('sn' => $order['sn'], 'status' => 'success', 'amount' => $order['amount'], 'paidTime' => time())); $info = array('orderId' => $order['id'], 'note' => $data['remark']); $this->getCourseService()->becomeStudent($order['targetId'], $order['userId'], $info); $member = $this->getCourseService()->getCourseMember($course['id'], $user['id']); if (isset($data["isAdminAdded"]) && $data["isAdminAdded"] == 1) { $this->getNotificationService()->notify($member['userId'], 'student-create', array('courseId' => $course['id'], 'courseTitle' => $course['title'])); } $this->getLogService()->info('course', 'add_student', "课程《{$course['title']}》(#{$course['id']}),添加学员{$user['nickname']}(#{$user['id']}),备注:{$data['remark']}"); return array($course, $member, $order); }
public function listAction(Request $request, $id) { $classroom = $this->getClassroomService()->getClassroom($id); $courses = $this->getClassroomService()->findActiveCoursesByClassroomId($id); $coursesNum = count($courses); $user = $this->getCurrentUser(); $member = $user ? $this->getClassroomService()->getClassroomMember($classroom['id'], $user['id']) : null; if (!$this->getClassroomService()->canLookClassroom($classroom['id'])) { return $this->createMessageResponse('info', "非常抱歉,您无权限访问该{$classroomSetting['name']},如有需要请联系客服", '', 3, $this->generateUrl('homepage')); } $conditions = array('classroomId' => $id); $reviewsNum = $this->getClassroomReviewService()->searchReviewCount($conditions); $paginator = new Paginator($this->get('request'), $reviewsNum, 20); $reviews = $this->getClassroomReviewService()->searchReviews($conditions, array('createdTime', 'DESC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); $reviewUserIds = ArrayToolkit::column($reviews, 'userId'); $reviewUsers = $this->getUserService()->findUsersByIds($reviewUserIds); $classroom = $this->getClassroomService()->getClassroom($id); $review = $this->getClassroomReviewService()->getUserClassroomReview($user['id'], $classroom['id']); $layout = 'ClassroomBundle:Classroom:layout.html.twig'; if ($member && !$member['locked']) { $layout = 'ClassroomBundle:Classroom:join-layout.html.twig'; } if (!$classroom) { $classroomDescription = array(); } else { $classroomDescription = $classroom['about']; $classroomDescription = strip_tags($classroomDescription, ''); $classroomDescription = preg_replace("/ /", "", $classroomDescription); } return $this->render("ClassroomBundle:Classroom\\Review:list.html.twig", array('classroom' => $classroom, 'courses' => $courses, 'paginator' => $paginator, 'reviewsNum' => $reviewsNum, 'reviews' => $reviews, 'userReview' => $review, 'reviewSaveUrl' => $this->generateUrl('classroom_review_create', array('id' => $id)), 'users' => $reviewUsers, 'member' => $member, 'layout' => $layout, 'classroomDescription' => $classroomDescription, 'canReview' => $this->isClassroomMember($classroom, $user['id']))); }
/** * 获取最新资讯列表 * * 可传入的参数: * count 必需 课程数量,取值不能超过100 * * type: featured 可选 是否头条 * promoted 可选 是否推荐 * sticky 可选 是否置顶 * categoryId: 分类ID * * @param array $arguments 参数 * @return array 资讯列表 */ public function getData(array $arguments) { $this->checkCount($arguments); $conditions = array(); if (!empty($arguments['type']) && $arguments['type'] == 'featured') { $conditions['featured'] = 1; } if (!empty($arguments['type']) && $arguments['type'] == 'promoted') { $conditions['promoted'] = 1; } if (!empty($arguments['type']) && $arguments['type'] == 'sticky') { $conditions['sticky'] = 1; } if (!empty($arguments['categoryId'])) { $conditions['categoryId'] = (int) $arguments['categoryId']; $conditions['includeChildren'] = 1; } $conditions['status'] = 'published'; $articles = $this->getArticleService()->searchArticles($conditions, 'created', 0, $arguments['count']); $categorise = $this->getCategoryService()->findCategoriesByIds(ArrayToolkit::column($articles, 'categoryId')); foreach ($articles as $key => $article) { if (empty($article['categoryId'])) { continue; } if ($article['categoryId'] == $categorise[$article['categoryId']]['id']) { $articles[$key]['category'] = $categorise[$article['categoryId']]; } } return $articles; }
public function uploadMaterial($material) { if (!ArrayToolkit::requireds($material, array('courseId', 'fileId'))) { throw $this->createServiceException('参数缺失,上传失败!'); } $course = $this->getCourseService()->getCourse($material['courseId']); if (empty($course)) { throw $this->createServiceException('课程不存在,上传资料失败!'); } $fields = array('courseId' => $material['courseId'], 'lessonId' => empty($material['lessonId']) ? 0 : $material['lessonId'], 'description' => empty($material['description']) ? '' : $material['description'], 'userId' => $this->getCurrentUser()->id, 'createdTime' => time()); if (empty($material['fileId'])) { if (empty($material['link'])) { throw $this->createServiceException('资料链接地址不能为空,添加资料失败!'); } $fields['fileId'] = 0; $fields['link'] = $material['link']; $fields['title'] = empty($material['description']) ? $material['link'] : $material['description']; } else { $fields['fileId'] = (int) $material['fileId']; $file = $this->getUploadFileService()->getFile($material['fileId']); if (empty($file)) { throw $this->createServiceException('文件不存在,上传资料失败!'); } $fields['link'] = ''; $fields['title'] = $file['filename']; $fields['fileSize'] = $file['size']; } $material = $this->getMaterialDao()->addMaterial($fields); $this->getCourseService()->increaseLessonMaterialCount($fields['lessonId']); return $material; }
/** *类似这样的,提交数据保存到数据的流程是: * * 1. 检查参数是否正确,不正确就抛出异常 * 2. 过滤数据 * 3. 插入到数据库 * 4. 更新其他相关的缓存字段 */ public function saveNote(array $note) { if (!ArrayToolkit::requireds($note, array('lessonId', 'courseId', 'content'))) { throw $this->createServiceException('缺少必要的字段,保存笔记失败'); } list($course, $member) = $this->getCourseService()->tryTakeCourse($note['courseId']); $user = $this->getCurrentUser(); if (!$this->getCourseService()->getCourseLesson($note['courseId'], $note['lessonId'])) { throw $this->createServiceException('课时不存在,保存笔记失败'); } $note = ArrayToolkit::filter($note, array('courseId' => 0, 'lessonId' => 0, 'content' => '')); $note['content'] = $this->purifyHtml($note['content']) ?: ''; $note['length'] = $this->calculateContnentLength($note['content']); $existNote = $this->getUserLessonNote($user['id'], $note['lessonId']); if (!$existNote) { $note['userId'] = $user['id']; $note['createdTime'] = time(); $note = $this->getNoteDao()->addNote($note); } else { $note['updatedTime'] = time(); $note = $this->getNoteDao()->updateNote($existNote['id'], $note); } $this->getCourseService()->setMemberNoteNumber($note['courseId'], $note['userId'], $this->getNoteDao()->getNoteCountByUserIdAndCourseId($note['userId'], $note['courseId'])); return $note; }
public function modifyUserInfoAction(Request $request) { $formData = $request->request->all(); $user = $this->getCurrentUser(); if (empty($user)) { return $this->createMessageResponse('error', '用户未登录,不能购买。'); } $course = $this->getCourseService()->getCourse($formData['targetId']); if (empty($course)) { return $this->createMessageResponse('error', '课程不存在,不能购买。'); } $userInfo = ArrayToolkit::parts($formData, array('truename', 'mobile', 'qq', 'company', 'weixin', 'weibo', 'idcard', 'gender', 'job', 'intField1', 'intField2', 'intField3', 'intField4', 'intField5', 'floatField1', 'floatField2', 'floatField3', 'floatField4', 'floatField5', 'dateField1', 'dateField2', 'dateField3', 'dateField4', 'dateField5', 'varcharField1', 'varcharField2', 'varcharField3', 'varcharField4', 'varcharField5', 'varcharField10', 'varcharField6', 'varcharField7', 'varcharField8', 'varcharField9', 'textField1', 'textField2', 'textField3', 'textField4', 'textField5', 'textField6', 'textField7', 'textField8', 'textField9', 'textField10')); $userInfo = $this->getUserService()->updateUserProfile($user['id'], $userInfo); $coinSetting = $this->setting("coin"); if (isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"] == 1 && isset($coinSetting["price_type"]) && $coinSetting["price_type"] == "Coin" && $course['coinPrice'] == 0 || $course['price'] == 0) { $formData['amount'] = 0; $formData['totalPrice'] = 0; $formData['priceType'] = empty($coinSetting["priceType"]) ? 'RMB' : $coinSetting["priceType"]; $formData['coinRate'] = empty($coinSetting["coinRate"]) ? 1 : $coinSetting["coinRate"]; $formData['coinAmount'] = 0; $order = $this->getCourseOrderService()->createOrder($formData); if ($order['status'] == 'paid') { return $this->redirect($this->generateUrl('course_show', array('id' => $order['targetId']))); } } return $this->redirect($this->generateUrl('order_show', array('targetId' => $formData['targetId'], 'targetType' => 'course'))); }
public function updateSeqsAction(Request $request) { $data = $request->request->get('data'); $ids = ArrayToolkit::column($data, 'id'); $this->getNavigationService()->updateNavigationsSequenceByIds($ids); return $this->createJsonResponse(true); }
/** * 获取所有用户的最新动态 * * 可传入的参数: * mode 必需 动态的模式(simple, full) * count 必需 获取动态数量 * objectType 可选 动态所属对象类型 * objectId 可选 动态所属对象编号 * * @param array $arguments 参数 * @return array 用户列表 */ public function getData(array $arguments) { $conditions = array(); if (isset($arguments['private'])) { if ($arguments['private'] == 0) { $conditions['private'] = 0; } } if (isset($arguments['objectType']) && isset($arguments['objectId'])) { if ($arguments['objectType'] == 'course') { $conditions['courseIds'] = array($arguments['objectId']); } else { $courses = $this->getClassroomService()->findActiveCoursesByClassroomId($classroom['id']); if ($courses) { $courseIds = ArrayToolkit::column($courses, 'id'); $conditions['classroomCourseIds'] = $courseIds; $conditions['classroomId'] = $arguments['objectId']; } else { $conditions['onlyClassroomId'] = $arguments['objectId']; } } } $statuses = $this->getStatusService()->searchStatuses($conditions, array('createdTime', 'DESC'), 0, $arguments['count']); if ($statuses) { $userIds = ArrayToolkit::column($statuses, 'userId'); $users = $this->getUserService()->findUsersByIds($userIds); $manager = ExtensionManager::instance(); foreach ($statuses as &$status) { $status['user'] = $users[$status['userId']]; $status['message'] = $manager->renderStatus($status, $arguments['mode']); unset($status); } } return $statuses; }
public function recommendClassroomsAction($course) { $classrooms = array(); $classrooms = array_merge($classrooms, array_values($this->getClassroomService()->findClassroomsByCourseId($course['id']))); $belongCourseClassroomIds = ArrayToolkit::column($classrooms, 'id'); if ($course['categoryId'] > 0) { $classrooms = array_merge($classrooms, $this->getClassroomService()->searchClassrooms(array('categoryIds' => array($course['categoryId']), 'private' => 0), array('recommendedSeq', 'ASC'), 0, 8)); } $classrooms = array_merge($classrooms, $this->getClassroomService()->searchClassrooms(array('recommended' => 1, 'private' => 0, 'status' => 'published'), array('recommendedSeq', 'ASC'), 0, 11)); $recommends = array(); foreach ($classrooms as $key => $classroom) { if (isset($recommends[$classroom['id']])) { continue; } if (count($recommends) >= 8) { break; } if (in_array($classroom['id'], $belongCourseClassroomIds)) { $classroom['belogCourse'] = true; } if ($classroom['status'] == 'published') { $recommends[$classroom['id']] = $classroom; } } return $this->render('TopxiaWebBundle:Course/Part:normal-header-recommend-classrooms.html.twig', array('classrooms' => $recommends)); }
public function listAction(Request $request) { $user = $this->getCurrentUser(); list($course, $member) = $this->getCourseService()->tryTakeCourse($request->query->get('courseId')); $items = $this->getCourseService()->getCourseItems($course['id']); $learnStatuses = $this->getCourseService()->getUserLearnLessonStatuses($user['id'], $course['id']); $homeworkPlugin = $this->getAppService()->findInstallApp('Homework'); $homeworkLessonIds = array(); $exercisesLessonIds = array(); $testpaperIds = array(); array_walk($items, function ($item, $key) use(&$testpaperIds) { if ($item['type'] == 'testpaper') { array_push($testpaperIds, $item['mediaId']); } }); $testpapers = $this->getTestpaperService()->findTestpapersByIds($testpaperIds); if ($homeworkPlugin) { $lessons = $this->getCourseService()->getCourseLessons($course['id']); $lessonIds = ArrayToolkit::column($lessons, 'id'); $homeworks = $this->getHomeworkService()->findHomeworksByCourseIdAndLessonIds($course['id'], $lessonIds); $exercises = $this->getExerciseService()->findExercisesByLessonIds($lessonIds); $homeworkLessonIds = ArrayToolkit::column($homeworks, 'lessonId'); $exercisesLessonIds = ArrayToolkit::column($exercises, 'lessonId'); } return $this->render('TopxiaWebBundle:LessonLessonPlugin:list.html.twig', array('course' => $course, 'items' => $items, 'learnStatuses' => $learnStatuses, 'currentTime' => time(), 'weeks' => array("日", "一", "二", "三", "四", "五", "六"), 'homeworkLessonIds' => $homeworkLessonIds, 'exercisesLessonIds' => $exercisesLessonIds, 'member' => $member, 'testpapers' => $testpapers)); }
/** * 获取加精的课程话题列表 * * 可传入的参数: * type 选填 话题类型 * count 必需 课程话题数量,取值不能超过100 * * @param array $arguments 参数 * @return array 课程话题 */ public function getData(array $arguments) { $this->checkCount($arguments); if (empty($arguments['type'])) { $type = ""; } else { $type = $arguments['type']; } $arguments['status'] = '1'; $threads = $this->getThreadService()->findEliteThreadsByType($type, $arguments['status'], 0, $arguments['count']); $courses = $this->getCourseService()->findCoursesByIds(ArrayToolkit::column($threads, 'courseId')); $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($threads, 'userId')); $latestPostUsers = $this->getUserService()->findUsersByIds(ArrayToolkit::column($threads, 'latestPostUserId')); foreach ($threads as $key => $thread) { if ($thread['courseId'] == $courses[$thread['courseId']]['id']) { $threads[$key]['course'] = $courses[$thread['courseId']]; } if ($thread['userId'] == $users[$thread['userId']]['id']) { $threads[$key]['user'] = $users[$thread['userId']]; } if ($thread['latestPostUserId'] == $latestPostUsers[$thread['latestPostUserId']]['id']) { $threads[$key]['latestPostUser'] = $latestPostUsers[$thread['latestPostUserId']]; } } return $threads; }
public function indexAction(Request $request, $status) { $courses = $this->getCourseService()->searchCourses(array('type' => 'live', 'status' => 'published'), $sort = 'latest', 0, 1000); $courseIds = ArrayToolkit::column($courses, 'id'); $courses = ArrayToolkit::index($courses, 'id'); $conditions['type'] = "live"; switch ($status) { case 'coming': $conditions['startTimeGreaterThan'] = time(); break; case 'end': $conditions['endTimeLessThan'] = time(); break; case 'underway': $conditions['startTimeLessThan'] = time(); $conditions['endTimeGreaterThan'] = time(); break; } $conditions['courseIds'] = $courseIds; $conditions['status'] = 'published'; $paginator = new Paginator($request, $this->getCourseService()->searchLessonCount($conditions), 20); if ($status == 'end') { $lessons = $this->getCourseService()->searchLessons($conditions, array('startTime', 'DESC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); } else { $lessons = $this->getCourseService()->searchLessons($conditions, array('startTime', 'ASC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); } return $this->render('TopxiaAdminBundle:LiveCourse:index.html.twig', array('status' => $status, 'lessons' => $lessons, 'courses' => $courses, 'paginator' => $paginator)); }
public function createMoneyCard(array $moneyCardData) { $batch = ArrayToolkit::parts($moneyCardData, array('money', 'cardPrefix', 'cardLength', 'number', 'note', 'deadline')); $batch['money'] = (int) $batch['money']; $batch['cardLength'] = (int) $batch['cardLength']; $batch['number'] = (int) $batch['number']; if ($batch['money'] <= 0) { throw $this->createServiceException('ERROR! Money Value Less Than Zero!'); } if ($batch['cardLength'] <= 0) { throw $this->createServiceException('ERROR! CardLength Less Than Zero!'); } if ($batch['number'] <= 0) { throw $this->createServiceException('ERROR! Card Number Less Than Zero!'); } $batch['rechargedNumber'] = 0; $batch['userId'] = $this->getCurrentUser()->id; $batch['createdTime'] = time(); $moneyCardIds = $this->makeRands($batch['cardLength'], $batch['number'], $batch['cardPrefix'], $moneyCardData['passwordLength']); if (!$this->getMoneyCardDao()->isCardIdAvaliable($moneyCardIds)) { throw $this->createServiceException('卡号有重复,生成失败,请重新生成!'); } $batch = $this->getMoneyCardBatchDao()->addBatch($batch); $moneyCards = array(); foreach ($moneyCardIds as $cardid => $cardPassword) { $moneyCards[] = array('cardId' => $cardid, 'password' => $cardPassword, 'deadline' => $moneyCardData['deadline'], 'cardStatus' => 'normal', 'batchId' => $batch['id']); } $this->getMoneyCardDao()->addMoneyCard($moneyCards); $this->getLogService()->info('money_card_batch', 'create', "创建新批次充值卡,卡号前缀为({$batch['cardPrefix']}),批次为({$batch['id']})"); return $batch; }
public function indexAction(Request $request) { $conditions = $request->query->all(); $conditions = ArrayToolkit::parts($conditions, array('nickname')); $paginator = new Paginator($this->get('request'), $this->getUserService()->searchUserCount($conditions), 20); $users = $this->getUserService()->searchUsers($conditions, array('id', 'ASC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); $inviteInformations = array(); foreach ($users as $key => $user) { $invitedRecords = $this->getInviteRecordService()->findRecordsByInviteUserId($user['id']); $payingUserCount = 0; $coinAmountTotalPrice = 0; $amountTotalPrice = 0; $totalPrice = 0; $totalCoinAmount = 0; $totalAmount = 0; foreach ($invitedRecords as $keynum => $invitedRecord) { $coinAmountTotalPrice = $this->getOrderService()->analysisCoinAmount(array('userId' => $invitedRecord['invitedUserId'], 'coinAmount' => 0, 'status' => 'paid', 'paidStartTime' => $invitedRecord['inviteTime'])); $amountTotalPrice = $this->getOrderService()->analysisAmount(array('userId' => $invitedRecord['invitedUserId'], 'amount' => 0, 'status' => 'paid', 'paidStartTime' => $invitedRecord['inviteTime'])); $tempPrice = $this->getOrderService()->analysisTotalPrice(array('userId' => $invitedRecord['invitedUserId'], 'status' => 'paid', 'paidStartTime' => $invitedRecord['inviteTime'])); if ($coinAmountTotalPrice || $amountTotalPrice) { $payingUserCount = $payingUserCount + 1; } $totalCoinAmount = $totalCoinAmount + $coinAmountTotalPrice; $totalAmount = $totalAmount + $amountTotalPrice; $totalPrice = $totalPrice + $tempPrice; } $inviteInformations[] = array('id' => $user['id'], 'nickname' => $user['nickname'], 'payingUserCount' => $payingUserCount, 'payingUserTotalPrice' => $totalPrice, 'coinAmountPrice' => $totalCoinAmount, 'amountPrice' => $totalAmount, 'count' => count($invitedRecords)); } return $this->render('TopxiaAdminBundle:Invite:index.html.twig', array('paginator' => $paginator, 'inviteInformations' => $inviteInformations)); }
public function indexAction(Request $request) { $fields = $request->query->all(); $conditions = array('roles' => '', 'keywordType' => '', 'keyword' => '', 'keywordUserType' => ''); if (empty($fields)) { $fields = array(); } $conditions = array_merge($conditions, $fields); //根据mobile查询user_profile获得userIds if (isset($conditions['keywordType']) && $conditions['keywordType'] == 'verifiedMobile') { $profilesCount = $this->getUserService()->searchUserProfileCount(array('mobile' => $conditions['keyword'])); $userProfiles = $this->getUserService()->searchUserProfiles(array('mobile' => $conditions['keyword']), array('id', 'DESC'), 0, $profilesCount); $userIds = ArrayToolkit::column($userProfiles, 'id'); if (!empty($userIds)) { unset($conditions['keywordType']); unset($conditions['keyword']); $conditions['userIds'] = $userIds; } } $userCount = $this->getUserService()->searchUserCount($conditions); $paginator = new Paginator($this->get('request'), $userCount, 20); $users = $this->getUserService()->searchUsers($conditions, array('createdTime', 'DESC'), $paginator->getOffsetCount(), $paginator->getPerPageCount()); $app = $this->getAppService()->findInstallApp("UserImporter"); $showUserExport = false; if (!empty($app) && array_key_exists('version', $app)) { $showUserExport = version_compare($app['version'], "1.0.2", ">="); } $userIds = ArrayToolkit::column($users, 'id'); $profiles = $this->getUserService()->findUserProfilesByIds($userIds); return $this->render('TopxiaAdminBundle:User:index.html.twig', array('users' => $users, 'userCount' => $userCount, 'paginator' => $paginator, 'profiles' => $profiles, 'showUserExport' => $showUserExport)); }
public function showAction(Request $request, $courseId, $threadId) { list($course, $member) = $this->buildLayoutDataWithTakenAccess($request, $courseId); $user = $this->getCurrentUser(); if ($member && !$this->getCourseService()->isMemberNonExpired($course, $member)) { $isMemberNonExpired = false; } else { $isMemberNonExpired = true; } $thread = $this->getThreadService()->getThread($course['id'], $threadId); if (empty($thread)) { throw $this->createNotFoundException("话题不存在,或已删除。"); } $paginator = new Paginator($request, $this->getThreadService()->getThreadPostCount($course['id'], $thread['id']), 30); $posts = $this->getThreadService()->findThreadPosts($thread['courseId'], $thread['id'], 'default', $paginator->getOffsetCount(), $paginator->getPerPageCount()); if ($thread['type'] == 'question' && $paginator->getCurrentPage() == 1) { $elitePosts = $this->getThreadService()->findThreadElitePosts($thread['courseId'], $thread['id'], 0, 10); } else { $elitePosts = array(); } $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($posts, 'userId')); $this->getThreadService()->hitThread($courseId, $threadId); $isManager = $this->getCourseService()->canManageCourse($course['id']); $lesson = $this->getCourseService()->getCourseLesson($course['id'], $thread['lessonId']); return $this->render("TopxiaWebBundle:CourseThread:show.html.twig", array('course' => $course, 'member' => $member, 'lesson' => $lesson, 'thread' => $thread, 'author' => $this->getUserService()->getUser($thread['userId']), 'posts' => $posts, 'elitePosts' => $elitePosts, 'users' => $users, 'isManager' => $isManager, 'isMemberNonExpired' => $isMemberNonExpired, 'paginator' => $paginator)); }
public function indexAction(Request $request, $id) { $course = $this->getCourseService()->tryManageCourse($id); $courseItems = $this->getCourseService()->getCourseItems($course['id']); $lessonIds = ArrayToolkit::column($courseItems, 'id'); if ($this->isPluginInstalled('Homework')) { $exercises = $this->getServiceKernel()->createService('Homework:Homework.ExerciseService')->findExercisesByLessonIds($lessonIds); $homeworks = $this->getServiceKernel()->createService('Homework:Homework.HomeworkService')->findHomeworksByCourseIdAndLessonIds($course['id'], $lessonIds); } $mediaMap = array(); foreach ($courseItems as $item) { if ($item['itemType'] != 'lesson') { continue; } if (empty($item['mediaId'])) { continue; } if (empty($mediaMap[$item['mediaId']])) { $mediaMap[$item['mediaId']] = array(); } $mediaMap[$item['mediaId']][] = $item['id']; } $mediaIds = array_keys($mediaMap); $files = $this->getUploadFileService()->findFilesByIds($mediaIds); foreach ($files as $file) { $lessonIds = $mediaMap[$file['id']]; foreach ($lessonIds as $lessonId) { $courseItems["lesson-{$lessonId}"]['mediaStatus'] = $file['convertStatus']; } } $default = $this->getSettingService()->get('default', array()); return $this->render('TopxiaWebBundle:CourseLessonManage:index.html.twig', array('course' => $course, 'items' => $courseItems, 'exercises' => empty($exercises) ? array() : $exercises, 'homeworks' => empty($homeworks) ? array() : $homeworks, 'files' => ArrayToolkit::index($files, 'id'), 'default' => $default)); }
public function logsAction(Request $request) { $paginator = new Paginator($this->get('request'), $this->getAppService()->findLogCount(), 30); $logs = $this->getAppService()->findLogs($paginator->getOffsetCount(), $paginator->getPerPageCount()); $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($logs, 'userId')); return $this->render('TopxiaAdminBundle:App:logs.html.twig', array('logs' => $logs, 'users' => $users)); }
public function latestReviewsBlockAction($number) { $reviews = $this->getReviewService()->searchReviews(array(), 'latest', 0, $number); $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($reviews, 'userId')); $courses = $this->getCourseService()->findCoursesByIds(ArrayToolkit::column($reviews, 'courseId')); return $this->render('TopxiaWebBundle:Default:latest-reviews-block.html.twig', array('reviews' => $reviews, 'users' => $users, 'courses' => $courses)); }
/** * 获取最高解决的悬赏 * * 可传入的参数: * * count 个娄 * * @param array $arguments 参数 * @return array 悬赏数 */ public function getData(array $arguments) { $conditions = array('sort' => 'reward', 'rewardType' => $arguments['rewardType'], 'solved' => 1); $threads = $this->getThreadService()->searchThreads($conditions, $conditions['sort'], 0, 10); $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($threads, 'userId')); return $threads; }
public function showAllAction(Request $request, $targetType, $targetId) { $conditions = array('targetType' => $targetType, 'targetId' => $targetId); $announcements = $this->getAnnouncementService()->searchAnnouncements($conditions, array('createdTime', 'DESC'), 0, 10000); $users = $this->getUserService()->findUsersByIds(ArrayToolkit::column($announcements, 'userId')); return $this->render('TopxiaWebBundle:Announcement:announcement-show-all-modal.html.twig', array('announcements' => $announcements, 'users' => $users)); }
public function mobileSelectAction(Request $request) { $operationMobile = $this->getSettingService()->get('operation_mobile', array()); $courseGrids = $this->getSettingService()->get('operation_course_grids', array()); $settingMobile = $this->getSettingService()->get('mobile', array()); $default = array('courseIds' => ''); $mobile = array_merge($default, $courseGrids); if ($request->getMethod() == 'POST') { $courseGrids = $request->request->all(); $mobile = array_merge($operationMobile, $settingMobile, $courseGrids); $this->getSettingService()->set('operation_mobile', $operationMobile); $this->getSettingService()->set('operation_course_grids', $courseGrids); $this->getSettingService()->set('mobile', $mobile); $this->getLogService()->info('system', 'update_settings', "更新移动客户端设置", $mobile); $this->setFlashMessage('success', '移动客户端设置已保存!'); } $courseIds = explode(",", $mobile['courseIds']); $courses = $this->getCourseService()->findCoursesByIds($courseIds); $courses = ArrayToolkit::index($courses, 'id'); $sortedCourses = array(); foreach ($courseIds as $value) { if (!empty($value)) { $sortedCourses[] = $courses[$value]; } } return $this->render('TopxiaAdminBundle:System:course-select.html.twig', array('mobile' => $mobile, 'courses' => $sortedCourses)); }
public function indexAction(Request $request, $courseId) { $course = $this->getCourseService()->getCourse($courseId); $lessons = $this->getCourseService()->getCourseLessons($courseId); $lessons = ArrayToolkit::index($lessons, 'homeworkId'); $homeworks = array(); $homeworkService = $this->getHomeworkService(); $conditions = array(); $conditions['course_id'] = $course['id']; $orderBy = array(); $orderBy[] = 'create_at'; $orderBy[] = 'DESC'; $count = $homeworkService->searchHomeworksCount($conditions); $page_size = 20; $paginator = new Paginator($request, $count, $page_size); $start = $paginator->getOffsetCount(); $limit = $paginator->getPerPageCount(); $homeworks = $homeworkService->searchHomeworks($conditions, $orderBy, $start, $limit); $homeworks = $this->addLessonName($homeworks, $lessons); $storageSetting = $this->getSettingService()->get("storage"); $tpl = 'HomeworkBundle:Homework:index.html.twig'; $assignBox = array(); $assignBox['course'] = $course; $assignBox['homeworks'] = $homeworks; $assignBox['paginator'] = $paginator; $assignBox['now'] = $_SERVER['REQUEST_TIME']; $assignBox['storageSetting'] = $storageSetting; return $this->render($tpl, $assignBox); }