Added summit booking period

new fields for summit entity

* begin_allow_booking_date
* end_allow_booking_date

Change-Id: Ib4c297eaaf7d01bc3418c582e57f4c0a1e779d60
This commit is contained in:
smarcet 2019-12-11 21:49:15 -03:00
parent d02e2d9fec
commit 1ae6937966
9 changed files with 201 additions and 28 deletions

View File

@ -49,6 +49,8 @@ final class SummitValidationRulesFactory
'api_feed_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
'api_feed_key' => 'nullable|string|required_with:api_feed_type',
'begin_allow_booking_date' => 'nullable|date_format:U',
'end_allow_booking_date' => 'nullable|required_with:begin_allow_booking_date|date_format:U|after_or_equal:begin_allow_booking_date',
];
}
@ -80,6 +82,8 @@ final class SummitValidationRulesFactory
'api_feed_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
'api_feed_key' => 'nullable|string|required_with:api_feed_type',
'begin_allow_booking_date' => 'nullable|date_format:U',
'end_allow_booking_date' => 'nullable|required_with:begin_allow_booking_date|date_format:U|after_or_equal:begin_allow_booking_date',
];
}
}

View File

@ -11,7 +11,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\ORM\QueryBuilder;
/**
* Class DoctrineHavingFilterMapping
* @package utils
@ -27,6 +29,7 @@ class DoctrineHavingFilterMapping extends DoctrineFilterMapping
* @var string
*/
protected $having;
/**
* DoctrineFilterMapping constructor.
* @param string $condition
@ -35,7 +38,7 @@ class DoctrineHavingFilterMapping extends DoctrineFilterMapping
{
parent::__construct($condition);
$this->groupBy = $groupBy;
$this->having = $having;
$this->having = $having;
}
/**
@ -43,34 +46,57 @@ class DoctrineHavingFilterMapping extends DoctrineFilterMapping
* @param FilterElement $filter
* @return QueryBuilder
*/
public function apply(QueryBuilder $query, FilterElement $filter){
$param_count = $query->getParameters()->count() + 1;
public function apply(QueryBuilder $query, FilterElement $filter)
{
$param_count = $query->getParameters()->count();
$where = $this->where;
$has_param = false;
$value = $filter->getValue();
if(strstr($where,":value")) {
$where = str_replace(":value", ":value_" . $param_count, $where);
$has_param = true;
$value = $filter->getValue();
if (!empty($where)) {
if (strstr($where, ":value")) {
++$param_count;
$where = str_replace(":value", ":value_" . $param_count, $where);
$has_param = true;
}
if (strstr($where, ":operator"))
$where = str_replace(":operator", $filter->getOperator(), $where);
$query = $query->andWhere($where);
if ($has_param) {
$query = $query->setParameter(":value_" . $param_count, $value);
}
}
if(strstr($where,":operator"))
$where = str_replace(":operator", $filter->getOperator(), $where);
$query = $query->andWhere($where);
if($has_param){
$query = $query->setParameter(":value_".$param_count, $value);
if (!empty($this->groupBy)) {
$query = $query->addGroupBy($this->groupBy);
}
$query = $query->addGroupBy($this->groupBy);
if (!empty($this->having)) {
$has_param = false;
if (strstr($this->having, ":value_count") && is_array($value)) {
$this->having = str_replace(":value_count", count($value), $this->having);
}
if(strstr($this->having,":value_count") && is_array($value)){
$this->having = str_replace(":value_count", count($value), $this->having);
if (strstr($this->having, ":value")) {
++$param_count;
$this->having = str_replace(":value", ":value_" . $param_count, $this->having);
$has_param = true;
}
if (strstr($this->having, ":operator"))
$this->having = str_replace(":operator", $filter->getOperator(), $this->having);
if ($has_param) {
$query = $query->setParameter(":value_" . $param_count, $value);
}
$query = $query->andHaving($this->having);
}
$query = $query->andHaving($this->having);
return $query;
}
}

View File

@ -26,5 +26,9 @@ final class AdminSummitSerializer extends SummitSerializer
'ExternalSummitId' => 'external_summit_id:json_string',
'CalendarSyncName' => 'calendar_sync_name:json_string',
'CalendarSyncDesc' => 'calendar_sync_desc:json_string',
// External Feeds
'ApiFeedType' => 'api_feed_type:json_string',
'ApiFeedUrl' => 'api_feed_url:json_string',
'ApiFeedKey' => 'api_feed_key:json_string',
];
}

View File

@ -57,10 +57,8 @@ class SummitSerializer extends SilverStripeSerializer
'MeetingRoomBookingEndTime' => 'meeting_room_booking_end_time:datetime_epoch',
'MeetingRoomBookingSlotLength' => 'meeting_room_booking_slot_length:json_int',
'MeetingRoomBookingMaxAllowed' => 'meeting_room_booking_max_allowed:json_int',
// External Feeds
'ApiFeedType' => 'api_feed_type:json_string',
'ApiFeedUrl' => 'api_feed_url:json_string',
'ApiFeedKey' => 'api_feed_key:json_string',
'BeginAllowBookingDate' => 'begin_allow_booking_date:datetime_epoch',
'EndAllowBookingDate' => 'end_allow_booking_date:datetime_epoch',
];
protected static $allowed_relations = [

View File

@ -69,6 +69,23 @@ final class SummitFactory
$summit->setCalendarSyncDesc(trim($data['calendar_sync_desc']));
}
if(array_key_exists('begin_allow_booking_date', $data) && array_key_exists('end_allow_booking_date', $data)) {
if (isset($data['begin_allow_booking_date']) && isset($data['end_allow_booking_date'])) {
$start_datetime = intval($data['begin_allow_booking_date']);
$start_datetime = new \DateTime("@$start_datetime");
$start_datetime->setTimezone($summit->getTimeZone());
$end_datetime = intval($data['end_allow_booking_date']);
$end_datetime = new \DateTime("@$end_datetime");
$end_datetime->setTimezone($summit->getTimeZone());
// set local time from UTC
$summit->setBeginAllowBookingDate($start_datetime);
$summit->setEndAllowBookingDate($end_datetime);
}
else{
$summit->clearAllowBookingDates();
}
}
if(array_key_exists('start_date', $data) && array_key_exists('end_date', $data)) {
if (isset($data['start_date']) && isset($data['end_date'])) {
$start_datetime = intval($data['start_date']);

View File

@ -67,8 +67,10 @@ class SummitBookableVenueRoom extends SummitVenueRoom
*/
public function addReservation(SummitRoomReservation $reservation){
$criteria = Criteria::create();
if(!$this->summit->isBookingPeriodOpen())
throw new ValidationException(sprintf("booking period is not open for summit %s", $this->summit->getId()));
$criteria = Criteria::create();
$start_date = $reservation->getStartDatetime();
$end_date = $reservation->getEndDatetime();

View File

@ -200,6 +200,18 @@ class Summit extends SilverstripeBaseModel
*/
private $meeting_booking_room_allowed_attributes;
/**
* @ORM\Column(name="BeginAllowBookingDate", type="datetime")
* @var \DateTime
*/
private $begin_allow_booking_date;
/**
* @ORM\Column(name="EndAllowBookingDate", type="datetime")
* @var \DateTime
*/
private $end_allow_booking_date;
/**
* @ORM\OneToMany(targetEntity="SummitEvent", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY")
*/
@ -2738,4 +2750,51 @@ SQL;
$this->api_feed_key = $api_feed_key;
}
/**
* @return DateTime
*/
public function getBeginAllowBookingDate(): ?DateTime
{
return $this->begin_allow_booking_date;
}
/**
* @param DateTime $begin_allow_booking_date
*/
public function setBeginAllowBookingDate(DateTime $begin_allow_booking_date): void
{
$this->begin_allow_booking_date = $begin_allow_booking_date;
}
/**
* @return DateTime
*/
public function getEndAllowBookingDate(): ?DateTime
{
return $this->end_allow_booking_date;
}
/**
* @param DateTime $end_allow_booking_date
*/
public function setEndAllowBookingDate(DateTime $end_allow_booking_date): void
{
$this->end_allow_booking_date = $end_allow_booking_date;
}
public function clearAllowBookingDates():void{
$this->begin_allow_booking_date = $this->end_allow_booking_date = null;
}
/**
* @return bool
*/
public function isBookingPeriodOpen():bool{
$now_utc = new \DateTime('now', new \DateTimeZone('UTC'));
if(!is_null($this->begin_allow_booking_date) && !is_null($this->end_allow_booking_date)){
return $now_utc >= $this->begin_allow_booking_date && $now_utc <= $this->end_allow_booking_date;
}
return false;
}
}

View File

@ -1,7 +1,16 @@
<?php
namespace Database\Migrations\Model;
<?php namespace Database\Migrations\Model;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;

View File

@ -0,0 +1,54 @@
<?php
namespace Database\Migrations\Model;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\Migrations\Schema\Builder;
use LaravelDoctrine\Migrations\Schema\Table;
/**
* Class Version20191212002736
* @package Database\Migrations\Model
*/
final class Version20191212002736 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("Summit") && !$builder->hasColumn("Summit", "BeginAllowBookingDate")) {
$builder->table('Summit', function (Table $table) {
$table->dateTime("BeginAllowBookingDate")->setNotnull(false);
$table->dateTime("EndAllowBookingDate")->setNotnull(false);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("Summit") && $builder->hasColumn("Summit", "BeginAllowBookingDate")) {
$builder->table('Member', function (Table $table) {
$table->dropColumn("BeginAllowBookingDate");
$table->dropColumn("EndAllowBookingDate");
});
}
}
}