@EXT\Route(
"/import",
name="apiv2_event_import"
)
@EXT\Method("POST")

@param Workspace $workspace

@return \Symfony\Component\HttpFoundation\Response
974817
public function importAction(Request $request)
    {
        $data = json_decode($request->getContent(), true);
        $file = $data['file'];
        $workspace = $data['workspace'];
        $workspace = $workspace['id'] ? $this->om->getObject($workspace, Workspace::class) : null;
        $fileEntity = $this->om->getObject($file, PublicFile::class) ?? new PublicFile();
        $file = $this->serializer->deserialize($file, $fileEntity);
        $fileData = $this->container->get('claroline.utilities.file')->getContents($file);
        $events = $this->container->get('claroline.manager.agenda_manager')->import($fileData, $workspace);

        return new JsonResponse(array_map(function (Event $event) {
            return $this->serializer->serialize($event);
        }, $events));
    }
533039
public function addImport(string $importName): NamespaceContext
    {
        $importName = \trim($importName, '\\');
        
        if (false !== ($offset = \strrpos($importName, '\\'))) {
            $this->imports[\strtolower(\substr($importName, $offset + 1))] = $importName;
        } else {
            $this->imports[\strtolower($importName)] = $importName;
        }
        
        return $this;
    }
215051
public function addUserAction(Workspace $workspace, User $user)
    {
        $role = $workspace->getDefaultRole();
        $this->roleManager->associateRole($user, $role);
        $this->dispatcher->dispatch(
            'claroline_workspace_register_user',
            'WorkspaceAddUser',
            [$role, $user]
        );

        if ($user->getUuid() === $this->container->get('security.token_storage')->getToken()->getUser()->getUuid()) {
            $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
            $this->container->get('security.token_storage')->setToken($token);
        }

        return $user;
    }
723344
public function findWorkspaceRoot(Workspace $workspace)
    {
        $builder = new ResourceQueryBuilder();
        $builder->selectAsEntity()
            ->whereInWorkspace($workspace)
            ->whereParentIsNull();
        $query = $this->_em->createQuery($builder->getDql());
        $query->setParameters($builder->getParameters());

        return $query->getOneOrNullResult();
    }
628271
public function listTinyMceDestinationsAction(Workspace $workspace = null)
    {
        $data = $this->finder->search(
          ResourceNode::class, [
            'filters' => [
                'meta.uploadDestination' => true,
                'roles' => array_map(function ($role) {
                    return $role->getRole();
                }, $this->tokenStorage->getToken()->getRoles()),
            ],
          ],
          [Options::SERIALIZE_MINIMAL]
        );

        return new JsonResponse($data['data']);
    }
524048
public function findPersonalUser(Workspace $workspace)
    {
        $user = $this->userRepo->findBy(array('personalWorkspace' => $workspace));

        return (count($user) === 1) ? $user[0]: null;
    }
777228
public function workspaceEditAction(Workspace $workspace)
    {
        if (!$this->authorization->isGranted('parameters', $workspace)) {
            throw new AccessDeniedException();
        }

        $wsRegisteredName = $workspace->getName();
        $wsRegisteredDisplayable = $workspace->isDisplayable();
        $workspaceAdminTool = $this->toolManager->getAdminToolByName('workspace_management');
        $isAdmin = $this->authorization->isGranted('OPEN', $workspaceAdminTool);
        $expDate = is_null($workspace->getCreationDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getEndDate()
        );
        $form = $this->formFactory->create(
            FormFactory::TYPE_WORKSPACE_EDIT,
            array(null, null, null, null, null, $isAdmin, $expDate),
            $workspace
        );
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $this->workspaceManager->editWorkspace($workspace);
            $this->workspaceManager->rename($workspace, $workspace->getName());
            $displayable = $workspace->isDisplayable();

            if (!$displayable && $displayable !== $wsRegisteredDisplayable) {
                $this->workspaceTagManager->deleteAllAdminRelationsFromWorkspace($workspace);
            }

            return $this->redirect(
                $this->generateUrl(
                    'claro_workspace_open_tool',
                    array(
                        'workspaceId' => $workspace->getId(),
                        'toolName' => 'parameters'
                    )
                )
            );
        } else {
            $workspace->setName($wsRegisteredName);
        }

        $user = $this->tokenStorage->getToken()->getUser();

        if ($workspace->getSelfRegistration()) {
            $url = $this->router->generate(
                'claro_workspace_subscription_url_generate',
                array('workspace' => $workspace->getId()),
                true
            );
        } else {
            $url = '';
        }

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace,
            'url' => $url,
            'user' => $user
        );
    }
