src/CorporateTrainingBundle/Controller/ProjectPlan/ProjectPlanManageController.php line 1030

Open in your IDE?
  1. <?php
  2. namespace CorporateTrainingBundle\Controller\ProjectPlan;
  3. use AppBundle\Common\ArrayToolkit;
  4. use AppBundle\Common\Exception\AccessDeniedException;
  5. use AppBundle\Common\Paginator;
  6. use AppBundle\Controller\BaseController;
  7. use Biz\File\Service\UploadFileService;
  8. use CorporateTrainingBundle\Biz\Enroll\Service\EnrollRecordService;
  9. use CorporateTrainingBundle\Biz\OfflineCourse\Service\OfflineCourseService;
  10. use CorporateTrainingBundle\Biz\ProjectPlan\Service\PassingCriteriaService;
  11. use CorporateTrainingBundle\Biz\ProjectPlan\Service\ProjectPlanService;
  12. use CorporateTrainingBundle\Biz\ProjectPlan\Service\StageItemSortService;
  13. use CorporateTrainingBundle\Biz\ProjectPlan\Service\StageService;
  14. use CorporateTrainingBundle\Biz\ResourceScope\Service\ResourceAccessScopeService;
  15. use CorporateTrainingBundle\Biz\ResourceScope\Service\ResourceVisibleScopeService;
  16. use CorporateTrainingBundle\Biz\TargetPlan\Service\TargetPlanService;
  17. use CorporateTrainingBundle\Biz\UserAttribute\Service\UserAttributeService;
  18. use ExamPlugin\Biz\TestPaper\Service\TestPaperService;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  22. use Topxia\Service\Common\ServiceKernel;
  23. class ProjectPlanManageController extends BaseController
  24. {
  25.     public function createAction(Request $request)
  26.     {
  27.         $user $this->getCurrentUser();
  28.         if (!$this->getProjectPlanService()->hasManageProjectPlanPermission()) {
  29.             return $this->createMessageResponse('error''project_plan.message.can_not_create_message');
  30.         }
  31.         return $this->render(
  32.             'project-plan/create.html.twig',
  33.             [
  34.                 'user' => $user,
  35.             ]
  36.         );
  37.     }
  38.     public function overviewBoardAction($id)
  39.     {
  40.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  41.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  42.         }
  43.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  44.         $conditions['projectPlanId'] = $projectPlan['id'];
  45.         $projectPlanMemberNum $this->getProjectPlanMemberService()->countProjectPlanMembers($conditions);
  46.         if (== $projectPlan['requireAudit']) {
  47.             $recordCounts $this->getEnrollRecordService()->countEnrollRecords(['targetId' => $projectPlan['id'], 'status' => 'submitted']);
  48.         }
  49.         $projectPlanItems $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(['projectPlanId' => $projectPlan['id']], [], 0PHP_INT_MAX);
  50.         $details $this->getProjectPlanService()->findTaskDetailByTimeRangeAndProjectPlanId(strtotime(date('Y-m-d'time())), strtotime(date('Y-m-d 23:59:59'time())), $projectPlan['id']);
  51.         // 处理单个线下课 多个签到 多个游戏的bug
  52.         $items = [];
  53.         if (!empty($details)) {
  54.             foreach ($details as $number => $detail) {
  55.                 if ('offline_course' == $detail['itemType'] && in_array($detail['type'], ['sign''game'])) {
  56.                     $details[$detail['itemId']][$detail['type']][] = $detail;
  57.                     unset($details[$number]);
  58.                 }
  59.             }
  60.             foreach ($details as $detail) {
  61.                 if (!empty($detail['sign'][0]) || !empty($detail['game'][0])) {
  62.                     if (!empty($detail['sign'][0])) {
  63.                         $items[$detail['sign'][0]['itemId']][] = $detail['sign'][0];
  64.                     }
  65.                     if (!empty($detail['game'][0])) {
  66.                         $items[$detail['game'][0]['itemId']][] = $detail['game'][0];
  67.                     }
  68.                 } else {
  69.                     $items[] = $detail;
  70.                 }
  71.             }
  72.             foreach ($items as $num => $item) {
  73.                 if (!empty($item[0])) {
  74.                     $infos $item;
  75.                     unset($items[$num]);
  76.                     $items[$num]['itemType'] = $infos[0]['itemType'];
  77.                     $items[$num]['itemId'] = $infos[0]['itemId'];
  78.                     $items[$num]['title'] = $infos[0]['title'];
  79.                     $items[$num]['types'] = $infos;
  80.                 }
  81.             }
  82.         }
  83.         return $this->render(
  84.             'project-plan/overview-board.html.twig',
  85.             [
  86.                 'projectPlan' => $projectPlan,
  87.                 'projectPlanItems' => $projectPlanItems,
  88.                 'projectPlanMemberNum' => $projectPlanMemberNum,
  89.                 'recordCounts' => !empty($recordCounts) ? $recordCounts 0,
  90.                 'detail' => $items,
  91.                 'time' => time(),
  92.             ]
  93.         );
  94.     }
  95.     public function itemsDetailAction($projectPlanId)
  96.     {
  97.         $projectPlanItems $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(['projectPlanId' => $projectPlanId], [], 0PHP_INT_MAX);
  98.         $projectPlanItems $this->getManageUrl($projectPlanItems);
  99.         return $this->createJsonResponse($projectPlanItems);
  100.     }
  101.     public function baseAction(Request $request$id)
  102.     {
  103.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  104.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  105.         }
  106.         $this->getResourceVisibleScopeService()->migrateResourceShowable('project'$id);
  107.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  108.         $advancedOption $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
  109.         if ('POST' == $request->getMethod()) {
  110.             $fields $request->request->all();
  111.             $org $this->getOrgService()->getOrgByOrgCode($fields['orgCode']);
  112.             if (!empty($fields['orgCode']) && !$this->getCurrentUser()->hasManagePermissionWithOrgCode($fields['orgCode'])) {
  113.                 throw new AccessDeniedException($this->trans('admin.manage.org_no_permission'));
  114.             }
  115.             $fields['orgId'] = $org['id'];
  116.             $fields $this->conversionTime($fields$projectPlan);
  117.             if (== $fields['requireEnrollment']) {
  118.                 $fields['requireAudit'] = 0;
  119.             }
  120.             $scopes $this->buildAccessScope($fields);
  121.             $this->getResourceAccessService()->setResourceAccessScope($projectPlan['id'], 'projectPlan'$scopes);
  122.             $this->getResourceVisibleScopeService()->setResourceVisibleScope($id'projectPlan'$fields);
  123.             $this->getProjectPlanService()->updateProjectPlan($id$fields);
  124.             $this->setFlashMessage('success''project_plan.message.update_success_message');
  125.             $fields['projectPlanId'] = $id;
  126.             $fields $this->filterAdvancedOption($fields);
  127.             if (empty($advancedOption)) {
  128.                 $this->getProjectPlanService()->createProjectPlanAdvancedOption($fields);
  129.             } else {
  130.                 $this->getProjectPlanService()->updateProjectPlanAdvancedOption($advancedOption['id'], $fields);
  131.             }
  132.             return $this->redirectToRoute('project_plan_manage_base', ['id' => $id]);
  133.         }
  134.         $materials = empty($advancedOption) ? [] : [$advancedOption['material2'], $advancedOption['material3']];
  135.         $owner $this->getUserService()->getUser($projectPlan['ownerId']);
  136.         $ownerProfile $this->getUserService()->getUserProfile($projectPlan['ownerId']);
  137.         $owner['truename'] = $ownerProfile['truename'];
  138.         return $this->render(
  139.             'project-plan/base.html.twig',
  140.             [
  141.                 'projectPlan' => $projectPlan,
  142.                 'owner' => $owner,
  143.                 'advancedOption' => $advancedOption,
  144.                 'materials' => $materials,
  145.             ]
  146.         );
  147.     }
  148.     public function shareAction(Request $request$id)
  149.     {
  150.         $this->getResourceVisibleScopeService()->migrateResourceShowable('project'$id);
  151.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  152.         $qrcodeImgUrl $this->qrcode('project_plan_detail', ['id' => $projectPlan['id']]);
  153.         $shareUrl $request->getSchemeAndHttpHost().$this->generateUrl('project_plan_detail', ['id' => $projectPlan['id']]);
  154.         return $this->render(
  155.             'admin/project-plan/share.html.twig',
  156.             [
  157.                 'qrcodeImgUrl' => $qrcodeImgUrl,
  158.                 'projectPlan' => $projectPlan,
  159.                 'shareUrl' => $shareUrl,
  160.             ]
  161.         );
  162.     }
  163.     public function coverAction(Request $request$id)
  164.     {
  165.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  166.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  167.         }
  168.         if ($request->isMethod('POST')) {
  169.             $data $request->request->all();
  170.             $this->getProjectPlanService()->changeCover($id$data);
  171.             return $this->redirect($this->generateUrl('project_plan_manage_cover', ['id' => $id]));
  172.         }
  173.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  174.         return $this->render(
  175.             'project-plan/cover.html.twig',
  176.             [
  177.                 'projectPlan' => $projectPlan,
  178.             ]
  179.         );
  180.     }
  181.     public function coverCropAction(Request $request$id)
  182.     {
  183.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  184.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  185.         }
  186.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  187.         if ('POST' == $request->getMethod()) {
  188.             $data $request->request->all();
  189.             $this->getProjectPlanService()->changeCover(
  190.                 $projectPlan['id'],
  191.                 json_decode($data['images'], true)
  192.             );
  193.             return $this->redirect($this->generateUrl(
  194.                 'project_plan_manage_cover',
  195.                 ['id' => $projectPlan['id']]
  196.             ));
  197.         }
  198.         $fileId $request->getSession()->get('fileId');
  199.         list($pictureUrl$naturalSize$scaledSize) = $this->getFileService()->getImgFileMetaInfo($fileId480270);
  200.         return $this->render(
  201.             'project-plan/cover-crop.html.twig',
  202.             [
  203.                 'projectPlan' => $projectPlan,
  204.                 'pictureUrl' => $pictureUrl,
  205.                 'naturalSize' => $naturalSize,
  206.                 'scaledSize' => $scaledSize,
  207.             ]
  208.         );
  209.     }
  210.     public function headerAction($projectPlan)
  211.     {
  212.         $user $this->getCurrentUser();
  213.         if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlan['id']) && !$user->hasPermission('admin_data_center_project_plan')) {
  214.             throw $this->createAccessDeniedException('No project plan management permissions');
  215.         }
  216.         return $this->render(
  217.             '@CorporateTraining/project-plan/header.html.twig',
  218.             [
  219.                 'projectPlan' => $projectPlan,
  220.             ]
  221.         );
  222.     }
  223.     public function ajaxPublishAction(Request $request$id)
  224.     {
  225.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  226.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.publish.message.no_permission')]);
  227.         }
  228.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  229.         if (empty($projectPlan)) {
  230.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.message.project_plan_empty')]);
  231.         }
  232.         if (!$projectPlan['startTime']) {
  233.             $success false;
  234.             $message ServiceKernel::instance()->trans('project_plan.publish.message.data_empty');
  235.         }
  236.         if ($projectPlan['showable'] && !$projectPlan['enrollmentStartDate'] && !$projectPlan['isPermanentEnrollment']) {
  237.             $success false;
  238.             $message ServiceKernel::instance()->trans('project_plan.publish.message.data_empty');
  239.         } else {
  240.             $this->getProjectPlanService()->publishProjectPlan($id);
  241.             $success true;
  242.             $message '';
  243.         }
  244.         return $this->createJsonResponse(['success' => $success'message' => $message]);
  245.     }
  246.     public function projectPlanPublishedConfigurationAction(Request $request$id)
  247.     {
  248.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  249.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.publish.message.no_permission')]);
  250.         }
  251.         $this->getResourceVisibleScopeService()->migrateResourceShowable('project'$id);
  252.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  253.         return $this->render(
  254.             '@CorporateTraining/project-plan/published-configuration.html.twig',
  255.             [
  256.                 'projectPlan' => $projectPlan,
  257.             ]
  258.         );
  259.     }
  260.     public function ajaxCloseAction(Request $request$id)
  261.     {
  262.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  263.             return $this->createJsonResponse(false);
  264.         }
  265.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  266.         if (empty($projectPlan)) {
  267.             return $this->createJsonResponse(false);
  268.         }
  269.         $result $this->getProjectPlanService()->closeProjectPlan($id);
  270.         if ($result) {
  271.             return $this->createJsonResponse(true);
  272.         }
  273.         return $this->createJsonResponse(false);
  274.     }
  275.     public function ajaxArchiveAction(Request $request$id)
  276.     {
  277.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  278.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.archive.message.no_permission')]);
  279.         }
  280.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  281.         if (empty($projectPlan)) {
  282.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.message.project_plan_empty')]);
  283.         }
  284.         $this->getProjectPlanService()->archiveProjectPlan($id);
  285.         return $this->createJsonResponse(['success' => true'message' => '']);
  286.     }
  287.     public function ajaxRemoveAction(Request $request$id)
  288.     {
  289.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  290.             return $this->createJsonResponse(false);
  291.         }
  292.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  293.         if (empty($projectPlan)) {
  294.             return $this->createJsonResponse(false);
  295.         }
  296.         $result $this->getProjectPlanService()->deleteProjectPlan($id);
  297.         if ($result) {
  298.             return $this->createJsonResponse(true);
  299.         }
  300.         return $this->createJsonResponse(false);
  301.     }
  302.     /**
  303.      * @param Request $request
  304.      * @param         $id
  305.      *
  306.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  307.      *
  308.      * @throws \Codeages\Biz\Framework\Service\Exception\AccessDeniedException
  309.      *
  310.      * @deprecated
  311.      */
  312.     public function itemRemoveAction(Request $request$id)
  313.     {
  314.         $projectPlanItem $this->getProjectPlanService()->getProjectPlanItem($id);
  315.         if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanItem['projectPlanId'])) {
  316.             return $this->createJsonResponse(['success' => 'false''message' => ServiceKernel::instance()->trans('project_plan.message.can_not_manage_message')]);
  317.         }
  318.         $result $this->getProjectPlanService()->deleteProjectPlanItem($id);
  319.         if ($result) {
  320.             return $this->createJsonResponse(true);
  321.         }
  322.         return $this->createJsonResponse(false);
  323.     }
  324.     public function itemsAction(Request $request$id)
  325.     {
  326.         if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
  327.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  328.         }
  329.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  330.         return $this->render('@CorporateTraining/project-plan/item-manage.html.twig', ['projectPlan' => $projectPlan]);
  331.     }
  332.     public function itemTypeChooseAction(Request $request$id)
  333.     {
  334.         return $this->render('project-plan/item/choose-item-type.html.twig', ['id' => $id'unableToChoose' => $this->getUnableChooseItemTypes($id)]);
  335.     }
  336.     /**
  337.      * @param Request $request
  338.      * @param         $id
  339.      * @param         $type
  340.      *
  341.      * @return \Symfony\Component\HttpFoundation\JsonResponse|Response
  342.      *
  343.      * @throws \Exception
  344.      *
  345.      * @deprecated
  346.      */
  347.     public function itemAddAction(Request $request$id$type)
  348.     {
  349.         if ($request->isMethod('POST')) {
  350.             $data $request->request->all();
  351.             $message $this->validateItem($data$type);
  352.             if ($message) {
  353.                 return $this->createJsonResponse(['success' => false'message' => $message]);
  354.             }
  355.             $data['creator'] = $this->getCurrentUser()->getId();
  356.             $this->getProjectPlanService()->setProjectPlanItems($id$data$type);
  357.             return $this->createJsonResponse(['success' => true'message' => '']);
  358.         }
  359.         $projectPlanMetas $this->getProjectPlanMetas();
  360.         return $this->forward(
  361.             $projectPlanMetas[$type]['controller'].'::createAction',
  362.             [
  363.                 'projectPlanId' => $id,
  364.             ]
  365.         );
  366.     }
  367.     /**
  368.      * @param Request $request
  369.      * @param         $id
  370.      * @param         $projectPlanId
  371.      *
  372.      * @return \Symfony\Component\HttpFoundation\JsonResponse|Response
  373.      *
  374.      * @throws \Exception
  375.      *
  376.      * @deprecated
  377.      */
  378.     public function itemUpdateAction(Request $request$id$projectPlanId)
  379.     {
  380.         $item $this->getProjectPlanService()->getProjectPlanItem($id);
  381.         if ($request->isMethod('POST')) {
  382.             $data $request->request->all();
  383.             $data['projectPlanId'] = $projectPlanId;
  384.             $message $this->validateItem($data$item['targetType']);
  385.             if ($message) {
  386.                 return $this->createJsonResponse(['success' => false'message' => $message]);
  387.             }
  388.             $this->getProjectPlanService()->updatePlanItem($id$data$item['targetType']);
  389.             return $this->createJsonResponse(['success' => true'message' => '']);
  390.         }
  391.         $projectPlanMetas $this->getProjectPlanMetas();
  392.         return $this->forward(
  393.             $projectPlanMetas[$item['targetType']]['controller'].'::updateAction',
  394.             [
  395.                 'id' => $id,
  396.             ]
  397.         );
  398.     }
  399.     /**
  400.      * @param Request $request
  401.      * @param         $id
  402.      *
  403.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  404.      *
  405.      * @throws \Codeages\Biz\Framework\Service\Exception\AccessDeniedException
  406.      *
  407.      * @deprecated
  408.      */
  409.     public function itemDeleteAction(Request $request$id)
  410.     {
  411.         $item $this->getProjectPlanService()->getProjectPlanItem($id);
  412.         $this->getProjectPlanService()->deleteProjectPlanItem($id);
  413.         return $this->createJsonResponse(true);
  414.     }
  415.     /**
  416.      * @param Request $request
  417.      * @param         $id
  418.      * @param         $type
  419.      *
  420.      * @return Response
  421.      */
  422.     public function itemListAction(Request $request$id$type)
  423.     {
  424.         $projectPlanMetas $this->getProjectPlanMetas();
  425.         return $this->forward(
  426.             $projectPlanMetas[$type]['controller'].'::listAction',
  427.             [
  428.                 'request' => $request,
  429.                 'id' => $id,
  430.             ]
  431.         );
  432.     }
  433.     public function enrollAction(Request $request$id)
  434.     {
  435.         $user $this->getCurrentUser();
  436.         if (!$user->isLogin()) {
  437.             throw $this->createAccessDeniedException();
  438.         }
  439.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  440.         $advancedOption $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
  441.         if ('published' != $projectPlan['status']) {
  442.             throw $this->createAccessDeniedException('Project plan not published');
  443.         }
  444.         $canAccess $projectPlan['conditionalAccess'] ? $this->getResourceAccessService()->canUserAccessResource('projectPlan'$projectPlan['id'], $user['id']) : true;
  445.         if ('POST' === $request->getMethod()) {
  446.             if (!$canAccess) {
  447.                 return $this->createAccessDeniedException($this->trans('resource_scope.no_permission'));
  448.             }
  449.             $fields $request->request->all();
  450.             $attachments $request->request->get('attachment');
  451.             if (== $projectPlan['requireAdvance']) {
  452.                 if (== $advancedOption['requireRemark'] && empty($fields['remark'])) {
  453.                     return $this->createJsonResponse(
  454.                         [
  455.                             'append' => false,
  456.                             'html' => '',
  457.                             'error' => [
  458.                                 'name' => 'error',
  459.                                 'message' => $this->trans('enroll.remark_not_fill'),
  460.                             ],
  461.                         ],
  462.                         Response::HTTP_INTERNAL_SERVER_ERROR
  463.                     );
  464.                 }
  465.                 if (== $advancedOption['requireMaterial'] && !empty($attachments)) {
  466.                     foreach ($attachments as $attachment) {
  467.                         if (empty($attachment['fileIds'])) {
  468.                             return $this->createJsonResponse(
  469.                                 [
  470.                                     'append' => false,
  471.                                     'html' => '',
  472.                                     'error' => [
  473.                                         'name' => 'error',
  474.                                         'message' => $this->trans('enroll.material_not_upload'),
  475.                                     ],
  476.                                 ],
  477.                                 Response::HTTP_INTERNAL_SERVER_ERROR
  478.                             );
  479.                         }
  480.                     }
  481.                 }
  482.             }
  483.             $record $this->getEnrollStrategyContext()->createStrategy('projectPlan')->submitEnrollment($id$user['id'], $fields);
  484.             $this->uploadMaterialAttachments($attachments$record);
  485.             return $this->createJsonResponse(true);
  486.         }
  487.         if (!empty($projectPlan['requireEnrollment']) && $projectPlan['conditionalAccess'] && !$canAccess) {
  488.             return $this->render(
  489.                 '@CorporateTraining/project-plan/can-not-enroll-modal.html.twig',
  490.                 []
  491.             );
  492.         }
  493.         return $this->render(
  494.             '@CorporateTraining/project-plan/detail/attend-modal.html.twig',
  495.             [
  496.                 'projectPlan' => $projectPlan,
  497.                 'advancedOption' => empty($advancedOption) ? [] : $advancedOption,
  498.                 'canAccess' => $canAccess,
  499.             ]
  500.         );
  501.     }
  502.     public function viewQrcodeAction($id)
  503.     {
  504.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  505.         $qrcodeImgUrl $this->qrcode('project_plan_detail', ['id' => $projectPlan['id']]);
  506.         return $this->render(
  507.             'project-plan/qr-code.html.twig',
  508.             [
  509.                 'projectPlan' => $projectPlan,
  510.                 'qrcodeImgUrl' => $qrcodeImgUrl,
  511.             ]
  512.         );
  513.     }
  514.     public function detailAction($id)
  515.     {
  516.         $canAccess true;
  517.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  518.         if ('published' != $projectPlan['status']) {
  519.             return $this->render('@CorporateTraining/project-plan/detail/detail-not-published.html.twig');
  520.         }
  521.         if (!$this->getProjectPlanService()->canUserVisitResource($id)) {
  522.             return $this->render('@CorporateTraining/project-plan/detail/detail-not-open.html.twig');
  523.         }
  524.         $projectPlanAdvancedOptions $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($projectPlan['id']);
  525.         $projectPlan['requireRemind'] = 0;
  526.         if (!empty($projectPlanAdvancedOptions['remindRequirement'])) {
  527.             $projectPlan['requireRemind'] = $projectPlanAdvancedOptions['requireRemind'];
  528.             $projectPlan['remindRequirement'] = $projectPlanAdvancedOptions['remindRequirement'];
  529.         }
  530.         $projectPlan['studentNum'] = $this->getProjectPlanMemberService()->countProjectPlanMembers(['projectPlanId' => $id]);
  531.         $projectPlanItems $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(
  532.             ['projectPlanId' => $id],
  533.             ['seq' => 'ASC'],
  534.             0,
  535.             PHP_INT_MAX
  536.         );
  537.         if ($projectPlan['conditionalAccess']) {
  538.             $canAccess $this->getResourceAccessService()->canUserAccessResource('projectPlan'$projectPlan['id'], $this->getCurrentUser()->getId());
  539.         }
  540.         $passingCriteria = [];
  541.         if (ProjectPlanService::PASSING_MODE_AUTO == $projectPlan['passingMode']) {
  542.             $passingCriteria $this->getPassingCriteriaService()->getPassingCriteriaByProjectPlanId($projectPlan['id']);
  543.         }
  544.         return $this->render(
  545.             '@CorporateTraining/project-plan/detail/detail.html.twig',
  546.             [
  547.                 'projectPlan' => $projectPlan,
  548.                 'projectPlanItems' => $projectPlanItems,
  549.                 'canAccess' => $canAccess,
  550.                 'passingCriteria' => $passingCriteria,
  551.             ]
  552.         );
  553.     }
  554.     public function itemDetailAction($projectPlanId$itemId)
  555.     {
  556.         return $this->render(
  557.             '@CorporateTraining/project-plan/item/detail.html.twig',
  558.             [
  559.                 'projectPlanId' => $projectPlanId,
  560.                 'itemId' => $itemId,
  561.             ]
  562.         );
  563.     }
  564.     /**
  565.      * @param $projectPlanItems
  566.      * @param $projectPlanId
  567.      *
  568.      * @return Response|null
  569.      *
  570.      * @deprecated
  571.      */
  572.     public function courseTaskListAction($projectPlanItems$projectPlanId)
  573.     {
  574.         $userId $this->getCurrentUser()->getId();
  575.         $member $this->getProjectPlanMemberService()->getProjectPlanMemberByUserIdAndProjectPlanId($userId$projectPlanId);
  576.         if (!empty($member)) {
  577.             return $this->forward('CorporateTrainingBundle\Controller\StudyCenter\MyTaskController::courseTaskListAction', [
  578.                 'projectPlanItems' => $projectPlanItems,
  579.                 'userId' => $userId,
  580.                 'projectPlanId' => $projectPlanId,
  581.                 'tabType' => 'myTask',
  582.             ]);
  583.         }
  584.         return $this->render(
  585.             '@CorporateTraining/project-plan/detail/task-list/list.html.twig',
  586.             array_merge(
  587.                 [
  588.                     'projectPlanId' => $projectPlanId,
  589.                     'currentTime' => time(),
  590.                 ],
  591.                 $this->buildProjectPlanItems($projectPlanItems)
  592.             )
  593.         );
  594.     }
  595.     public function ajaxItemBodyAction($targetType$targetId)
  596.     {
  597.         $targetType $this->get('corporatetrainingbundle.twig.web_extension')->underlineToLine($targetType);
  598.         return $this->render("project-plan/detail/task-list/{$targetType}-item-body.html.twig", ['id' => $targetId]);
  599.     }
  600.     public function advancedOptionAction(Request $request$id)
  601.     {
  602.         $projectPlan $this->getProjectPlanService()->getProjectPlan($id);
  603.         $advancedOption $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
  604.         if ('POST' === $request->getMethod()) {
  605.             $fields $request->request->all();
  606.             $fields['projectPlanId'] = $id;
  607.             $fields $this->filterAdvancedOption($fields);
  608.             if (empty($advancedOption)) {
  609.                 $result $this->getProjectPlanService()->createProjectPlanAdvancedOption($fields);
  610.             } else {
  611.                 $result $this->getProjectPlanService()->updateProjectPlanAdvancedOption($advancedOption['id'], $fields);
  612.             }
  613.             return $this->createJsonResponse($result);
  614.         }
  615.         $materials = empty($advancedOption) ? [] : [$advancedOption['material2'], $advancedOption['material3']];
  616.         return $this->render(
  617.             '@CorporateTraining/project-plan/advanced-options-modal.html.twig',
  618.             [
  619.                 'projectPlan' => $projectPlan,
  620.                 'advancedOption' => $advancedOption,
  621.                 'materials' => $materials,
  622.             ]
  623.         );
  624.     }
  625.     public function crowdMatchAction(Request $request)
  626.     {
  627.         $queryString $request->query->get('q');
  628.         $attributes = ['userGroup''org''post'];
  629.         $name $this->getUserAttributeService()->searchAttributesNames($attributes$queryString);
  630.         return $this->createJsonResponse($name);
  631.     }
  632.     public function projectPlanListAction(Request $request)
  633.     {
  634.         $conditions $request->query->all();
  635.         $conditions['status'] = 'published';
  636.         $conditions $this->buildProjectPlanListConditions($conditions);
  637.         $count $this->getProjectPlanService()->countProjectPlans(
  638.             $conditions
  639.         );
  640.         $paginator = new Paginator(
  641.             $request,
  642.             $count,
  643.             20
  644.         );
  645.         $projectPlans $this->getProjectPlanService()->searchProjectPlanOrderByEnrollmentStatus(
  646.             $conditions,
  647.             $paginator->getOffsetCount(),
  648.             $paginator->getPerPageCount()
  649.         );
  650.         foreach ($projectPlans as &$projectPlan) {
  651.             $projectPlan['canAccess'] = true;
  652.             if ($projectPlan['conditionalAccess']) {
  653.                 $projectPlan['canAccess'] = $this->getResourceAccessService()->canUserAccessResource('projectPlan'$projectPlan['id'], $this->getCurrentUser()->getId());
  654.             }
  655.         }
  656.         return $this->render(
  657.             '@CorporateTraining/project-plan/list.html.twig',
  658.             [
  659.                 'enrollment' => empty($conditions['enrollment']) ? $conditions['enrollment'],
  660.                 'projectPlans' => $projectPlans,
  661.                 'paginator' => $paginator,
  662.             ]
  663.         );
  664.     }
  665.     /**
  666.      * @param Request $request
  667.      *
  668.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  669.      *
  670.      * @deprecated
  671.      */
  672.     public function sortItemAction(Request $request)
  673.     {
  674.         $ids $request->request->get('ids');
  675.         if (!empty($ids)) {
  676.             $this->getProjectPlanService()->sortItems($ids);
  677.         }
  678.         return $this->createJsonResponse(true);
  679.     }
  680.     public function viewExamQrcodeAction($id$examId)
  681.     {
  682.         $exam $this->getExamService()->getExam($examId);
  683.         $qrcodeImgUrl $this->qrcode('can_do_exam', ['id' => $id'examId' => $examId]);
  684.         return $this->render(
  685.             'project-plan/exam-manage/qrcode/qr-code.html.twig',
  686.             [
  687.                 'exam' => $exam,
  688.                 'qrcodeImgUrl' => $qrcodeImgUrl,
  689.             ]
  690.         );
  691.     }
  692.     public function canDoExamAction($id$examId)
  693.     {
  694.         $user $this->getCurrentUser();
  695.         $member $this->getProjectPlanMemberService()->getProjectPlanMemberByUserIdAndProjectPlanId($user['id'], $id);
  696.         if (empty($member)) {
  697.             return $this->render(
  698.                 'project-plan/exam-manage/qrcode/error.html.twig',
  699.                 [
  700.                     'message' => ServiceKernel::instance()->trans('project_plan.can_do_exam.message.no_permission'),
  701.                 ]
  702.             );
  703.         }
  704.         $projectPlanItem $this->getProjectPlanService()->getProjectPlanItemByProjectPlanIdAndTargetIdAndTargetType($id$examIdProjectPlanService::ITEM_TYPE_ONLINE_EXAM);
  705.         $examMember $this->getExamService()->getMemberByExamIdIdAndUserId($examId$user['id']);
  706.         if (empty($examMember)) {
  707.             $this->getExamService()->createMember(['examId' => $examId'userId' => $user['id']]);
  708.         }
  709.         return $this->redirect(
  710.             $this->generateUrl('project_plan_exam_show', ['projectPlanId' => $id'itemId' => $projectPlanItem['id'], 'id' => $examId])
  711.         );
  712.     }
  713.     public function projectPlanBaseConfigurationAction($projectPlanId)
  714.     {
  715.         if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanId)) {
  716.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  717.         }
  718.         $this->getResourceVisibleScopeService()->migrateResourceShowable('project'$projectPlanId);
  719.         $projectPlan $this->getProjectPlanService()->getProjectPlan($projectPlanId);
  720.         return $this->render('@CorporateTraining/project-plan/base/base-setting.html.twig', [
  721.             'projectPlan' => $projectPlan,
  722.             'base_nav' => 'base-configuration',
  723.         ]);
  724.     }
  725.     public function projectPlanPublishConfigurationAction($projectPlanId)
  726.     {
  727.         if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanId)) {
  728.             return $this->createMessageResponse('error''project_plan.message.can_not_manage_message');
  729.         }
  730.         $this->getResourceVisibleScopeService()->migrateResourceShowable('project'$projectPlanId);
  731.         $projectPlan $this->getProjectPlanService()->getProjectPlan($projectPlanId);
  732.         return $this->render('@CorporateTraining/project-plan/base/publish-setting.html.twig', [
  733.             'projectPlan' => $projectPlan,
  734.             'base_nav' => 'publish-configuration',
  735.         ]);
  736.     }
  737.     public function interactiveGamesCreateAction(Request $request$projectPlanId)
  738.     {
  739.         $projectPlan $this->getProjectPlanService()->getProjectPlan($projectPlanId);
  740.         if ($request->isMethod('POST')) {
  741.             $fields $request->request->all();
  742.             $games $this->getGamesService()->createGames($fields);
  743.             return $this->createJsonResponse(['result' => true'data' => $games]);
  744.         }
  745.         return $this->render(
  746.             'project-plan/offline-course/interactive-games-create.html.twig',
  747.             [
  748.                 'projectPlan' => $projectPlan,
  749.                 'gameId' => 0,
  750.                 'items' => [],
  751.             ]
  752.         );
  753.     }
  754.     /**
  755.      * @param Request $request
  756.      * @param         $projectPlanId
  757.      * @param         $gameId
  758.      *
  759.      * @return \Symfony\Component\HttpFoundation\JsonResponse|Response|null
  760.      *
  761.      * @deprecated
  762.      */
  763.     public function interactiveGamesUpdateAction(Request $request$projectPlanId$gameId)
  764.     {
  765.         $projectPlan $this->getProjectPlanService()->getProjectPlan($projectPlanId);
  766.         $games $this->getGamesService()->getGames($gameId);
  767.         $boddQuestions $this->getBoddQuestionsService()->searchBoddQuestions(['gameId' => $gameId], ['seq' => 'ASC'], 0PHP_INT_MAX);
  768.         $questionIds = [-1];
  769.         $questionSeqs = [];
  770.         if (!empty($boddQuestions)) {
  771.             $questionIds array_column($boddQuestions'questionId');
  772.             foreach ($boddQuestions as $boddQuestion) {
  773.                 $questionSeqs[$boddQuestion['questionId']]['seq'] = $boddQuestion['seq'];
  774.                 $questionSeqs[$boddQuestion['questionId']]['scoreFactor'] = $boddQuestion['scoreFactor'];
  775.                 $questionSeqs[$boddQuestion['questionId']]['duration'] = $boddQuestion['duration'];
  776.             }
  777.         }
  778.         $questions $this->getQuestionService()->findQuestionsByIds($questionIds);
  779.         foreach ($questions as $question) {
  780.             $item = [];
  781.             if ($question['subCount'] > 0) {
  782.                 $subQuestions $this->getQuestionService()->findQuestionsByParentId($question['id']);
  783.                 $item['subItems'] = [];
  784.                 foreach ($subQuestions as $subQuestion) {
  785.                     $item['subItems'][] = [
  786.                         'questionId' => $subQuestion['id'],
  787.                         'questionType' => $subQuestion['type'],
  788.                         'question' => $subQuestion,
  789.                         'parentId' => $question['id'],
  790.                     ];
  791.                 }
  792.             }
  793.             $item['questionId'] = $question['id'];
  794.             $item['questionType'] = $question['type'];
  795.             $item['question'] = $question;
  796.             $item['seq'] = $questionSeqs[$question['id']]['seq'] ?? 0;
  797.             $item['scoreFactor'] = $questionSeqs[$question['id']]['scoreFactor'] ?? 0;
  798.             $item['duration'] = $questionSeqs[$question['id']]['duration'] ?? 0;
  799.             $items[$question['id']] = $item;
  800.         }
  801.         foreach ($boddQuestions as $boddQuestion) {
  802.             $questionLists[] = $items[$boddQuestion['questionId']];
  803.         }
  804.         if ($request->isMethod('POST')) {
  805.             $fields $request->request->all();
  806.             $games $this->getGamesService()->updateGames($gameId$fields);
  807.             return $this->createJsonResponse(['result' => true'data' => $games]);
  808.         }
  809.         return $this->render(
  810.             'project-plan/offline-course/interactive-games-create.html.twig',
  811.             [
  812.                 'projectPlan' => $projectPlan,
  813.                 'games' => $games,
  814.                 'items' => $questionLists ?? [],
  815.                 'gameId' => $gameId,
  816.             ]
  817.         );
  818.     }
  819.     protected function getUnableChooseItemTypes($projectPlanId)
  820.     {
  821.         $unableToChoose = [];
  822.         $needPlugins = [
  823.             'exam' => [
  824.                 'pluginCode' => 'Exam',
  825.                 'message' => 'project_plan.preparation.items.choose_exam_item_info',
  826.             ],
  827.             'questionnaire' => [
  828.                 'pluginCode' => 'Survey',
  829.                 'message' => 'project_plan.preparation.items.choose_survey_item_info',
  830.             ],
  831.         ];
  832.         foreach ($needPlugins as $type => $needPlugin) {
  833.             if (!$this->isPluginInstalled($needPlugin['pluginCode'])) {
  834.                 $unableToChoose[$type]['reason'] = $needPlugin['message'];
  835.             }
  836.         }
  837.         $targetPlanItems $this->getProjectPlanService()->findProjectPlanItemsByProjectPlanIdAndTargetType($projectPlanId'target_plan_531');
  838.         if (!empty($targetPlanItems)) {
  839.             $unableToChoose['targetPlan531']['reason'] = 'project_plan.preparation.items.choose_target_plan_item_info';
  840.         }
  841.         return $unableToChoose;
  842.     }
  843.     protected function buildProjectPlanItems($projectPlanItems)
  844.     {
  845.         $projectPlanItemsGroupByTargetType ArrayToolkit::group($projectPlanItems'targetType');
  846.         if (isset($projectPlanItemsGroupByTargetType['course'])) {
  847.             $courses $this->getCourseService()->findCoursesByIds(array_column($projectPlanItemsGroupByTargetType['course'], 'targetId'));
  848.         }
  849.         if (isset($projectPlanItemsGroupByTargetType['exam'])) {
  850.             $exams $this->getExamService()->findExamsByIds(array_column($projectPlanItemsGroupByTargetType['exam'], 'targetId'));
  851.             $exams array_column($examsnull'id');
  852.         }
  853.         if (isset($projectPlanItemsGroupByTargetType['offline_course'])) {
  854.             $offlineCourses $this->getOfflineCourseService()->findOfflineCoursesByIds(array_column($projectPlanItemsGroupByTargetType['offline_course'], 'targetId'));
  855.             $offlineCourses array_column($offlineCoursesnull'id');
  856.             $users $this->getUserService()->findUsersByIds(array_column($offlineCourses'teacherId'));
  857.             $userProfiles $this->getUserService()->findUserProfilesByIds(array_column($offlineCourses'teacherId'));
  858.         }
  859.         if (isset($projectPlanItemsGroupByTargetType['offline_exam'])) {
  860.             $offlineExams $this->getOfflineExamService()->findOfflineExamByIds(array_column($projectPlanItemsGroupByTargetType['offline_exam'], 'targetId'));
  861.             $offlineExams array_column($offlineExamsnull'id');
  862.         }
  863.         if (isset($projectPlanItemsGroupByTargetType['target_plan_531'])) {
  864.             $targetPlans $this->getTargetPlanService()->findTargetPlanMapWithCurrentUserResultByIds(array_column($projectPlanItemsGroupByTargetType['target_plan_531'], 'targetId'));
  865.         }
  866.         return [
  867.             'projectPlanItems' => $projectPlanItems,
  868.             'courses' => $courses ?? [],
  869.             'exams' => $exams ?? [],
  870.             'offlineCourses' => $offlineCourses ?? [],
  871.             'offlineExams' => $offlineExams ?? [],
  872.             'users' => $users ?? [],
  873.             'userProfiles' => $userProfiles ?? [],
  874.             'targetPlans' => $targetPlans ?? [],
  875.         ];
  876.     }
  877.     protected function getManageUrl($projectPlanItems)
  878.     {
  879.         $isInstallSurvey $this->isPluginInstalled('Survey');
  880.         $isInstallExam $this->isPluginInstalled('Exam');
  881.         foreach ($projectPlanItems as &$projectPlanItem) {
  882.             if ('offline_course' === $projectPlanItem['targetType']) {
  883.                 $projectPlanItem['url'] = $this->generateUrl('project_plan_manage_items', ['id' => $projectPlanItem['projectPlanId']]);
  884.             } elseif ('exam' === $projectPlanItem['targetType'] && $isInstallExam) {
  885.                 $projectPlanItem['url'] = $this->generateUrl('project_plan_exam_manage_member_list', ['id' => $projectPlanItem['projectPlanId'], 'examId' => $projectPlanItem['targetId'], 'type' => 'exam']);
  886.             } elseif ('offline_exam' === $projectPlanItem['targetType']) {
  887.                 $projectPlanItem['url'] = $this->generateUrl('project_plan_offline_exam_manage_member_list', ['id' => $projectPlanItem['projectPlanId'], 'taskId' => $projectPlanItem['targetId']]);
  888.             } elseif ('questionnaire' === $projectPlanItem['targetType'] && $isInstallSurvey) {
  889.                 $projectPlanItem['url'] = $this->generateUrl('project_plan_survey_data_manage_list', ['id' => $projectPlanItem['projectPlanId']]);
  890.             } else {
  891.                 $projectPlanItem['url'] = $this->generateUrl('project_plan_manage_items', ['id' => $projectPlanItem['projectPlanId']]);
  892.             }
  893.         }
  894.         return $projectPlanItems;
  895.     }
  896.     protected function qrcode($url$array)
  897.     {
  898.         $token $this->getTokenService()->makeToken('qrcode', [
  899.             'data' => [
  900.                 'url' => $this->generateUrl($url$arrayUrlGeneratorInterface::ABSOLUTE_URL),
  901.             ],
  902.             'duration' => 3600 24 365,
  903.         ]);
  904.         $url $this->generateUrl('common_parse_qrcode', ['token' => $token['token']], UrlGeneratorInterface::ABSOLUTE_URL);
  905.         return $this->generateUrl('common_qrcode', ['text' => $url], UrlGeneratorInterface::ABSOLUTE_URL);
  906.     }
  907.     protected function uploadMaterialAttachments($attachments$record)
  908.     {
  909.         $useFiles $this->getUploadFileService()->searchUseFiles(['targetTypes' => ['projectPlaning.material1''projectPlaning.material2''projectPlaning.material3'], 'targetId' => $record['id']]);
  910.         if (!empty($useFiles)) {
  911.             foreach ($useFiles as $useFile) {
  912.                 $this->getUploadFileService()->deleteUseFile($useFile['id']);
  913.             }
  914.         }
  915.         if (!empty($attachments)) {
  916.             $user $this->getCurrentUser();
  917.             $orgs $this->getOrgService()->findOrgsByIds($user['orgIds']);
  918.             $org reset($orgs);
  919.             $userProfile $this->getUserService()->getUserProfile($user['id']);
  920.             $orgName = empty($org) ? '' $org['name'].'+';
  921.             $trueName = empty($userProfile['truename']) ? '' $userProfile['truename'].'+';
  922.             $mobile = empty($userProfile['mobile']) ? '' $userProfile['mobile'].'+';
  923.             foreach ($attachments as $key => $attachment) {
  924.                 $file $this->getUploadFileService()->getFile($attachment['fileIds']);
  925.                 $filename $orgName.$trueName.$mobile.$file['filename'];
  926.                 $this->getUploadFileService()->update($attachment['fileIds'], ['name' => $filename]);
  927.                 $this->getUploadFileService()->createUseFiles($attachment['fileIds'], $record['id'], $attachment['targetType'], $attachment['type']);
  928.             }
  929.         }
  930.     }
  931.     protected function buildProjectPlanListConditions($conditions)
  932.     {
  933.         $conditions['ids'] = [];
  934.         if (!empty($conditions['timeStatus'])) {
  935.             if ('ongoing' === $conditions['timeStatus']) {
  936.                 $projectPlanIds = [-1];
  937.                 $ongoingDateProjectPlanConditions array_merge(['endTime_GE' => time(), 'startTime_LE' => time(), 'timeMode' => ProjectPlanService::TIME_MODE_DATE], $conditions);
  938.                 $ongoingDeadlineProjectPlanConditions array_merge(['timeMode' => ProjectPlanService::TIME_MODE_DEADLINE], $conditions);
  939.                 $projectPlanIds array_unique(array_merge($projectPlanIdsarray_column($this->getProjectPlanService()->searchProjectPlans($ongoingDateProjectPlanConditions, [], 0PHP_INT_MAX, ['id']), 'id')));
  940.                 $projectPlanIds array_unique(array_merge($projectPlanIdsarray_column($this->getProjectPlanService()->searchProjectPlans($ongoingDeadlineProjectPlanConditions, [], 0PHP_INT_MAX, ['id']), 'id')));
  941.                 if (!empty($conditions['ids'])) {
  942.                     $conditions['ids'] = array_intersect($conditions['ids'], $projectPlanIds);
  943.                 } else {
  944.                     $conditions['ids'] = $projectPlanIds;
  945.                 }
  946.             } elseif ('end' === $conditions['timeStatus']) {
  947.                 $conditions array_merge(['endTime_LE' => time(), 'timeMode' => ProjectPlanService::TIME_MODE_DATE], $conditions);
  948.             }
  949.         }
  950.         if (!empty($conditions['enrollment'])) {
  951.             $dateEnrollmentConditions $conditions;
  952.             $permanentEnrollmentConditions $conditions;
  953.             $permanentEnrollmentConditions['isPermanentEnrollment'] = 1;
  954.             $dateEnrollmentConditions['enrollmentEndDate_GE'] = time();
  955.             $dateEnrollmentConditions['enrollmentStartDate_LE'] = time();
  956.             $enrollmentProjectPlanIds = [-1];
  957.             $enrollmentProjectPlanIds array_unique(array_merge($enrollmentProjectPlanIdsarray_column($this->getProjectPlanService()->searchProjectPlans($dateEnrollmentConditions, [], 0PHP_INT_MAX, ['id']), 'id')));
  958.             $enrollmentProjectPlanIds array_unique(array_merge($enrollmentProjectPlanIdsarray_column($this->getProjectPlanService()->searchProjectPlans($permanentEnrollmentConditions, [], 0PHP_INT_MAX, ['id']), 'id')));
  959.             if (!empty($conditions['ids'])) {
  960.                 $conditions['ids'] = array_intersect($conditions['ids'], $enrollmentProjectPlanIds);
  961.             } else {
  962.                 $conditions['ids'] = $enrollmentProjectPlanIds;
  963.             }
  964.         }
  965.         if (isset($conditions['categoryId']) && empty($conditions['categoryId'])) {
  966.             unset($conditions['categoryId']);
  967.         }
  968.         $visibleIds $this->getResourceVisibleScopeService()->findVisibleResourceIdsByResourceTypeAndUserId('projectPlan'$this->getCurrentUser()->getId());
  969.         if (!empty($conditions['ids'])) {
  970.             $conditions['ids'] = array_intersect($conditions['ids'], $visibleIds);
  971.         } else {
  972.             $conditions['ids'] = $visibleIds;
  973.         }
  974.         return $conditions;
  975.     }
  976.     protected function filterAdvancedOption($fields)
  977.     {
  978.         $materials json_decode($fields['materials'], true);
  979.         $fields['material2'] = empty($materials[0]) ? '' $materials[0];
  980.         $fields['material3'] = empty($materials[1]) ? '' $materials[1];
  981.         return $fields;
  982.     }
  983.     protected function conversionTime($data$projectPlan)
  984.     {
  985.         if (array_key_exists('startDateTime'$data)) {
  986.             $data['startTime'] = empty($data['startDateTime']) ? strtotime($data['startDateTime']);
  987.         } else {
  988.             $data['startTime'] = $projectPlan['startTime'];
  989.         }
  990.         if (array_key_exists('endDateTime'$data)) {
  991.             $data['endTime'] = empty($data['endDateTime']) ? strtotime($data['endDateTime'].' 23:59:59');
  992.         } else {
  993.             $data['endTime'] = $projectPlan['endTime'];
  994.         }
  995.         if (array_key_exists('enrollmentStartDate'$data)) {
  996.             $data['enrollmentStartDate'] = empty($data['enrollmentStartDate']) ? strtotime($data['enrollmentStartDate']);
  997.         } else {
  998.             $data['enrollmentStartDate'] = $projectPlan['enrollmentStartDate'];
  999.         }
  1000.         if (array_key_exists('enrollmentEndDate'$data)) {
  1001.             $data['enrollmentEndDate'] = empty($data['enrollmentStartDate']) ? strtotime($data['enrollmentEndDate'].' 23:59:59');
  1002.         } else {
  1003.             $data['enrollmentEndDate'] = $projectPlan['enrollmentEndDate'];
  1004.         }
  1005.         return $data;
  1006.     }
  1007.     protected function validateItem($fields$type)
  1008.     {
  1009.         $message '';
  1010.         if ('exam' == $type) {
  1011.             $testpaper $this->getTestPaperService()->getTestPaper($fields['mediaId']);
  1012.             if (empty($testpaper) || 'published' != $testpaper['status']) {
  1013.                 $message $this->trans('exam.exam.testpaper_unpublished_or_deleted');
  1014.             }
  1015.         }
  1016.         return $message;
  1017.     }
  1018.     protected function getProjectPlanMetas()
  1019.     {
  1020.         return $this->container->get('corporatetraining.extension.manager')->getProjectPlanItems();
  1021.     }
  1022.     /**
  1023.      * @return \CorporateTrainingBundle\Biz\ProjectPlan\Service\Impl\ProjectPlanServiceImpl
  1024.      */
  1025.     protected function getProjectPlanService()
  1026.     {
  1027.         return $this->createService('CorporateTrainingBundle:ProjectPlan:ProjectPlanService');
  1028.     }
  1029.     /**
  1030.      * @return \ExamPlugin\Biz\Exam\Service\Impl\ExamServiceImpl
  1031.      */
  1032.     protected function getExamService()
  1033.     {
  1034.         return $this->createService('ExamPlugin:Exam:ExamService');
  1035.     }
  1036.     /**
  1037.      * @return \CorporateTrainingBundle\Biz\ProjectPlan\Service\Impl\MemberServiceImpl
  1038.      */
  1039.     protected function getProjectPlanMemberService()
  1040.     {
  1041.         return $this->createService('CorporateTrainingBundle:ProjectPlan:MemberService');
  1042.     }
  1043.     /**
  1044.      * @return \Biz\Course\Service\Impl\CourseServiceImpl
  1045.      */
  1046.     protected function getCourseService()
  1047.     {
  1048.         return $this->createService('Course:CourseService');
  1049.     }
  1050.     /**
  1051.      * @return \Biz\Content\Service\Impl\FileServiceImpl
  1052.      */
  1053.     protected function getFileService()
  1054.     {
  1055.         return $this->createService('Content:FileService');
  1056.     }
  1057.     /**
  1058.      * @return OfflineCourseService
  1059.      */
  1060.     protected function getOfflineCourseService()
  1061.     {
  1062.         return $this->createService('CorporateTrainingBundle:OfflineCourse:OfflineCourseService');
  1063.     }
  1064.     /**
  1065.      * @return \CorporateTrainingBundle\Biz\OfflineCourse\Service\Impl\TaskServiceImpl
  1066.      */
  1067.     protected function getOfflineCourseTaskService()
  1068.     {
  1069.         return $this->createService('CorporateTrainingBundle:OfflineCourse:TaskService');
  1070.     }
  1071.     /**
  1072.      * @return \CorporateTrainingBundle\Biz\OfflineCourse\Service\Impl\MemberServiceImpl
  1073.      */
  1074.     protected function getOfflineCourseMemberService()
  1075.     {
  1076.         return $this->createService('CorporateTrainingBundle:OfflineCourse:MemberService');
  1077.     }
  1078.     /**
  1079.      * @return \Biz\Org\Service\Impl\OrgServiceImpl
  1080.      */
  1081.     protected function getOrgService()
  1082.     {
  1083.         return $this->createService('Org:OrgService');
  1084.     }
  1085.     /**
  1086.      * @return \Biz\Course\Service\Impl\CourseSetServiceImpl
  1087.      */
  1088.     protected function getCourseSetService()
  1089.     {
  1090.         return $this->createService('Course:CourseSetService');
  1091.     }
  1092.     protected function getPostService()
  1093.     {
  1094.         return $this->createService('CorporateTrainingBundle:Post:PostService');
  1095.     }
  1096.     /**
  1097.      * @return \CorporateTrainingBundle\Biz\OfflineExam\Service\Impl\OfflineExamServiceImpl
  1098.      */
  1099.     protected function getOfflineExamService()
  1100.     {
  1101.         return $this->createservice('CorporateTrainingBundle:OfflineExam:OfflineExamService');
  1102.     }
  1103.     /**
  1104.      * @return TargetPlanService
  1105.      */
  1106.     protected function getTargetPlanService()
  1107.     {
  1108.         return $this->createService('CorporateTrainingBundle:TargetPlan:TargetPlanService');
  1109.     }
  1110.     protected function getCategoryService()
  1111.     {
  1112.         return $this->createService('Taxonomy:CategoryService');
  1113.     }
  1114.     protected function getTaskResultService()
  1115.     {
  1116.         return $this->createService('Task:TaskResultService');
  1117.     }
  1118.     protected function getPostCourseService()
  1119.     {
  1120.         return $this->createService('CorporateTrainingBundle:PostCourse:PostCourseService');
  1121.     }
  1122.     /**
  1123.      * @return TestPaperService
  1124.      */
  1125.     protected function getTestPaperService()
  1126.     {
  1127.         return $this->createService('ExamPlugin:TestPaper:TestPaperService');
  1128.     }
  1129.     /**
  1130.      * @return UserAttributeService
  1131.      */
  1132.     protected function getUserAttributeService()
  1133.     {
  1134.         return $this->createService('CorporateTrainingBundle:UserAttribute:UserAttributeService');
  1135.     }
  1136.     protected function getUserGroupService()
  1137.     {
  1138.         return $this->createService('CorporateTrainingBundle:UserGroup:UserGroupService');
  1139.     }
  1140.     /**
  1141.      * @return UploadFileService
  1142.      */
  1143.     protected function getUploadFileService()
  1144.     {
  1145.         return $this->createService('File:UploadFileService');
  1146.     }
  1147.     protected function getMemberService()
  1148.     {
  1149.         return $this->createService('Course:MemberService');
  1150.     }
  1151.     protected function getTaskService()
  1152.     {
  1153.         return $this->createService('Task:TaskService');
  1154.     }
  1155.     /**
  1156.      * @return \Biz\User\Service\Impl\TokenServiceImpl
  1157.      */
  1158.     protected function getTokenService()
  1159.     {
  1160.         return $this->createService('User:TokenService');
  1161.     }
  1162.     /**
  1163.      * @return ResourceVisibleScopeService
  1164.      */
  1165.     protected function getResourceVisibleScopeService()
  1166.     {
  1167.         return $this->getBiz()->service('ResourceScope:ResourceVisibleScopeService');
  1168.     }
  1169.     /**
  1170.      * @return ResourceAccessScopeService
  1171.      */
  1172.     protected function getResourceAccessService()
  1173.     {
  1174.         return $this->createService('ResourceScope:ResourceAccessScopeService');
  1175.     }
  1176.     protected function getEnrollStrategyContext()
  1177.     {
  1178.         return $this->getBiz()['enroll_strategy_context'];
  1179.     }
  1180.     /**
  1181.      * @return EnrollRecordService
  1182.      */
  1183.     protected function getEnrollRecordService()
  1184.     {
  1185.         return $this->createService('CorporateTrainingBundle:Enroll:EnrollRecordService');
  1186.     }
  1187.     protected function getGamesService()
  1188.     {
  1189.         return $this->createService('Games:GamesService');
  1190.     }
  1191.     protected function getBoddQuestionsService()
  1192.     {
  1193.         return $this->createService('Bodd:BoddQuestionsService');
  1194.     }
  1195.     protected function getQuestionService()
  1196.     {
  1197.         return $this->createService('Question:QuestionService');
  1198.     }
  1199.     /**
  1200.      * @return PassingCriteriaService
  1201.      */
  1202.     private function getPassingCriteriaService()
  1203.     {
  1204.         return $this->createService('CorporateTrainingBundle:ProjectPlan:PassingCriteriaService');
  1205.     }
  1206.     /**
  1207.      * @return StageItemSortService
  1208.      */
  1209.     protected function getStageItemSortService()
  1210.     {
  1211.         return $this->createService('CorporateTrainingBundle:ProjectPlan:StageItemSortService');
  1212.     }
  1213.     /**
  1214.      * @return StageService
  1215.      */
  1216.     protected function getStageService()
  1217.     {
  1218.         return $this->createService('CorporateTrainingBundle:ProjectPlan:StageService');
  1219.     }
  1220. }