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 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 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')));
 }
示例#4
0
 public function createOrder($order)
 {
     if (!ArrayToolkit::requireds($order, array('userId', 'title', 'amount', 'targetType', 'targetId', 'payment'))) {
         throw $this->createServiceException('创建订单失败:缺少参数。');
     }
     $order = ArrayToolkit::parts($order, array('userId', 'title', 'amount', 'targetType', 'targetId', 'payment', 'note', 'snPrefix', 'data', 'couponCode', 'coinAmount', 'coinRate', 'priceType', 'totalPrice', 'coupon', 'couponDiscount', 'discountId', 'discount'));
     $orderUser = $this->getUserService()->getUser($order['userId']);
     if (empty($orderUser)) {
         throw $this->createServiceException("订单用户(#{$order['userId']})不存在,不能创建订单。");
     }
     if (!in_array($order['payment'], array('none', 'alipay', 'alipaydouble', 'tenpay', 'coin'))) {
         throw $this->createServiceException('创建订单失败:payment取值不正确。');
     }
     $order['sn'] = $this->generateOrderSn($order);
     unset($order['snPrefix']);
     if (!empty($order['couponCode'])) {
         $couponInfo = $this->getCouponService()->checkCouponUseable($order['couponCode'], $order['targetType'], $order['targetId'], $order['amount']);
         if ($couponInfo['useable'] != 'yes') {
             throw $this->createServiceException("优惠码不可用");
         }
     }
     unset($order['couponCode']);
     $order['amount'] = number_format($order['amount'], 2, '.', '');
     if (intval($order['amount'] * 100) == 0) {
         $order['payment'] = 'none';
     }
     $order['status'] = 'created';
     $order['createdTime'] = time();
     $order = $this->getOrderDao()->addOrder($order);
     $this->_createLog($order['id'], 'created', '创建订单');
     return $order;
 }
示例#5
0
 public function updateTag($id, array $fields)
 {
     $tag = $this->getTag($id);
     if (empty($tag)) {
         throw $this->createServiceException("标签(#{$id})不存在,更新失败!");
     }
     $fields = ArrayToolkit::parts($fields, array('name'));
     $this->filterTagFields($fields, $tag);
     $this->getLogService()->info('tag', 'update', "编辑标签{$fields['name']}(#{$id})");
     return $this->getTagDao()->updateTag($id, $fields);
 }
示例#6
0
 public function get(Application $app, Request $request)
 {
     $conditions = ArrayToolkit::parts($request->query->all(), array('categoryId'));
     $sort = $request->query->get('sort', 'published');
     $start = $request->query->get('start', 0);
     $limit = $request->query->get('limit', 10);
     $total = $this->getArticleService()->searchArticlesCount($conditions);
     $start = $start == -1 ? rand(0, $total - 1) : $start;
     $articles = $this->getArticleService()->searchArticles($conditions, $sort, $start, $limit);
     return $this->wrap($this->filter($articles), $total);
 }
 public function createAttribute($attribute)
 {
     $attribute = ArrayToolkit::parts($attribute, array('name', 'categoryId', 'attrType', 'attrValues'));
     if (!ArrayToolkit::requireds($attribute, array('name', 'categoryId', 'attrType'))) {
         throw $this->createServiceException("缺少必要参数,,添加属性失败");
     }
     $this->_filterAttributeFields($attribute);
     $attribute = $this->getAttributeDao()->addAttribute($attribute);
     //   $this->getLogService()->info('attribute', 'create', "添加栏目 {$attribute['name']}(#{$attribute['id']})", $attribute);
     return $attribute;
 }