962699
public function importAction()
    {

        $form = $this->formFactory->create(new ImportUserType(true));
        $form->handleRequest($this->request);
        $mode = $form->get('mode')->getData();

        if ($mode === 'update') {
            $form = $this->formFactory->create(new ImportUserType(true, 1));
            $form->handleRequest($this->request);
        }

        if ($form->isValid()) {
            $file = $form->get('file')->getData();
            $sendMail = $form->get('sendMail')->getData();
            $data = file_get_contents($file);
            $data = $this->container->get('claroline.utilities.misc')->formatCsvOutput($data);
            $lines = str_getcsv($data, PHP_EOL);
            $users = array();
            $toUpdate = array();
            $sessionFlashBag = $this->session->getFlashBag();

            foreach ($lines as $line) {

                if ($mode === 'update') {
                    $datas = str_getcsv($line, ';');
                    $username = $datas[2];
                    $email = $datas[4];
                    $existingUser = $this->userManager->getUserByUsernameOrMail(
                        $username,
                        $email
                    );

                    if (is_null($existingUser)) {
                        $users[] = $datas;
                    } else {
                        $toUpdate[] = $datas;
                    }
                } else {
                    $users[] = str_getcsv($line, ';');
                }
            }

            $roleUser = $this->roleManager->getRoleByName('ROLE_USER');
            $max = $roleUser->getMaxUsers();
            $total = $this->userManager->countUsersByRoleIncludingGroup($roleUser);

            if ($total + count($users) > $max) {

                return array('form' => $form->createView(), 'error' => 'role_user unavailable');
            }

            $additionalRoles = $form->get('roles')->getData();

            foreach ($additionalRoles as $additionalRole) {
                $max = $additionalRole->getMaxUsers();
                $total = $this->userManager->countUsersByRoleIncludingGroup($additionalRole);

                if ($total + count($users) > $max) {

                    return array(
                        'form' => $form->createView(),
                        'error' => $additionalRole->getName() . ' unavailable'
                    );
                }
            }

            if (count($toUpdate) > 0) {
                $updatedNames = $this->userManager->updateImportedUsers(
                    $toUpdate,
                    $additionalRoles->toArray()
                );

                foreach ($updatedNames as $name) {
                    $msg =  '<' . $name . '> ';
                    $msg .= $this->translator->trans(
                        'has_been_updated',
                        array(),
                        'platform'
                    );
                    $sessionFlashBag->add('success', $msg);
                }
            }
            $createdNames = $this->userManager->importUsers(
                $users,
                $sendMail,
                null,
                $additionalRoles
            );

            foreach ($createdNames as $name) {
                $msg =  '<' . $name . '> ';
                $msg .= $this->translator->trans(
                    'has_been_created',
                    array(),
                    'platform'
                );
                $sessionFlashBag->add('success', $msg);
            }

            return new RedirectResponse($this->router->generate('claro_admin_users_index'));
        }

        return array('form' => $form->createView());
    }
205750
public function registerAndRedirect(Workspace $workspace, Request $request)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ($workspace->getSelfRegistration()) {
            if ($workspace->getRegistrationValidation()) {
                $this->workspaceManager->addUserQueue($workspace, $user);
            } else {
                $this->workspaceManager->addUserAction($workspace, $user);
            }

            return $this->openAction($workspace->getId(), $request);
        } else {
            throw new \Exception('No self registration allowed');
        }
    }
