public function inverseActionValue(OrderedTool $orderedTool, Role $role, $action) { $tool = $orderedTool->getTool(); $maskDecoder = $this->maskManager->getMaskDecoderByToolAndName($tool, $action); $maskValue = $maskDecoder->getValue(); if (!is_null($maskDecoder)) { $rights = $this->toolRightsRepo->findRightsByRoleAndOrderedTool($role, $orderedTool); if (is_null($rights)) { $this->setToolRights($orderedTool, $role, $maskValue); } else { $rightsMask = $rights->getMask() ^ $maskValue; $rights->setMask($rightsMask); $this->om->persist($rights); $this->om->flush(); } } }
private function createAdminOrderedTool(ObjectManager $manager, Tool $tool) { $orderedTool = new OrderedTool(); $orderedTool->setTool($tool); $orderedTool->setType(0); $orderedTool->setOrder(1); $orderedTool->setLocked(false); $orderedTool->setName($tool->getName()); $orderedTool->setVisibleInDesktop(true); $manager->persist($orderedTool); }
private function initializeAdminDesktopMenuConfiguration() { $this->log('Initializing default desktop menu configuration...'); $parametersTool = $this->toolManager->getOneToolByName('parameters'); $resourcesTool = $this->toolManager->getOneToolByName('resource_manager'); $messageTool = $this->toolManager->getOneToolByName('message'); $this->om->startFlushSuite(); if (!is_null($parametersTool)) { $paramOt = $this->toolManager->getOneAdminOrderedToolByToolAndType($parametersTool); if (is_null($paramOt)) { $paramOt = new OrderedTool(); $paramOt->setTool($parametersTool); $paramOt->setType(0); $paramOt->setOrder(1); $paramOt->setLocked(false); $paramOt->setName($parametersTool->getName()); } $paramOt->setVisibleInDesktop(true); $this->om->persist($paramOt); } if (!is_null($resourcesTool)) { $resourceOt = $this->toolManager->getOneAdminOrderedToolByToolAndType($resourcesTool); if (is_null($resourceOt)) { $resourceOt = new OrderedTool(); $resourceOt->setTool($resourcesTool); $resourceOt->setType(0); $resourceOt->setOrder(2); $resourceOt->setLocked(false); $resourceOt->setName($resourcesTool->getName()); } $resourceOt->setVisibleInDesktop(true); $this->om->persist($resourceOt); } if (!is_null($messageTool)) { $messageOt = $this->toolManager->getOneAdminOrderedToolByToolAndType($messageTool); if (is_null($messageOt)) { $messageOt = new OrderedTool(); $messageOt->setTool($messageTool); $messageOt->setType(0); $messageOt->setOrder(3); $messageOt->setLocked(false); $messageOt->setName($messageTool->getName()); } $messageOt->setVisibleInDesktop(true); $this->om->persist($messageOt); } $this->om->endFlushSuite(); }
public function postUpdate() { /** @var \Claroline\CoreBundle\Repository\UserRepository $userRepository */ $userRepository = $this->entityManager->getRepository('ClarolineCoreBundle:User'); /** @var \Doctrine\ORM\Query $usersQuery */ $usersQuery = $userRepository->findAllEnabledUsers(false); $users = $usersQuery->iterate(); /** @var \Claroline\CoreBundle\Repository\OrderedToolRepository $orderedToolRepo */ $orderedToolRepo = $this->entityManager->getRepository('ClarolineCoreBundle:Tool\\OrderedTool'); $toolName = 'my_portfolios'; $tool = $this->entityManager->getRepository('ClarolineCoreBundle:Tool\\Tool')->findOneByName($toolName); if (null === $tool) { $tool = new Tool(); $tool->setDisplayableInWorkspace(false)->setName($toolName)->setClass('list-alt'); $this->entityManager->persist($tool); $this->entityManager->flush(); } $countUser = $userRepository->countAllEnabledUsers(); $index = 0; $this->log(sprintf('%d ordered tools to add for users - %s', $countUser, date('Y/m/d H:i:s'))); foreach ($users as $row) { $user = $row[0]; /** @var \Claroline\CoreBundle\Entity\Tool\OrderedTool $orderedTools */ $orderedTool = $orderedToolRepo->findOneBy(['tool' => $tool, 'user' => $user, 'type' => 1]); if (null === $orderedTool) { $orderedTool = new OrderedTool(); $orderedTool->setName($toolName); $orderedTool->setTool($tool); $orderedTool->setUser($user); $orderedTool->setVisibleInDesktop(true); $orderedTool->setOrder(1); $orderedTool->setType(1); $this->entityManager->persist($orderedTool); ++$index; if ($index % 200 === 0) { $this->entityManager->flush(); $this->entityManager->clear($orderedTool); $this->log(sprintf(' %d ordered tools added - %s', 200, date('Y/m/d H:i:s'))); } } } if ($index % 200 !== 0) { $this->entityManager->flush(); $this->entityManager->clear(); $this->log(sprintf(' %d ordered tools added - %s', $index % 200, date('Y/m/d H:i:s'))); } }
/** * {@inheritdoc} */ public function load(ObjectManager $om) { $messagePlugin = $this->getPluginFromIdentityMapOrScheduledForInsert($om, 'Claroline', 'MessageBundle'); if (!is_null($messagePlugin)) { $toolRepo = $om->getRepository('ClarolineCoreBundle:Tool\\Tool'); $messageTool = $toolRepo->findOneBy(array('name' => 'message')); if (is_null($messageTool)) { $messageTool = new Tool(); $messageTool->setName('message'); $messageTool->setClass('envelope'); $messageTool->setDisplayableInWorkspace(false); $messageTool->setDisplayableInDesktop(true); $messageTool->setPlugin($messagePlugin); $om->persist($messageTool); $adminMessageOt = new OrderedTool(); $adminMessageOt->setName('message'); $adminMessageOt->setTool($messageTool); $adminMessageOt->setLocked(false); $adminMessageOt->setOrder(1); $adminMessageOt->setType(0); $adminMessageOt->setVisibleInDesktop(true); $om->persist($adminMessageOt); $userRepo = $om->getRepository('ClarolineCoreBundle:User'); $users = $userRepo->findAllEnabledUsers(); foreach ($users as $user) { $messageOt = new OrderedTool(); $messageOt->setName('message'); $messageOt->setTool($messageTool); $messageOt->setUser($user); $messageOt->setLocked(false); $messageOt->setOrder(1); $messageOt->setType(0); $messageOt->setVisibleInDesktop(true); $om->persist($messageOt); } } else { $messageTool->setPlugin($messagePlugin); $om->persist($messageTool); } $om->flush(); } }
/** * @EXT\Route( * "/tools/order/update/admin/ordered/tool/{orderedTool}/type/{type}/next/{nextOrderedToolId}", * name="claro_admin_desktop_update_ordered_tool_order", * defaults={"type"=0}, * options={"expose"=true} * ) * @EXT\ParamConverter("user", options={"authenticatedUser"=true}) * * @param OrderedTool $orderedTool * @param int type * @param int nextOrderedToolId * * @return \Symfony\Component\HttpFoundation\Response */ public function updateOrderedToolOrderAction(OrderedTool $orderedTool, $nextOrderedToolId, $type = 0) { if (is_null($orderedTool->getUser()) && $orderedTool->getType() === intval($type)) { $this->toolManager->reorderAdminOrderedTool($orderedTool, $nextOrderedToolId, $type); return new Response('success', 200); } else { throw new AccessDeniedException(); } }
/** * @EXT\Route( * "/ordered/tool/{orderedTool}/role/{role}/action/{action}/inverse", * name="claro_workspace_inverse_ordered_tool_right", * options={"expose"=true} * ) * @param OrderedTool $orderedTool * @param Role $role * @param string $action * * @return \Symfony\Component\HttpFoundation\Response */ public function inverseWorkspaceOrderedToolRightAction(OrderedTool $orderedTool, Role $role, $action) { $workspace = $orderedTool->getWorkspace(); $this->checkAccess($workspace); $this->toolRightsManager->inverseActionValue($orderedTool, $role, $action); return new Response('success', 200); }
public function createOrderedToolByToolForAllUsers(LoggerInterface $logger, Tool $tool, $type = 0, $isVisible = true) { $toolName = $tool->getName(); $usersQuery = $this->userRepo->findAllEnabledUsers(false); $users = $usersQuery->iterate(); $this->om->startFlushSuite(); $index = 0; $countUser = $this->userRepo->countAllEnabledUsers(); $logger->info(sprintf("%d users to check tools on.", $countUser)); foreach ($users as $row) { $user = $row[0]; /** @var \Claroline\CoreBundle\Entity\Tool\OrderedTool[] $orderedTools */ $orderedTools = $this->orderedToolRepo->findOrderedToolsByToolAndUser($tool, $user, $type); if (count($orderedTools) === 0) { $orderedTool = new OrderedTool(); $orderedTool->setName($toolName); $orderedTool->setTool($tool); $orderedTool->setUser($user); $orderedTool->setVisibleInDesktop($isVisible); $orderedTool->setOrder(1); $orderedTool->setType($type); $this->om->persist($orderedTool); $index++; if ($index % 100 === 0) { $this->om->forceFlush(); $this->om->clear($orderedTool); $logger->info(sprintf(" %d users checked.", 100)); } } else { $orderedTool = $orderedTools[0]; if ($orderedTool->isVisibleInDesktop() !== $isVisible) { $orderedTool->setVisibleInDesktop($isVisible); $this->om->persist($orderedTool); $index++; if ($index % 100 === 0) { $this->om->forceFlush(); $this->om->clear($orderedTool); $logger->info(sprintf(" %d users checked.", 100)); } } } } if ($index % 100 !== 0) { $logger->info(sprintf(" %d users checked.", 100 - $index)); } $this->om->endFlushSuite(); }
protected static function createDesktopTool(Tool $tool, User $user, $position) { $orderedTool = new OrderedTool(); $orderedTool->setName($tool->getName()); $orderedTool->setTool($tool); $orderedTool->setUser($user); $orderedTool->setOrder($position); self::create("orderedTool/{$user->getUsername()}-{$tool->getName()}", $orderedTool); }
/** * @EXT\Route( * "/tools/order/update/tool/{orderedTool}/type/{type}/next/{nextOrderedToolId}", * name="claro_desktop_update_ordered_tool_order", * defaults={"type"=0}, * options={"expose"=true} * ) * @EXT\ParamConverter("user", options={"authenticatedUser"=true}) * * @param OrderedTool $orderedTool * @param int type * @param int nextOrderedToolId * * @return \Symfony\Component\HttpFoundation\Response */ public function updateDesktopOrderedToolOrderAction(User $user, OrderedTool $orderedTool, $nextOrderedToolId, $type = 0) { if ($orderedTool->getUser() === $user && $orderedTool->getType() === intval($type)) { $this->toolManager->reorderDesktopOrderedTool($user, $orderedTool, $nextOrderedToolId, $type); return new Response('success', 200); } else { throw new AccessDeniedException(); } }
private function addMyContactsTool() { $this->log('Installing my_contacts tool...'); $om = $this->container->get('claroline.persistence.object_manager'); $toolManager = $this->container->get('claroline.manager.tool_manager'); $myContactsTool = $toolManager->getOneToolByName('my_contacts'); if (is_null($myContactsTool)) { $myContactsTool = new Tool(); $myContactsTool->setName('my_contacts'); $myContactsTool->setClass('users'); $myContactsTool->setIsWorkspaceRequired(false); $myContactsTool->setIsDesktopRequired(false); $myContactsTool->setDisplayableInWorkspace(false); $myContactsTool->setDisplayableInDesktop(true); $myContactsTool->setExportable(false); $myContactsTool->setIsConfigurableInWorkspace(false); $myContactsTool->setIsConfigurableInDesktop(false); $myContactsTool->setIsLockedForAdmin(false); $myContactsTool->setIsAnonymousExcluded(true); $toolManager->create($myContactsTool); $myContactsOt = new OrderedTool(); $myContactsOt->setTool($myContactsTool); $myContactsOt->setType(0); $myContactsOt->setOrder(10); $myContactsOt->setLocked(false); $myContactsOt->setName($myContactsTool->getName()); $myContactsOt->setVisibleInDesktop(true); $om->persist($myContactsOt); $om->flush(); } }