Move Level attribute from Presentation to SummitEvent

Change-Id: Id9f072ad84a7972cbc388364eebf5a4687e447f9
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2020-12-08 17:48:21 -03:00
parent d8a377bf78
commit 294bb8f42b
14 changed files with 247 additions and 66 deletions

View File

@ -55,6 +55,7 @@ final class EventTypeValidationRulesFactory
'use_sponsors' => 'sometimes|boolean',
'are_sponsors_mandatory' => 'sometimes|boolean|required_with:use_sponsors',
'allows_attachment' => 'sometimes|boolean',
'allows_level' => 'sometimes|boolean',
'is_private' => 'sometimes|boolean',
'is_default' => 'sometimes|boolean',
];

View File

@ -453,6 +453,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'allow_feedback' => 'sometimes|boolean',
'tags' => 'sometimes|string_array',
'sponsors' => 'sometimes|int_array',
'level' => 'sometimes|string',
// presentation rules
'attendees_expected_learnt' => 'sometimes|string|max:1100',
'attending_media' => 'sometimes|boolean',
@ -539,6 +540,7 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
'track_id' => 'sometimes|required|integer',
'tags' => 'sometimes|string_array',
'sponsors' => 'sometimes|int_array',
'level' => 'sometimes|string',
// presentation rules
'attendees_expected_learnt' => 'sometimes|string|max:1100',
'attending_media' => 'sometimes|boolean',

View File

@ -30,6 +30,7 @@ class SummitEventTypeSerializer extends SilverStripeSerializer
'UseSponsors' => 'use_sponsors:json_boolean',
'AreSponsorsMandatory' => 'are_sponsors_mandatory:json_boolean',
'AllowsAttachment' => 'allows_attachment:json_boolean',
'AllowsLevel' => 'allows_level:json_boolean',
'Default' => 'is_default:json_boolean',
'SummitId' => 'summit_id:json_int',
];

View File

@ -0,0 +1,28 @@
<?php namespace models\summit;
/**
* Copyright 2020 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.
**/
/**
* Interface ISummitEventLevel
* @package models\summit
*/
interface ISummitEventLevel
{
const BeginnerLevel = 'Beginner';
const IntermediateLevel = 'Intermediate';
const AdvancedLevel = 'Advanced';
const NALevel = 'N/A';
const ValidLevels = [self::BeginnerLevel, self::IntermediateLevel, self::AdvancedLevel, self::NALevel];
}

View File

@ -20,12 +20,12 @@ interface ISummitEventType
{
// default types
const HandonLabs = 'Hand-on Labs';
const Lunch_Breaks = 'Lunch & Breaks';
const HandonLabs = 'Hand-on Labs';
const Lunch_Breaks = 'Lunch & Breaks';
const EveningEvents = 'Evening Events';
const GroupsEvents = 'Groups Events';
const Lunch = 'Lunch';
const Breaks = 'Breaks';
const Breakfast = 'Breakfast';
const GroupsEvents = 'Groups Events';
const Lunch = 'Lunch';
const Breaks = 'Breaks';
const Breakfast = 'Breakfast';
const MarketplaceHours = 'Marketplace Hours';
}

View File

@ -38,13 +38,6 @@ class Presentation extends SummitEvent
const SelectionStatus_Unaccepted = 'unaccepted';
const SelectionStatus_Alternate = 'alternate';
const BeginnerLevel = 'Beginner';
const IntermediateLevel = 'Intermediate';
const AdvancedLevel = 'Advanced';
const NALevel = 'N/A';
const ValidLevels = [self::BeginnerLevel, self::IntermediateLevel, self::AdvancedLevel, self::NALevel];
/**
* Defines the phase that a presentation has been created, but
* no information has been saved to it.
@ -86,12 +79,6 @@ class Presentation extends SummitEvent
const MaxAllowedLinks = 5;
/**
* @ORM\Column(name="Level", type="string")
* @var string
*/
protected $level;
/**
* @ORM\Column(name="Slug", type="string")
* @var string
@ -233,26 +220,6 @@ class Presentation extends SummitEvent
$this->attending_media = false;
}
/**
* @return string
*/
public function getLevel()
{
return $this->level;
}
/**
* @param string $level
* @throws ValidationException
*/
public function setLevel(string $level):void
{
if(!in_array($level, self::ValidLevels))
throw new ValidationException(sprintf("Level %s is invalid.", $level));
$this->level = $level;
}
/**
* @return string
*/
@ -269,7 +236,6 @@ class Presentation extends SummitEvent
$this->problem_addressed = $problem_addressed;
}
/**
* @return string
*/

View File