859805
public function openDeniedAction(Workspace $workspace, $action)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        //check the expiration date first
        $now = new \DateTime();
        $dateValidity = true;

        if ($workspace->getEndDate()) {
            if ($now->getTimeStamp() > $workspace->getEndDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        if ($workspace->getStartDate()) {
            if ($now->getTimeStamp() < $workspace->getStartDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        return [
          'workspace' => $workspace,
          'action' => $action,
          'dateValidity' => $dateValidity,
          'isInQueue' => $this->workspaceManager->isUserInValidationQueue($workspace, $user),
        ];
    }
466105
public function importAction()
    {
        $success = null;
        $request = $this->getRequest();
        $data    = $request->getPost();
        $form    = $this->getServiceLocator()
                        ->get( 'Form' )
                        ->create( 'Grid\Paragraph\ChangeLayout\Import', array(
                            'returnUri' => $request->getQuery( 'returnUri' ),
                        ) );

        $form->setAttribute(
            'action',
            $this->url()
                 ->fromRoute( 'Grid\Paragraph\ChangeLayout\Import', array(
                     'locale'       => (string) $this->locale(),
                     'paragraphId'  => $this->paragraphId,
                     'returnUri'    => $request->getQuery( 'returnUri' ),
                 ) )
        );

        if ( $request->isPost() )
        {
            $form->setData( $data );

            if ( $form->isValid() )
            {
                $data       = $form->getData();
                $beforeId   = $this->getLayoutId();
                $clonedId   = $this->getParagraphModel()
                                   ->cloneFrom( $data['importId'], '_central' );
                $success    = $this->saveLayout( $clonedId );

                $this->getServiceLocator()
                     ->get( 'Grid\Menu\Model\Menu\Model' )
                     ->interleaveParagraphs( $clonedId, $beforeId );
            }
            else
            {
                $success    = false;
            }
        }

        if ( true === $success )
        {
            $this->messenger()
                 ->add( 'paragraph.action.importLayout.success',
                        'paragraph', Message::LEVEL_INFO );
        }

        if ( false === $success )
        {
            $this->messenger()
                 ->add( 'paragraph.action.importLayout.failed',
                        'paragraph', Message::LEVEL_ERROR );
        }

        if ( null !== $success )
        {
            return $this->redirect()
                        ->toUrl( $form->get( 'returnUri' )
                                      ->getValue() );
        }

        $view = new ViewModel( array(
            'form' => $form,
        ) );
        return $view->setTerminal( true );
    }
535932
private function getRegistration(Workspace $workspace, array $options)
    {
        if ($workspace->getDefaultRole()) {
            if (in_array(Options::REFRESH_UUID, $options)) {
                $defaultRole = [
                  'translationKey' => $workspace->getDefaultRole()->getTranslationKey(),
                  'type' => $workspace->getDefaultRole()->getType(),
                ];
            } else {
                $defaultRole = [
                    'id' => $workspace->getDefaultRole()->getUuid(),
                    'name' => $workspace->getDefaultRole()->getName(),
                    'type' => $workspace->getDefaultRole()->getType(), // TODO : should be a string for better data readability
                    'translationKey' => $workspace->getDefaultRole()->getTranslationKey(),
                ];
            }
        } else {
            $defaultRole = null;
        }

        return [
            'validation' => $workspace->getRegistrationValidation(),
            'waitingForRegistration' => $workspace->getSelfRegistration() ? $this->waitingForRegistration($workspace) : false,
            'selfRegistration' => $workspace->getSelfRegistration(),
            'selfUnregistration' => $workspace->getSelfUnregistration(),
            'defaultRole' => $defaultRole,
        ];
    }
644603
public function urlSubscriptionGenerateAction(Workspace $workspace)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ( $user === 'anon.') {
            return $this->redirect(
                $this->generateUrl(
                    'claro_workspace_subscription_url_generate_anonymous',
                    array(
                        'workspace' => $workspace->getId(),
                        'toolName' => 'home'
                    )
                )
            );
        }

        $this->workspaceManager->addUserAction($workspace, $user);

        return $this->redirect(
            $this->generateUrl(
                'claro_workspace_open_tool', array('workspaceId' => $workspace->getId(), 'toolName' => 'home')
            )
        );
    }
94633
public function findByWorkspaceWithUsersFromGroup(Workspace $workspace)
    {
        $dql = '
            SELECT u
            FROM Claroline\CoreBundle\Entity\User u
            JOIN u.roles ur
            LEFT JOIN u.groups g
            LEFT JOIN g.roles gr
            LEFT JOIN gr.workspace grws
            LEFT JOIN ur.workspace uws
            WHERE (uws.id = :wsId
            OR grws.id = :wsId)
            AND u.isEnabled = true
         ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('wsId', $workspace->getId());
        $res = $query->getResult();
        return $res;
    }
1062796
public function multipleTeamsCreateFormAction(Workspace $workspace, User $user)
    {
        $this->checkWorkspaceManager($workspace, $user);
        $params = $this->teamManager->getParametersByWorkspace($workspace);
        $form = $this->formFactory->create(new MultipleTeamsType($params));

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace
        );
    }
910518
public function buildRunWorkflow(Import $import, ImportRun $importRun = null)
    {
        //build basics
        $workflow = $this->buildBaseWorkflow($import);

        //output
        $workflow->addWriter($import->getTargetStorage()->writer());

        //collect statistics by default
        $statisticsCollector = new ImportRunEventSubscriber($import);
        $this->eventDispatcher->addSubscriber($statisticsCollector);

        return $workflow;
    }
35752
public function initWorkspaceBaseRole(array $roles, Workspace $workspace)
    {
        $this->om->startFlushSuite();
        $entityRoles = array();

        $entityRoles['ROLE_WS_MANAGER'] = $this->createWorkspaceRole(
            "ROLE_WS_MANAGER_{$workspace->getGuid()}",
            'manager',
            $workspace,
            true
        );

        $this->om->endFlushSuite();

        return $entityRoles;
    }