示例#8
0
 public function get(Application $app, Request $request)
 {
     $conditions = ArrayToolkit::parts($request->query->all(), array());
     $sort = $request->query->get('sort', 'created');
     $start = $request->query->get('start', 0);
     $limit = $request->query->get('limit', 10);
     $total = $this->getThreadService()->searchThreadCount($conditions);
     $start = $start == -1 ? rand(0, $total - 1) : $start;
     $threads = $this->getThreadService()->searchThreads($conditions, $sort, $start, $limit);
     return $this->wrap($this->filter($threads), $total);
 }
 public function createProduct($fields)
 {
     if (!ArrayToolkit::requireds($fields, array('name'))) {
         throw $this->createServiceException('缺少必要字段,创建课程失败!');
     }
     $fields = ArrayToolkit::parts($fields, array('name', 'price', 'categoryId', 'userId'));
     $fields['productDetail'] = !empty($fields['productDetail']) ? $this->purifyHtml($fields['productDetail']) : '';
     $fields['userId'] = $this->getCurrentUser()->id;
     $fields['createdTime'] = time();
     $product = $this->getCourseDao()->addProduct(ProductSerialize::serialize($fields));
     return $product;
 }
 public function createGift($gift)
 {
     if (!ArrayToolkit::requireds($gift, array('giftName'))) {
         throw $this->createServiceException('缺少必要字段,添加礼品失败!');
     }
     $gift = ArrayToolkit::parts($gift, array('giftName', 'points', 'detail'));
     $gift['detail'] = !empty($gift['detail']) ? $this->purifyHtml($gift['detail']) : '';
     $gift['createdTime'] = time();
     $gift = $this->getGiftDao()->addGift($gift);
     $gift = $this->getGift($gift['id']);
     //   $this->getLogService()->info('gift', 'create', "添加礼品《{$gift['giftName']}》(#{$gift['id']})");
     return $gift;
 }
示例#11
0
 public function userAvatarAction(Request $request)
 {
     $defaultSetting = $this->getSettingService()->get('default', array());
     if ($request->getMethod() == 'POST') {
         $userDefaultSetting = $request->request->all();
         $userDefaultSetting = ArrayToolkit::parts($userDefaultSetting, array('defaultAvatar'));
         $defaultSetting = array_merge($defaultSetting, $userDefaultSetting);
         $this->getSettingService()->set('default', $defaultSetting);
         $this->getLogService()->info('system', 'update_settings', "更新头像设置", $userDefaultSetting);
         $this->setFlashMessage('success', '头像设置已保存!');
     }
     return $this->render('TopxiaAdminBundle:System:user-avatar.html.twig', array('defaultSetting' => $defaultSetting));
 }
 public function indexAction(Request $request)
 {
     $sensitiveWordSetting = $this->getSettingService()->get("sensitiveWord", array());
     if ($request->getMethod() == 'POST') {
         $fields = $request->request->all();
         $sensitiveWordSetting = ArrayToolkit::parts($fields, array("enabled", "ignoreWord", "wordReplace", "firstLevel", "secondLevel"));
         $keywords = explode("\r\n", $sensitiveWordSetting["secondLevel"]);
         $keywordFilter = new KeywordFilter();
         $keywordFilter->addKeywords($keywords);
         $this->getSettingService()->set("sensitiveWord", $sensitiveWordSetting);
     }
     return $this->render('TopxiaAdminBundle:SensitiveWord:index.html.twig', array("sensitiveWordSetting" => $sensitiveWordSetting));
 }
