Пример #1
0
 public function findWidgetPaths(array $userRoles, array $roots = array(), PathWidgetConfig $config = null)
 {
     $builder = new ResourceQueryBuilder();
     $builder->selectAsEntity(false, 'Innova\\PathBundle\\Entity\\Path\\Path');
     if (!empty($roots)) {
         $builder->whereRootIn($roots);
     }
     $builder->whereTypeIn(array('innova_path'));
     $builder->whereRoleIn($userRoles);
     // Add filters if defined
     if ($config) {
         // Add widget STATUS filters
         $statusList = $config->getStatus();
         if (!empty($statusList)) {
             $whereStatus = array();
             foreach ($statusList as $status) {
                 switch ($status) {
                     case 'draft':
                         $whereStatus[] = 'node.published = 0';
                         break;
                     case 'published':
                         $whereStatus[] = '(node.published = 1 AND resource.modified = 0)';
                         break;
                     case 'modified':
                         $whereStatus[] = '(node.published = 1 AND resource.modified = 1)';
                         break;
                 }
             }
             if (!empty($whereStatus)) {
                 $builder->addWhereClause(implode($whereStatus, ' OR '));
             }
         }
         // Add widget TAG filters
         $tagList = $config->getTags();
         if (0 < count($tagList)) {
             $tags = array();
             foreach ($tagList as $tag) {
                 $tags[] = $tag->getId();
             }
             // Join with the corresponding TaggedObject entities
             $builder->addJoinClause('LEFT JOIN ClarolineTagBundle:TaggedObject AS t WITH t.objectId = node.id');
             $builder->addWhereClause('t.id IS NOT NULL');
             $builder->addWhereClause('t.tag IN (' . implode($tags, ', ') . ')');
         }
     }
     $builder->orderByName();
     $dql = $builder->getDql();
     $query = $this->_em->createQuery($dql);
     $query->setParameters($builder->getParameters());
     $resources = $query->getResult();
     return $resources;
 }
 public function testFilters()
 {
     $qb = new ResourceQueryBuilder();
     $mockedWorkspace = $this->mock('Claroline\\CoreBundle\\Entity\\Workspace\\Workspace');
     $mockedWorkspace->shouldReceive('getId')->once()->andReturn(123);
     $mockedParent = $this->mock('Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode');
     $mockedParent->shouldReceive('getId')->once()->andReturn(456);
     $mockedUser = $this->mock('Claroline\\CoreBundle\\Entity\\User');
     $mockedUser->shouldReceive('getId')->once()->andReturn(789);
     $dql = $qb->selectAsEntity(true)->whereInWorkspace($mockedWorkspace)->whereParentIs($mockedParent)->wherePathLike('foo', false)->whereRoleIn(array('ROLE_FOO', 'ROLE_BAR'))->whereCanOpen()->whereInUserWorkspace($mockedUser)->whereTypeIn(array('baz', 'bat'))->whereRootIn(array('foo-root', 'bar-root'))->whereDateFrom('2013-03-01')->whereDateTo('2013-04-01')->whereNameLike('foobar')->whereIsExportable(true)->whereParentIsNull()->orderByPath()->groupById()->getDql();
     $eol = PHP_EOL;
     $expectedDql = "SELECT node{$eol}" . "FROM Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode node{$eol}" . "JOIN node.creator creator{$eol}" . "JOIN node.resourceType resourceType{$eol}" . "LEFT JOIN node.next next{$eol}" . "LEFT JOIN node.previous previous{$eol}" . "LEFT JOIN node.parent parent{$eol}" . "LEFT JOIN node.icon icon{$eol}" . "LEFT JOIN node.rights rights{$eol}" . "JOIN rights.role rightRole{$eol}" . "WHERE node.workspace = :workspace_id{$eol}" . "AND node.parent = :ar_parentId{$eol}" . "AND node.path LIKE :pathlike{$eol}" . "AND node.path <> :path{$eol}" . "AND {$eol}" . "({$eol}" . "    rightRole.name = :role_0{$eol}" . "    OR rightRole.name = :role_1{$eol}" . "){$eol}" . "AND BIT_AND(rights.mask, 1) = 1{$eol}" . "AND node.workspace IN{$eol}" . "({$eol}" . "    SELECT aw FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace aw{$eol}" . "    JOIN aw.roles r{$eol}" . "    WHERE r IN (SELECT r2 FROM Claroline\\CoreBundle\\Entity\\Role r2 {$eol}" . "       LEFT JOIN r2.users u {$eol}" . "       LEFT JOIN r2.groups g {$eol}" . "       LEFT JOIN g.users u2 {$eol}" . "       WHERE u.id = :user_id OR u2.id = :user_id {$eol}" . "   ) {$eol}" . ") {$eol}{$eol}" . "AND resourceType.name = :type_0{$eol}" . "OR resourceType.name = :type_1{$eol}" . "AND {$eol}" . "({$eol}" . "    node.path LIKE :root_0{$eol}" . "    OR node.path LIKE :root_1{$eol}" . "){$eol}" . "AND node.creationDate >= :dateFrom{$eol}" . "AND node.creationDate <= :dateTo{$eol}" . "AND node.name LIKE :name{$eol}" . "AND resourceType.isExportable = :isExportable{$eol}" . "AND node.parent IS NULL{$eol}" . "ORDER BY node.path{$eol}" . "GROUP BY node.id{$eol}";
     $this->assertEquals($expectedDql, $dql);
     $this->assertEquals(array(':workspace_id' => 123, ':ar_parentId' => 456, ':pathlike' => 'foo%', ':path' => 'foo', ':role_0' => 'ROLE_FOO', ':role_1' => 'ROLE_BAR', ':user_id' => 789, ':type_0' => 'baz', ':type_1' => 'bat', ':root_0' => 'foo-root%', ':root_1' => 'bar-root%', ':dateFrom' => '2013-03-01', ':dateTo' => '2013-04-01', ':name' => '%foobar%', ':isExportable' => true), $qb->getParameters());
 }
Пример #3
0
 public function findAccessibleByUser(array $roots = array(), array $userRoles)
 {
     $builder = new ResourceQueryBuilder();
     $builder->selectAsEntity(false, 'Innova\\PathBundle\\Entity\\Path\\Path');
     if (!empty($roots)) {
         $builder->whereRootIn($roots);
     }
     $builder->whereTypeIn(array('innova_path'));
     $builder->whereRoleIn($userRoles);
     $builder->orderByName();
     $dql = $builder->getDql();
     $query = $this->_em->createQuery($dql);
     $query->setParameters($builder->getParameters());
     $resources = $query->getResult();
     return $resources;
 }
Пример #4
0
 public function findByMimeTypeAndParent($mimeType, ResourceNode $parent, array $roles)
 {
     $builder = new ResourceQueryBuilder();
     if (!$this->isWorkspaceManager($parent, $roles)) {
         $dql = $builder->selectAsEntity(false, 'Claroline\\CoreBundle\\Entity\\Resource\\File')->whereParentIs($parent)->whereMimeTypeIs('%' . $mimeType . '%')->whereHasRoleIn($roles)->getDql();
     } else {
         $dql = $builder->selectAsEntity(false, 'Claroline\\CoreBundle\\Entity\\Resource\\File')->whereParentIs($parent)->whereMimeTypeIs('%' . $mimeType . '%')->getDql();
     }
     $query = $this->_em->createQuery($dql);
     $query->setParameters($builder->getParameters());
     $resources = $query->getResult();
     return $resources;
 }