From a57b59820d70980c7b46d0c60fe466c867163a4d Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Sat, 9 Dec 2017 13:55:29 -0300 Subject: [PATCH] Added event publishing to TBD location Change-Id: If7cf20bb681da3deebd7e8f93deb0b486fb72eb8 --- .../OAuth2SummitLocationsApiController.php | 30 ++++---- app/Http/Utils/Filters/Filter.php | 14 +++- app/Http/routes.php | 4 +- .../Repositories/ISummitEventRepository.php | 8 +++ .../Summit/DoctrineSummitEventRepository.php | 70 ++++++++++++++++++- app/Services/Model/SummitService.php | 13 ++-- tests/OAuth2SummitApiTest.php | 32 +++++++++ 7 files changed, 145 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php index 864f68c4..f716af68 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitLocationsApiController.php @@ -135,7 +135,7 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController /** * @param string $summit_id - * @param int $location_id + * @param string $location_id * @param bool $published * @return PagingResponse * @throws EntityNotFoundException @@ -147,17 +147,19 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController if (is_null($summit)) throw new EntityNotFoundException; - $location = $summit->getLocation($location_id); - if (is_null($location)) - throw new EntityNotFoundException; + if(strtolower($location_id) != "tbd") { + $location = $summit->getLocation(intval($location_id)); + if (is_null($location)) + throw new EntityNotFoundException; + } $values = Input::all(); - $rules = array - ( + $rules = + [ 'page' => 'integer|min:1', 'per_page' => 'required_with:page|integer|min:5|max:100', - ); + ]; $validation = Validator::make($values, $rules); @@ -206,14 +208,19 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController if(is_null($filter)) $filter = new Filter(); - $filter->addFilterCondition(FilterParser::buildFilter('location_id','==', $location_id)); + $filter->addFilterCondition(FilterParser::buildFilter('summit_id','==', $summit_id)); + + if(intval($location_id) > 0) + $filter->addFilterCondition(FilterParser::buildFilter('location_id','==', $location_id)); if($published) { $filter->addFilterCondition(FilterParser::buildFilter('published','==', 1)); } - return $this->event_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order); + return strtolower($location_id) == "tbd" ? + $this->event_repository->getAllByPageLocationTBD(new PagingInfo($page, $per_page), $filter, $order): + $this->event_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order); } /** @@ -252,7 +259,6 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController public function getLocationPublishedEvents($summit_id, $location_id) { try { - return $this->ok($this->_getLocationEvents($summit_id, $location_id, true)->toArray(Request::input('expand', ''))); } catch (EntityNotFoundException $ex1) { @@ -263,10 +269,6 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController Log::warning($ex2); return $this->error412($ex2->getMessages()); } - catch(FilterParserException $ex3){ - Log::warning($ex3); - return $this->error412($ex3->getMessages()); - } catch (Exception $ex) { Log::error($ex); return $this->error500($ex); diff --git a/app/Http/Utils/Filters/Filter.php b/app/Http/Utils/Filters/Filter.php index 64b7cfd5..6e7a4fc0 100644 --- a/app/Http/Utils/Filters/Filter.php +++ b/app/Http/Utils/Filters/Filter.php @@ -54,7 +54,7 @@ final class Filter */ public function getFilter($field) { - $res = array(); + $res = []; foreach ($this->filters as $filter) { if ($filter instanceof FilterElement && $filter->getField() === $field) { @@ -62,7 +62,7 @@ final class Filter } else if (is_array($filter)) { // OR - $or_res = array(); + $or_res = []; foreach ($filter as $e) { if ($e instanceof FilterElement && $e->getField() === $field) { $or_res[] = $e; @@ -74,6 +74,16 @@ final class Filter return $res; } + /** + * @param string $field + * @return null|FilterElement + */ + public function getUniqueFilter($field){ + $res = $this->getFilter($field); + return count($res) == 1 ? $res[0]:null; + } + + /** * @param string $field * @return bool diff --git a/app/Http/routes.php b/app/Http/routes.php index e50a949b..1eba2d33 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -244,8 +244,8 @@ Route::group([ Route::get('/airports', 'OAuth2SummitLocationsApiController@getAirports'); Route::group(array('prefix' => '{location_id}'), function () { Route::get('', 'OAuth2SummitLocationsApiController@getLocation'); - Route::get('/events/published','OAuth2SummitLocationsApiController@getLocationPublishedEvents'); - Route::get('/events','OAuth2SummitLocationsApiController@getLocationEvents'); + Route::get('/events/published','OAuth2SummitLocationsApiController@getLocationPublishedEvents')->where('location_id', 'tbd|[0-9]+'); + Route::get('/events','OAuth2SummitLocationsApiController@getLocationEvents')->where('location_id', 'tbd|[0-9]+'); }); }); diff --git a/app/Models/Foundation/Summit/Repositories/ISummitEventRepository.php b/app/Models/Foundation/Summit/Repositories/ISummitEventRepository.php index 83877a9a..be2387da 100644 --- a/app/Models/Foundation/Summit/Repositories/ISummitEventRepository.php +++ b/app/Models/Foundation/Summit/Repositories/ISummitEventRepository.php @@ -38,6 +38,14 @@ interface ISummitEventRepository extends IBaseRepository */ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null); + /** + * @param PagingInfo $paging_info + * @param Filter|null $filter + * @param Order|null $order + * @return PagingResponse + */ + public function getAllByPageLocationTBD(PagingInfo $paging_info, Filter $filter = null, Order $order = null); + /** * @param int $event_id */ diff --git a/app/Repositories/Summit/DoctrineSummitEventRepository.php b/app/Repositories/Summit/DoctrineSummitEventRepository.php index e5cc3560..13de1c22 100644 --- a/app/Repositories/Summit/DoctrineSummitEventRepository.php +++ b/app/Repositories/Summit/DoctrineSummitEventRepository.php @@ -168,14 +168,14 @@ final class DoctrineSummitEventRepository public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null) { $class = $filter->hasFilter('speaker') - || $filter->hasFilter('selection_status') - || $filter->hasFilter('speaker_email')? + || $filter->hasFilter('selection_status') + || $filter->hasFilter('speaker_email')? \models\summit\Presentation::class: \models\summit\SummitEvent::class; $query = $this->getEntityManager()->createQueryBuilder() ->select("e") - ->from($class, "e"); + ->from($class, "e")->leftJoin("e.location", 'l', Join::LEFT_JOIN); if(!is_null($filter)){ $filter->apply2Query($query, $this->getFilterMappings()); @@ -240,4 +240,68 @@ final class DoctrineSummitEventRepository { return SummitEvent::class; } + + /** + * @param PagingInfo $paging_info + * @param Filter|null $filter + * @param Order|null $order + * @return PagingResponse + */ + public function getAllByPageLocationTBD(PagingInfo $paging_info, Filter $filter = null, Order $order = null) + { + $class = $filter->hasFilter('speaker') + || $filter->hasFilter('selection_status') + || $filter->hasFilter('speaker_email')? + \models\summit\Presentation::class: + \models\summit\SummitEvent::class; + + $query = $this->getEntityManager()->createQueryBuilder() + ->select("e") + ->from($class, "e") + ->leftJoin("e.location", 'l', Join::LEFT_JOIN) + ->where("l.id is null"); + + if(!is_null($filter)){ + $filter->apply2Query($query, $this->getFilterMappings()); + } + + if (!is_null($order)) { + $order->apply2Query($query, $this->getOrderMappings()); + } else { + //default order + $query = $query->addOrderBy("e.start_date",'ASC'); + $query = $query->addOrderBy("e.end_date", 'ASC'); + } + + if($class == \models\summit\Presentation::class) { + $query = $query->innerJoin("e.category", "cc", Join::WITH); + $query = $query->leftJoin("e.speakers", "sp", Join::WITH); + $query = $query->leftJoin('e.selected_presentations', "ssp", Join::LEFT_JOIN); + $query = $query->leftJoin('ssp.list', "sspl", Join::LEFT_JOIN); + $query = $query->leftJoin('e.moderator', "spm", Join::LEFT_JOIN); + $query = $query->leftJoin('sp.member', "spmm", Join::LEFT_JOIN); + $query = $query->leftJoin('sp.registration_request', "sprr", Join::LEFT_JOIN); + } + + $query = $query + ->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')") + ->setFirstResult($paging_info->getOffset()) + ->setMaxResults($paging_info->getPerPage()); + + $paginator = new Paginator($query, $fetchJoinCollection = true); + $total = $paginator->count(); + $data = []; + + foreach($paginator as $entity) + $data[]= $entity; + + return new PagingResponse + ( + $total, + $paging_info->getPerPage(), + $paging_info->getCurrentPage(), + $paging_info->getLastPage($total), + $data + ); + } } \ No newline at end of file diff --git a/app/Services/Model/SummitService.php b/app/Services/Model/SummitService.php index 79a28402..85a6f81d 100644 --- a/app/Services/Model/SummitService.php +++ b/app/Services/Model/SummitService.php @@ -810,16 +810,19 @@ final class SummitService implements ISummitService throw new ValidationException(sprintf("end_date its not assigned to event id %s!", $event_id)); if (isset($data['location_id'])) { - $location = $summit->getLocation(intval($data['location_id'])); - if (is_null($location)) - throw new EntityNotFoundException(sprintf("location id %s does not exists!", $data['location_id'])); - $event->setLocation($location); + $location_id = intval($data['location_id']); + $event->clearLocation(); + if($location_id > 0){ + $location = $summit->getLocation($location_id); + if (is_null($location)) + throw new EntityNotFoundException(sprintf("location id %s does not exists!", $data['location_id'])); + $event->setLocation($location); + } } $this->validateBlackOutTimesAndTimes($event); $event->unPublish(); $event->publish(); - $this->event_repository->add($event); return $event; }); diff --git a/tests/OAuth2SummitApiTest.php b/tests/OAuth2SummitApiTest.php index cb42b2e6..ad99218e 100644 --- a/tests/OAuth2SummitApiTest.php +++ b/tests/OAuth2SummitApiTest.php @@ -1973,6 +1973,38 @@ final class OAuth2SummitApiTest extends ProtectedApiTest $this->assertTrue(!is_null($events)); } + public function testCurrentSummitPublishedLocationTBAEvents() + { + $params = array + ( + 'id' => 23, + 'location_id' => "tba", + ); + + $headers = array + ( + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ); + + $response = $this->action + ( + "GET", + "OAuth2SummitLocationsApiController@getLocationPublishedEvents", + $params, + array(), + array(), + array(), + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(200); + + $events = json_decode($content); + $this->assertTrue(!is_null($events)); + } + public function testAddPresentationVideo($summit_id = 7, $presentation_id = 15404) { $params = array