示例#13
0
 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);
     //判断用户是否为VIP
     $vipStatus = $courseVip = null;
     if ($this->isPluginInstalled('Vip') && $this->setting('vip.enabled')) {
         $courseVip = $course['vipLevelId'] > 0 ? $this->getLevelService()->getLevel($course['vipLevelId']) : null;
         if ($courseVip) {
             $vipStatus = $this->getVipService()->checkUserInMemberLevel($user['id'], $courseVip['id']);
             if ($vipStatus == 'ok') {
                 $formData['becomeUseMember'] = true;
             }
         }
     }
     //免费课程,直接加入并进入课时
     $coinSetting = $this->setting("coin");
     $courseSetting = $this->getSettingService()->get('course', array());
     $coinEnable = isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"] == 1;
     //$userInfoEnable = isset($courseSetting['buy_fill_userinfo']) && $courseSetting['buy_fill_userinfo'] == 1;
     if ($coinEnable && isset($coinSetting['price_type']) && $coinSetting['price_type'] == "Coin" && $course['coinPrice'] == 0 || (!isset($coinSetting['price_type']) || $coinSetting['price_type'] == "RMB") && $course['price'] == 0 || $vipStatus == 'ok') {
         $data = array("price" => 0, "remark" => '');
         $this->getCourseMemberService()->becomeStudentAndCreateOrder($user["id"], $course['id'], $data);
         if (isset($formData['lessonId'])) {
             return $this->redirect($this->generateUrl('course_learn', array('id' => $course['id'])) . '#lesson/' . $formData['lessonId']);
         } else {
             return $this->redirect($this->generateUrl('course_show', array('id' => $course['id'])));
         }
     }
     if (isset($coinSetting["coin_enabled"]) && $coinSetting["coin_enabled"] == 1 && isset($coinSetting["price_type"]) && $coinSetting["price_type"] == "Coin" && $course['coinPrice'] == 0 || $course['price'] == 0 || $vipStatus == 'ok') {
         $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 courseAvatarAction(Request $request)
 {
     $defaultSetting = $this->getSettingService()->get('default', array());
     if ($request->getMethod() == 'POST') {
         $defaultSetting = $request->request->all();
         $courseDefaultSetting = ArrayToolkit::parts($defaultSetting, array('defaultCoursePicture'));
         $default = $this->getSettingService()->get('default', array());
         $defaultSetting = array_merge($default, $courseDefaultSetting);
         $this->getSettingService()->set('default', $defaultSetting);
         $this->getLogService()->info('system', 'update_settings', "更新课程默认图片设置", $defaultSetting);
         $this->setFlashMessage('success', '课程默认图片设置已保存!');
     }
     return $this->render('TopxiaAdminBundle:System:course-avatar.html.twig', array('defaultSetting' => $defaultSetting, 'hasOwnCopyright' => false));
 }
 public function updateHomework($id, array $fields)
 {
     $Homework = $this->getHomework($id);
     if (empty($Homework)) {
         throw $this->createNoteFoundException("作业(#{$id})不存在,更新作业失败!");
     }
     $fields = ArrayToolkit::parts($fields, array('id', 'content'));
     if (empty($fields)) {
         throw $this->createServiceException('参数不正确,更新作业失败!');
     }
     $this->_filterHomeworkFields($fields);
     $fields['update_at'] = $_SERVER['REQUEST_TIME'];
     $this->getLogService()->info('Homework', 'update', "编辑作业 {$fields['content']}(#{$id})", $fields);
     return $this->getHomeworkDao()->updateHomework($id, $fields);
 }
示例#16
0
 public function settingsAction(Request $request)
 {
     $postedParams = $request->request->all();
     $coinSettingsSaved = $this->getSettingService()->get('coin', array());
     $default = array('coin_enabled' => 0, 'cash_model' => 'none', 'cash_rate' => 1, 'coin_name' => '虚拟币', 'coin_content' => '', 'coin_picture' => '', 'coin_picture_50_50' => '', 'coin_picture_30_30' => '', 'coin_picture_20_20' => '', 'coin_picture_10_10' => '');
     $coinSettingsSaved = array_merge($default, $coinSettingsSaved);
     if ($request->getMethod() == 'POST') {
         $fields = $request->request->all();
         $coinSettingsPosted = ArrayToolkit::parts($fields, array('coin_enabled', 'cash_model', 'cash_rate', 'coin_name', 'coin_content', 'coin_picture', 'coin_picture_50_50', 'coin_picture_30_30', 'coin_picture_20_20', 'coin_picture_10_10'));
         $this->getSettingService()->set('coin', $coinSettingsPosted);
         $this->getLogService()->info('system', 'update_settings', "更新Coin虚拟币设置", $coinSettingsPosted);
         $this->setFlashMessage('success', '虚拟币设置已保存!');
         return $this->settingsRenderedPage($coinSettingsPosted);
     }
     return $this->settingsRenderedPage($coinSettingsSaved);
 }
 public function inviteSetAction(Request $request)
 {
     $default = array('invite_code_setting' => 0, 'promoted_user_value' => '', 'promote_user_value' => '', 'deadline' => 90, 'inviteInfomation_template' => '{{registerUrl}}');
     if ($request->getMethod() == 'POST') {
         $inviteSetting = $request->request->all();
         $inviteSetting = ArrayToolkit::parts($inviteSetting, array('invite_code_setting', 'promoted_user_value', 'promote_user_value', 'deadline', 'inviteInfomation_template'));
         $inviteSetting = array_merge($default, $inviteSetting);
         $this->getSettingService()->set('invite', $inviteSetting);
         $this->setFlashMessage('success', '邀请码设置已保存!');
         goto response;
     }
     $inviteSetting = $this->getSettingService()->get('invite', array());
     $inviteSetting = array_merge($default, $inviteSetting);
     response:
     return $this->render('TopxiaAdminBundle:Invite:set.html.twig', array('inviteSetting' => $inviteSetting, 'inviteInfomation_template' => $inviteSetting['inviteInfomation_template']));
 }
示例#18
0
 public function get(Application $app, Request $request)
 {
     $conditions = ArrayToolkit::parts($request->query->all(), array('categoryId'));
     $sort = $request->query->get('sort', 'published');
     $start = $request->query->get('start', 0);
     $limit = $request->query->get('limit', 10);
     $total = $this->getArticleService()->searchArticlesCount($conditions);
     $start = $start == -1 ? rand(0, $total - 1) : $start;
     $articles = $this->getArticleService()->searchArticles($conditions, $sort, $start, $limit);
     //添加报名人数
     $ArticleService = $this->getServiceKernel()->createService('Article.ArticleService');
     foreach ($articles as $key => $article) {
         $temp_count = $ArticleService->getArticleLikesCountByArticleId($article['id']);
         $articles[$key]['enroll'] = $temp_count;
     }
     return $this->wrap($this->filter($articles), $total);
 }
示例#19
0
 public function updateContent($id, $fields)
 {
     $content = $this->getContent($id);
     if (empty($content)) {
         throw $this->createServiceException('内容不存在,更新失败!');
     }
     $type = ContentTypeFactory::create($content['type']);
     $fields = $type->convert($fields);
     $fields = ArrayToolkit::parts($fields, $type->getFields());
     // if(isset($fields['body'])){
     //     $fields['body'] = $this->purifyHtml($fields['body']);
     // }
     $this->getContentDao()->updateContent($id, ContentSerialize::serialize($fields));
     $content = $this->getContent($id);
     $this->getLogService()->info('content', 'update', "内容《({$content['title']})》({$content['id']})更新", $content);
     return $content;
 }
示例#20
0
 public function payAction(Request $request)
 {
     $formData = $request->request->all();
     $user = $this->getCurrentUser();
     if (empty($user)) {
         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);
     $order = $this->getCourseOrderService()->createOrder($formData);
     if ($order['status'] == 'paid') {
         return $this->redirect($this->generateUrl('course_show', array('id' => $order['targetId'])));
     } else {
         $payRequestParams = array('returnUrl' => $this->generateUrl('course_order_pay_return', array('name' => $order['payment']), true), 'notifyUrl' => $this->generateUrl('course_order_pay_notify', array('name' => $order['payment']), true), 'showUrl' => $this->generateUrl('course_show', array('id' => $order['targetId']), true));
         return $this->forward('TopxiaWebBundle:Order:submitPayRequest', array('order' => $order, 'requestParams' => $payRequestParams));
     }
 }
示例#21
0
 public function registerApp($app)
 {
     if (!ArrayToolkit::requireds($app, array('code', 'name', 'version'))) {
         throw $this->createServiceException('参数缺失,注册APP失败!');
     }
     $app = ArrayToolkit::parts($app, array('code', 'name', 'description', 'version', 'type'));
     $app['fromVersion'] = $app['version'];
     $app['description'] = empty($app['description']) ? '' : $app['description'];
     $app['icon'] = empty($app['icon']) ? '' : $app['icon'];
     $app['developerId'] = 0;
     $app['developerName'] = empty($app['author']) ? '未知' : $app['author'];
     $app['installedTime'] = time();
     $app['updatedTime'] = time();
     $exist = $this->getAppDao()->getAppByCode($app['code']);
     if ($exist) {
         return $this->getAppDao()->updateApp($exist['id'], $app);
     }
     return $this->getAppDao()->addApp($app);
 }
 public function createAction(Request $request, $courseId, $type)
 {
     $course = $this->getCourseService()->tryManageCourse($courseId);
     if ($request->getMethod() == 'POST') {
         $data = $request->request->all();
         $question = $this->getQuestionService()->createQuestion($data);
         if ($data['submission'] == 'continue') {
             $urlParams = ArrayToolkit::parts($question, array('target', 'difficulty', 'parentId'));
             $urlParams['type'] = $type;
             $urlParams['courseId'] = $courseId;
             $urlParams['goto'] = $request->query->get('goto', null);
             $this->setFlashMessage('success', '题目添加成功,请继续添加。');
             return $this->redirect($this->generateUrl('course_manage_question_create', $urlParams));
         } elseif ($data['submission'] == 'continue_sub') {
             $this->setFlashMessage('success', '题目添加成功,请继续添加子题。');
             return $this->redirect($request->query->get('goto', $this->generateUrl('course_manage_question', array('courseId' => $courseId, 'parentId' => $question['id']))));
         } else {
             $this->setFlashMessage('success', '题目添加成功。');
             return $this->redirect($request->query->get('goto', $this->generateUrl('course_manage_question', array('courseId' => $courseId))));
         }
     }
     $question = array('id' => 0, 'type' => $type, 'target' => $request->query->get('target'), 'difficulty' => $request->query->get('difficulty', 'normal'), 'parentId' => $request->query->get('parentId', 0));
     if ($question['parentId'] > 0) {
         $parentQuestion = $this->getQuestionService()->getQuestion($question['parentId']);
         if (empty($parentQuestion)) {
             return $this->createMessageResponse('error', '父题不存在,不能创建子题!');
         }
     } else {
         $parentQuestion = null;
     }
     if ($this->container->hasParameter('enabled_features')) {
         $features = $this->container->getParameter('enabled_features');
     } else {
         $features = array();
     }
     $enabledAudioQuestion = in_array('audio_question', $features);
     return $this->render("TopxiaWebBundle:CourseQuestionManage:question-form-{$type}.html.twig", array('course' => $course, 'question' => $question, 'parentQuestion' => $parentQuestion, 'targetsChoices' => $this->getQuestionTargetChoices($course), 'categoryChoices' => $this->getQuestionCategoryChoices($course), 'enabledAudioQuestion' => $enabledAudioQuestion));
 }
 public function updateCategory($id, array $fields)
 {
     $category = $this->getCategory($id);
     if (empty($category)) {
         throw $this->createNoteFoundException("栏目(#{$id})不存在,更新栏目失败!");
     }
     $fields = ArrayToolkit::parts($fields, array('name', 'code', 'weight', 'parentId', 'publishArticle', 'seoTitle', 'seoKeyword', 'seoDesc', 'published'));
     if (empty($fields)) {
         throw $this->createServiceException('参数不正确,更新栏目失败!');
     }
     $this->_filterCategoryFields($fields);
     $this->getLogService()->info('category', 'update', "编辑栏目 {$fields['name']}(#{$id})", $fields);
     return $this->getCategoryDao()->updateCategory($id, $fields);
 }
示例#24
0
 public function updateCourseLessonReplayByLessonId($lessonId, $fields)
 {
     $lesson = $this->getLesson($lessonId);
     if (empty($lesson)) {
         throw $this->createServiceException('直播课时不存在,更新失败!');
     }
     $fields = ArrayToolkit::parts($fields, array('hidden'));
     return $this->getCourseLessonReplayDao()->updateCourseLessonReplayByLessonId($lessonId, $fields);
 }
 protected function copyExercises($courseId, $newCourse, $newLessons)
 {
     $exercises = $this->getExerciseDao()->findExercisesByCourseId($courseId);
     $map = array();
     foreach ($exercises as $exercise) {
         $fields = ArrayToolkit::parts($exercise, array('itemCount', 'source', 'difficulty', 'questionTypeRange', 'createdUserId'));
         $fields['courseId'] = $newCourse['id'];
         if ($exercise['lessonId']) {
             $fields['lessonId'] = $newLessons[$exercise['lessonId']]['id'];
         } else {
             $fields['lessonId'] = 0;
         }
         $fields['createdTime'] = time();
         $fields['copyId'] = $exercise['id'];
         $map[$exercise['id']] = $this->getExerciseDao()->addExercise($fields);
     }
     return $map;
 }
示例#26
0
 public function updatePost($courseId, $id, $fields)
 {
     $fields['content'] = $this->sensitiveFilter($fields['content'], 'course-thread-post-update');
     $post = $this->getPost($courseId, $id);
     if (empty($post)) {
         throw $this->createServiceException("回帖#{$id}不存在。");
     }
     $user = $this->getCurrentUser();
     $user->isLogin() && $user->id == $post['userId'] || $this->getCourseService()->tryManageCourse($courseId);
     $fields = ArrayToolkit::parts($fields, array('content'));
     if (empty($fields)) {
         throw $this->createServiceException('参数缺失。');
     }
     //更新post过滤html
     $fields['content'] = $this->purifyHtml($fields['content']);
     return $this->getThreadPostDao()->updatePost($id, $fields);
 }
示例#27
0
 public function modifyUserInfoAction(Request $request)
 {
     $formData = $request->request->all();
     $user = $this->getCurrentUser();
     if (empty($user)) {
         return $this->createMessageResponse('error', '用户未登录,不能购买。');
     }
     $classroom = $this->getClassroomService()->getClassroom($formData['targetId']);
     if (empty($classroom)) {
         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");
     //判断用户是否为VIP
     $vipStatus = $classroomVip = null;
     if ($this->isPluginInstalled('Vip') && $this->setting('vip.enabled')) {
         $classroomVip = $classroom['vipLevelId'] > 0 ? $this->getLevelService()->getLevel($classroom['vipLevelId']) : null;
         if ($classroomVip) {
             $vipStatus = $this->getVipService()->checkUserInMemberLevel($user['id'], $classroom['vipLevelId']);
             if ($vipStatus == 'ok') {
                 $formData['becomeUseMember'] = true;
             }
         }
     }
     if ($classroom['price'] == 0 || $vipStatus == 'ok') {
         $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->getClassroomOrderService()->createOrder($formData);
         if ($order['status'] == 'paid') {
             return $this->redirect($this->generateUrl('classroom_show', array('id' => $order['targetId'])));
         }
     }
     return $this->redirect($this->generateUrl('order_show', array('targetId' => $formData['targetId'], 'targetType' => 'classroom')));
 }
示例#28
0
 /**
  * 要过滤要更新的字段
  */
 public function updateClassroom($id, $fields)
 {
     $fields = ArrayToolkit::parts($fields, array('rating', 'ratingNum', 'categoryId', 'title', 'status', 'about', 'description', 'price', 'vipLevelId', 'smallPicture', 'middlePicture', 'largePicture', 'headTeacherId', 'teacherIds', 'assistantIds', 'hitNum', 'auditorNum', 'studentNum', 'courseNum', 'lessonNum', 'threadNum', 'postNum', 'income', 'createdTime', 'private', 'service', 'maxRate', 'buyable', 'showable'));
     if (empty($fields)) {
         throw $this->createServiceException('参数不正确,更新失败!');
     }
     $classroom = $this->getClassroomDao()->updateClassroom($id, $fields);
     return $classroom;
 }
示例#29
0
 public function submitTestpaperAnswer($id, $answers)
 {
     if (empty($answers)) {
         return array();
     }
     $user = $this->getCurrentUser();
     $testpaperResult = $this->getTestpaperResultDao()->getTestpaperResult($id);
     if ($testpaperResult['userId'] != $user['id']) {
         throw $this->createAccessDeniedException('无权修改其他学员的试卷!');
     }
     if (in_array($testpaperResult['status'], array('reviewing', 'finished'))) {
         throw $this->createServiceException("已经交卷的试卷不能更改答案!");
     }
     //已经有记录的
     $itemResults = $this->filterTestAnswers($testpaperResult['id'], $answers);
     $itemIdsOld = ArrayToolkit::index($itemResults, 'questionId');
     $answersOld = ArrayToolkit::parts($answers, array_keys($itemIdsOld));
     if (!empty($answersOld)) {
         $this->getTestpaperItemResultDao()->updateItemAnswers($testpaperResult['id'], $answersOld);
     }
     //还没记录的
     $itemIdsNew = array_diff(array_keys($answers), array_keys($itemIdsOld));
     $answersNew = ArrayToolkit::parts($answers, $itemIdsNew);
     if (!empty($answersNew)) {
         $this->getTestpaperItemResultDao()->addItemAnswers($testpaperResult['id'], $answersNew, $testpaperResult['testId'], $user['id']);
     }
     //测试数据
     return $this->filterTestAnswers($testpaperResult['id'], $answers);
 }
 public function updateApply($applyId, $fields)
 {
     $apply = $this->getApply($applyId);
     if (empty($apply)) {
         throw $this->createServiceException('申请不存在,更新失败!');
     }
     $user = $this->getCurrentUser();
     $user->isLogin() && $user->id == $apply['userId'];
     $fields = ArrayToolkit::parts($fields, array('title', 'content'));
     if (empty($fields)) {
         throw $this->createServiceException('参数缺失,更新失败。');
     }
     //更新thread过滤html
     $fields['content'] = $this->purifyHtml($fields['content']);
     return $this->getApplyDao()->updateApply($applyId, $fields);
 }