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 {
44 GROUP_CONCAT(us.subscribed_id ORDER BY us.subscribed_id SEPARATOR "\\n") AS sids
58 GROUP_CONCAT(ud.dance_id ORDER BY ud.dance_id SEPARATOR "\\n") AS dids
68 GROUP_CONCAT(c.id ORDER BY c.id SEPARATOR "\\n") AS cids,
69 GROUP_CONCAT(c.mail ORDER BY c.id SEPARATOR "\\n") AS cmails,
70 GROUP_CONCAT(c.summary ORDER BY c.id SEPARATOR "\\n") AS csummaries,
71 GROUP_CONCAT(IFNULL(c.synchronized, 'NULL') ORDER BY c.id SEPARATOR "\\n") AS csynchronizeds
72 FROM Rapsys\AirBundle\Entity\GoogleToken AS t
73 JOIN Rapsys\AirBundle\Entity\GoogleCalendar AS c ON (c.google_token_id = t.id)
77 LEFT JOIN Rapsys\AirBundle\Entity\UserDance AS ud ON (ud.user_id = a.uid)
79 LEFT JOIN Rapsys\AirBundle\Entity\UserSubscription AS us ON (us.user_id = b.uid)
82 //Replace bundle entity name by table name
83 $req = str_replace($this->tableKeys
, $this->tableValues
, $req);
85 //Get result set mapping instance
86 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
87 $rsm = new ResultSetMapping();
90 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
91 //addScalarResult($sqlColName, $resColName, $type = 'string');
93 ->addScalarResult('tid', 'tid', 'integer')
94 ->addScalarResult('gmail', 'gmail', 'string')
95 ->addScalarResult('uid', 'uid', 'integer')
96 ->addScalarResult('access', 'access', 'string')
97 ->addScalarResult('refresh', 'refresh', 'string')
98 ->addScalarResult('created', 'created', 'datetime')
99 ->addScalarResult('expired', 'expired', 'datetime')
100 ->addScalarResult('cids', 'cids', 'string')
101 ->addScalarResult('cmails', 'cmails', 'string')
102 ->addScalarResult('csummaries', 'csummaries', 'string')
103 ->addScalarResult('csynchronizeds', 'csynchronizeds', 'string')
104 ->addScalarResult('dids', 'dids', 'string')
105 ->addScalarResult('sids', 'sids', 'string')
106 ->addIndexByScalar('tid');
113 ->createNativeQuery($req, $rsm)
117 foreach($tokens as $tid => $token) {
119 $cids = explode("\n", $token['cids']);
122 $cmails = explode("\n", $token['cmails']);
125 $csummaries = explode("\n", $token['csummaries']);
128 $csynchronizeds = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $token['csynchronizeds']));
133 'mail' => $token['gmail'],
134 'uid' => $token['uid'],
135 'access' => $token['access'],
136 'refresh' => $token['refresh'],
137 'created' => $token['created'],
138 'expired' => $token['expired'],
141 'subscriptions' => []
144 //Iterate on calendars
145 foreach($cids as $k => $cid) {
146 $result[$tid]['calendars'][$cid] = [
148 'mail' => $cmails[$k],
149 'summary' => $csummaries[$k],
150 'synchronized' => $csynchronizeds[$k]
155 $dids = explode("\n", $token['dids']);
158 foreach($dids as $k => $did) {
159 $result[$tid]['dances'][$did] = [
165 $sids = explode("\n", $token['sids']);
167 //Iterate on subscriptions
168 foreach($sids as $k => $sid) {
169 $result[$tid]['subscriptions'][$sid] = [