Ejemplo n.º 1
0
 public function searchPartialList($searches, $page, $limit, $count = false, $exclude = false)
 {
     $baseFieldsName = Group::getSearchableFields();
     $qb = $this->om->createQueryBuilder();
     $count ? $qb->select('count(g)') : $qb->select('g');
     $qb->from('Claroline\\CoreBundle\\Entity\\Group', 'g');
     //Admin can see everything, but the others... well they can only see their own organizations.
     //Cli always win aswell
     if (php_sapi_name() !== 'cli' || $this->container->get('kernel')->getEnvironment() === 'test') {
         if (!$this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
             $currentUser = $this->container->get('security.token_storage')->getToken()->getUser();
             $qb->join('g.organizations', 'go');
             $qb->join('go.administrators', 'ga');
             $qb->andWhere('ga.id = :userId');
             $qb->setParameter('userId', $currentUser->getId());
         }
     }
     foreach ($searches as $key => $search) {
         foreach ($search as $id => $el) {
             if (in_array($key, $baseFieldsName)) {
                 $string = "UPPER (g.{$key})";
                 if ($exclude) {
                     $string .= ' NOT';
                 }
                 $string .= " LIKE :{$key}{$id}";
                 $qb->andWhere($string);
                 $qb->setParameter($key . $id, '%' . strtoupper($el) . '%');
             }
         }
     }
     $query = $qb->getQuery();
     if ($page !== null && $limit !== null && !$count) {
         $query->setMaxResults($limit);
         $query->setFirstResult($page * $limit);
     }
     return $count ? $query->getSingleScalarResult() : $query->getResult();
 }
Ejemplo n.º 2
0
 /**
  * @ApiDoc(
  *     description="Returns the searchable user fields",
  *     views = {"user"}
  * )
  */
 public function getGroupSearchableFieldsAction()
 {
     $baseFields = Group::getSearchableFields();
     return $baseFields;
 }