/**
  * @EXT\Route(
  *     "/api/cursus/document/model/{documentModel}/edit",
  *     name="api_put_cursus_document_model_edition",
  *     options = {"expose"=true}
  * )
  * @EXT\ParamConverter("user", converter="current_user")
  */
 public function putDocumentModelEditAction(DocumentModel $documentModel)
 {
     $documentModelDatas = $this->request->request->get('documentModelDatas', false);
     $documentModel->setName($documentModelDatas['name']);
     $documentModel->setContent($documentModelDatas['content']);
     $documentModel->setDocumentType($documentModelDatas['documentType']);
     $this->cursusManager->persistDocumentModel($documentModel);
     $serializedDocumentModel = $this->serializer->serialize($documentModel, 'json', SerializationContext::create()->setGroups(['api_cursus']));
     return new JsonResponse($serializedDocumentModel, 200);
 }
Пример #2
0
 public function generateDocumentFromModel(DocumentModel $documentModel, $sourceId, array $users = null)
 {
     $type = $documentModel->getDocumentType();
     $content = $documentModel->getContent();
     switch ($type) {
         case DocumentModel::SESSION_INVITATION:
             $session = $this->courseSessionRepo->findOneById($sourceId);
             if (is_null($users)) {
                 $users = $this->getUsersBySessionAndType($session, CourseSessionUser::LEARNER);
             }
             $title = $this->translator->trans('session_invitation', [], 'cursus');
             $body = $this->convertKeysForSession($session, $content);
             $this->sendInvitation($title, $users, $body);
             break;
         case DocumentModel::SESSION_EVENT_INVITATION:
             $sessionEvent = $this->sessionEventRepo->findOneById($sourceId);
             if (is_null($users)) {
                 $users = $this->getUsersBySessionEventAndStatus($sessionEvent, SessionEventUser::REGISTERED);
             }
             $title = $this->translator->trans('session_event_invitation', [], 'cursus');
             $body = $this->convertKeysForSessionEvent($sessionEvent, $content);
             $this->sendInvitation($title, $users, $body);
             break;
         case DocumentModel::SESSION_CERTIFICATE:
             $session = $this->courseSessionRepo->findOneById($sourceId);
             if (is_null($users)) {
                 $users = $this->getUsersBySessionAndType($session, CourseSessionUser::LEARNER);
             }
             $body = $this->convertKeysForSession($session, $content, false);
             $this->generateCertificatesForUsers($users, $body, $session);
             break;
         case DocumentModel::SESSION_EVENT_CERTIFICATE:
             $sessionEvent = $this->sessionEventRepo->findOneById($sourceId);
             if (is_null($users)) {
                 $users = $this->getUsersBySessionEventAndStatus($sessionEvent, SessionEventUser::REGISTERED);
             }
             $body = $this->convertKeysForSessionEvent($sessionEvent, $content);
             $this->generateEventCertificatesForUsers($users, $body, $sessionEvent);
             break;
     }
 }