コード例 #1
0
ファイル: ToolManager.php プロジェクト: ngydat/CoreBundle
 public function createOrderedToolByToolForAllUsers(LoggerInterface $logger, Tool $tool, $type = 0, $isVisible = true)
 {
     $toolName = $tool->getName();
     $usersQuery = $this->userRepo->findAllEnabledUsers(false);
     $users = $usersQuery->iterate();
     $this->om->startFlushSuite();
     $index = 0;
     $countUser = $this->userRepo->countAllEnabledUsers();
     $logger->info(sprintf("%d users to check tools on.", $countUser));
     foreach ($users as $row) {
         $user = $row[0];
         /** @var \Claroline\CoreBundle\Entity\Tool\OrderedTool[] $orderedTools */
         $orderedTools = $this->orderedToolRepo->findOrderedToolsByToolAndUser($tool, $user, $type);
         if (count($orderedTools) === 0) {
             $orderedTool = new OrderedTool();
             $orderedTool->setName($toolName);
             $orderedTool->setTool($tool);
             $orderedTool->setUser($user);
             $orderedTool->setVisibleInDesktop($isVisible);
             $orderedTool->setOrder(1);
             $orderedTool->setType($type);
             $this->om->persist($orderedTool);
             $index++;
             if ($index % 100 === 0) {
                 $this->om->forceFlush();
                 $this->om->clear($orderedTool);
                 $logger->info(sprintf("    %d users checked.", 100));
             }
         } else {
             $orderedTool = $orderedTools[0];
             if ($orderedTool->isVisibleInDesktop() !== $isVisible) {
                 $orderedTool->setVisibleInDesktop($isVisible);
                 $this->om->persist($orderedTool);
                 $index++;
                 if ($index % 100 === 0) {
                     $this->om->forceFlush();
                     $this->om->clear($orderedTool);
                     $logger->info(sprintf("    %d users checked.", 100));
                 }
             }
         }
     }
     if ($index % 100 !== 0) {
         $logger->info(sprintf("    %d users checked.", 100 - $index));
     }
     $this->om->endFlushSuite();
 }
コード例 #2
0
ファイル: RoleManager.php プロジェクト: ngydat/CoreBundle
 public function associateWorkspaceRolesByImport(Workspace $workspace, array $datas)
 {
     $this->om->startFlushSuite();
     $i = 1;
     foreach ($datas as $data) {
         $username = $data[0];
         $roleName = $data[1];
         $user = $this->userRepo->findOneUserByUsername($username);
         $roles = $this->roleRepo->findRolesByWorkspaceCodeAndTranslationKey($workspace->getCode(), $roleName);
         if (!is_null($user) && count($roles) > 0) {
             $this->associateRoles($user, $roles);
         }
         if ($i % 100 === 0) {
             $this->om->forceFlush();
         }
         $i++;
     }
     $this->om->endFlushSuite();
 }
コード例 #3
0
 public function getTopByCriteria($range = null, $topType = null, $max = 30)
 {
     if ($topType == null) {
         $topType = 'top_users_connections';
     }
     $listData = array();
     switch ($topType) {
         case 'top_extension':
             $listData = $this->resourceRepo->findMimeTypesWithMostResources($max);
             break;
         case 'top_workspaces_resources':
             $listData = $this->workspaceRepo->findWorkspacesWithMostResources($max);
             break;
         case 'top_workspaces_connections':
             $listData = $this->topWSByAction($range, LogWorkspaceToolReadEvent::ACTION, $max);
             break;
         case 'top_resources_views':
             $listData = $this->topResourcesByAction($range, LogResourceReadEvent::ACTION, $max);
             break;
         case 'top_resources_downloads':
             $listData = $this->topResourcesByAction($range, LogResourceExportEvent::ACTION, $max);
             break;
         case 'top_users_connections':
             $listData = $this->topUsersByAction($range, LogUserLoginEvent::ACTION, $max);
             break;
         case 'top_users_workspaces_enrolled':
             $listData = $this->userRepo->findUsersEnrolledInMostWorkspaces($max);
             break;
         case 'top_users_workspaces_owners':
             $listData = $this->userRepo->findUsersOwnersOfMostWorkspaces($max);
             break;
         case 'top_media_views':
             $listData = $this->topMediaByAction($range, LogResourceReadEvent::ACTION, $max);
             break;
     }
     return $listData;
 }
コード例 #4
0
 /**
  * @param \Claroline\CoreBundle\Entity\Group $group
  * @param array                              $users
  *
  * @return array
  */
 public function importUsers(Group $group, array $users)
 {
     $toImport = $this->userRepo->findByUsernames($users);
     return $this->addUsersToGroup($group, $toImport);
 }
コード例 #5
0
ファイル: WorkspaceManager.php プロジェクト: ChMat/CoreBundle
 /**
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  *
  * @return \Claroline\CoreBundle\Entity\User|null
  */
 public function findPersonalUser(Workspace $workspace)
 {
     $user = $this->userRepo->findBy(array('personalWorkspace' => $workspace));
     return count($user) === 1 ? $user[0] : null;
 }
コード例 #6
0
 /**
  * Imports wiki object from array
  * (see WikiImporter for structure and description).
  *
  * @param array $data
  * @param $rootPath
  * @param $loggedUser
  *
  * @return Wiki
  */
 public function importWiki(array $data, $rootPath, $loggedUser)
 {
     $wiki = new Wiki();
     if (isset($data['data'])) {
         $wikiData = $data['data'];
         $wiki->setMode($wikiData['options']['mode']);
         $sectionsMap = array();
         foreach ($wikiData['sections'] as $section) {
             $entitySection = new Section();
             $entitySection->setWiki($wiki);
             $entitySection->setDeleted($section['deleted']);
             $entitySection->setDeletionDate($section['deletion_date']);
             $entitySection->setCreationDate($section['creation_date']);
             $author = null;
             if ($section['author'] !== null) {
                 $author = $this->userRepository->findOneByUsername($section['author']);
             }
             if ($author === null) {
                 $author = $loggedUser;
             }
             $entitySection->setAuthor($author);
             $parentSection = null;
             if ($section['parent_id'] !== null) {
                 $parentSection = $sectionsMap[$section['parent_id']];
                 $entitySection->setParent($parentSection);
             }
             if ($section['is_root']) {
                 $wiki->setRoot($entitySection);
                 $this->om->persist($wiki);
             }
             foreach ($section['contributions'] as $contribution) {
                 $contributionData = $contribution['contribution'];
                 $entityContribution = new Contribution();
                 $entityContribution->setSection($entitySection);
                 $entityContribution->setTitle($contributionData['title']);
                 $entityContribution->setCreationDate($contributionData['creation_date']);
                 $contributor = null;
                 if ($contributionData['contributor'] !== null) {
                     $contributor = $this->userRepository->findOneByUsername($contributionData['contributor']);
                 }
                 if ($contributor === null) {
                     $contributor = $loggedUser;
                 }
                 $entityContribution->setContributor($contributor);
                 $text = file_get_contents($rootPath . DIRECTORY_SEPARATOR . $contributionData['path']);
                 $entityContribution->setText($text);
                 if ($contributionData['is_active']) {
                     $entitySection->setActiveContribution($entityContribution);
                     if ($parentSection !== null) {
                         $this->sectionRepository->persistAsLastChildOf($entitySection, $parentSection);
                     } else {
                         $this->sectionRepository->persistAsFirstChild($entitySection);
                     }
                 }
                 $this->om->persist($entityContribution);
             }
             $sectionsMap[$section['id']] = $entitySection;
         }
     }
     return $wiki;
 }