Ejemplo n.º 1
0
 protected static function createWorkspaceTool(Tool $tool, Workspace $workspace, array $roles, $position)
 {
     $orderedTool = new OrderedTool();
     $orderedTool->setName($tool->getName());
     $orderedTool->setTool($tool);
     $orderedTool->setWorkspace($workspace);
     $orderedTool->setOrder($position);
     self::create("orderedTool/{$workspace->getName()}-{$tool->getName()}", $orderedTool);
 }
Ejemplo n.º 2
0
 /**
  * @param \Claroline\CoreBundle\Entity\Tool\Tool           $tool
  * @param int                                              $position
  * @param string                                           $name
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  *
  * @return \Claroline\CoreBundle\Entity\Tool\OrderedTool
  *
  * @throws ToolPositionAlreadyOccupiedException
  */
 public function setWorkspaceTool(Tool $tool, $position, $name, Workspace $workspace, $orderedToolType = 0)
 {
     $switchTool = null;
     $orderedTool = $this->orderedToolRepo->findOneBy(['workspace' => $workspace, 'tool' => $tool]);
     if (!$orderedTool) {
         $orderedTool = new OrderedTool();
     }
     // At the workspace creation, the workspace id is still null because we only flush once at the very end.
     if ($workspace->getId() !== null) {
         $switchTool = $this->orderedToolRepo->findOneBy(['workspace' => $workspace, 'order' => $position, 'type' => $orderedToolType]);
     }
     while (!is_null($switchTool)) {
         ++$position;
         $switchTool = $this->orderedToolRepo->findOneBy(['workspace' => $workspace, 'order' => $position, 'type' => $orderedToolType]);
     }
     $orderedTool->setWorkspace($workspace);
     $orderedTool->setName($name);
     $orderedTool->setOrder($position);
     $orderedTool->setTool($tool);
     $orderedTool->setType($orderedToolType);
     $this->om->persist($orderedTool);
     $this->om->flush();
     return $orderedTool;
 }