@ -11,9 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Common\Collections\ArrayCollection;
use models\summit\SummitEventType;
use Doctrine\ORM\Mapping AS ORM;
/**
* Class PresentationType
@ -94,9 +92,10 @@ class PresentationType extends SummitEventType
* @param string $type
* @return bool
*/
public static function IsPresentationEventType(Summit $summit, $type){
public static function IsPresentationEventType(Summit $summit, $type)
{
try{
try {
$sql = <<<SQL
SELECT COUNT(DISTINCT(PresentationType.ID))
FROM PresentationType
@ -107,9 +106,8 @@ SQL;
$stmt = self::prepareRawSQLStatic($sql);
$stmt->execute(['summit_id' => $summit->getId(), 'type' => $type]);
$res = $stmt->fetchAll(\PDO::FETCH_COLUMN);
return count($res) > 0 ;
}
catch (\Exception $ex){
return count($res) > 0;
} catch (\Exception $ex) {
}
return false;
@ -118,7 +116,8 @@ SQL;
/**
* @return array()
*/
static public function presentationTypes(){
static public function presentationTypes()
{
return [IPresentationType::Presentation, IPresentationType::Keynotes, IPresentationType::LightingTalks, IPresentationType::Panel];
}
@ -202,7 +201,8 @@ SQL;
return $this->moderator_label;
}
public function getClassName(){
public function getClassName()
{
return 'PresentationType';
}
@ -291,11 +291,12 @@ SQL;
public function __construct()
{
parent::__construct();
$this->are_speakers_mandatory = false;
$this->use_speakers = false;
$this->use_moderator = false;
$this->is_moderator_mandatory = false;
$this->are_speakers_mandatory = false;
$this->use_speakers = false;
$this->use_moderator = false;
$this->is_moderator_mandatory = false;
$this->should_be_available_on_cfp = false;
$this->allows_level = true;
$this->allowed_media_upload_types = new ArrayCollection();
$this->max_moderators = 0;
$this->max_speakers = 0;
@ -303,21 +304,25 @@ SQL;
$this->min_speakers = 0;
}
public function addAllowedMediaUploadType(SummitMediaUploadType $type){
if($this->allowed_media_upload_types->contains($type)) return;
public function addAllowedMediaUploadType(SummitMediaUploadType $type)
{
if ($this->allowed_media_upload_types->contains($type)) return;
$this->allowed_media_upload_types->add($type);
}
public function removeAllowedMediaUploadType(SummitMediaUploadType $type){
if(!$this->allowed_media_upload_types->contains($type)) return;
public function removeAllowedMediaUploadType(SummitMediaUploadType $type)
{
if (!$this->allowed_media_upload_types->contains($type)) return;
$this->allowed_media_upload_types->removeElement($type);
}
public function clearAllowedMediaUploadType(){
public function clearAllowedMediaUploadType()
{
$this->allowed_media_upload_types->clear();
}
public function getAllowedMediaUploadTypes(){
public function getAllowedMediaUploadTypes()
{
return $this->allowed_media_upload_types;
}
}

View File

@ -79,6 +79,12 @@ class SummitEvent extends SilverstripeBaseModel
*/
protected $occupancy;
/**
* @ORM\Column(name="Level", type="string")
* @var string
*/
protected $level;
/**
* @ORM\Column(name="StartDate", type="datetime")
* @var \DateTime
@ -1283,4 +1289,23 @@ class SummitEvent extends SilverstripeBaseModel
$this->mux_playback_id = $mux_playback_id;
}
/**
* @return string
*/
public function getLevel()
{
return $this->level;
}
/**
* @param string $level
* @throws ValidationException
*/
public function setLevel(string $level):void
{
if(!in_array($level, ISummitEventLevel::ValidLevels))
throw new ValidationException(sprintf("Level %s is invalid.", $level));
$this->level = $level;
}
}

View File

@ -68,6 +68,12 @@ class SummitEventType extends SilverstripeBaseModel
*/
protected $allows_attachment;
/**
* @ORM\Column(name="AllowsLevel", type="boolean")
* @var bool
*/
protected $allows_level;
/**
* @ORM\Column(name="IsDefault", type="boolean")
* @var bool
@ -234,6 +240,7 @@ class SummitEventType extends SilverstripeBaseModel
$this->are_sponsors_mandatory = false;
$this->allows_attachment = false;
$this->is_private = false;
$this->allows_level = false;
$this->summit_documents = new ArrayCollection();
}
@ -316,4 +323,21 @@ SQL;
public function clearSummitDocuments(){
$this->summit_documents->clear();
}
/**
* @return bool
*/
public function isAllowsLevel(): bool
{
return $this->allows_level;
}
/**
* @param bool $allows_level
*/
public function setAllowsLevel(bool $allows_level): void
{
$this->allows_level = $allows_level;
}
}

View File

@ -123,6 +123,9 @@ final class SummitEventTypeFactory
if(isset($data['is_default']))
$event_type->setIsDefault(boolval($data['is_default']));
if(isset($data['allows_level']))
$event_type->setAllowsLevel(boolval($data['allows_level']));
$summit->addEventType($event_type);
return $event_type;
}

View File

@ -458,7 +458,7 @@ final class PresentationService
if (isset($data['social_description']))
$presentation->setSocialSummary(strip_tags(trim($data['social_description'])));
if (isset($data['level']))
if (isset($data['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$presentation->setLevel($data['level']);
if (isset($data['attendees_expected_learnt']))

View File

@ -761,6 +761,7 @@ final class SummitService extends AbstractService implements ISummitService
if (is_null($event_type)) $event_type = $old_event_type;
}
// new event
if (is_null($event))
$event = SummitEventFactory::build($event_type, $summit);
@ -770,6 +771,9 @@ final class SummitService extends AbstractService implements ISummitService
if (isset($data['title']))
$event->setTitle(html_entity_decode(trim($data['title'])));
if (isset($data['level']) && !is_null($event_type) && $event_type->isAllowsLevel())
$event->setLevel($data['level']);
if (isset($data['description']))
$event->setAbstract(html_entity_decode(trim($data['description'])));
@ -917,9 +921,6 @@ final class SummitService extends AbstractService implements ISummitService
if (isset($data['attendees_expected_learnt']))
$event->setAttendeesExpectedLearnt(html_entity_decode($data['attendees_expected_learnt']));
if (isset($data['level']))
$event->setLevel($data['level']);
$event->setAttendingMedia(isset($data['attending_media']) ?
filter_var($data['attending_media'], FILTER_VALIDATE_BOOLEAN) : 0);
@ -2865,6 +2866,9 @@ final class SummitService extends AbstractService implements ISummitService
$event->setAbstract(html_entity_decode($abstract));
}
if (isset($row['level']))
$event->setLevel($row['level']);
if (isset($row['social_summary']))
$event->setSocialSummary($row['social_summary']);
@ -2950,9 +2954,6 @@ final class SummitService extends AbstractService implements ISummitService
if (isset($row['attendees_expected_learnt']))
$event->setAttendeesExpectedLearnt($row['attendees_expected_learnt']);
if (isset($row['level']))
$event->setLevel($row['level']);
if (isset($row['problem_addressed']))
$event->setProblemAddressed($row['problem_addressed']);

View File

@ -0,0 +1,65 @@
<?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 Version20201208150500
* @package Database\Migrations\Model
*/
class Version20201208150500 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SummitEvent") && !$builder->hasColumn("SummitEvent", "Level")) {
$builder->table('SummitEvent', function (Table $table) {
$table->string("Level", 255)->setNotnull(false)->setDefault('Beginner');
});
}
if($schema->hasTable("SummitEventType") && !$builder->hasColumn("SummitEventType", "AllowsLevel")) {
$builder->table('SummitEventType', function (Table $table) {
$table->boolean("AllowsLevel")->setNotnull(true)->setDefault(false);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SummitEvent") && $builder->hasColumn("SummitEvent", "Level")) {
$builder->table('SummitEvent', function (Table $table) {
$table->dropColumn("Level");
});
}
if($schema->hasTable("SummitEventType") && $builder->hasColumn("SummitEventType", "AllowsLevel")) {
$builder->table('SummitEventType', function (Table $table) {
$table->dropColumn("AllowsLevel");
});
}
}
}

View File

@ -0,0 +1,60 @@
<?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;
/**
* Class Version20201208151735
* @package Database\Migrations\Model
*/
class Version20201208151735 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$sql = <<<SQL
ALTER TABLE SummitEvent MODIFY Level
enum('Beginner', 'Intermediate', 'Advanced', 'N/A') default 'Beginner';
SQL;
$this->addSql($sql);
$sql = <<<SQL
UPDATE SummitEvent SET SummitEvent.Level = (SELECT Presentation.Level
FROM Presentation WHERE Presentation.ID = SummitEvent.ID);
SQL;
$this->addSql($sql);
$sql = <<<SQL
alter table Presentation drop column Level;
SQL;
$this->addSql($sql);
$sql = <<<SQL
UPDATE SummitEventType set AllowsLevel = 1 where ClassName = 'PresentationType';
SQL;
$this->addSql($sql);
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}