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:
parent
d02e2d9fec
commit
1ae6937966
@ -49,6 +49,8 @@ final class SummitValidationRulesFactory
|
|||||||
'api_feed_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
|
'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_url' => 'nullable|string|url|required_with:api_feed_type',
|
||||||
'api_feed_key' => 'nullable|string|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_type' => sprintf('nullable|in:%s',implode(',', Summit::$valid_feed_types)),
|
||||||
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
|
'api_feed_url' => 'nullable|string|url|required_with:api_feed_type',
|
||||||
'api_feed_key' => 'nullable|string|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',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DoctrineHavingFilterMapping
|
* Class DoctrineHavingFilterMapping
|
||||||
* @package utils
|
* @package utils
|
||||||
@ -27,6 +29,7 @@ class DoctrineHavingFilterMapping extends DoctrineFilterMapping
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $having;
|
protected $having;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DoctrineFilterMapping constructor.
|
* DoctrineFilterMapping constructor.
|
||||||
* @param string $condition
|
* @param string $condition
|
||||||
@ -43,33 +46,56 @@ class DoctrineHavingFilterMapping extends DoctrineFilterMapping
|
|||||||
* @param FilterElement $filter
|
* @param FilterElement $filter
|
||||||
* @return QueryBuilder
|
* @return QueryBuilder
|
||||||
*/
|
*/
|
||||||
public function apply(QueryBuilder $query, FilterElement $filter){
|
public function apply(QueryBuilder $query, FilterElement $filter)
|
||||||
$param_count = $query->getParameters()->count() + 1;
|
{
|
||||||
|
$param_count = $query->getParameters()->count();
|
||||||
$where = $this->where;
|
$where = $this->where;
|
||||||
$has_param = false;
|
$has_param = false;
|
||||||
|
|
||||||
$value = $filter->getValue();
|
$value = $filter->getValue();
|
||||||
|
|
||||||
if(strstr($where,":value")) {
|
if (!empty($where)) {
|
||||||
|
if (strstr($where, ":value")) {
|
||||||
|
++$param_count;
|
||||||
$where = str_replace(":value", ":value_" . $param_count, $where);
|
$where = str_replace(":value", ":value_" . $param_count, $where);
|
||||||
$has_param = true;
|
$has_param = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strstr($where,":operator"))
|
if (strstr($where, ":operator"))
|
||||||
$where = str_replace(":operator", $filter->getOperator(), $where);
|
$where = str_replace(":operator", $filter->getOperator(), $where);
|
||||||
|
|
||||||
$query = $query->andWhere($where);
|
$query = $query->andWhere($where);
|
||||||
|
|
||||||
if($has_param){
|
if ($has_param) {
|
||||||
$query = $query->setParameter(":value_".$param_count, $value);
|
$query = $query->setParameter(":value_" . $param_count, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->groupBy)) {
|
||||||
$query = $query->addGroupBy($this->groupBy);
|
$query = $query->addGroupBy($this->groupBy);
|
||||||
|
}
|
||||||
|
|
||||||
if(strstr($this->having,":value_count") && is_array($value)){
|
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);
|
$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;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -26,5 +26,9 @@ final class AdminSummitSerializer extends SummitSerializer
|
|||||||
'ExternalSummitId' => 'external_summit_id:json_string',
|
'ExternalSummitId' => 'external_summit_id:json_string',
|
||||||
'CalendarSyncName' => 'calendar_sync_name:json_string',
|
'CalendarSyncName' => 'calendar_sync_name:json_string',
|
||||||
'CalendarSyncDesc' => 'calendar_sync_desc: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',
|
||||||
];
|
];
|
||||||
}
|
}
|
@ -57,10 +57,8 @@ class SummitSerializer extends SilverStripeSerializer
|
|||||||
'MeetingRoomBookingEndTime' => 'meeting_room_booking_end_time:datetime_epoch',
|
'MeetingRoomBookingEndTime' => 'meeting_room_booking_end_time:datetime_epoch',
|
||||||
'MeetingRoomBookingSlotLength' => 'meeting_room_booking_slot_length:json_int',
|
'MeetingRoomBookingSlotLength' => 'meeting_room_booking_slot_length:json_int',
|
||||||
'MeetingRoomBookingMaxAllowed' => 'meeting_room_booking_max_allowed:json_int',
|
'MeetingRoomBookingMaxAllowed' => 'meeting_room_booking_max_allowed:json_int',
|
||||||
// External Feeds
|
'BeginAllowBookingDate' => 'begin_allow_booking_date:datetime_epoch',
|
||||||
'ApiFeedType' => 'api_feed_type:json_string',
|
'EndAllowBookingDate' => 'end_allow_booking_date:datetime_epoch',
|
||||||
'ApiFeedUrl' => 'api_feed_url:json_string',
|
|
||||||
'ApiFeedKey' => 'api_feed_key:json_string',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static $allowed_relations = [
|
protected static $allowed_relations = [
|
||||||
|
@ -69,6 +69,23 @@ final class SummitFactory
|
|||||||
$summit->setCalendarSyncDesc(trim($data['calendar_sync_desc']));
|
$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(array_key_exists('start_date', $data) && array_key_exists('end_date', $data)) {
|
||||||
if (isset($data['start_date']) && isset($data['end_date'])) {
|
if (isset($data['start_date']) && isset($data['end_date'])) {
|
||||||
$start_datetime = intval($data['start_date']);
|
$start_datetime = intval($data['start_date']);
|
||||||
|
@ -67,8 +67,10 @@ class SummitBookableVenueRoom extends SummitVenueRoom
|
|||||||
*/
|
*/
|
||||||
public function addReservation(SummitRoomReservation $reservation){
|
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();
|
$start_date = $reservation->getStartDatetime();
|
||||||
$end_date = $reservation->getEndDatetime();
|
$end_date = $reservation->getEndDatetime();
|
||||||
|
|
||||||
|
@ -200,6 +200,18 @@ class Summit extends SilverstripeBaseModel
|
|||||||
*/
|
*/
|
||||||
private $meeting_booking_room_allowed_attributes;
|
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")
|
* @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;
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
<?php
|
<?php namespace Database\Migrations\Model;
|
||||||
|
/**
|
||||||
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\Migrations\AbstractMigration;
|
||||||
use Doctrine\DBAL\Schema\Schema as Schema;
|
use Doctrine\DBAL\Schema\Schema as Schema;
|
||||||
|
|
||||||
|
54
database/migrations/model/Version20191212002736.php
Normal file
54
database/migrations/model/Version20191212002736.php
Normal 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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user