Beispiel #1
0
 /**
  * Persists and flush a group.
  *
  * @param \Claroline\CoreBundle\Entity\Group $group
  */
 public function insertGroup(Group $group)
 {
     $group->setGuid($this->container->get('claroline.utilities.misc')->generateGuid());
     $this->om->persist($group);
     $this->eventDispatcher->dispatch('log', 'Log\\LogGroupCreate', array($group));
     $this->om->flush();
 }
Beispiel #2
0
 public function group($name)
 {
     $group = new Group();
     $group->setGuid($this->container->get('claroline.utilities.misc')->generateGuid());
     $group->setName($name);
     $this->om->persist($group);
     return $group;
 }
 protected function persistGroup($name)
 {
     $group = new Group();
     $group->setName($name);
     $group->setGuid($name);
     $this->om->persist($group);
     return $group;
 }
 public function manageGroupCreation(array $datas)
 {
     $logs = [];
     $identicalGroupTxt = $this->translator->trans('identical_group_name', [], 'platform');
     $groupTxt = $this->translator->trans('group', [], 'platform');
     $createdTxt = $this->translator->trans('has_been_created', [], 'platform');
     $existedTxt = $this->translator->trans('already_exists', [], 'platform');
     $this->om->startFlushSuite();
     // Checks for double entries
     foreach ($datas as $lineNb => $lineDatas) {
         if (!isset($lineDatas['error'])) {
             $groupName = strtolower($lineDatas['name']);
             foreach ($datas as $lineNbBis => $lineDatasBis) {
                 if ($lineNb !== $lineNbBis && !isset($lineDatasBis['error']) && $groupName === strtolower($lineDatasBis['name'])) {
                     $groupNameBis = $lineDatasBis['name'];
                     $datas[$lineNb]['error'] = "[{$lineNb}] {$identicalGroupTxt} [{$groupName}]";
                     $datas[$lineNbBis]['error'] = "[{$lineNbBis}] {$identicalGroupTxt} [{$groupNameBis}]";
                 }
             }
         }
     }
     foreach ($datas as $lineNb => $lineDatas) {
         if (isset($lineDatas['error'])) {
             $logs[] = $lineDatas['error'];
         } else {
             $groupName = $lineDatas['name'];
             $group = $this->groupManager->getGroupByName($groupName);
             if (is_null($group)) {
                 $group = new Group();
                 $group->setName($groupName);
                 $group->setGuid($this->ut->generateGuid());
                 $this->om->persist($group);
                 $logs[] = "{$groupTxt} [{$groupName}] {$createdTxt}";
             } else {
                 $logs[] = "{$groupTxt} [{$groupName}] {$existedTxt}";
             }
         }
     }
     $this->om->endFlushSuite();
     return $logs;
 }