<?php
namespace CorporateTrainingBundle\Controller\ProjectPlan;
use AppBundle\Common\ArrayToolkit;
use AppBundle\Common\Exception\AccessDeniedException;
use AppBundle\Common\Paginator;
use AppBundle\Controller\BaseController;
use Biz\File\Service\UploadFileService;
use CorporateTrainingBundle\Biz\Enroll\Service\EnrollRecordService;
use CorporateTrainingBundle\Biz\OfflineCourse\Service\OfflineCourseService;
use CorporateTrainingBundle\Biz\ProjectPlan\Service\PassingCriteriaService;
use CorporateTrainingBundle\Biz\ProjectPlan\Service\ProjectPlanService;
use CorporateTrainingBundle\Biz\ProjectPlan\Service\StageItemSortService;
use CorporateTrainingBundle\Biz\ProjectPlan\Service\StageService;
use CorporateTrainingBundle\Biz\ResourceScope\Service\ResourceAccessScopeService;
use CorporateTrainingBundle\Biz\ResourceScope\Service\ResourceVisibleScopeService;
use CorporateTrainingBundle\Biz\TargetPlan\Service\TargetPlanService;
use CorporateTrainingBundle\Biz\UserAttribute\Service\UserAttributeService;
use ExamPlugin\Biz\TestPaper\Service\TestPaperService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Topxia\Service\Common\ServiceKernel;
class ProjectPlanManageController extends BaseController
{
public function createAction(Request $request)
{
$user = $this->getCurrentUser();
if (!$this->getProjectPlanService()->hasManageProjectPlanPermission()) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_create_message');
}
return $this->render(
'project-plan/create.html.twig',
[
'user' => $user,
]
);
}
public function overviewBoardAction($id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$conditions['projectPlanId'] = $projectPlan['id'];
$projectPlanMemberNum = $this->getProjectPlanMemberService()->countProjectPlanMembers($conditions);
if (1 == $projectPlan['requireAudit']) {
$recordCounts = $this->getEnrollRecordService()->countEnrollRecords(['targetId' => $projectPlan['id'], 'status' => 'submitted']);
}
$projectPlanItems = $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(['projectPlanId' => $projectPlan['id']], [], 0, PHP_INT_MAX);
$details = $this->getProjectPlanService()->findTaskDetailByTimeRangeAndProjectPlanId(strtotime(date('Y-m-d', time())), strtotime(date('Y-m-d 23:59:59', time())), $projectPlan['id']);
// 处理单个线下课 多个签到 多个游戏的bug
$items = [];
if (!empty($details)) {
foreach ($details as $number => $detail) {
if ('offline_course' == $detail['itemType'] && in_array($detail['type'], ['sign', 'game'])) {
$details[$detail['itemId']][$detail['type']][] = $detail;
unset($details[$number]);
}
}
foreach ($details as $detail) {
if (!empty($detail['sign'][0]) || !empty($detail['game'][0])) {
if (!empty($detail['sign'][0])) {
$items[$detail['sign'][0]['itemId']][] = $detail['sign'][0];
}
if (!empty($detail['game'][0])) {
$items[$detail['game'][0]['itemId']][] = $detail['game'][0];
}
} else {
$items[] = $detail;
}
}
foreach ($items as $num => $item) {
if (!empty($item[0])) {
$infos = $item;
unset($items[$num]);
$items[$num]['itemType'] = $infos[0]['itemType'];
$items[$num]['itemId'] = $infos[0]['itemId'];
$items[$num]['title'] = $infos[0]['title'];
$items[$num]['types'] = $infos;
}
}
}
return $this->render(
'project-plan/overview-board.html.twig',
[
'projectPlan' => $projectPlan,
'projectPlanItems' => $projectPlanItems,
'projectPlanMemberNum' => $projectPlanMemberNum,
'recordCounts' => !empty($recordCounts) ? $recordCounts : 0,
'detail' => $items,
'time' => time(),
]
);
}
public function itemsDetailAction($projectPlanId)
{
$projectPlanItems = $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(['projectPlanId' => $projectPlanId], [], 0, PHP_INT_MAX);
$projectPlanItems = $this->getManageUrl($projectPlanItems);
return $this->createJsonResponse($projectPlanItems);
}
public function baseAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$this->getResourceVisibleScopeService()->migrateResourceShowable('project', $id);
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$advancedOption = $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
if ('POST' == $request->getMethod()) {
$fields = $request->request->all();
$org = $this->getOrgService()->getOrgByOrgCode($fields['orgCode']);
if (!empty($fields['orgCode']) && !$this->getCurrentUser()->hasManagePermissionWithOrgCode($fields['orgCode'])) {
throw new AccessDeniedException($this->trans('admin.manage.org_no_permission'));
}
$fields['orgId'] = $org['id'];
$fields = $this->conversionTime($fields, $projectPlan);
if (0 == $fields['requireEnrollment']) {
$fields['requireAudit'] = 0;
}
$scopes = $this->buildAccessScope($fields);
$this->getResourceAccessService()->setResourceAccessScope($projectPlan['id'], 'projectPlan', $scopes);
$this->getResourceVisibleScopeService()->setResourceVisibleScope($id, 'projectPlan', $fields);
$this->getProjectPlanService()->updateProjectPlan($id, $fields);
$this->setFlashMessage('success', 'project_plan.message.update_success_message');
$fields['projectPlanId'] = $id;
$fields = $this->filterAdvancedOption($fields);
if (empty($advancedOption)) {
$this->getProjectPlanService()->createProjectPlanAdvancedOption($fields);
} else {
$this->getProjectPlanService()->updateProjectPlanAdvancedOption($advancedOption['id'], $fields);
}
return $this->redirectToRoute('project_plan_manage_base', ['id' => $id]);
}
$materials = empty($advancedOption) ? [] : [$advancedOption['material2'], $advancedOption['material3']];
$owner = $this->getUserService()->getUser($projectPlan['ownerId']);
$ownerProfile = $this->getUserService()->getUserProfile($projectPlan['ownerId']);
$owner['truename'] = $ownerProfile['truename'];
return $this->render(
'project-plan/base.html.twig',
[
'projectPlan' => $projectPlan,
'owner' => $owner,
'advancedOption' => $advancedOption,
'materials' => $materials,
]
);
}
public function shareAction(Request $request, $id)
{
$this->getResourceVisibleScopeService()->migrateResourceShowable('project', $id);
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$qrcodeImgUrl = $this->qrcode('project_plan_detail', ['id' => $projectPlan['id']]);
$shareUrl = $request->getSchemeAndHttpHost().$this->generateUrl('project_plan_detail', ['id' => $projectPlan['id']]);
return $this->render(
'admin/project-plan/share.html.twig',
[
'qrcodeImgUrl' => $qrcodeImgUrl,
'projectPlan' => $projectPlan,
'shareUrl' => $shareUrl,
]
);
}
public function coverAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
if ($request->isMethod('POST')) {
$data = $request->request->all();
$this->getProjectPlanService()->changeCover($id, $data);
return $this->redirect($this->generateUrl('project_plan_manage_cover', ['id' => $id]));
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
return $this->render(
'project-plan/cover.html.twig',
[
'projectPlan' => $projectPlan,
]
);
}
public function coverCropAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if ('POST' == $request->getMethod()) {
$data = $request->request->all();
$this->getProjectPlanService()->changeCover(
$projectPlan['id'],
json_decode($data['images'], true)
);
return $this->redirect($this->generateUrl(
'project_plan_manage_cover',
['id' => $projectPlan['id']]
));
}
$fileId = $request->getSession()->get('fileId');
list($pictureUrl, $naturalSize, $scaledSize) = $this->getFileService()->getImgFileMetaInfo($fileId, 480, 270);
return $this->render(
'project-plan/cover-crop.html.twig',
[
'projectPlan' => $projectPlan,
'pictureUrl' => $pictureUrl,
'naturalSize' => $naturalSize,
'scaledSize' => $scaledSize,
]
);
}
public function headerAction($projectPlan)
{
$user = $this->getCurrentUser();
if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlan['id']) && !$user->hasPermission('admin_data_center_project_plan')) {
throw $this->createAccessDeniedException('No project plan management permissions');
}
return $this->render(
'@CorporateTraining/project-plan/header.html.twig',
[
'projectPlan' => $projectPlan,
]
);
}
public function ajaxPublishAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.publish.message.no_permission')]);
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if (empty($projectPlan)) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.message.project_plan_empty')]);
}
if (!$projectPlan['startTime']) {
$success = false;
$message = ServiceKernel::instance()->trans('project_plan.publish.message.data_empty');
}
if ($projectPlan['showable'] && !$projectPlan['enrollmentStartDate'] && !$projectPlan['isPermanentEnrollment']) {
$success = false;
$message = ServiceKernel::instance()->trans('project_plan.publish.message.data_empty');
} else {
$this->getProjectPlanService()->publishProjectPlan($id);
$success = true;
$message = '';
}
return $this->createJsonResponse(['success' => $success, 'message' => $message]);
}
public function projectPlanPublishedConfigurationAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.publish.message.no_permission')]);
}
$this->getResourceVisibleScopeService()->migrateResourceShowable('project', $id);
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
return $this->render(
'@CorporateTraining/project-plan/published-configuration.html.twig',
[
'projectPlan' => $projectPlan,
]
);
}
public function ajaxCloseAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createJsonResponse(false);
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if (empty($projectPlan)) {
return $this->createJsonResponse(false);
}
$result = $this->getProjectPlanService()->closeProjectPlan($id);
if ($result) {
return $this->createJsonResponse(true);
}
return $this->createJsonResponse(false);
}
public function ajaxArchiveAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.archive.message.no_permission')]);
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if (empty($projectPlan)) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.message.project_plan_empty')]);
}
$this->getProjectPlanService()->archiveProjectPlan($id);
return $this->createJsonResponse(['success' => true, 'message' => '']);
}
public function ajaxRemoveAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createJsonResponse(false);
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if (empty($projectPlan)) {
return $this->createJsonResponse(false);
}
$result = $this->getProjectPlanService()->deleteProjectPlan($id);
if ($result) {
return $this->createJsonResponse(true);
}
return $this->createJsonResponse(false);
}
/**
* @param Request $request
* @param $id
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @throws \Codeages\Biz\Framework\Service\Exception\AccessDeniedException
*
* @deprecated
*/
public function itemRemoveAction(Request $request, $id)
{
$projectPlanItem = $this->getProjectPlanService()->getProjectPlanItem($id);
if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanItem['projectPlanId'])) {
return $this->createJsonResponse(['success' => 'false', 'message' => ServiceKernel::instance()->trans('project_plan.message.can_not_manage_message')]);
}
$result = $this->getProjectPlanService()->deleteProjectPlanItem($id);
if ($result) {
return $this->createJsonResponse(true);
}
return $this->createJsonResponse(false);
}
public function itemsAction(Request $request, $id)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($id)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
return $this->render('@CorporateTraining/project-plan/item-manage.html.twig', ['projectPlan' => $projectPlan]);
}
public function itemTypeChooseAction(Request $request, $id)
{
return $this->render('project-plan/item/choose-item-type.html.twig', ['id' => $id, 'unableToChoose' => $this->getUnableChooseItemTypes($id)]);
}
/**
* @param Request $request
* @param $id
* @param $type
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|Response
*
* @throws \Exception
*
* @deprecated
*/
public function itemAddAction(Request $request, $id, $type)
{
if ($request->isMethod('POST')) {
$data = $request->request->all();
$message = $this->validateItem($data, $type);
if ($message) {
return $this->createJsonResponse(['success' => false, 'message' => $message]);
}
$data['creator'] = $this->getCurrentUser()->getId();
$this->getProjectPlanService()->setProjectPlanItems($id, $data, $type);
return $this->createJsonResponse(['success' => true, 'message' => '']);
}
$projectPlanMetas = $this->getProjectPlanMetas();
return $this->forward(
$projectPlanMetas[$type]['controller'].'::createAction',
[
'projectPlanId' => $id,
]
);
}
/**
* @param Request $request
* @param $id
* @param $projectPlanId
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|Response
*
* @throws \Exception
*
* @deprecated
*/
public function itemUpdateAction(Request $request, $id, $projectPlanId)
{
$item = $this->getProjectPlanService()->getProjectPlanItem($id);
if ($request->isMethod('POST')) {
$data = $request->request->all();
$data['projectPlanId'] = $projectPlanId;
$message = $this->validateItem($data, $item['targetType']);
if ($message) {
return $this->createJsonResponse(['success' => false, 'message' => $message]);
}
$this->getProjectPlanService()->updatePlanItem($id, $data, $item['targetType']);
return $this->createJsonResponse(['success' => true, 'message' => '']);
}
$projectPlanMetas = $this->getProjectPlanMetas();
return $this->forward(
$projectPlanMetas[$item['targetType']]['controller'].'::updateAction',
[
'id' => $id,
]
);
}
/**
* @param Request $request
* @param $id
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @throws \Codeages\Biz\Framework\Service\Exception\AccessDeniedException
*
* @deprecated
*/
public function itemDeleteAction(Request $request, $id)
{
$item = $this->getProjectPlanService()->getProjectPlanItem($id);
$this->getProjectPlanService()->deleteProjectPlanItem($id);
return $this->createJsonResponse(true);
}
/**
* @param Request $request
* @param $id
* @param $type
*
* @return Response
*/
public function itemListAction(Request $request, $id, $type)
{
$projectPlanMetas = $this->getProjectPlanMetas();
return $this->forward(
$projectPlanMetas[$type]['controller'].'::listAction',
[
'request' => $request,
'id' => $id,
]
);
}
public function enrollAction(Request $request, $id)
{
$user = $this->getCurrentUser();
if (!$user->isLogin()) {
throw $this->createAccessDeniedException();
}
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$advancedOption = $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
if ('published' != $projectPlan['status']) {
throw $this->createAccessDeniedException('Project plan not published');
}
$canAccess = $projectPlan['conditionalAccess'] ? $this->getResourceAccessService()->canUserAccessResource('projectPlan', $projectPlan['id'], $user['id']) : true;
if ('POST' === $request->getMethod()) {
if (!$canAccess) {
return $this->createAccessDeniedException($this->trans('resource_scope.no_permission'));
}
$fields = $request->request->all();
$attachments = $request->request->get('attachment');
if (1 == $projectPlan['requireAdvance']) {
if (1 == $advancedOption['requireRemark'] && empty($fields['remark'])) {
return $this->createJsonResponse(
[
'append' => false,
'html' => '',
'error' => [
'name' => 'error',
'message' => $this->trans('enroll.remark_not_fill'),
],
],
Response::HTTP_INTERNAL_SERVER_ERROR
);
}
if (1 == $advancedOption['requireMaterial'] && !empty($attachments)) {
foreach ($attachments as $attachment) {
if (empty($attachment['fileIds'])) {
return $this->createJsonResponse(
[
'append' => false,
'html' => '',
'error' => [
'name' => 'error',
'message' => $this->trans('enroll.material_not_upload'),
],
],
Response::HTTP_INTERNAL_SERVER_ERROR
);
}
}
}
}
$record = $this->getEnrollStrategyContext()->createStrategy('projectPlan')->submitEnrollment($id, $user['id'], $fields);
$this->uploadMaterialAttachments($attachments, $record);
return $this->createJsonResponse(true);
}
if (!empty($projectPlan['requireEnrollment']) && $projectPlan['conditionalAccess'] && !$canAccess) {
return $this->render(
'@CorporateTraining/project-plan/can-not-enroll-modal.html.twig',
[]
);
}
return $this->render(
'@CorporateTraining/project-plan/detail/attend-modal.html.twig',
[
'projectPlan' => $projectPlan,
'advancedOption' => empty($advancedOption) ? [] : $advancedOption,
'canAccess' => $canAccess,
]
);
}
public function viewQrcodeAction($id)
{
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$qrcodeImgUrl = $this->qrcode('project_plan_detail', ['id' => $projectPlan['id']]);
return $this->render(
'project-plan/qr-code.html.twig',
[
'projectPlan' => $projectPlan,
'qrcodeImgUrl' => $qrcodeImgUrl,
]
);
}
public function detailAction($id)
{
$canAccess = true;
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
if ('published' != $projectPlan['status']) {
return $this->render('@CorporateTraining/project-plan/detail/detail-not-published.html.twig');
}
if (!$this->getProjectPlanService()->canUserVisitResource($id)) {
return $this->render('@CorporateTraining/project-plan/detail/detail-not-open.html.twig');
}
$projectPlanAdvancedOptions = $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($projectPlan['id']);
$projectPlan['requireRemind'] = 0;
if (!empty($projectPlanAdvancedOptions['remindRequirement'])) {
$projectPlan['requireRemind'] = $projectPlanAdvancedOptions['requireRemind'];
$projectPlan['remindRequirement'] = $projectPlanAdvancedOptions['remindRequirement'];
}
$projectPlan['studentNum'] = $this->getProjectPlanMemberService()->countProjectPlanMembers(['projectPlanId' => $id]);
$projectPlanItems = $this->getProjectPlanService()->searchProjectPlanItemsWithDetail(
['projectPlanId' => $id],
['seq' => 'ASC'],
0,
PHP_INT_MAX
);
if ($projectPlan['conditionalAccess']) {
$canAccess = $this->getResourceAccessService()->canUserAccessResource('projectPlan', $projectPlan['id'], $this->getCurrentUser()->getId());
}
$passingCriteria = [];
if (ProjectPlanService::PASSING_MODE_AUTO == $projectPlan['passingMode']) {
$passingCriteria = $this->getPassingCriteriaService()->getPassingCriteriaByProjectPlanId($projectPlan['id']);
}
return $this->render(
'@CorporateTraining/project-plan/detail/detail.html.twig',
[
'projectPlan' => $projectPlan,
'projectPlanItems' => $projectPlanItems,
'canAccess' => $canAccess,
'passingCriteria' => $passingCriteria,
]
);
}
public function itemDetailAction($projectPlanId, $itemId)
{
return $this->render(
'@CorporateTraining/project-plan/item/detail.html.twig',
[
'projectPlanId' => $projectPlanId,
'itemId' => $itemId,
]
);
}
/**
* @param $projectPlanItems
* @param $projectPlanId
*
* @return Response|null
*
* @deprecated
*/
public function courseTaskListAction($projectPlanItems, $projectPlanId)
{
$userId = $this->getCurrentUser()->getId();
$member = $this->getProjectPlanMemberService()->getProjectPlanMemberByUserIdAndProjectPlanId($userId, $projectPlanId);
if (!empty($member)) {
return $this->forward('CorporateTrainingBundle\Controller\StudyCenter\MyTaskController::courseTaskListAction', [
'projectPlanItems' => $projectPlanItems,
'userId' => $userId,
'projectPlanId' => $projectPlanId,
'tabType' => 'myTask',
]);
}
return $this->render(
'@CorporateTraining/project-plan/detail/task-list/list.html.twig',
array_merge(
[
'projectPlanId' => $projectPlanId,
'currentTime' => time(),
],
$this->buildProjectPlanItems($projectPlanItems)
)
);
}
public function ajaxItemBodyAction($targetType, $targetId)
{
$targetType = $this->get('corporatetrainingbundle.twig.web_extension')->underlineToLine($targetType);
return $this->render("project-plan/detail/task-list/{$targetType}-item-body.html.twig", ['id' => $targetId]);
}
public function advancedOptionAction(Request $request, $id)
{
$projectPlan = $this->getProjectPlanService()->getProjectPlan($id);
$advancedOption = $this->getProjectPlanService()->getProjectPlanAdvancedOptionByProjectPlanId($id);
if ('POST' === $request->getMethod()) {
$fields = $request->request->all();
$fields['projectPlanId'] = $id;
$fields = $this->filterAdvancedOption($fields);
if (empty($advancedOption)) {
$result = $this->getProjectPlanService()->createProjectPlanAdvancedOption($fields);
} else {
$result = $this->getProjectPlanService()->updateProjectPlanAdvancedOption($advancedOption['id'], $fields);
}
return $this->createJsonResponse($result);
}
$materials = empty($advancedOption) ? [] : [$advancedOption['material2'], $advancedOption['material3']];
return $this->render(
'@CorporateTraining/project-plan/advanced-options-modal.html.twig',
[
'projectPlan' => $projectPlan,
'advancedOption' => $advancedOption,
'materials' => $materials,
]
);
}
public function crowdMatchAction(Request $request)
{
$queryString = $request->query->get('q');
$attributes = ['userGroup', 'org', 'post'];
$name = $this->getUserAttributeService()->searchAttributesNames($attributes, $queryString);
return $this->createJsonResponse($name);
}
public function projectPlanListAction(Request $request)
{
$conditions = $request->query->all();
$conditions['status'] = 'published';
$conditions = $this->buildProjectPlanListConditions($conditions);
$count = $this->getProjectPlanService()->countProjectPlans(
$conditions
);
$paginator = new Paginator(
$request,
$count,
20
);
$projectPlans = $this->getProjectPlanService()->searchProjectPlanOrderByEnrollmentStatus(
$conditions,
$paginator->getOffsetCount(),
$paginator->getPerPageCount()
);
foreach ($projectPlans as &$projectPlan) {
$projectPlan['canAccess'] = true;
if ($projectPlan['conditionalAccess']) {
$projectPlan['canAccess'] = $this->getResourceAccessService()->canUserAccessResource('projectPlan', $projectPlan['id'], $this->getCurrentUser()->getId());
}
}
return $this->render(
'@CorporateTraining/project-plan/list.html.twig',
[
'enrollment' => empty($conditions['enrollment']) ? 0 : $conditions['enrollment'],
'projectPlans' => $projectPlans,
'paginator' => $paginator,
]
);
}
/**
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*
* @deprecated
*/
public function sortItemAction(Request $request)
{
$ids = $request->request->get('ids');
if (!empty($ids)) {
$this->getProjectPlanService()->sortItems($ids);
}
return $this->createJsonResponse(true);
}
public function viewExamQrcodeAction($id, $examId)
{
$exam = $this->getExamService()->getExam($examId);
$qrcodeImgUrl = $this->qrcode('can_do_exam', ['id' => $id, 'examId' => $examId]);
return $this->render(
'project-plan/exam-manage/qrcode/qr-code.html.twig',
[
'exam' => $exam,
'qrcodeImgUrl' => $qrcodeImgUrl,
]
);
}
public function canDoExamAction($id, $examId)
{
$user = $this->getCurrentUser();
$member = $this->getProjectPlanMemberService()->getProjectPlanMemberByUserIdAndProjectPlanId($user['id'], $id);
if (empty($member)) {
return $this->render(
'project-plan/exam-manage/qrcode/error.html.twig',
[
'message' => ServiceKernel::instance()->trans('project_plan.can_do_exam.message.no_permission'),
]
);
}
$projectPlanItem = $this->getProjectPlanService()->getProjectPlanItemByProjectPlanIdAndTargetIdAndTargetType($id, $examId, ProjectPlanService::ITEM_TYPE_ONLINE_EXAM);
$examMember = $this->getExamService()->getMemberByExamIdIdAndUserId($examId, $user['id']);
if (empty($examMember)) {
$this->getExamService()->createMember(['examId' => $examId, 'userId' => $user['id']]);
}
return $this->redirect(
$this->generateUrl('project_plan_exam_show', ['projectPlanId' => $id, 'itemId' => $projectPlanItem['id'], 'id' => $examId])
);
}
public function projectPlanBaseConfigurationAction($projectPlanId)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanId)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$this->getResourceVisibleScopeService()->migrateResourceShowable('project', $projectPlanId);
$projectPlan = $this->getProjectPlanService()->getProjectPlan($projectPlanId);
return $this->render('@CorporateTraining/project-plan/base/base-setting.html.twig', [
'projectPlan' => $projectPlan,
'base_nav' => 'base-configuration',
]);
}
public function projectPlanPublishConfigurationAction($projectPlanId)
{
if (!$this->getProjectPlanService()->canManageProjectPlan($projectPlanId)) {
return $this->createMessageResponse('error', 'project_plan.message.can_not_manage_message');
}
$this->getResourceVisibleScopeService()->migrateResourceShowable('project', $projectPlanId);
$projectPlan = $this->getProjectPlanService()->getProjectPlan($projectPlanId);
return $this->render('@CorporateTraining/project-plan/base/publish-setting.html.twig', [
'projectPlan' => $projectPlan,
'base_nav' => 'publish-configuration',
]);
}
public function interactiveGamesCreateAction(Request $request, $projectPlanId)
{
$projectPlan = $this->getProjectPlanService()->getProjectPlan($projectPlanId);
if ($request->isMethod('POST')) {
$fields = $request->request->all();
$games = $this->getGamesService()->createGames($fields);
return $this->createJsonResponse(['result' => true, 'data' => $games]);
}
return $this->render(
'project-plan/offline-course/interactive-games-create.html.twig',
[
'projectPlan' => $projectPlan,
'gameId' => 0,
'items' => [],
]
);
}
/**
* @param Request $request
* @param $projectPlanId
* @param $gameId
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|Response|null
*
* @deprecated
*/
public function interactiveGamesUpdateAction(Request $request, $projectPlanId, $gameId)
{
$projectPlan = $this->getProjectPlanService()->getProjectPlan($projectPlanId);
$games = $this->getGamesService()->getGames($gameId);
$boddQuestions = $this->getBoddQuestionsService()->searchBoddQuestions(['gameId' => $gameId], ['seq' => 'ASC'], 0, PHP_INT_MAX);
$questionIds = [-1];
$questionSeqs = [];
if (!empty($boddQuestions)) {
$questionIds = array_column($boddQuestions, 'questionId');
foreach ($boddQuestions as $boddQuestion) {
$questionSeqs[$boddQuestion['questionId']]['seq'] = $boddQuestion['seq'];
$questionSeqs[$boddQuestion['questionId']]['scoreFactor'] = $boddQuestion['scoreFactor'];
$questionSeqs[$boddQuestion['questionId']]['duration'] = $boddQuestion['duration'];
}
}
$questions = $this->getQuestionService()->findQuestionsByIds($questionIds);
foreach ($questions as $question) {
$item = [];
if ($question['subCount'] > 0) {
$subQuestions = $this->getQuestionService()->findQuestionsByParentId($question['id']);
$item['subItems'] = [];
foreach ($subQuestions as $subQuestion) {
$item['subItems'][] = [
'questionId' => $subQuestion['id'],
'questionType' => $subQuestion['type'],
'question' => $subQuestion,
'parentId' => $question['id'],
];
}
}
$item['questionId'] = $question['id'];
$item['questionType'] = $question['type'];
$item['question'] = $question;
$item['seq'] = $questionSeqs[$question['id']]['seq'] ?? 0;
$item['scoreFactor'] = $questionSeqs[$question['id']]['scoreFactor'] ?? 0;
$item['duration'] = $questionSeqs[$question['id']]['duration'] ?? 0;
$items[$question['id']] = $item;
}
foreach ($boddQuestions as $boddQuestion) {
$questionLists[] = $items[$boddQuestion['questionId']];
}
if ($request->isMethod('POST')) {
$fields = $request->request->all();
$games = $this->getGamesService()->updateGames($gameId, $fields);
return $this->createJsonResponse(['result' => true, 'data' => $games]);
}
return $this->render(
'project-plan/offline-course/interactive-games-create.html.twig',
[
'projectPlan' => $projectPlan,
'games' => $games,
'items' => $questionLists ?? [],
'gameId' => $gameId,
]
);
}
protected function getUnableChooseItemTypes($projectPlanId)
{
$unableToChoose = [];
$needPlugins = [
'exam' => [
'pluginCode' => 'Exam',
'message' => 'project_plan.preparation.items.choose_exam_item_info',
],
'questionnaire' => [
'pluginCode' => 'Survey',
'message' => 'project_plan.preparation.items.choose_survey_item_info',
],
];
foreach ($needPlugins as $type => $needPlugin) {
if (!$this->isPluginInstalled($needPlugin['pluginCode'])) {
$unableToChoose[$type]['reason'] = $needPlugin['message'];
}
}
$targetPlanItems = $this->getProjectPlanService()->findProjectPlanItemsByProjectPlanIdAndTargetType($projectPlanId, 'target_plan_531');
if (!empty($targetPlanItems)) {
$unableToChoose['targetPlan531']['reason'] = 'project_plan.preparation.items.choose_target_plan_item_info';
}
return $unableToChoose;
}
protected function buildProjectPlanItems($projectPlanItems)
{
$projectPlanItemsGroupByTargetType = ArrayToolkit::group($projectPlanItems, 'targetType');
if (isset($projectPlanItemsGroupByTargetType['course'])) {
$courses = $this->getCourseService()->findCoursesByIds(array_column($projectPlanItemsGroupByTargetType['course'], 'targetId'));
}
if (isset($projectPlanItemsGroupByTargetType['exam'])) {
$exams = $this->getExamService()->findExamsByIds(array_column($projectPlanItemsGroupByTargetType['exam'], 'targetId'));
$exams = array_column($exams, null, 'id');
}
if (isset($projectPlanItemsGroupByTargetType['offline_course'])) {
$offlineCourses = $this->getOfflineCourseService()->findOfflineCoursesByIds(array_column($projectPlanItemsGroupByTargetType['offline_course'], 'targetId'));
$offlineCourses = array_column($offlineCourses, null, 'id');
$users = $this->getUserService()->findUsersByIds(array_column($offlineCourses, 'teacherId'));
$userProfiles = $this->getUserService()->findUserProfilesByIds(array_column($offlineCourses, 'teacherId'));
}
if (isset($projectPlanItemsGroupByTargetType['offline_exam'])) {
$offlineExams = $this->getOfflineExamService()->findOfflineExamByIds(array_column($projectPlanItemsGroupByTargetType['offline_exam'], 'targetId'));
$offlineExams = array_column($offlineExams, null, 'id');
}
if (isset($projectPlanItemsGroupByTargetType['target_plan_531'])) {
$targetPlans = $this->getTargetPlanService()->findTargetPlanMapWithCurrentUserResultByIds(array_column($projectPlanItemsGroupByTargetType['target_plan_531'], 'targetId'));
}
return [
'projectPlanItems' => $projectPlanItems,
'courses' => $courses ?? [],
'exams' => $exams ?? [],
'offlineCourses' => $offlineCourses ?? [],
'offlineExams' => $offlineExams ?? [],
'users' => $users ?? [],
'userProfiles' => $userProfiles ?? [],
'targetPlans' => $targetPlans ?? [],
];
}
protected function getManageUrl($projectPlanItems)
{
$isInstallSurvey = $this->isPluginInstalled('Survey');
$isInstallExam = $this->isPluginInstalled('Exam');
foreach ($projectPlanItems as &$projectPlanItem) {
if ('offline_course' === $projectPlanItem['targetType']) {
$projectPlanItem['url'] = $this->generateUrl('project_plan_manage_items', ['id' => $projectPlanItem['projectPlanId']]);
} elseif ('exam' === $projectPlanItem['targetType'] && $isInstallExam) {
$projectPlanItem['url'] = $this->generateUrl('project_plan_exam_manage_member_list', ['id' => $projectPlanItem['projectPlanId'], 'examId' => $projectPlanItem['targetId'], 'type' => 'exam']);
} elseif ('offline_exam' === $projectPlanItem['targetType']) {
$projectPlanItem['url'] = $this->generateUrl('project_plan_offline_exam_manage_member_list', ['id' => $projectPlanItem['projectPlanId'], 'taskId' => $projectPlanItem['targetId']]);
} elseif ('questionnaire' === $projectPlanItem['targetType'] && $isInstallSurvey) {
$projectPlanItem['url'] = $this->generateUrl('project_plan_survey_data_manage_list', ['id' => $projectPlanItem['projectPlanId']]);
} else {
$projectPlanItem['url'] = $this->generateUrl('project_plan_manage_items', ['id' => $projectPlanItem['projectPlanId']]);
}
}
return $projectPlanItems;
}
protected function qrcode($url, $array)
{
$token = $this->getTokenService()->makeToken('qrcode', [
'data' => [
'url' => $this->generateUrl($url, $array, UrlGeneratorInterface::ABSOLUTE_URL),
],
'duration' => 3600 * 24 * 365,
]);
$url = $this->generateUrl('common_parse_qrcode', ['token' => $token['token']], UrlGeneratorInterface::ABSOLUTE_URL);
return $this->generateUrl('common_qrcode', ['text' => $url], UrlGeneratorInterface::ABSOLUTE_URL);
}
protected function uploadMaterialAttachments($attachments, $record)
{
$useFiles = $this->getUploadFileService()->searchUseFiles(['targetTypes' => ['projectPlaning.material1', 'projectPlaning.material2', 'projectPlaning.material3'], 'targetId' => $record['id']]);
if (!empty($useFiles)) {
foreach ($useFiles as $useFile) {
$this->getUploadFileService()->deleteUseFile($useFile['id']);
}
}
if (!empty($attachments)) {
$user = $this->getCurrentUser();
$orgs = $this->getOrgService()->findOrgsByIds($user['orgIds']);
$org = reset($orgs);
$userProfile = $this->getUserService()->getUserProfile($user['id']);
$orgName = empty($org) ? '' : $org['name'].'+';
$trueName = empty($userProfile['truename']) ? '' : $userProfile['truename'].'+';
$mobile = empty($userProfile['mobile']) ? '' : $userProfile['mobile'].'+';
foreach ($attachments as $key => $attachment) {
$file = $this->getUploadFileService()->getFile($attachment['fileIds']);
$filename = $orgName.$trueName.$mobile.$file['filename'];
$this->getUploadFileService()->update($attachment['fileIds'], ['name' => $filename]);
$this->getUploadFileService()->createUseFiles($attachment['fileIds'], $record['id'], $attachment['targetType'], $attachment['type']);
}
}
}
protected function buildProjectPlanListConditions($conditions)
{
$conditions['ids'] = [];
if (!empty($conditions['timeStatus'])) {
if ('ongoing' === $conditions['timeStatus']) {
$projectPlanIds = [-1];
$ongoingDateProjectPlanConditions = array_merge(['endTime_GE' => time(), 'startTime_LE' => time(), 'timeMode' => ProjectPlanService::TIME_MODE_DATE], $conditions);
$ongoingDeadlineProjectPlanConditions = array_merge(['timeMode' => ProjectPlanService::TIME_MODE_DEADLINE], $conditions);
$projectPlanIds = array_unique(array_merge($projectPlanIds, array_column($this->getProjectPlanService()->searchProjectPlans($ongoingDateProjectPlanConditions, [], 0, PHP_INT_MAX, ['id']), 'id')));
$projectPlanIds = array_unique(array_merge($projectPlanIds, array_column($this->getProjectPlanService()->searchProjectPlans($ongoingDeadlineProjectPlanConditions, [], 0, PHP_INT_MAX, ['id']), 'id')));
if (!empty($conditions['ids'])) {
$conditions['ids'] = array_intersect($conditions['ids'], $projectPlanIds);
} else {
$conditions['ids'] = $projectPlanIds;
}
} elseif ('end' === $conditions['timeStatus']) {
$conditions = array_merge(['endTime_LE' => time(), 'timeMode' => ProjectPlanService::TIME_MODE_DATE], $conditions);
}
}
if (!empty($conditions['enrollment'])) {
$dateEnrollmentConditions = $conditions;
$permanentEnrollmentConditions = $conditions;
$permanentEnrollmentConditions['isPermanentEnrollment'] = 1;
$dateEnrollmentConditions['enrollmentEndDate_GE'] = time();
$dateEnrollmentConditions['enrollmentStartDate_LE'] = time();
$enrollmentProjectPlanIds = [-1];
$enrollmentProjectPlanIds = array_unique(array_merge($enrollmentProjectPlanIds, array_column($this->getProjectPlanService()->searchProjectPlans($dateEnrollmentConditions, [], 0, PHP_INT_MAX, ['id']), 'id')));
$enrollmentProjectPlanIds = array_unique(array_merge($enrollmentProjectPlanIds, array_column($this->getProjectPlanService()->searchProjectPlans($permanentEnrollmentConditions, [], 0, PHP_INT_MAX, ['id']), 'id')));
if (!empty($conditions['ids'])) {
$conditions['ids'] = array_intersect($conditions['ids'], $enrollmentProjectPlanIds);
} else {
$conditions['ids'] = $enrollmentProjectPlanIds;
}
}
if (isset($conditions['categoryId']) && empty($conditions['categoryId'])) {
unset($conditions['categoryId']);
}
$visibleIds = $this->getResourceVisibleScopeService()->findVisibleResourceIdsByResourceTypeAndUserId('projectPlan', $this->getCurrentUser()->getId());
if (!empty($conditions['ids'])) {
$conditions['ids'] = array_intersect($conditions['ids'], $visibleIds);
} else {
$conditions['ids'] = $visibleIds;
}
return $conditions;
}
protected function filterAdvancedOption($fields)
{
$materials = json_decode($fields['materials'], true);
$fields['material2'] = empty($materials[0]) ? '' : $materials[0];
$fields['material3'] = empty($materials[1]) ? '' : $materials[1];
return $fields;
}
protected function conversionTime($data, $projectPlan)
{
if (array_key_exists('startDateTime', $data)) {
$data['startTime'] = empty($data['startDateTime']) ? 0 : strtotime($data['startDateTime']);
} else {
$data['startTime'] = $projectPlan['startTime'];
}
if (array_key_exists('endDateTime', $data)) {
$data['endTime'] = empty($data['endDateTime']) ? 0 : strtotime($data['endDateTime'].' 23:59:59');
} else {
$data['endTime'] = $projectPlan['endTime'];
}
if (array_key_exists('enrollmentStartDate', $data)) {
$data['enrollmentStartDate'] = empty($data['enrollmentStartDate']) ? 0 : strtotime($data['enrollmentStartDate']);
} else {
$data['enrollmentStartDate'] = $projectPlan['enrollmentStartDate'];
}
if (array_key_exists('enrollmentEndDate', $data)) {
$data['enrollmentEndDate'] = empty($data['enrollmentStartDate']) ? 0 : strtotime($data['enrollmentEndDate'].' 23:59:59');
} else {
$data['enrollmentEndDate'] = $projectPlan['enrollmentEndDate'];
}
return $data;
}
protected function validateItem($fields, $type)
{
$message = '';
if ('exam' == $type) {
$testpaper = $this->getTestPaperService()->getTestPaper($fields['mediaId']);
if (empty($testpaper) || 'published' != $testpaper['status']) {
$message = $this->trans('exam.exam.testpaper_unpublished_or_deleted');
}
}
return $message;
}
protected function getProjectPlanMetas()
{
return $this->container->get('corporatetraining.extension.manager')->getProjectPlanItems();
}
/**
* @return \CorporateTrainingBundle\Biz\ProjectPlan\Service\Impl\ProjectPlanServiceImpl
*/
protected function getProjectPlanService()
{
return $this->createService('CorporateTrainingBundle:ProjectPlan:ProjectPlanService');
}
/**
* @return \ExamPlugin\Biz\Exam\Service\Impl\ExamServiceImpl
*/
protected function getExamService()
{
return $this->createService('ExamPlugin:Exam:ExamService');
}
/**
* @return \CorporateTrainingBundle\Biz\ProjectPlan\Service\Impl\MemberServiceImpl
*/
protected function getProjectPlanMemberService()
{
return $this->createService('CorporateTrainingBundle:ProjectPlan:MemberService');
}
/**
* @return \Biz\Course\Service\Impl\CourseServiceImpl
*/
protected function getCourseService()
{
return $this->createService('Course:CourseService');
}
/**
* @return \Biz\Content\Service\Impl\FileServiceImpl
*/
protected function getFileService()
{
return $this->createService('Content:FileService');
}
/**
* @return OfflineCourseService
*/
protected function getOfflineCourseService()
{
return $this->createService('CorporateTrainingBundle:OfflineCourse:OfflineCourseService');
}
/**
* @return \CorporateTrainingBundle\Biz\OfflineCourse\Service\Impl\TaskServiceImpl
*/
protected function getOfflineCourseTaskService()
{
return $this->createService('CorporateTrainingBundle:OfflineCourse:TaskService');
}
/**
* @return \CorporateTrainingBundle\Biz\OfflineCourse\Service\Impl\MemberServiceImpl
*/
protected function getOfflineCourseMemberService()
{
return $this->createService('CorporateTrainingBundle:OfflineCourse:MemberService');
}
/**
* @return \Biz\Org\Service\Impl\OrgServiceImpl
*/
protected function getOrgService()
{
return $this->createService('Org:OrgService');
}
/**
* @return \Biz\Course\Service\Impl\CourseSetServiceImpl
*/
protected function getCourseSetService()
{
return $this->createService('Course:CourseSetService');
}
protected function getPostService()
{
return $this->createService('CorporateTrainingBundle:Post:PostService');
}
/**
* @return \CorporateTrainingBundle\Biz\OfflineExam\Service\Impl\OfflineExamServiceImpl
*/
protected function getOfflineExamService()
{
return $this->createservice('CorporateTrainingBundle:OfflineExam:OfflineExamService');
}
/**
* @return TargetPlanService
*/
protected function getTargetPlanService()
{
return $this->createService('CorporateTrainingBundle:TargetPlan:TargetPlanService');
}
protected function getCategoryService()
{
return $this->createService('Taxonomy:CategoryService');
}
protected function getTaskResultService()
{
return $this->createService('Task:TaskResultService');
}
protected function getPostCourseService()
{
return $this->createService('CorporateTrainingBundle:PostCourse:PostCourseService');
}
/**
* @return TestPaperService
*/
protected function getTestPaperService()
{
return $this->createService('ExamPlugin:TestPaper:TestPaperService');
}
/**
* @return UserAttributeService
*/
protected function getUserAttributeService()
{
return $this->createService('CorporateTrainingBundle:UserAttribute:UserAttributeService');
}
protected function getUserGroupService()
{
return $this->createService('CorporateTrainingBundle:UserGroup:UserGroupService');
}
/**
* @return UploadFileService
*/
protected function getUploadFileService()
{
return $this->createService('File:UploadFileService');
}
protected function getMemberService()
{
return $this->createService('Course:MemberService');
}
protected function getTaskService()
{
return $this->createService('Task:TaskService');
}
/**
* @return \Biz\User\Service\Impl\TokenServiceImpl
*/
protected function getTokenService()
{
return $this->createService('User:TokenService');
}
/**
* @return ResourceVisibleScopeService
*/
protected function getResourceVisibleScopeService()
{
return $this->getBiz()->service('ResourceScope:ResourceVisibleScopeService');
}
/**
* @return ResourceAccessScopeService
*/
protected function getResourceAccessService()
{
return $this->createService('ResourceScope:ResourceAccessScopeService');
}
protected function getEnrollStrategyContext()
{
return $this->getBiz()['enroll_strategy_context'];
}
/**
* @return EnrollRecordService
*/
protected function getEnrollRecordService()
{
return $this->createService('CorporateTrainingBundle:Enroll:EnrollRecordService');
}
protected function getGamesService()
{
return $this->createService('Games:GamesService');
}
protected function getBoddQuestionsService()
{
return $this->createService('Bodd:BoddQuestionsService');
}
protected function getQuestionService()
{
return $this->createService('Question:QuestionService');
}
/**
* @return PassingCriteriaService
*/
private function getPassingCriteriaService()
{
return $this->createService('CorporateTrainingBundle:ProjectPlan:PassingCriteriaService');
}
/**
* @return StageItemSortService
*/
protected function getStageItemSortService()
{
return $this->createService('CorporateTrainingBundle:ProjectPlan:StageItemSortService');
}
/**
* @return StageService
*/
protected function getStageService()
{
return $this->createService('CorporateTrainingBundle:ProjectPlan:StageService');
}
}