From: Raphaël Gertz Date: Tue, 27 Feb 2024 15:33:32 +0000 (+0100) Subject: Add google token repository X-Git-Tag: 0.3.0~63 X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/0d1506d19bdfd940084aa4dbe132383ddf9ce52b Add google token repository --- diff --git a/Repository/GoogleTokenRepository.php b/Repository/GoogleTokenRepository.php new file mode 100644 index 0000000..3ddced2 --- /dev/null +++ b/Repository/GoogleTokenRepository.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Rapsys\AirBundle\Repository; + +use Doctrine\ORM\AbstractQuery; +use Doctrine\ORM\Query\ResultSetMapping; + +use Rapsys\AirBundle\Repository; + +/** + * GoogleTokenRepository + */ +class GoogleTokenRepository extends Repository { + /** + * Find google tokens indexed by id + * + * @return array The google tokens array + */ + public function findAllIndexed(): array { + //Set the request + $req = <<tableKeys, $this->tableValues, $req); + + //Get result set mapping instance + //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php + $rsm = new ResultSetMapping(); + + //Declare all fields + //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php + //addScalarResult($sqlColName, $resColName, $type = 'string'); + $rsm + ->addScalarResult('tid', 'tid', 'integer') + ->addScalarResult('gmail', 'gmail', 'string') + ->addScalarResult('uid', 'uid', 'integer') + ->addScalarResult('access', 'access', 'string') + ->addScalarResult('refresh', 'refresh', 'string') + ->addScalarResult('expired', 'expired', 'datetime') + ->addScalarResult('cids', 'cids', 'string') + ->addScalarResult('cmails', 'cmails', 'string') + ->addScalarResult('csummaries', 'csummaries', 'string') + ->addScalarResult('csynchronizeds', 'csynchronizeds', 'string') + ->addIndexByScalar('tid'); + + //Set result array + $result = []; + + //Get tokens + $tokens = $this->_em + ->createNativeQuery($req, $rsm) + ->getArrayResult(); + + //Iterate on tokens + foreach($tokens as $tid => $token) { + //Set cids + $cids = explode("\n", $token['cids']); + + //Set cmails + $cmails = explode("\n", $token['cmails']); + + //Set csummaries + $csummaries = explode("\n", $token['csummaries']); + + //Set csynchronizeds + $csynchronizeds = array_map(function($v){return new \DateTime($v);}, explode("\n", $token['csynchronizeds'])); + + //Set result + $result[$tid] = [ + 'id' => $tid, + 'mail' => $token['gmail'], + 'uid' => $token['uid'], + 'access' => $token['access'], + 'refresh' => $token['refresh'], + 'expired' => $token['expired'], + 'calendars' => [] + ]; + + //Iterate on + foreach($cids as $k => $cid) { + $result[$tid]['calendars'][$cid] = [ + 'id' => $cid, + 'mail' => $cmails[$k], + 'summary' => $csummaries[$k], + 'synchronized' => $csynchronizeds[$k] + ]; + } + } + + //Return result + return $result; + } +}