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;
 }
示例#2
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;
 }