src/AppBundle/Controller/DefaultController.php line 102

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Common\ArrayToolkit;
  4. use Biz\Classroom\Service\ClassroomService;
  5. use Biz\CloudPlatform\CloudAPIFactory;
  6. use Biz\CloudPlatform\Service\AppService;
  7. use Biz\Content\Service\BlockService;
  8. use Biz\Content\Service\NavigationService;
  9. use Biz\Course\Service\CourseService;
  10. use Biz\Course\Service\CourseSetService;
  11. use Biz\System\Service\SettingService;
  12. use Biz\Taxonomy\Service\CategoryService;
  13. use Biz\Theme\Service\ThemeService;
  14. use Biz\User\Service\BatchNotificationService;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. class DefaultController extends BaseController
  19. {
  20.     public function indexAction(Request $request)
  21.     {
  22.         $user $this->getCurrentUser();
  23.         if (!empty($user['id'])) {
  24.             $this->getBatchNotificationService()->checkoutBatchNotification($user['id']);
  25.         }
  26.         $custom $this->isCustom();
  27.         $friendlyLinks $this->getNavigationService()->getOpenedNavigationsTreeByType('friendlyLink');
  28.         return $this->render('default/index.html.twig', ['friendlyLinks' => $friendlyLinks'custom' => $custom]);
  29.     }
  30.     public function appDownloadAction()
  31.     {
  32.         $meCount $this->getMeCount();
  33.         $mobileCode = (empty($meCount['mobileCode']) ? 'edusohov3' $meCount['mobileCode']);
  34.         if ($this->getWebExtension()->isMicroMessenger() && 'edusohov3' == $mobileCode) {
  35.             $url 'http://a.app.qq.com/o/simple.jsp?pkgname=com.edusoho.kuozhi';
  36.         } else {
  37.             $url $this->generateUrl('mobile_download', ['from' => 'qrcode''code' => $mobileCode], UrlGeneratorInterface::ABSOLUTE_URL);
  38.         }
  39.         return $this->render('mobile/app-download.html.twig', [
  40.             'url' => $url,
  41.         ]);
  42.     }
  43.     public function promotedTeacherBlockAction()
  44.     {
  45.         $teacher $this->getUserService()->findLatestPromotedTeacher(01);
  46.         if ($teacher) {
  47.             $teacher $teacher[0];
  48.             $teacher array_merge(
  49.                 $teacher,
  50.                 $this->getUserService()->getUserProfile($teacher['id'])
  51.             );
  52.         }
  53.         if (isset($teacher['locked']) && '0' !== $teacher['locked']) {
  54.             $teacher null;
  55.         }
  56.         return $this->render('default/promoted-teacher-block.html.twig', [
  57.             'teacher' => $teacher,
  58.         ]);
  59.     }
  60.     public function latestReviewsBlockAction($number)
  61.     {
  62.         $reviews $this->getReviewService()->searchReviews(['private' => 0], 'latest'0$number);
  63.         $users $this->getUserService()->findUsersByIds(ArrayToolkit::column($reviews'userId'));
  64.         $courses $this->getCourseService()->findCoursesByIds(ArrayToolkit::column($reviews'courseId'));
  65.         $courseSets $this->getCourseSetService()->findCourseSetsByIds(ArrayToolkit::column($courses'courseSetId'));
  66.         $courseSets ArrayToolkit::index($courseSets'id');
  67.         return $this->render('default/latest-reviews-block.html.twig', [
  68.             'reviews' => $reviews,
  69.             'users' => $users,
  70.             'courses' => $courses,
  71.             'courseSets' => $courseSets,
  72.         ]);
  73.     }
  74.     public function topNavigationAction($siteNav null$isMobile false)
  75.     {
  76.         $navigations $this->getNavigationService()->getOpenedNavigationsTreeByType('top');
  77.         return $this->render('default/top-navigation.html.twig', [
  78.             'navigations' => $navigations,
  79.             'siteNav' => $siteNav,
  80.             'isMobile' => $isMobile,
  81.         ]);
  82.     }
  83.     public function footNavigationAction()
  84.     {
  85.         $navigations $this->getNavigationService()->findNavigationsByType('foot'0100);
  86.         return $this->render('default/foot-navigation.html.twig', [
  87.             'navigations' => $navigations,
  88.         ]);
  89.     }
  90.     public function friendlyLinkAction()
  91.     {
  92.         $friendlyLinks $this->getNavigationService()->getOpenedNavigationsTreeByType('friendlyLink');
  93.         return $this->render('default/friend-link.html.twig', [
  94.             'friendlyLinks' => $friendlyLinks,
  95.         ]);
  96.     }
  97.     public function customerServiceAction()
  98.     {
  99.         $customerServiceSetting $this->getSettingService()->get('customerService', []);
  100.         return $this->render('default/customer-service-online.html.twig', [
  101.             'customerServiceSetting' => $customerServiceSetting,
  102.         ]);
  103.     }
  104.     public function jumpAction(Request $request)
  105.     {
  106.         $courseId = (int) $request->query->get('id');
  107.         if ($this->getCourseMemberService()->isCourseTeacher($courseId$this->getCurrentUser()->id)) {
  108.             $url $this->generateUrl('live_course_manage_replay', ['id' => $courseId]);
  109.         } else {
  110.             $url $this->generateUrl('course_show', ['id' => $courseId]);
  111.         }
  112.         $jumpScript "<script type=\"text/javascript\"> if (top.location !== self.location) {top.location = \"{$url}\";}</script>";
  113.         return new Response($jumpScript);
  114.     }
  115.     public function coursesCategoryAction(Request $request)
  116.     {
  117.         $conditions $request->query->all();
  118.         $conditions['status'] = 'published';
  119.         $conditions['parentId'] = 0;
  120.         $categoryId = isset($conditions['categoryId']) ? $conditions['categoryId'] : 0;
  121.         $orderBy $conditions['orderBy'];
  122.         $courseType = isset($conditions['courseType']) ? $conditions['courseType'] : 'course';
  123.         $config $this->getThemeService()->getCurrentThemeConfig();
  124.         if (!empty($config['confirmConfig'])) {
  125.             $config $config['confirmConfig']['blocks']['left'];
  126.             foreach ($config as $template) {
  127.                 if (('course-grid-with-condition-index' == $template['code'] && 'course' == $courseType)
  128.                     || ('open-course' == $template['code'] && 'open-course' == $courseType)) {
  129.                     $config $template;
  130.                 }
  131.             }
  132.             $config['orderBy'] = $orderBy;
  133.             $config['categoryId'] = $categoryId;
  134.             return $this->render('default/'.$config['code'].'.html.twig', [
  135.                 'config' => $config,
  136.             ]);
  137.         } else {
  138.             return $this->render('default/course-grid-with-condition-index.html.twig', [
  139.                 'categoryId' => $categoryId,
  140.                 'orderBy' => $orderBy,
  141.             ]);
  142.         }
  143.     }
  144.     public function translateAction(Request $request)
  145.     {
  146.         $locale $request->query->get('language');
  147.         $targetPath $request->query->get('_target_path');
  148.         $request->getSession()->set('_locale'$locale);
  149.         $currentUser $this->getCurrentUser();
  150.         if ($currentUser->isLogin()) {
  151.             $this->getUserService()->updateUserLocale($currentUser['id'], $locale);
  152.         }
  153.         return $this->redirectSafely($targetPath);
  154.     }
  155.     public function clientTimeCheckAction(Request $request)
  156.     {
  157.         $clientTime $request->request->get('clientTime');
  158.         $clientTime strtotime($clientTime);
  159.         if ($clientTime time()) {
  160.             return $this->createJsonResponse(false);
  161.         }
  162.         return $this->createJsonResponse(true);
  163.     }
  164.     private function getMeCount()
  165.     {
  166.         $meCount $this->setting('meCount'false);
  167.         if (false === $meCount) {
  168.             // 判断是否是定制用户
  169.             $result CloudAPIFactory::create('leaf')->get('/me');
  170.             $this->getSettingService()->set('meCount'$result);
  171.         }
  172.         $meCount $this->setting('meCount');
  173.         return $meCount;
  174.     }
  175.     private function isCustom()
  176.     {
  177.         $result $this->getMeCount();
  178.         return isset($result['hasMobile']) ? $result['hasMobile'] : 0;
  179.     }
  180.     /**
  181.      * @return SettingService
  182.      */
  183.     protected function getSettingService()
  184.     {
  185.         return $this->getBiz()->service('System:SettingService');
  186.     }
  187.     /**
  188.      * @return NavigationService
  189.      */
  190.     protected function getNavigationService()
  191.     {
  192.         return $this->getBiz()->service('Content:NavigationService');
  193.     }
  194.     /**
  195.      * @return BlockService
  196.      */
  197.     protected function getBlockService()
  198.     {
  199.         return $this->getBiz()->service('Content:BlockService');
  200.     }
  201.     /**
  202.      * @return CourseService
  203.      */
  204.     protected function getCourseService()
  205.     {
  206.         return $this->getBiz()->service('Course:CourseService');
  207.     }
  208.     protected function getReviewService()
  209.     {
  210.         return $this->getBiz()->service('Course:ReviewService');
  211.     }
  212.     /**
  213.      * @return CategoryService
  214.      */
  215.     protected function getCategoryService()
  216.     {
  217.         return $this->getBiz()->service('Taxonomy:CategoryService');
  218.     }
  219.     /**
  220.      * @return AppService
  221.      */
  222.     protected function getAppService()
  223.     {
  224.         return $this->getBiz()->service('CloudPlatform:AppService');
  225.     }
  226.     /**
  227.      * @return ClassroomService
  228.      */
  229.     protected function getClassroomService()
  230.     {
  231.         return $this->getBiz()->service('Classroom:ClassroomService');
  232.     }
  233.     /**
  234.      * @return BatchNotificationService
  235.      */
  236.     protected function getBatchNotificationService()
  237.     {
  238.         return $this->getBiz()->service('User:BatchNotificationService');
  239.     }
  240.     /**
  241.      * @return ThemeService
  242.      */
  243.     protected function getThemeService()
  244.     {
  245.         return $this->getBiz()->service('Theme:ThemeService');
  246.     }
  247.     /**
  248.      * @return CourseSetService
  249.      */
  250.     protected function getCourseSetService()
  251.     {
  252.         return $this->getBiz()->service('Course:CourseSetService');
  253.     }
  254.     protected function getCourseMemberService()
  255.     {
  256.         return $this->getBiz()->service('Course:MemberService');
  257.     }
  258.     protected function getTaskService()
  259.     {
  260.         return $this->getBiz()->service('Task:TaskService');
  261.     }
  262. }