/**
  *类似这样的,提交数据保存到数据的流程是:
  *
  *  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' => '', 'status' => 0));
     $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['updatedTime'] = time();
         $note = $this->getNoteDao()->addNote($note);
         $this->getDispatcher()->dispatch('course.note.create', new ServiceEvent($note));
     } else {
         $note['updatedTime'] = time();
         $note = $this->getNoteDao()->updateNote($existNote['id'], $note);
         $this->getDispatcher()->dispatch('course.note.update', new ServiceEvent($note, array('preStatus' => $existNote['status'])));
     }
     $this->getCourseService()->setMemberNoteNumber($note['courseId'], $note['userId'], $this->getNoteDao()->getNoteCountByUserIdAndCourseId($note['userId'], $note['courseId']));
     return $note;
 }
示例#2
0
 public function indexAction(Request $request)
 {
     $fields = $request->query->all();
     $fields = ArrayToolkit::filter($fields, array('nextExcutedStartTime' => '', 'nextExcutedEndTime' => '', 'name' => '', 'cycle' => ''));
     $paginator = new Paginator($this->get('request'), $this->getJobService()->searchJobsCount($fields), 30);
     $jobs = $this->getJobService()->searchJobs($fields, 'nextExcutedTime', $paginator->getOffsetCount(), $paginator->getPerPageCount());
     return $this->render('TopxiaAdminBundle:System:jobs.html.twig', array('jobs' => $jobs, 'paginator' => $paginator));
 }
 private function _filterAttributeFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('name' => '', 'attrType' => 0, 'attrValues' => '', 'parentId' => 0));
     if (empty($fields['name'])) {
         throw $this->createServiceException("名称不能为空,保存属性失败");
     }
     return $fields;
 }
 private function _filterGiftFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('giftName' => '', 'detail' => '', 'points' => 0));
     if (!empty($fields['detail'])) {
         $fields['detail'] = $this->purifyHtml($fields['detail'], true);
     }
     return $fields;
 }
 public function updateField($id, $fields)
 {
     $fields = ArrayToolkit::filter($fields, array("title" => "", "seq" => "", "enabled" => 0));
     if (isset($fields['title']) && empty($fields['title'])) {
         throw $this->createServiceException('字段名称不能为空!');
     }
     if (isset($fields['seq']) && empty($fields['seq'])) {
         throw $this->createServiceException('字段排序不能为空!');
     }
     if (isset($fields['seq']) && !intval($fields['seq'])) {
         throw $this->createServiceException('字段排序只能为数字!');
     }
     return $this->getUserFieldDao()->updateField($id, $fields);
 }
示例#6
0
 public function updateLesson($courseId, $lessonId, $fields)
 {
     $argument = $fields;
     $course = $this->getCourse($courseId);
     if (empty($course)) {
         throw $this->createServiceException("课程(#{$courseId})不存在!");
     }
     $lesson = $this->getCourseLesson($courseId, $lessonId);
     if (empty($lesson)) {
         throw $this->createServiceException("课时(#{$lessonId})不存在!");
     }
     $fields = ArrayToolkit::filter($fields, array('title' => '', 'summary' => '', 'content' => '', 'media' => array(), 'mediaId' => 0, 'number' => 0, 'seq' => 0, 'chapterId' => 0, 'free' => 0, 'length' => 0, 'startTime' => 0, 'giveCredit' => 0, 'requireCredit' => 0, 'homeworkId' => 0, 'exerciseId' => 0, 'testMode' => 'normal', 'testStartTime' => 0, 'suggestHours' => '1.0', 'replayStatus' => 'ungenerated'));
     if (isset($fields['title'])) {
         $fields['title'] = $this->purifyHtml($fields['title']);
     }
     $fields['type'] = $lesson['type'];
     if ($fields['type'] == 'live' && isset($fields['startTime'])) {
         $fields['endTime'] = $fields['startTime'] + $fields['length'] * 60;
         $fields['suggestHours'] = $fields['length'] / 60;
     }
     if (array_key_exists('media', $fields)) {
         $this->fillLessonMediaFields($fields);
     }
     $updatedLesson = LessonSerialize::unserialize($this->getLessonDao()->updateLesson($lessonId, LessonSerialize::serialize($fields)));
     $this->updateCourseCounter($course['id'], array('giveCredit' => $this->getLessonDao()->sumLessonGiveCreditByCourseId($course['id'])));
     // Update link count of the course lesson file, if the lesson file is changed
     if (array_key_exists('mediaId', $fields)) {
         if ($fields['mediaId'] != $lesson['mediaId']) {
             // Incease the link count of the new selected lesson file
             if (!empty($fields['mediaId'])) {
                 $this->getUploadFileService()->waveUploadFile($fields['mediaId'], 'usedCount', 1);
             }
             // Decrease the link count of the original lesson file
             if (!empty($lesson['mediaId'])) {
                 $this->getUploadFileService()->waveUploadFile($lesson['mediaId'], 'usedCount', -1);
             }
         }
     }
     $this->getLogService()->info('course', 'update_lesson', "更新课时《{$updatedLesson['title']}》({$updatedLesson['id']})", $updatedLesson);
     $updatedLesson['fields'] = $lesson;
     $this->dispatchEvent("course.lesson.update", array('argument' => $argument, 'lesson' => $updatedLesson));
     return $updatedLesson;
 }
 protected function _filterCategoryFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('name' => '', 'code' => '', 'weight' => 0, 'publishArticle' => '', 'seoTitle' => '', 'seoDesc' => '', 'published' => 1, 'parentId' => 0));
     if (empty($fields['name'])) {
         throw $this->createServiceException("名称不能为空,保存栏目失败");
     }
     if (empty($fields['code'])) {
         throw $this->createServiceException("编码不能为空,保存栏目失败");
     } else {
         if (!preg_match("/^[a-zA-Z0-9_]+\$/i", $fields['code'])) {
             throw $this->createServiceException("编码({$fields['code']})含有非法字符,保存栏目失败");
         }
         if (ctype_digit($fields['code'])) {
             throw $this->createServiceException("编码({$fields['code']})不能全为数字,保存栏目失败");
         }
     }
     return $fields;
 }
示例#8
0
 public function updateLesson($courseId, $lessonId, $fields)
 {
     $course = $this->getCourse($courseId);
     if (empty($course)) {
         throw $this->createServiceException("课程(#{$courseId})不存在!");
     }
     $lesson = $this->getCourseLesson($courseId, $lessonId);
     if (empty($lesson)) {
         throw $this->createServiceException("课时(#{$lessonId})不存在!");
     }
     $fields = ArrayToolkit::filter($fields, array('title' => '', 'summary' => '', 'content' => '', 'media' => array(), 'mediaId' => 0, 'free' => 0, 'length' => 0, 'startTime' => 0, 'giveCredit' => 0, 'requireCredit' => 0, 'homeworkId' => 0, 'exerciseId' => 0));
     if (isset($fields['title'])) {
         $fields['title'] = $this->purifyHtml($fields['title']);
     }
     $fields['type'] = $lesson['type'];
     if ($fields['type'] == 'live') {
         $fields['endTime'] = $fields['startTime'] + $fields['length'] * 60;
     }
     $this->fillLessonMediaFields($fields);
     $updatedLesson = LessonSerialize::unserialize($this->getLessonDao()->updateLesson($lessonId, LessonSerialize::serialize($fields)));
     $this->updateCourseCounter($course['id'], array('giveCredit' => $this->getLessonDao()->sumLessonGiveCreditByCourseId($course['id'])));
     // Update link count of the course lesson file, if the lesson file is changed
     if ($fields['mediaId'] != $lesson['mediaId']) {
         // Incease the link count of the new selected lesson file
         if (!empty($fields['mediaId'])) {
             $this->getUploadFileService()->increaseFileUsedCount(array($fields['mediaId']));
         }
         // Decrease the link count of the original lesson file
         if (!empty($lesson['mediaId'])) {
             $this->getUploadFileService()->decreaseFileUsedCount(array($lesson['mediaId']));
         }
     }
     $this->getLogService()->info('course', 'update_lesson', "更新课时《{$updatedLesson['title']}》({$updatedLesson['id']})", $updatedLesson);
     $this->dispatchEvent("course.lesson.update", $updatedLesson);
     return $updatedLesson;
 }
 public function updateUserProfile($id, $fields)
 {
     $user = $this->getUser($id);
     if (empty($user)) {
         throw $this->createServiceException('用户不存在,更新用户失败。');
     }
     $fields = ArrayToolkit::filter($fields, array('truename' => '', 'gender' => 'secret', 'iam' => '', 'idcard' => '', 'birthday' => null, 'city' => '', 'mobile' => '', 'qq' => '', 'school' => '', 'class' => '', 'company' => '', 'job' => '', 'signature' => '', 'title' => '', 'about' => '', 'weibo' => '', 'weixin' => '', 'site' => '', 'intField1' => null, 'intField2' => null, 'intField3' => null, 'intField4' => null, 'intField5' => null, 'dateField1' => null, 'dateField2' => null, 'dateField3' => null, 'dateField4' => null, 'dateField5' => null, 'floatField1' => null, 'floatField2' => null, 'floatField3' => null, 'floatField4' => null, 'floatField5' => null, 'textField1' => "", 'textField2' => "", 'textField3' => "", 'textField4' => "", 'textField5' => "", 'textField6' => "", 'textField7' => "", 'textField8' => "", 'textField9' => "", 'textField10' => "", 'varcharField1' => "", 'varcharField2' => "", 'varcharField3' => "", 'varcharField4' => "", 'varcharField5' => "", 'varcharField6' => "", 'varcharField7' => "", 'varcharField8' => "", 'varcharField9' => "", 'varcharField10' => ""));
     if (empty($fields)) {
         return $this->getProfileDao()->getProfile($id);
     }
     if (isset($fields['title'])) {
         $this->getUserDao()->updateUser($id, array('title' => $fields['title']));
         $this->dispatchEvent('user.update', new ServiceEvent(array('user' => $user, 'fields' => $fields)));
     }
     unset($fields['title']);
     if (!empty($fields['gender']) && !in_array($fields['gender'], array('male', 'female', 'secret'))) {
         throw $this->createServiceException('性别不正确,更新用户失败。');
     }
     if (!empty($fields['birthday']) && !SimpleValidator::date($fields['birthday'])) {
         throw $this->createServiceException('生日不正确,更新用户失败。');
     }
     if (!empty($fields['mobile']) && !SimpleValidator::mobile($fields['mobile'])) {
         throw $this->createServiceException('手机不正确,更新用户失败。');
     }
     if (!empty($fields['qq']) && !SimpleValidator::qq($fields['qq'])) {
         throw $this->createServiceException('QQ不正确,更新用户失败。');
     }
     if (!empty($fields['about'])) {
         $fields['about'] = $this->purifyHtml($fields['about']);
     }
     $userProfile = $this->getProfileDao()->updateProfile($id, $fields);
     $this->dispatchEvent('profile.update', new ServiceEvent(array('user' => $user, 'fields' => $fields)));
     return $userProfile;
 }
示例#10
0
 public function updateLesson($courseId, $lessonId, $fields)
 {
     $course = $this->getCourse($courseId);
     if (empty($course)) {
         throw $this->createServiceException("课程(#{$courseId})不存在!");
     }
     $lesson = $this->getCourseLesson($courseId, $lessonId);
     if (empty($lesson)) {
         throw $this->createServiceException("课时(#{$lessonId})不存在!");
     }
     $fields = ArrayToolkit::filter($fields, array('title' => '', 'summary' => '', 'content' => '', 'media' => array(), 'mediaId' => 0, 'free' => 0, 'length' => 0, 'startTime' => 0, 'giveCredit' => 0, 'requireCredit' => 0));
     if (isset($fields['title'])) {
         $fields['title'] = $this->purifyHtml($fields['title']);
     }
     $fields['type'] = $lesson['type'];
     if ($fields['type'] == 'live') {
         $fields['endTime'] = $fields['startTime'] + $fields['length'] * 60;
     }
     $this->fillLessonMediaFields($fields);
     $lesson = LessonSerialize::unserialize($this->getLessonDao()->updateLesson($lessonId, LessonSerialize::serialize($fields)));
     $this->updateCourseCounter($course['id'], array('giveCredit' => $this->getLessonDao()->sumLessonGiveCreditByCourseId($course['id'])));
     $this->getLogService()->info('course', 'update_lesson', "更新课时《{$lesson['title']}》({$lesson['id']})", $lesson);
     return $lesson;
 }
 private function _filterProductFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('name' => '', 'price' => 0, 'productBrief' => '', 'categoryId' => 0, 'relatedIds' => array()));
     if (!empty($fields['detail'])) {
         $fields['detail'] = $this->purifyHtml($fields['detail'], true);
     }
     return $fields;
 }
 private function _filterAttributeFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('productId' => 0, 'attrId' => 0, 'attrValue' => ''));
     return $fields;
 }
 private function _filterExchangeFields($fields)
 {
     $fields = ArrayToolkit::filter($fields, array('title' => '', 'about' => '', 'points' => 0));
     if (!empty($fields['about'])) {
         $fields['about'] = $this->purifyHtml($fields['about'], true);
     }
     return $fields;
 }
 public function updateLesson($courseId, $lessonId, $fields)
 {
     $course = $this->getCourse($courseId);
     if (empty($course)) {
         throw $this->createServiceException("课程(#{$courseId})不存在!");
     }
     $lesson = $this->getCourseLesson($courseId, $lessonId);
     if (empty($lesson)) {
         throw $this->createServiceException("课时(#{$lessonId})不存在!");
     }
     $fields = ArrayToolkit::filter($fields, array('title' => '', 'content' => '', 'summary' => '', 'media' => array(), 'mediaId' => 0, 'free' => 0, 'length' => 0, 'startTime' => 0, 'giveCredit' => 0, 'requireCredit' => 0, 'homeworkId' => 0, 'exerciseId' => 0, 'first_image' => ''));
     if (isset($fields['content'])) {
         $fields['content'] = $this->purifyHtml($fields['content']);
     }
     $updatedLesson = LessonSerialize::unserialize($this->getLessonDao()->updateLesson($lessonId, LessonSerialize::serialize($fields)));
     $this->updateCourseCounter($course['id'], array('giveCredit' => $this->getLessonDao()->sumLessonGiveCreditByCourseId($course['id'])));
     // Update link count of the course lesson file, if the lesson file is changed
     $this->getLogService()->info('course', 'update_lesson', "更新课时《{$updatedLesson['title']}》({$updatedLesson['id']})", $updatedLesson);
     return $updatedLesson;
 }