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 {
43 GROUP_CONCAT(us.subscribed_id ORDER BY us.subscribed_id SEPARATOR "\\n") AS sids
56 GROUP_CONCAT(ud.dance_id ORDER BY ud.dance_id SEPARATOR "\\n") AS dids
65 GROUP_CONCAT(c.id ORDER BY c.id SEPARATOR "\\n") AS cids,
66 GROUP_CONCAT(c.mail ORDER BY c.id SEPARATOR "\\n") AS cmails,
67 GROUP_CONCAT(c.summary ORDER BY c.id SEPARATOR "\\n") AS csummaries,
68 GROUP_CONCAT(IFNULL(c.synchronized, 'NULL') ORDER BY c.id SEPARATOR "\\n") AS csynchronizeds
69 FROM Rapsys\AirBundle\Entity\GoogleToken AS t
70 JOIN Rapsys\AirBundle\Entity\GoogleCalendar AS c ON (c.google_token_id = t.id)
74 LEFT JOIN Rapsys\AirBundle\Entity\UserDance AS ud ON (ud.user_id = a.uid)
76 LEFT JOIN Rapsys\AirBundle\Entity\UserSubscription AS us ON (us.user_id = b.uid)
79 //Replace bundle entity name by table name
80 $req = str_replace($this->tableKeys
, $this->tableValues
, $req);
82 //Get result set mapping instance
83 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
84 $rsm = new ResultSetMapping();
87 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
88 //addScalarResult($sqlColName, $resColName, $type = 'string');
90 ->addScalarResult('tid', 'tid', 'integer')
91 ->addScalarResult('gmail', 'gmail', 'string')
92 ->addScalarResult('uid', 'uid', 'integer')
93 ->addScalarResult('access', 'access', 'string')
94 ->addScalarResult('refresh', 'refresh', 'string')
95 ->addScalarResult('expired', 'expired', 'datetime')
96 ->addScalarResult('cids', 'cids', 'string')
97 ->addScalarResult('cmails', 'cmails', 'string')
98 ->addScalarResult('csummaries', 'csummaries', 'string')
99 ->addScalarResult('csynchronizeds', 'csynchronizeds', 'string')
100 ->addScalarResult('dids', 'dids', 'string')
101 ->addScalarResult('sids', 'sids', 'string')
102 ->addIndexByScalar('tid');
109 ->createNativeQuery($req, $rsm)
113 foreach($tokens as $tid => $token) {
115 $cids = explode("\n", $token['cids']);
118 $cmails = explode("\n", $token['cmails']);
121 $csummaries = explode("\n", $token['csummaries']);
124 $csynchronizeds = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $token['csynchronizeds']));
129 'mail' => $token['gmail'],
130 'uid' => $token['uid'],
131 'access' => $token['access'],
132 'refresh' => $token['refresh'],
133 'expired' => $token['expired'],
136 'subscriptions' => []
139 //Iterate on calendars
140 foreach($cids as $k => $cid) {
141 $result[$tid]['calendars'][$cid] = [
143 'mail' => $cmails[$k],
144 'summary' => $csummaries[$k],
145 'synchronized' => $csynchronizeds[$k]
150 $dids = explode("\n", $token['dids']);
153 foreach($dids as $k => $did) {
154 $result[$tid]['dances'][$did] = [
160 $sids = explode("\n", $token['sids']);
162 //Iterate on subscriptions
163 foreach($sids as $k => $sid) {
164 $result[$tid]['subscriptions'][$sid] = [