/** * @Route("/regenerate_rss", name="icap_notification_regenerate_rss_url") * @Template("IcapNotificationBundle:Parameters:config.html.twig") * @ParamConverter("user", options={"authenticatedUser" = true}) */ public function regenerateRssUrlAction(User $user) { $parametersManager = $this->getParametersManager(); $parameters = $parametersManager->regenerateRssId($user->getId()); $types = $parametersManager->allTypesList($parameters); return array('types' => $types, 'rssId' => $parameters->getRssId()); }
public function registerUserToCursusHierarchy($platformName, User $user, $cursusId) { $targetPlatformUrl = $this->friendRepo->findOneByName($platformName); $url = 'clarolinecursusbundle/api/users/' . $user->getId() . '/tos/' . $cursusId . '/cursus/hierarchy/add.json'; $serverOutput = $this->apiManager->url($targetPlatformUrl, $url); return json_decode($serverOutput, true); }
/** * Returns the ancestors of a message (the message itself is also returned). * * @param Message $message * * @return array[Message] */ public function findAncestors(Message $message, User $user) { $dql = "\n SELECT m\n FROM Claroline\\MessageBundle\\Entity\\Message m\n JOIN m.userMessages um\n JOIN um.user u\n WHERE m.lft BETWEEN m.lft AND m.rgt\n AND m.root = {$message->getRoot()}\n AND m.lvl <= {$message->getLvl()}\n AND (\n u.id = :userid\n OR m.user = :userid\n )\n "; $query = $this->_em->createQuery($dql); $query->setParameter('userid', $user->getId()); return $query->getResult(); }
/** * @param User $user * @param bool $executeQuery * * @return Query|array */ public function findByUserWithAccessToken(User $user, $executeQuery = true) { $query = $this->getEntityManager()->createQuery('SELECT c, at FROM ClarolineCoreBundle:Oauth\\Client c JOIN c.accessTokens at WHERE at.user = :userId')->setParameter('userId', $user->getId()); return $executeQuery ? $query->getResult() : $query; }
private function getUserKey(User $user) { if ($user === null) { return 'anonymous'; } else { return $user->getId(); } }
/** * Admin or not * * @param User $user * @return boolean */ public function adminOrNot(User $user) { $adminInnova = false; // TODO : change service to @security.authorization_checker if ($this->securityContext->isGranted('ROLE_ADMIN' === true) && $this->get('security.context')->getToken()->getUser()->getId() == $user->getId()) { $adminInnova = true; } return $adminInnova; }
/** * @param User $user * @param bool $getQuery * * @return Query|array */ public function findByUser(User $user, $getQuery = false) { $query = $this->getEntityManager()->createQuery('SELECT bc, b, bt FROM IcapBadgeBundle:BadgeClaim bc JOIN bc.badge b JOIN b.translations bt WHERE bc.user = :userId')->setParameter('userId', $user->getId()); return $getQuery ? $query : $query->getResult(); }
/** * @param User $user * @param bool $executeQuery * * @return Query|array */ public function findByUser(User $user, $executeQuery = true) { $query = $this->getEntityManager()->createQuery('SELECT b, ub, bt FROM IcapBadgeBundle:Badge b JOIN b.userBadges ub JOIN b.translations bt WHERE ub.user = :userId')->setParameter('userId', $user->getId()); return $executeQuery ? $query->getResult() : $query; }
/** * @param User $user * @param bool $executeQuery * * @return Query|array */ public function findByUser(User $user, $executeQuery = true) { $query = $this->getEntityManager()->createQuery('SELECT badgeCollection, userBadges FROM IcapBadgeBundle:BadgeCollection badgeCollection LEFT JOIN badgeCollection.userBadges userBadges WHERE badgeCollection.user = :userId ORDER BY badgeCollection.name ASC')->setParameter('userId', $user->getId()); return $executeQuery ? $query->getResult() : $query; }
public function testPutOrganizationActionIsProtected() { $orga = $this->persister->organization('orga'); $this->persister->flush(); $this->logIn($this->john); $fields = array('name' => 'rename', 'email' => '*****@*****.**', 'administrators' => $this->admin->getId()); $form = array('organization_form' => $fields); $this->client->request('PUT', "/api/organizations/{$orga->getId()}.json", $form); $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); }
/** * @param Wiki $wiki * @param bool $isAdmin * @param User $user * * @return Tree $tree */ public function buildSectionTree(Wiki $wiki, $isAdmin, User $user = null) { $queryBuilder = $this->createQueryBuilder('section')->join('section.activeContribution', 'contribution')->select('section, contribution')->andWhere('section.root = :rootId')->orderBy('section.root, section.left', 'ASC')->setParameter('rootId', $wiki->getRoot()->getId()); $queryBuilder->andWhere($queryBuilder->expr()->orX('section.deleted = :deleted', $queryBuilder->expr()->isNull('section.deleted')))->setParameter('deleted', false); if ($isAdmin === false) { $queryBuilder->andWhere($queryBuilder->expr()->orX('section.visible = :visible', 'section.author = :userId'))->setParameter('visible', true)->setParameter('userId', $user->getId()); } $options = ['decorate' => false]; $tree = $this->buildTree($queryBuilder->getQuery()->getArrayResult(), $options); return $tree; }
public function findByWorkspaceAndUser(Workspace $workspace, User $user) { $dql = ' SELECT rwt, t FROM Claroline\\CoreBundle\\Entity\\Workspace\\RelWorkspaceTag rwt JOIN rwt.workspace w JOIN rwt.tag t JOIN t.user u WHERE u.id = :userId AND w.id = :workspaceId '; $query = $this->_em->createQuery($dql); $query->setParameter('userId', $user->getId()); $query->setParameter('workspaceId', $workspace->getId()); return $query->getResult(); }
public function jsonSerialize() { return array('id' => $this->id, 'userId' => $this->user->getId(), 'stepId' => $this->step->getId(), 'status' => $this->status, 'authorized' => $this->authorized); }
/** * Finds UserMessage received or sent by a user, filtered by specific messages. * * @param User $user * @param array[Message] $messages * * @return array[UserMessage] */ public function findByMessages(User $user, array $messages) { $messageIds = array(); foreach ($messages as $message) { $messageIds[] = $message->getId(); } $dql = ' SELECT um FROM Claroline\\MessageBundle\\Entity\\UserMessage um JOIN um.user u JOIN um.message m WHERE m.id IN (:messageIds) AND u.id = :userId ORDER BY m.date DESC '; $query = $this->_em->createQuery($dql); $query->setParameter('messageIds', $messageIds); $query->setParameter('userId', $user->getId()); return $query->getResult(); }
/** * @EXT\Route( * "/password/edit/{user}", * name="claro_user_password_edit" * ) * @EXT\ParamConverter("loggedUser", options={"authenticatedUser" = true}) * @EXT\Template() */ public function editPasswordAction(User $user, User $loggedUser) { $isAdmin = $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN'); $isGrantedUserAdmin = $this->get('security.authorization_checker')->isGranted('OPEN', $this->toolManager->getAdminToolByName('user_management')); $selfEdit = $user->getId() === $loggedUser->getId() ? true : false; if (!$selfEdit && !$isAdmin && !$isGrantedUserAdmin) { throw new AccessDeniedException(); } $form = $this->createForm(new ResetPasswordType($selfEdit)); $oldPassword = $user->getPassword(); $form->handleRequest($this->request); if ($form->isValid()) { /** @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $sessionFlashBag */ $sessionFlashBag = $this->get('session')->getFlashBag(); /** @var \Symfony\Component\Translation\TranslatorInterface $translator */ $translator = $this->get('translator'); $continue = !$selfEdit; if ($selfEdit) { $user->setPlainPassword($form['password']->getData()); } if ($selfEdit && $this->encodePassword($user) === $oldPassword) { $continue = true; } if ($continue) { $user->setPlainPassword($form['plainPassword']->getData()); $user->setPassword($this->encodePassword($user)); $entityManager = $this->get('doctrine.orm.entity_manager'); $entityManager->persist($user); $entityManager->flush(); $sessionFlashBag->add('success', $translator->trans('edit_password_success', array(), 'platform')); } else { $sessionFlashBag->add('error', $translator->trans('edit_password_error_current', array(), 'platform')); } if ($selfEdit) { return $this->redirect($this->generateUrl('claro_profile_view')); } else { return $this->redirect($this->generateUrl('claro_admin_users_index')); } } return array('form' => $form->createView(), 'user' => $user); }
/** * Returns the non-visible tools in a user's desktop. * * @param User $user * * @return array[Tool] */ public function findDesktopUndisplayedToolsByUser(User $user, $orderedToolType = 0) { $dql = "\n SELECT tool\n FROM Claroline\\CoreBundle\\Entity\\Tool\\Tool tool\n WHERE tool NOT IN (\n SELECT tool_2\n FROM Claroline\\CoreBundle\\Entity\\Tool\\Tool tool_2\n JOIN tool_2.orderedTools ot_2\n JOIN ot_2.user user_2\n WHERE user_2.id = {$user->getId()}\n AND ot_2.type = :type\n )\n AND tool.isDisplayableInDesktop = true\n "; $query = $this->_em->createQuery($dql); $query->setParameter('type', $orderedToolType); return $query->getResult(); }
function getBaseName(User $user) { $BaseName = $user->getUsername() . $user->getId() . "/"; return $BaseName; }
/** * @param \Claroline\CoreBundle\Entity\User $user */ public function uploadAvatar(User $user) { if (null !== $user->getPictureFile()) { if (!is_writable($pictureDir = $this->uploadsDirectory . '/pictures/')) { throw new \Exception("{$pictureDir} is not writable"); } $user->setPicture(sha1($user->getPictureFile()->getClientOriginalName() . $user->getId()) . '.' . $user->getPictureFile()->guessExtension()); $user->getPictureFile()->move($pictureDir, $user->getPicture()); } }
/** * @param User $user * * @return bool */ public function hasGuide(User $user) { $isGuide = false; foreach ($this->getPortfolioGuides() as $portfolioGuide) { if ($user->getId() === $portfolioGuide->getUser()->getId()) { $isGuide = true; break; } } return $isGuide; }
/** * * @Route( * "/{resourceId}/examiners/{userId}", * name="innova_collecticiel_examiner_corrections", * requirements ={"resourceId" ="\d+","userId"="\d+"}, * defaults={"page" = 1 } * ) * * @Route( * "/{resourceId}/examiners/{userId}/{page}", * name="innova_collecticiel_examiner_corrections_paginated", * requirements ={"resourceId" ="\d+","userId"="\d+","page"="\d+"}, * defaults={"page" = 1 } * ) * * * @ParamConverter("dropzone",class="InnovaCollecticielBundle:Dropzone",options={"id" = "resourceId"}) * @ParamConverter("user",class="ClarolineCoreBundle:User",options={"id" = "userId"}) * @Template() * * * **/ public function correctionsByUserAction(Dropzone $dropzone, User $user, $page) { $this->get('innova.manager.dropzone_voter')->isAllowToOpen($dropzone); $this->get('innova.manager.dropzone_voter')->isAllowToEdit($dropzone); $correctionsQuery = $this->getDoctrine()->getManager()->getRepository('InnovaCollecticielBundle:Correction')->getByDropzoneUser($dropzone->getId(), $user->getId(), true); $adapter = new DoctrineORMAdapter($correctionsQuery); $pager = new Pagerfanta($adapter); $pager->setMaxPerPage(DropzoneBaseController::CORRECTION_PER_PAGE); try { $pager->setCurrentPage($page); } catch (NotValidCurrentPageException $e) { if ($page > 0) { return $this->redirect($this->generateUrl('innova_collecticiel_examiner_corrections_paginated', array('resourceId' => $dropzone->getId(), 'userId' => $user->getId()))); } else { throw new NotFoundHttpException(); } } $corrections = $pager->getCurrentPageResults(); return array('_resource' => $dropzone, 'dropzone' => $dropzone, 'pager' => $pager, 'user' => $user, 'corrections' => $corrections); }
public function getFutureDesktopEvents(User $user, $limit = null) { $dql = "\n SELECT e\n FROM Claroline\\AgendaBundle\\Entity\\Event e\n WHERE e.end > :dateEnd\n AND e.user = :userId\n AND e.isTask = false\n AND e.workspace is null\n AND e.isTaskDone = false\n ORDER BY e.start ASC\n "; $query = $this->_em->createQuery($dql); $query->setParameter('userId', $user->getId()); $query->setParameter('dateEnd', time()); if ($limit) { $query->setMaxResults($limit); } return $query->getResult(); }
public function jsonSerialize() { return ['id' => $this->id, 'userId' => $this->user instanceof User ? $this->user->getId() : 0, 'stepId' => $this->step->getId(), 'status' => $this->status, 'authorized' => $this->authorized, 'locked' => $this->locked, 'lockedcall' => $this->lockedcall]; }
public function getScorm2004ScoTrackingByUserAndSco(User $user, Scorm2004Sco $sco) { return $this->scorm2004ScoTrackingRepo->findOneBy(['user' => $user->getId(), 'sco' => $sco->getId()]); }
/** * @EXT\Route("/dashboards/preview/{workspaceId}/times", name="get_dashboard_spent_times_by_workspace") * @EXT\ParamConverter("user", converter="current_user", options={"allowAnonymous"=false}) * @EXT\ParamConverter("workspace", class="ClarolineCoreBundle:Workspace\Workspace", options={"mapping": {"workspaceId": "id"}}) * @EXT\Method("GET") */ public function getDashboardWorkspaceSpentTimesByWorkspace(User $user, Workspace $workspace) { $all = $user->getId() === $workspace->getCreator()->getId(); $data = $this->dashboardManager->getDashboardWorkspaceSpentTimes($workspace, $user, $all); return new JsonResponse($data); }
/** * Returns the workspaces which are visible for an authenticated user and allow * self-registration (user's workspaces are excluded). * * @param User $user * * @return array[Workspace] */ public function findWorkspacesWithSelfRegistrationBySearch(User $user, $search) { $dql = ' SELECT w FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w WHERE w.displayable = true AND w.selfRegistration = true AND ( UPPER(w.name) LIKE :search OR UPPER(w.code) LIKE :search ) AND w.id NOT IN ( SELECT w2.id FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w2 JOIN w2.roles r JOIN r.users u WHERE u.id = :userId ) ORDER BY w.name '; $query = $this->_em->createQuery($dql); $query->setParameter('userId', $user->getId()); $search = strtoupper($search); $query->setParameter('search', "%{$search}%"); return $query->getResult(); }
/** * @EXT\Route( * "user/{user}/infos/request", * name="claro_user_infos_request", * options = {"expose"=true} * ) */ public function userInfosRequestAction(User $user) { $datas = array('id' => $user->getId(), 'firstName' => $user->getFirstName(), 'lastName' => $user->getLastName(), 'username' => $user->getUsername(), 'mail' => $user->getMail(), 'phone' => $user->getPhone(), 'picture' => $user->getPicture()); return new JsonResponse($datas, 200); }
/** * @View(serializerGroups={"api"}) * @ApiDoc( * description="Update a workspace owner", * views = {"workspace"} * ) * @ParamConverter("user", class="ClarolineCoreBundle:User", options={"repository_method" = "findForApi"}) */ public function putWorkspaceOwnerAction(Workspace $workspace, User $user) { $currentCreator = $workspace->getCreator(); if ($currentCreator->getId() !== $user->getId()) { $this->om->startFlushSuite(); $role = $this->roleManager->getManagerRole($workspace); $this->roleManager->associateRole($user, $role); $this->roleManager->dissociateRole($currentCreator, $role); $workspace->setCreator($user); $this->workspaceManager->editWorkspace($workspace); $this->om->endFlushSuite(); } return $workspace; }
/** * Returns the roles of a user in a workspace. * * @param User $user The subject of the role * @param Workspace $workspace The workspace the role should be bound to * * @return null|Role */ public function findWorkspaceRolesForUser(User $user, Workspace $workspace) { $dql = "\n SELECT r FROM Claroline\\CoreBundle\\Entity\\Role r\n JOIN r.workspace ws\n JOIN r.users user\n WHERE ws.guid = '{$workspace->getGuid()}'\n AND r.name != 'ROLE_ADMIN'\n AND user.id = {$user->getId()}\n "; $query = $this->_em->createQuery($dql); return $query->getResult(); }
/** * @EXT\Route( * "/{workspaceId}/activity/parameters/{activityParametersId}/user/{userId}/past/evaluations/show/{displayType}", * name="claro_workspace_activities_past_evaluations_show", * options = {"expose": true} * ) * @EXT\ParamConverter("currentUser", options={"authenticatedUser" = true}) * @EXT\ParamConverter( * "user", * class="ClarolineCoreBundle:User", * options={"id" = "userId", "strictId" = true} * ) * @EXT\ParamConverter( * "workspace", * class="ClarolineCoreBundle:Workspace\Workspace", * options={"id" = "workspaceId", "strictId" = true} * ) * @EXT\ParamConverter( * "activityParameters", * class="ClarolineCoreBundle:Activity\ActivityParameters", * options={"id" = "activityParametersId", "strictId" = true} * ) * @EXT\Template("ClarolineCoreBundle:Tool/workspace/analytics:workspaceActivitiesPastEvaluations.html.twig") * * Displays past evaluations of one activity for one user * * @return Response * * @throws \Exception */ public function workspaceActivitiesPastEvaluationsShowAction(User $currentUser, User $user, Workspace $workspace, ActivityParameters $activityParameters, $displayType) { if (!$this->authorization->isGranted('analytics', $workspace)) { throw new AccessDeniedException(); } $roleNames = $currentUser->getRoles(); $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames); if (!$isWorkspaceManager && $currentUser->getId() !== $user->getId()) { throw new AccessDeniedException(); } $activity = $activityParameters->getActivity(); $ruleScore = null; $isResultVisible = false; if ($activityParameters->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParameters->getRules()) > 0) { $rule = $activityParameters->getRules()->first(); $score = $rule->getResult(); $scoreMax = $rule->getResultMax(); if (!is_null($score)) { $ruleScore = $score; if (!is_null($scoreMax)) { $ruleScore .= ' / ' . $scoreMax; } $ruleResultVisible = $rule->getIsResultVisible(); $isResultVisible = !empty($ruleResultVisible); } } $pastEvals = $this->activityManager->getPastEvaluationsByUserAndActivityParams($user, $activityParameters); return array('user' => $user, 'activity' => $activity, 'pastEvals' => $pastEvals, 'displayType' => $displayType, 'isWorkspaceManager' => $isWorkspaceManager, 'ruleScore' => $ruleScore, 'isResultVisible' => $isResultVisible); }
public function testUsersPasswordInitializeActionIsProtected() { $this->login($this->john); $this->client->request('GET', "/api/passwords/initializes/users.json?userIds[]={$this->userOrga->getId()}"); $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); }