commit 2dddc60fca75eb3350affccf8ba8b07505dd570b Author: smarcet Date: Tue Oct 13 19:16:00 2020 -0300 Added to summit payload collection dates_with_events Change-Id: I51cff8d9156e840bd7afe4ee90025fddaf752d62 Signed-off-by: smarcet diff --git a/app/ModelSerializers/Summit/SummitSerializer.php b/app/ModelSerializers/Summit/SummitSerializer.php index b7e30d5..1dd44e5 100644 --- a/app/ModelSerializers/Summit/SummitSerializer.php +++ b/app/ModelSerializers/Summit/SummitSerializer.php @@ -114,6 +114,7 @@ class SummitSerializer extends SilverStripeSerializer 'email_flows_events', 'summit_documents', 'featured_speakers', + 'dates_with_events', ]; /** @@ -131,6 +132,11 @@ class SummitSerializer extends SilverStripeSerializer $values = parent::serialize($expand, $fields, $relations, $params); if (!count($relations)) $relations = $this->getAllowedRelations(); + $values['dates_with_events'] = []; + foreach($summit->getSummitDaysWithEvents() as $day){ + $values['dates_with_events'][] = $day->format('Y-m-d'); + } + $timezone = $summit->getTimeZone(); $values['time_zone'] = null; diff --git a/app/Models/Foundation/Summit/Summit.php b/app/Models/Foundation/Summit/Summit.php index f98a13f..8127e46 100644 --- a/app/Models/Foundation/Summit/Summit.php +++ b/app/Models/Foundation/Summit/Summit.php @@ -1981,9 +1981,7 @@ SQL; */ public function getPresentationVotesCount() { - - - try { + try { $sql = <<featured_speakers->removeElement($speaker); } + /** + * @return array|DateTime[] + */ + public function getSummitDays():array { + if(is_null($this->begin_date)) return []; + if(is_null($this->end_date)) return []; + $beginDate = $this->getLocalBeginDate()->setTime(0,0,0); + $endDate = $this->getLocalEndDate()->setTime(0,0,0); + $res = []; + $res[] = clone $beginDate; + while($beginDate < $endDate){ + $res[] = clone($beginDate->modify('+1 day')); + } + return $res; + } + + /** + * @return array|DateTime[] + */ + public function getSummitDaysWithEvents():array { + $days = $this->getSummitDays(); + $list = []; + foreach ($days as $day){ + $begin = clone($day); + $begin = $begin->setTime(0,0,0); + $end = clone($day); + $end = $end->setTime(23,59,59); + $count = 0; + try { + $sql = <<= :begin and SummitEvent.EndDate <= :end) +SQL; + $stmt = $this->prepareRawSQL($sql); + $stmt->execute([ + 'summit_id' => $this->id, + 'begin' => $begin->format("Y-m-d H:i:s"), + 'end' => $end->format('Y-m-d H:i:s'), + ]); + $res = $stmt->fetchAll(\PDO::FETCH_COLUMN); + $count = count($res) > 0 ? $res[0] : 0; + } catch (\Exception $ex) { + $count = 0; + } + if($count > 0){ + $list[] = $day; + } + } + + return $list; + } + } diff --git a/tests/InsertSummitTestData.php b/tests/InsertSummitTestData.php index ffaae3f..e611927 100644 --- a/tests/InsertSummitTestData.php +++ b/tests/InsertSummitTestData.php @@ -68,7 +68,7 @@ trait InsertSummitTestData protected static function insertTestData(){ DB::setDefaultConnection("model"); - DB::table("Summit")->delete(); + //DB::table("Summit")->delete(); self::$summit_repository = EntityManager::getRepository(Summit::class); self::$summit = new Summit(); self::$summit->setActive(true); diff --git a/tests/OAuth2SummitApiTest.php b/tests/OAuth2SummitApiTest.php index 7a96098..f581d0b 100644 --- a/tests/OAuth2SummitApiTest.php +++ b/tests/OAuth2SummitApiTest.php @@ -162,11 +162,11 @@ final class OAuth2SummitApiTest extends ProtectedApiTest $this->assertResponseStatus(200); } - public function testGetSummit($summit_id = 26) + public function testGetSummit($summit_id = 31) { $params = [ - 'expand' => 'schedule', + //'expand' => 'schedule', 'id' => $summit_id ];