51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\CustomerAppAPI;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Catalyst\ApiBundle\Component\Response as ApiResponse;
|
|
|
|
use App\Entity\MotoliteEvent;
|
|
use App\Ramcar\MotoliteEventType;
|
|
|
|
class MotoliteEventController extends ApiController
|
|
{
|
|
public function getEvents(Request $req)
|
|
{
|
|
// validate params
|
|
$validity = $this->validateRequest($req, [
|
|
'limit',
|
|
]);
|
|
|
|
if (!$validity['is_valid']) {
|
|
return new ApiResponse(false, $validity['error']);
|
|
}
|
|
|
|
$limit = $req->query->get('limit');
|
|
|
|
// get all events
|
|
$results = $this->em->getRepository(MotoliteEvent::class)
|
|
->findBy([], ['event_time' => 'asc'], $limit);
|
|
|
|
if (empty($results)) {
|
|
return new ApiResponse(false, 'No events available.');
|
|
}
|
|
|
|
$events = [];
|
|
foreach ($results as $result) {
|
|
$events[] = [
|
|
'id' => $result->getID(),
|
|
'name' => $result->getName(),
|
|
'event_type' => MotoliteEventType::getName($result->getEventType()),
|
|
'event_time' => $result->getEventTime()->format("d M Y g:i A"),
|
|
'url' => $result->getUrl(),
|
|
'image_file' => $result->getImageFile(),
|
|
];
|
|
}
|
|
|
|
// response
|
|
return new ApiResponse(true, '', [
|
|
'events' => $events,
|
|
]);
|
|
}
|
|
}
|