1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle 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\AirBundle\Repository
;
14 use Doctrine\ORM\AbstractQuery
;
15 use Doctrine\ORM\Query\ResultSetMapping
;
17 use Rapsys\AirBundle\Repository
;
20 * GoogleTokenRepository
22 class GoogleTokenRepository
extends Repository
{
24 * Find google tokens indexed by id
26 * @return array The google tokens array
28 public function findAllIndexed(): array {
38 GROUP_CONCAT(c.id ORDER BY c.id SEPARATOR "\\n") AS cids,
39 GROUP_CONCAT(c.mail ORDER BY c.id SEPARATOR "\\n") AS cmails,
40 GROUP_CONCAT(c.summary ORDER BY c.id SEPARATOR "\\n") AS csummaries,
41 GROUP_CONCAT(IFNULL(c.synchronized, 'NULL') ORDER BY c.id SEPARATOR "\\n") AS csynchronizeds
42 FROM Rapsys\AirBundle\Entity\GoogleToken AS t
43 JOIN Rapsys\AirBundle\Entity\GoogleCalendar AS c ON (c.google_token_id = t.id)
48 //Replace bundle entity name by table name
49 $req = str_replace($this->tableKeys
, $this->tableValues
, $req);
51 //Get result set mapping instance
52 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
53 $rsm = new ResultSetMapping();
56 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
57 //addScalarResult($sqlColName, $resColName, $type = 'string');
59 ->addScalarResult('tid', 'tid', 'integer')
60 ->addScalarResult('gmail', 'gmail', 'string')
61 ->addScalarResult('uid', 'uid', 'integer')
62 ->addScalarResult('access', 'access', 'string')
63 ->addScalarResult('refresh', 'refresh', 'string')
64 ->addScalarResult('expired', 'expired', 'datetime')
65 ->addScalarResult('cids', 'cids', 'string')
66 ->addScalarResult('cmails', 'cmails', 'string')
67 ->addScalarResult('csummaries', 'csummaries', 'string')
68 ->addScalarResult('csynchronizeds', 'csynchronizeds', 'string')
69 ->addIndexByScalar('tid');
76 ->createNativeQuery($req, $rsm)
80 foreach($tokens as $tid => $token) {
82 $cids = explode("\n", $token['cids']);
85 $cmails = explode("\n", $token['cmails']);
88 $csummaries = explode("\n", $token['csummaries']);
91 $csynchronizeds = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $token['csynchronizeds']));
96 'mail' => $token['gmail'],
97 'uid' => $token['uid'],
98 'access' => $token['access'],
99 'refresh' => $token['refresh'],
100 'expired' => $token['expired'],
105 foreach($cids as $k => $cid) {
106 $result[$tid]['calendars'][$cid] = [
108 'mail' => $cmails[$k],
109 'summary' => $csummaries[$k],
110 'synchronized' => $csynchronizeds[$k]