public function chapter($title, $text, $lesson, $root) { $chapter = new Chapter(); $chapter->setTitle($title); $chapter->setText($text); $chapter->setLesson($lesson); $this->om->persist($chapter); $this->om->flush(); return $chapter; }
public function testDeleteCategoryNotAllowed() { $john = $this->persist->user('john'); $jane = $this->persist->user('jane'); $simupoll = $this->persist->simupoll('simupoll1', $john); $category = $this->persist->category('category1', $john, $simupoll); $this->om->flush(); $this->request('DELETE', "/simupoll/category/delete/{$category->getId()}", $jane); $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); }
/** * Returns the contents of a hint and records a log asserting that the hint * has been consulted for a given paper. * * @param Paper $paper * @param Hint $hint * * @return string */ public function viewHint(Paper $paper, Hint $hint) { $log = $this->om->getRepository('UJMExoBundle:LinkHintPaper')->findOneBy(['paper' => $paper, 'hint' => $hint]); if (!$log) { $log = new LinkHintPaper($hint, $paper); $this->om->persist($log); $this->om->flush(); } return $hint->getValue(); }
/** * Delete all Subscriptions of an Exercise. * * @param Exercise $exercise * @param bool $flush * * @return SubscriptionManager */ public function deleteSubscriptions(Exercise $exercise, $flush = false) { $subscriptions = $this->om->getRepository('UJMExoBundle:Subscription')->findByExercise($exercise); foreach ($subscriptions as $subscription) { $this->om->remove($subscription); } if ($flush) { $this->om->flush(); } return $this; }
public function updateDefaultPerms() { $tools = array(array('home', false, true), array('parameters', true, true), array('resource_manager', false, true), array('agenda', false, true), array('logs', false, true), array('analytics', false, true), array('users', false, true), array('badges', false, true)); $this->log('updating tools...'); foreach ($tools as $tool) { $entity = $this->om->getRepository('ClarolineCoreBundle:Tool\\Tool')->findOneByName($tool[0]); if ($entity) { $entity->setIsLockedForAdmin($tool[1]); $entity->setIsAnonymousExcluded($tool[2]); $this->om->persist($entity); } } $this->log('updating resource types...'); $resourceTypes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findAll(); foreach ($resourceTypes as $resourceType) { $resourceType->setDefaultMask(1); $this->om->persist($resourceType); } $this->om->flush(); $this->log('updating manager roles...'); $this->log('this may take a while...'); $managerRoles = $this->om->getRepository('ClarolineCoreBundle:Role')->searchByName('ROLE_WS_MANAGER'); foreach ($managerRoles as $role) { $this->conn->query("DELETE FROM claro_ordered_tool_role\n WHERE role_id = {$role->getId()}"); } $this->log('updating resource rights...'); $this->log('removing administrator rights...'); $roleAdmin = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_ADMIN'); $adminRights = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceRights')->findBy(array('role' => $roleAdmin)); foreach ($adminRights as $adminRight) { $this->om->remove($adminRight); } $this->om->flush(); $this->log('adding user rights... '); $this->log('it may take a while...'); $resourceNodes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findAll(); $roleUser = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_USER'); $this->om->startFlushSuite(); $i = 0; foreach ($resourceNodes as $resourceNode) { $rightsManager = $this->container->get('claroline.manager.rights_manager'); $rightsManager->create(0, $roleUser, $resourceNode, false); $i++; if ($i % 200 === 0) { $this->om->endFlushSuite(); $this->om->startFlushSuite(); } } $this->om->endFlushSuite(); }
public function postUpdate() { $coreIconWebDirRelativePath = "bundles/clarolinecore/images/resources/icons/"; $images = array(array('res_mspowerpoint.png', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'), array('res_msword.png', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')); $this->log('Adding new resource icons...'); foreach ($images as $image) { $rimg = new ResourceIcon(); $rimg->setRelativeUrl($coreIconWebDirRelativePath . $image[0]); $rimg->setMimeType($image[1]); $rimg->setShortcut(false); $this->objectManager->persist($rimg); $this->container->get('claroline.manager.icon_manager')->createShortcutIcon($rimg); } $this->objectManager->flush(); }
/** * Update the Exercise metadata. * * @param Exercise $exercise * @param \stdClass $metadata * * @throws ValidationException */ public function updateMetadata(Exercise $exercise, \stdClass $metadata) { $errors = $this->validator->validateExerciseMetadata($metadata); if (count($errors) > 0) { throw new ValidationException('Exercise metadata are not valid', $errors); } // Update ResourceNode $node = $exercise->getResourceNode(); $node->setName($metadata->title); // Update Exercise $exercise->setDescription($metadata->description); $exercise->setType($metadata->type); $exercise->setPickSteps($metadata->pick ? $metadata->pick : 0); $exercise->setShuffle($metadata->random); $exercise->setKeepSteps($metadata->keepSteps); $exercise->setMaxAttempts($metadata->maxAttempts); $exercise->setLockAttempt($metadata->lockAttempt); $exercise->setDispButtonInterrupt($metadata->dispButtonInterrupt); $exercise->setMetadataVisible($metadata->metadataVisible); $exercise->setMarkMode($metadata->markMode); $exercise->setCorrectionMode($metadata->correctionMode); $exercise->setAnonymous($metadata->anonymous); $exercise->setDuration($metadata->duration); $exercise->setStatistics($metadata->statistics ? true : false); $exercise->setMinimalCorrection($metadata->minimalCorrection ? true : false); $correctionDate = null; if (!empty($metadata->correctionDate) && CorrectionMode::AFTER_DATE === $metadata->correctionMode) { $correctionDate = \DateTime::createFromFormat('Y-m-d\\TH:i:s', $metadata->correctionDate); } $exercise->setDateCorrection($correctionDate); // Save to DB $this->om->persist($exercise); $this->om->flush(); }
public function postUpdate() { $installedBundles = $this->container->getParameter('kernel.bundles'); if (isset($installedBundles['IcapPortfolioBundle'])) { $icapPortfolioPlugin = $this->om->getRepository('ClarolineCoreBundle:Plugin')->findOneByBundleFQCN($installedBundles['IcapPortfolioBundle']); if (null === $icapPortfolioPlugin) { $this->log(' Creation of Portfolio plugin in database.'); $icapPortfolioPlugin = new Plugin(); $icapPortfolioPlugin->setVendorName('Icap'); $icapPortfolioPlugin->setBundleName('PortfolioBundle'); $icapPortfolioPlugin->setHasOptions(false); $this->om->persist($icapPortfolioPlugin); $this->om->flush(); } } }
public function deactivatePersonalWorkspaceRightsPerm(Role $role) { $access = $this->getPwsRightsManagementAccess($role); $access->setIsAccessible(false); $this->om->persist($access); $this->om->flush(); }
public function load(ObjectManager $manager) { $repository = $manager->getRepository('Claroline\\CoreBundle\\Entity\\ContentTranslation'); //mails $frTitle = 'Inscription à %platform_name%'; $frContent = "<div>Votre nom d'utilisateur est %username%</div></br>"; $frContent .= "<div>Votre mot de passe est %password%</div>"; $frContent .= "<div>%validation_mail%</div>"; $enTitle = 'Registration to %platform_name%'; $enContent = "<div>You username is %username%</div></br>"; $enContent .= "<div>Your password is %password%</div>"; $enContent .= "<div>%validation_mail%</div>"; $type = 'claro_mail_registration'; $content = new Content(); $content->setTitle($enTitle); $content->setContent($enContent); $content->setType($type); $repository->translate($content, 'title', 'fr', $frTitle); $repository->translate($content, 'content', 'fr', $frContent); $manager->persist($content); //layout $frLayout = '<div></div>%content%<div></hr>Powered by %platform_name%</div>'; $enLayout = '<div></div>%content%<div></hr>Powered by %platform_name%</div>'; $layout = new Content(); $layout->setContent($enLayout); $layout->setType('claro_mail_layout'); $repository->translate($layout, 'content', 'fr', $frLayout); $manager->persist($layout); $manager->flush(); }
public function refresh(ResourceIcon $icon) { $shortcut = $icon->getShortcutIcon(); $newUrl = $this->createShortcutFromRelativeUrl($icon->getRelativeUrl()); $shortcut->setRelativeUrl($newUrl); $this->om->persist($shortcut); $this->om->flush(); }
private function updatePersonalWorkspaceResourceRightsConfig(ObjectManager $manager) { $roleUser = $manager->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_USER'); $config = new PwsRightsManagementAccess(); $config->setRole($roleUser); $config->setIsAccessible(true); $manager->persist($config); $manager->flush(); }
/** * Close a Paper that is not finished (because the Exercise does not allow interruption). * * @param Paper $paper */ public function closePaper(Paper $paper) { if (!$paper->getEnd()) { $paper->setEnd(new \DateTime()); } $paper->setInterupt(true); // keep track that the user has not finished $paper->setScore($this->calculateScore($paper->getId())); $this->om->flush(); $this->checkPaperEvaluated($paper); }
public function load(ObjectManager $manager) { $tools = array(array('platform_parameters', 'cog'), array('user_management', 'user'), array('workspace_management', 'book'), array('registration_to_workspace', 'book'), array('platform_packages', 'wrench'), array('desktop_and_home', 'home'), array('desktop_tools', 'pencil'), array('platform_logs', 'bars'), array('platform_analytics', 'bar-chart-o'), array('roles_management', 'users'), array('widgets_management', 'list-alt')); foreach ($tools as $tool) { $entity = new AdminTool(); $entity->setName($tool[0]); $entity->setClass($tool[1]); $manager->persist($entity); } $manager->flush(); }
public function postUpdate() { $this->log('Updating cache...'); $this->container->get('claroline.manager.cache_manager')->refresh(); $this->log('Removing old cache...'); if (file_exists($this->oldCachePath)) { unlink($this->oldCachePath); } $this->log('Creating admin tools...'); $tools = array(array('platform_parameters', 'icon-cog'), array('user_management', 'icon-user'), array('workspace_management', 'icon-book'), array('badges_management', 'icon-trophy'), array('registration_to_workspace', 'icon-book'), array('platform_plugins', 'icon-wrench'), array('home_tabs', 'icon-th-large'), array('desktop_tools', 'icon-pencil'), array('platform_logs', 'icon-reorder'), array('platform_analytics', 'icon-bar-chart'), array('roles_management', 'icon-group')); $existingTools = $this->objectManager->getRepository('ClarolineCoreBundle:Tool\\AdminTool')->findAll(); if (count($existingTools) === 0) { foreach ($tools as $tool) { $entity = new AdminTool(); $entity->setName($tool[0]); $entity->setClass($tool[1]); $this->objectManager->persist($entity); } } $this->objectManager->flush(); }
public function load(ObjectManager $manager) { $tools = array(array('platform_parameters', 'cog'), array('user_management', 'user'), array('workspace_management', 'book'), array('registration_to_workspace', 'book'), array('desktop_and_home', 'home'), array('platform_logs', 'bars'), array('platform_analytics', 'bar-chart-o'), array('roles_management', 'users'), array('widgets_management', 'list-alt'), array('organization_management', 'institution')); foreach ($tools as $tool) { $entity = new AdminTool(); $entity->setName($tool[0]); $entity->setClass($tool[1]); $manager->persist($entity); } $manager->flush(); $this->container->get('claroline.manager.administration_manager')->addDefaultAdditionalActions(); }
/** * Retrieves all descendants of given ResourceNode and updates their * accessibility dates. * * @param ResourceNode $node A directory * @param datetime $accessibleFrom * @param datetime $accessibleUntil */ public function changeAccessibilityDate(ResourceNode $node, $accessibleFrom, $accessibleUntil) { if ($node->getResourceType()->getName() === 'directory') { $descendants = $this->resourceNodeRepo->findDescendants($node); foreach ($descendants as $descendant) { $descendant->setAccessibleFrom($accessibleFrom); $descendant->setAccessibleUntil($accessibleUntil); $this->om->persist($descendant); } $this->om->flush(); } }
/** * Update a content translation. * * @param Content $content A content entity * @param array $translation array('content' => 'foo', 'title' => 'foo') * @param string $locale A string with a locale value as 'en' or 'fr' * @param bool $reset A boolean in case of you whant to reset the values of the translation */ private function updateTranslation(Content $content, $translation, $locale = 'en', $reset = false) { if (isset($translation['title'])) { $content->setTitle($reset ? null : $translation['title']); } if (isset($translation['content'])) { $content->setContent($reset ? null : $translation['content']); } $content->setTranslatableLocale($locale); $content->setModified(); $this->manager->persist($content); $this->manager->flush(); }
private function showTermOfServices(GetResponseEvent $event) { if ($event->isMasterRequest() && ($user = $this->getUser($event->getRequest())) && !$user->hasAcceptedTerms() && !$this->isImpersonated() && ($content = $this->termsOfService->getTermsOfService(false))) { if (($termsOfService = $event->getRequest()->get('accept_terms_of_service_form')) && isset($termsOfService['terms_of_service'])) { $user->setAcceptedTerms(true); $this->manager->persist($user); $this->manager->flush(); } else { $form = $this->formFactory->create(new TermsOfServiceType(), $content); $response = $this->templating->render('ClarolineCoreBundle:Authentication:termsOfService.html.twig', ['form' => $form->createView()]); $event->setResponse(new Response($response)); } } }
/** * create the exercise. * * @param array $step - properties of the step * @param Exercise $exercise * * @return Step */ private function createStep(array $step, Exercise $exercise) { $newStep = new Step(); $newStep->setText($step['text']); $newStep->setOrder($step['order']); $newStep->setShuffle($step['shuffle']); $newStep->setNbQuestion($step['nbQuestion']); $newStep->setKeepSameQuestion($step['keepSameQuestion']); $newStep->setDuration($step['duration']); $newStep->setMaxAttempts($step['maxAttempts']); $newStep->setExercise($exercise); $this->om->persist($newStep); $this->om->flush(); return $newStep; }
/** * @param \Claroline\CoreBundle\Entity\Resource\ResourceIcon $icon */ public function delete(ResourceIcon $icon, Workspace $workspace = null) { if ($icon->getMimeType() === 'custom') { //search if this icon is used elsewhere (ie copy) $res = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findBy(array('icon' => $icon)); if (count($res) <= 1 && $icon->isShortcut() === false) { $shortcut = $icon->getShortcutIcon(); $this->om->remove($shortcut); $this->om->remove($icon); $this->om->flush(); $this->removeImageFromThumbDir($icon, $workspace); $this->removeImageFromThumbDir($icon->getShortcutIcon(), $workspace); } } }
/** * @DI\Observe("copy_widget_config_core_resource_logger") * * @param CopyWidgetConfigurationEvent $event */ public function onCopyWidgetConfiguration(CopyWidgetConfigurationEvent $event) { $source = $event->getWidgetInstance(); $copy = $event->getWidgetInstanceCopy(); $widgetConfig = $this->logManager->getLogConfig($source); if (!is_null($widgetConfig)) { $widgetConfigCopy = new LogWidgetConfig(); $widgetConfigCopy->setWidgetInstance($copy); $widgetConfigCopy->setAmount($widgetConfig->getAmount()); $widgetConfigCopy->setRestrictions($widgetConfig->getRestrictions()); $this->om->persist($widgetConfigCopy); $this->om->flush(); } $event->validateCopy(); $event->stopPropagation(); }
/** * @param UploadedFile $file * @param BlogOptions $options */ public function updateBanner(UploadedFile $file = null, BlogOptions $options) { $ds = DIRECTORY_SEPARATOR; if (file_exists($this->uploadDir . $ds . $options->getBannerBackgroundImage()) || $file === null) { @unlink($this->uploadDir . $ds . $options->getBannerBackgroundImage()); } if ($file) { $uniqid = uniqid(); $options->setBannerBackgroundImage($uniqid); $file->move($this->uploadDir, $uniqid); } else { $options->setBannerBackgroundImage(null); } $this->objectManager->persist($options); $this->objectManager->flush(); }
protected function createUserPublicProfilePreferences() { $this->log('Creating public profile preferences for users...'); /** @var \Claroline\CoreBundle\Repository\UserRepository $userRepository */ $userRepository = $this->objectManager->getRepository('ClarolineCoreBundle:User'); /** @var \CLaroline\CoreBundle\Entity\User[] $users */ $users = $userRepository->findWithPublicProfilePreferences(); foreach ($users as $user) { if (null === $user->getPublicProfilePreferences()) { $newUserPublicProfilePreferences = new UserPublicProfilePreferences(); $newUserPublicProfilePreferences->setUser($user); $this->objectManager->persist($newUserPublicProfilePreferences); } } $this->objectManager->flush(); $this->log('Public profile preferences for users created.'); }
public function handleUpdateImageURL(WebsiteOptions $options, $newPath, $imageStr) { $getImageValue = 'get' . ucfirst($imageStr); $setImageValue = 'set' . ucfirst($imageStr); $oldPath = $options->{$getImageValue}(); $options->{$setImageValue}($newPath); try { $this->om->persist($options); $this->om->flush(); } catch (\Exception $e) { $options->{$setImageValue}($oldPath); throw new \InvalidArgumentException(); } if (null !== $oldPath && !filter_var($oldPath, FILTER_VALIDATE_URL) && file_exists($this->webDir . DIRECTORY_SEPARATOR . $options->getUploadDir() . DIRECTORY_SEPARATOR . $oldPath)) { unlink($this->webDir . DIRECTORY_SEPARATOR . $options->getUploadDir() . DIRECTORY_SEPARATOR . $oldPath); } return array($imageStr => $options->getWebPath($imageStr)); }
public function checkIntegrity() { $resources = $this->resourceNodeRepo->findAll(); $batchSize = 500; $i = 0; foreach ($resources as $resource) { if ($resource->getWorkspace() === null && ($parent = $resource->getParent())) { if ($workspace = $parent->getWorkspace()) { $resource->setWorkspace($workspace); $this->om->persist($workspace); $this->log('Set workspace ' . $workspace->getName() . ' for ' . $resource->getName()); ++$i; if ($batchSize % $i === 0) { $this->om->flush(); } } } } $this->om->flush(); }
public function deleteDuplicatedOldOrderedTools() { $usersOts = $this->orderedToolRepo->findDuplicatedOldOrderedToolsByUsers(); $wsOts = $this->orderedToolRepo->findDuplicatedOldOrderedToolsByWorkspaces(); $exitingUsers = array(); foreach ($usersOts as $ot) { $toolId = $ot->getTool()->getId(); $userId = $ot->getUser()->getId(); if (isset($exitingUsers[$toolId])) { if (isset($exitingUsers[$toolId][$userId])) { $this->om->remove($ot); } else { $exitingUsers[$toolId][$userId] = true; } } else { $exitingUsers[$toolId] = array(); $exitingUsers[$toolId][$userId] = true; } } $this->om->flush(); $exitingWorkspaces = array(); foreach ($wsOts as $ot) { $toolId = $ot->getTool()->getId(); $workspaceId = $ot->getWorkspace()->getId(); if (isset($exitingWorkspaces[$toolId])) { if (isset($exitingWorkspaces[$toolId][$workspaceId])) { $this->om->remove($ot); } else { $exitingWorkspaces[$toolId][$workspaceId] = true; } } else { $exitingWorkspaces[$toolId] = array(); $exitingWorkspaces[$toolId][$workspaceId] = true; } } $this->om->flush(); }
/** * Reorder the Questions of a Step. * * @param Step $step * @param array $order an ordered array of Question IDs * * @return array array of errors if something went wrong */ public function reorderQuestions(Step $step, array $order) { $reorderToo = []; // List of Steps we need to reorder too (because we have transferred some Questions) foreach ($order as $pos => $questionId) { /** @var StepQuestion $stepQuestion */ $stepQuestion = $this->om->getRepository('UJMExoBundle:StepQuestion')->findByExerciseAndQuestion($step->getExercise(), $questionId); if (!$stepQuestion) { // Question is not linked to the Exercise, there is a problem with the order array return ['message' => 'Can not reorder the Question. Unknown question found.']; } $oldStep = $stepQuestion->getStep(); if ($oldStep !== $step) { // The question comes from another Step => destroy old link and create a new One $oldStep->removeStepQuestion($stepQuestion); $stepQuestion->setStep($step); $reorderToo[] = $oldStep; } // Update order $stepQuestion->setOrdre($pos); $this->om->persist($stepQuestion); } if (!empty($reorderToo)) { // In fact as the client call the server each time a Question is moved, there will be always one Step in this array /** @var Step $stepToReorder */ foreach ($reorderToo as $stepToReorder) { $stepQuestions = $stepToReorder->getStepQuestions(); /** @var StepQuestion $sqToReorder */ foreach ($stepQuestions as $pos => $sqToReorder) { $sqToReorder->setOrdre($pos); } } } $this->om->flush(); return []; }
public function testNestedFlushSuites() { $oom = $this->mock('Doctrine\\Common\\Persistence\\ObjectManager'); $oom->shouldReceive('flush')->once(); $om = new ObjectManager($oom); $om->startFlushSuite(); $om->flush(); $om->flush(); $om->startFlushSuite(); $om->flush(); $om->flush(); $om->endFlushSuite(); $om->flush(); $om->endFlushSuite(); }
public function persistworkspaceOptions(WorkspaceOptions $workspaceOptions) { $this->om->persist($workspaceOptions); $this->om->flush(); }