Skip to content
Permalink
Browse files

adding new api method getReports

  • Loading branch information...
teiling88 committed Aug 28, 2017
1 parent 1691e57 commit a56f8716f0bc47bd175c0dbaf207ae929697ab90
@@ -17,3 +17,4 @@ parameters:

# A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt
api_secret: ThisTokenIsNotSoSecretChangeIt
@@ -37,4 +37,6 @@ services:
oc.translation.crowdin_import:
class: OcBundle\Translation\CrowdinImport
arguments: ['@oc.util.dbal_connection']

oc.geo_cache.reports:
class: Oc\GeoCache\Reports
arguments: ['@oc.util.dbal_connection']
@@ -0,0 +1,33 @@
<?php
namespace AppBundle\Controller;
use Oc\GeoCache\Reports;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class ApiGeocacheController extends Controller
{
/**
* @Route("/api/geocache/getReports")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getReportsAction(Request $request)
{
if ($request->get('key') !== $this->container->getParameter('api_secret')) {
return new JsonResponse([]);
}
/** @var Reports $reports */
$reports = $this->container->get('oc.geo_cache.reports');
$geoCachesArray = explode('|', $request->get('geocaches'));
$geoCaches = $reports->getReportStatus($geoCachesArray);
return new JsonResponse($geoCaches);
}
}
@@ -0,0 +1,42 @@
<?php
namespace Oc\GeoCache;
use Doctrine\DBAL\Connection;
use Oc\Util\DbalConnection;
class Reports
{
/**
* @var DbalConnection
*/
private $connection;
/**
* @param DbalConnection $connection
*/
public function __construct(DbalConnection $connection)
{
$this->connection = $connection;
}
/**
* @param array $wpCodes
* @return array
*/
public function getReportStatus(array $wpCodes)
{
$query = $this->connection->getQueryBuilder()
->select('DISTINCT(wp_oc)')
->from('caches', 'c')
->innerJoin('c', 'cache_reports', 'cr', 'cr.cacheid = c.cache_id')
->where('wp_oc IN (:wpCodes)')
->andWhere('cr.status IN (:status)')
->setParameter(':wpCodes', $wpCodes, Connection::PARAM_STR_ARRAY)
->setParameter(':status', [1, 2], Connection::PARAM_INT_ARRAY);
$statement = $query->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
}

0 comments on commit a56f871

Please sign in to comment.
You can’t perform that action at this time.