コード例 #1
0
ファイル: ToolManager.php プロジェクト: ngydat/CoreBundle
 /**
  * Adds the tools missing in the database for a workspace.
  * Returns an array formatted like this:
  *
  * array(
  *     'tool'          => $tool,
  *     'workspace'     => $workspace,
  *     'visibility'    => array($roleId => $bool),
  *     'position'      => ...
  *     'displayedName' => ...
  * )
  *
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  *
  * @return array
  */
 public function addMissingWorkspaceTools(Workspace $workspace, $type = 0)
 {
     $undisplayedTools = $this->toolRepo->findUndisplayedToolsByWorkspace($workspace, $type);
     if (count($undisplayedTools) === 0) {
         return;
     }
     $initPos = $this->toolRepo->countDisplayedToolsByWorkspace($workspace, $type);
     $initPos++;
     $missingTools = array();
     $wsRoles = $this->roleManager->getWorkspaceConfigurableRoles($workspace);
     $this->om->startFlushSuite();
     foreach ($undisplayedTools as $undisplayedTool) {
         $wot = $this->orderedToolRepo->findOneBy(array('workspace' => $workspace, 'tool' => $undisplayedTool, 'type' => $type));
         //create a WorkspaceOrderedTool for each Tool that hasn't already one
         if ($wot === null) {
             $this->addWorkspaceTool($undisplayedTool, $initPos, $undisplayedTool->getName(), $workspace, $type);
         } else {
             continue;
         }
         foreach ($wsRoles as $role) {
             $roleVisibility[$role->getId()] = false;
         }
         $missingTools[] = array('tool' => $undisplayedTool, 'workspace' => $workspace, 'position' => $initPos, 'visibility' => $roleVisibility, 'displayedName' => $undisplayedTool->getName());
         $initPos++;
     }
     $this->om->endFlushSuite();
     return $missingTools;
 }