private function updateActivityRuleAction() { $this->log('Updating list of action that can be mapped to an activity rule...'); $fileType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('file'); $textType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('text'); $fileAction = $this->om->getRepository('ClarolineCoreBundle:Activity\\ActivityRuleAction')->findRuleActionByActionAndResourceType('resource-read', $fileType); $textAction = $this->om->getRepository('ClarolineCoreBundle:Activity\\ActivityRuleAction')->findRuleActionByActionAndResourceType('resource-read', $textType); $badgeAwardAction = $this->om->getRepository('ClarolineCoreBundle:Activity\\ActivityRuleAction')->findRuleActionByActionWithNoResourceType('badge-awarding'); if (is_null($fileAction)) { $fileAction = new ActivityRuleAction(); $fileAction->setAction('resource-read'); $fileAction->setResourceType($fileType); $this->om->persist($fileAction); } if (is_null($textAction)) { $textAction = new ActivityRuleAction(); $textAction->setAction('resource-read'); $textAction->setResourceType($textType); $this->om->persist($textAction); } if (is_null($badgeAwardAction)) { $badgeAwardAction = new ActivityRuleAction(); $badgeAwardAction->setAction('badge-awarding'); $this->om->persist($badgeAwardAction); } $this->om->flush(); }
/** * Loads one meta type (document) and four resource types handled by the platform core : * - File * - Directory * - Link * - Text * All these resource types have the 'document' meta type. * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { // resource type attributes : name, listable, navigable, class $resourceTypes = array(array('file', true), array('directory', true), array('text', true), array('resource_shortcut', false), array('activity', true)); $types[] = array(); foreach ($resourceTypes as $attributes) { $type = new ResourceType(); $type->setName($attributes[0]); $type->setExportable($attributes[1]); $manager->persist($type); $this->container->get('claroline.manager.mask_manager')->addDefaultPerms($type); $types[$attributes[0]] = $type; } //add special actions. $composeDecoder = new MaskDecoder(); $composeDecoder->setValue(pow(2, 10)); $composeDecoder->setName('compose'); $composeDecoder->setResourceType($types['activity']); $manager->persist($composeDecoder); $activityMenu = new MenuAction(); $activityMenu->setName('compose'); $activityMenu->setAsync(false); $activityMenu->setIsCustom(true); $activityMenu->setValue(pow(2, 10)); $activityMenu->setResourceType($types['activity']); $activityMenu->setIsForm(false); $manager->persist($activityMenu); $updateFile = new MenuAction(); $updateFile->setName('update_file'); $updateFile->setAsync(true); $updateFile->setIsCustom(true); $updateFile->setIsForm(false); $updateFile->setResourceType($types['file']); //16 is default for edit $updateFile->setValue(16); $manager->persist($updateFile); $fileAction = new ActivityRuleAction(); $fileAction->setAction('resource-read'); $fileAction->setResourceType($types['file']); $manager->persist($fileAction); $textAction = new ActivityRuleAction(); $textAction->setAction('resource-read'); $textAction->setResourceType($types['text']); $manager->persist($textAction); $badgeAwardAction = new ActivityRuleAction(); $badgeAwardAction->setAction('badge-awarding'); $manager->persist($badgeAwardAction); }
/** * @param array $rules * @param ResourceType $resourceType */ private function persistActivityRules($rules, ResourceType $resourceType) { $activityRuleActionRepository = $this->em->getRepository('Claroline\\CoreBundle\\Entity\\Activity\\ActivityRuleAction'); foreach ($rules as $rule) { $ruleAction = $activityRuleActionRepository->findOneBy(array('action' => $rule['action'], 'resourceType' => $resourceType)); if (is_null($ruleAction)) { $ruleAction = new ActivityRuleAction(); $ruleAction->setResourceType($resourceType); $ruleAction->setAction($rule['action']); } $this->em->persist($ruleAction); } $this->em->flush(); }