1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys UserBundle package. 
   6  * (c) Raphaël Gertz <symfony@rapsys.eu> 
   8  * For the full copyright and license information, please view the LICENSE 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\UserBundle\Repository
; 
  14 use Doctrine\ORM\Query\ResultSetMapping
; 
  15 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
; 
  20 class UserRepository 
extends EntityRepository 
{ 
  22          * Find user count as int 
  24          * @return integer The keywords count 
  26         public function findCountAsInt(): int { 
  29 SELECT COUNT(u.id) AS count 
  30 FROM RapsysUserBundle:User AS u 
  33                 //Get result set mapping instance 
  34                 $req = $this->replace($req); 
  36                 //Get result set mapping instance 
  37                 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php 
  38                 $rsm = new ResultSetMapping(); 
  41                 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php 
  42                 //addScalarResult($sqlColName, $resColName, $type = 'string'); 
  43                 $rsm->addScalarResult('count', 'count', 'integer'); 
  47                         ->createNativeQuery($req, $rsm) 
  48                         ->getSingleScalarResult(); 
  52          * Find all users as array 
  54          * @param integer $page The page 
  55          * @param integer $count The count 
  56          * @return array The users sorted by id 
  58         public function findAllAsArray(int $page, int $count): array { 
  66         CONCAT_WS(" ", u.forename, u.surname) AS pseudonym, 
  69         GROUP_CONCAT(g.id ORDER BY g.id SEPARATOR "\\n") AS g_ids, 
  70         GROUP_CONCAT(g.title ORDER BY g.id SEPARATOR "\\n") AS g_titles 
  71 FROM RapsysUserBundle:User AS u 
  72 JOIN RapsysUserBundle:UserGroup AS gu ON (gu.user_id = u.id) 
  73 JOIN RapsysUserBundle:Group AS g ON (g.id = gu.group_id) 
  74 JOIN RapsysUserBundle:Civility AS c ON (c.id = u.civility_id) 
  80                 //Replace bundle entity name by table name 
  81                 $req = $this->replace($req); 
  83                 //Get result set mapping instance 
  84                 //XXX: DEBUG: see ../blog.orig/src/Rapsys/UserBundle/Repository/ArticleRepository.php 
  85                 $rsm = new ResultSetMapping(); 
  88                 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php 
  89                 //addScalarResult($sqlColName, $resColName, $type = 'string'); 
  90                 $rsm->addScalarResult('id', 'id', 'integer') 
  91                         ->addScalarResult('mail', 'mail', 'string') 
  92                         ->addScalarResult('forename', 'forename', 'string') 
  93                         ->addScalarResult('surname', 'surname', 'string') 
  94                         ->addScalarResult('pseudonym', 'pseudonym', 'string') 
  95                         ->addScalarResult('c_id', 'c_id', 'integer') 
  96                         ->addScalarResult('c_title', 'c_title', 'string') 
  97                         //XXX: is a string because of \n separator 
  98                         ->addScalarResult('g_ids', 'g_ids', 'string') 
  99                         //XXX: is a string because of \n separator 
 100                         ->addScalarResult('g_titles', 'g_titles', 'string'); 
 104                         ->createNativeQuery($req, $rsm) 
 105                         ->setParameter('offset', $page * $count) 
 106                         ->setParameter('count', $count) 
 113                 foreach($res as $data) { 
 115                         $ret[$data['id']] = [ 
 116                                 'mail' => $data['mail'], 
 117                                 'forename' => $data['forename'], 
 118                                 'surname' => $data['surname'], 
 119                                 'pseudonym' => $data['pseudonym'], 
 121                                 'slug' => $this->slugger
->slug($data['pseudonym']), 
 122                                 'link' => $this->router
->generate('rapsys_user_edit', ['mail' => $short = $this->slugger
->short($data['mail']), 'hash' => $this->slugger
->hash($short)]) 
 126                         if (!empty($data['g_ids'])) { 
 128                                 $titles = explode("\n", $data['g_titles']); 
 130                                 //Iterate on each group 
 131                                 foreach(explode("\n", $data['g_ids']) as $k => $id) { 
 133                                         $ret[$data['id']]['groups'][$id] = [ 
 134                                                 'title' => $group = $this->translator
->trans($titles[$k]), 
 135                                                 #'slug' => $this->slugger->slug($group) 
 136                                                 #'link' => $this->router->generate('rapsys_user_group_view', ['id' => $id, 'slug' => $this->slugger->short($group)])