Added new endpoint to seed default event types per summit
POST /api/v1/summits/{id}/event-types/seed-defaults Change-Id: I8466fbbdec8410eb160545442b351187b8c2293d
This commit is contained in:
parent
59129e8a86
commit
fcec607f95
@ -31,6 +31,7 @@ use utils\FilterParser;
|
||||
use utils\OrderParser;
|
||||
use utils\PagingInfo;
|
||||
use Exception;
|
||||
use utils\PagingResponse;
|
||||
/**
|
||||
* Class OAuth2SummitsEventTypesApiController
|
||||
* @package App\Http\Controllers
|
||||
@ -47,6 +48,13 @@ final class OAuth2SummitsEventTypesApiController extends OAuth2ProtectedControll
|
||||
*/
|
||||
private $event_type_service;
|
||||
|
||||
/**
|
||||
* OAuth2SummitsEventTypesApiController constructor.
|
||||
* @param ISummitEventTypeRepository $repository
|
||||
* @param ISummitRepository $summit_repository
|
||||
* @param ISummitEventTypeService $event_type_service
|
||||
* @param IResourceServerContext $resource_server_context
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ISummitEventTypeRepository $repository,
|
||||
@ -442,4 +450,42 @@ final class OAuth2SummitsEventTypesApiController extends OAuth2ProtectedControll
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function seedDefaultEventTypesBySummit($summit_id){
|
||||
try {
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$event_types = $this->event_type_service->seedDefaultEventTypes($summit);
|
||||
|
||||
$response = new PagingResponse
|
||||
(
|
||||
count($event_types),
|
||||
count($event_types),
|
||||
1,
|
||||
1,
|
||||
$event_types
|
||||
);
|
||||
|
||||
return $this->created($response->toArray());
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -296,6 +296,7 @@ Route::group([
|
||||
Route::group(['prefix' => 'event-types'], function () {
|
||||
Route::get('', 'OAuth2SummitsEventTypesApiController@getAllBySummit');
|
||||
Route::get('csv', 'OAuth2SummitsEventTypesApiController@getAllBySummitCSV');
|
||||
Route::post('seed-defaults', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitsEventTypesApiController@seedDefaultEventTypesBySummit']);
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitsEventTypesApiController@addEventTypeBySummit']);
|
||||
Route::group(['prefix' => '{event_type_id}'], function () {
|
||||
Route::get('', 'OAuth2SummitsEventTypesApiController@getEventTypeBySummit');
|
||||
|
@ -0,0 +1,269 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Defaults;
|
||||
/**
|
||||
* Copyright 2018 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\ORM\Mapping AS ORM;
|
||||
use models\summit\PresentationType;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitEventType;
|
||||
|
||||
/**
|
||||
* Class DefaultPresentationType
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="DefaultPresentationType")
|
||||
* @package App\Models\Foundation\Summit\Defaults
|
||||
*/
|
||||
class DefaultPresentationType extends DefaultSummitEventType
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="MaxSpeakers", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $max_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MinSpeakers", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $min_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MaxModerators", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $max_moderators;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="MinModerators", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
protected $min_moderators;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseSpeakers", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_speakers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AreSpeakersMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $are_speakers_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseModerator", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_moderator;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsModeratorMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_moderator_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ShouldBeAvailableOnCFP", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $should_be_available_on_cfp;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ModeratorLabel", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $moderator_label;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxSpeakers()
|
||||
{
|
||||
return $this->max_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $max_speakers
|
||||
*/
|
||||
public function setMaxSpeakers($max_speakers)
|
||||
{
|
||||
$this->max_speakers = $max_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMinSpeakers()
|
||||
{
|
||||
return $this->min_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $min_speakers
|
||||
*/
|
||||
public function setMinSpeakers($min_speakers)
|
||||
{
|
||||
$this->min_speakers = $min_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxModerators()
|
||||
{
|
||||
return $this->max_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $max_moderators
|
||||
*/
|
||||
public function setMaxModerators($max_moderators)
|
||||
{
|
||||
$this->max_moderators = $max_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMinModerators()
|
||||
{
|
||||
return $this->min_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $min_moderators
|
||||
*/
|
||||
public function setMinModerators($min_moderators)
|
||||
{
|
||||
$this->min_moderators = $min_moderators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseSpeakers()
|
||||
{
|
||||
return $this->use_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $use_speakers
|
||||
*/
|
||||
public function setUseSpeakers($use_speakers)
|
||||
{
|
||||
$this->use_speakers = $use_speakers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAreSpeakersMandatory()
|
||||
{
|
||||
return $this->are_speakers_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $are_speakers_mandatory
|
||||
*/
|
||||
public function setAreSpeakersMandatory($are_speakers_mandatory)
|
||||
{
|
||||
$this->are_speakers_mandatory = $are_speakers_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseModerator()
|
||||
{
|
||||
return $this->use_moderator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $use_moderator
|
||||
*/
|
||||
public function setUseModerator($use_moderator)
|
||||
{
|
||||
$this->use_moderator = $use_moderator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isModeratorMandatory()
|
||||
{
|
||||
return $this->is_moderator_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_moderator_mandatory
|
||||
*/
|
||||
public function setIsModeratorMandatory($is_moderator_mandatory)
|
||||
{
|
||||
$this->is_moderator_mandatory = $is_moderator_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isShouldBeAvailableOnCfp()
|
||||
{
|
||||
return $this->should_be_available_on_cfp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $should_be_available_on_cfp
|
||||
*/
|
||||
public function setShouldBeAvailableOnCfp($should_be_available_on_cfp)
|
||||
{
|
||||
$this->should_be_available_on_cfp = $should_be_available_on_cfp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getModeratorLabel()
|
||||
{
|
||||
return $this->moderator_label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moderator_label
|
||||
*/
|
||||
public function setModeratorLabel($moderator_label)
|
||||
{
|
||||
$this->moderator_label = $moderator_label;
|
||||
}
|
||||
|
||||
protected function newType(){
|
||||
return new PresentationType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return SummitEventType
|
||||
*/
|
||||
public function buildType(Summit $summit){
|
||||
$new_type = parent::buildType($summit);
|
||||
$new_type->setMaxSpeakers($this->max_speakers);
|
||||
$new_type->setMinSpeakers($this->min_speakers);
|
||||
$new_type->setMaxModerators($this->max_moderators);
|
||||
$new_type->setMinModerators($this->min_moderators);
|
||||
$new_type->setUseSpeakers($this->use_speakers);
|
||||
$new_type->setAreSpeakersMandatory($this->are_speakers_mandatory);
|
||||
$new_type->setUseModerator($this->use_moderator);
|
||||
$new_type->setIsModeratorMandatory($this->is_moderator_mandatory);
|
||||
$new_type->setShouldBeAvailableOnCfp($this->should_be_available_on_cfp);
|
||||
$new_type->setModeratorLabel($this->moderator_label);
|
||||
return $new_type;
|
||||
}
|
||||
}
|
205
app/Models/Foundation/Summit/Defaults/DefaultSummitEventType.php
Normal file
205
app/Models/Foundation/Summit/Defaults/DefaultSummitEventType.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Defaults;
|
||||
/**
|
||||
* Copyright 2018 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\ORM\Mapping AS ORM;
|
||||
use models\summit\Summit;
|
||||
use models\summit\SummitEventType;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
* Class DefaultSummitEventType
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineDefaultSummitEventTypeRepository")
|
||||
* @ORM\Table(name="DefaultSummitEventType")
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
* @ORM\DiscriminatorMap({"DefaultSummitEventType" = "DefaultSummitEventType", "DefaultPresentationType" = "DefaultPresentationType"})
|
||||
* @package App\Models\Foundation\Summit\Defaults
|
||||
*/
|
||||
class DefaultSummitEventType extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="Type", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Color", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="BlackoutTimes", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $blackout_times;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="UseSponsors", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $use_sponsors;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AreSponsorsMandatory", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $are_sponsors_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="AllowsAttachment", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $allows_attachment;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsPrivate", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_private;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getColor()
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color
|
||||
*/
|
||||
public function setColor($color)
|
||||
{
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isBlackoutTimes()
|
||||
{
|
||||
return $this->blackout_times;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $blackout_times
|
||||
*/
|
||||
public function setBlackoutTimes($blackout_times)
|
||||
{
|
||||
$this->blackout_times = $blackout_times;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUseSponsors()
|
||||
{
|
||||
return $this->use_sponsors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $use_sponsors
|
||||
*/
|
||||
public function setUseSponsors($use_sponsors)
|
||||
{
|
||||
$this->use_sponsors = $use_sponsors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAreSponsorsMandatory()
|
||||
{
|
||||
return $this->are_sponsors_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $are_sponsors_mandatory
|
||||
*/
|
||||
public function setAreSponsorsMandatory($are_sponsors_mandatory)
|
||||
{
|
||||
$this->are_sponsors_mandatory = $are_sponsors_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAllowsAttachment()
|
||||
{
|
||||
return $this->allows_attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $allows_attachment
|
||||
*/
|
||||
public function setAllowsAttachment($allows_attachment)
|
||||
{
|
||||
$this->allows_attachment = $allows_attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrivate()
|
||||
{
|
||||
return $this->is_private;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_private
|
||||
*/
|
||||
public function setIsPrivate($is_private)
|
||||
{
|
||||
$this->is_private = $is_private;
|
||||
}
|
||||
|
||||
protected function newType(){
|
||||
return new SummitEventType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return SummitEventType
|
||||
*/
|
||||
public function buildType(Summit $summit){
|
||||
$new_type = $this->newType();
|
||||
$new_type->setSummit($summit);
|
||||
$new_type->setType($this->type);
|
||||
$new_type->setColor($this->color);
|
||||
$new_type->setBlackoutTimes($this->blackout_times);
|
||||
$new_type->setUseSponsors($this->use_sponsors);
|
||||
$new_type->setAreSponsorsMandatory($this->are_sponsors_mandatory);
|
||||
$new_type->setAllowsAttachment($this->allows_attachment);
|
||||
$new_type->setIsPrivate($this->is_private);
|
||||
$new_type->setAsDefault();
|
||||
return $new_type;
|
||||
}
|
||||
|
||||
}
|
@ -123,11 +123,29 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param int $summit_id
|
||||
* @return bool
|
||||
*/
|
||||
static public function isPrivate($type){
|
||||
static public function isPrivateType($type, $summit_id){
|
||||
$private_types = [ISummitEventType::GroupsEvents];
|
||||
return in_array($type, $private_types);
|
||||
|
||||
try{
|
||||
$sql = <<<SQL
|
||||
SELECT COUNT(DISTINCT(SummitEventType.ID))
|
||||
FROM SummitEventType
|
||||
WHERE SummitEventType.SummitID = :summit_id
|
||||
AND SummitEventType.Type = :$type
|
||||
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 false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,6 +187,12 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
|
||||
const ClassName = 'EVENT_TYPE';
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsPrivate", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_private;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
@ -219,6 +243,23 @@ class SummitEventType extends SilverstripeBaseModel
|
||||
$this->blackout_times = false;
|
||||
$this->are_sponsors_mandatory = false;
|
||||
$this->allows_attachment = false;
|
||||
$this->is_private = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrivate()
|
||||
{
|
||||
return $this->is_private;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_private
|
||||
*/
|
||||
public function setIsPrivate($is_private)
|
||||
{
|
||||
$this->is_private = $is_private;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2015 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -12,8 +12,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
namespace models\summit;
|
||||
|
||||
/**
|
||||
* Class SummitEventFactory
|
||||
* @package models\summit
|
||||
@ -22,21 +20,24 @@ final class SummitEventFactory
|
||||
{
|
||||
/**
|
||||
* @param SummitEventType $type
|
||||
* @param Summit $summit
|
||||
* @return SummitEvent
|
||||
*/
|
||||
static public function build(SummitEventType $type)
|
||||
static public function build(SummitEventType $type, Summit $summit)
|
||||
{
|
||||
$event = new SummitEvent();
|
||||
|
||||
if($type instanceof PresentationType)
|
||||
$event = new Presentation();
|
||||
|
||||
if(SummitEventType::isPrivate($type->getType()))
|
||||
if(SummitEventType::isPrivateType($type->getType(), $summit->getId()))
|
||||
$event = new SummitGroupEvent();
|
||||
|
||||
if($type->isAllowsAttachment())
|
||||
$event = new SummitEventWithFile();
|
||||
|
||||
$event->setSummit($summit);
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Repositories;
|
||||
/**
|
||||
* Copyright 2018 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 models\utils\IBaseRepository;
|
||||
/**
|
||||
* Interface IDefaultSummitEventTypeRepository
|
||||
* @package App\Models\Foundation\Summit\Repositories
|
||||
*/
|
||||
interface IDefaultSummitEventTypeRepository
|
||||
extends IBaseRepository
|
||||
{
|
||||
|
||||
}
|
@ -1143,7 +1143,7 @@ SQL;
|
||||
static public function allowToSee(SummitEvent $summit_event, Member $member = null)
|
||||
{
|
||||
|
||||
if (SummitEventType::isPrivate($summit_event->getType()->getType())) {
|
||||
if (SummitEventType::isPrivateType($summit_event->getType()->getType(), $summit_event->getSummitId())) {
|
||||
if (is_null($member))
|
||||
return false;
|
||||
|
||||
|
@ -140,5 +140,12 @@ class SilverstripeBaseModel extends BaseEntity
|
||||
return Registry::getManager(self::EntityManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntityManager
|
||||
*/
|
||||
protected static function getEMStatic(){
|
||||
return Registry::getManager(self::EntityManager);
|
||||
}
|
||||
|
||||
const EntityManager = 'ss';
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Defaults\DefaultSummitEventType;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\IPresentationSpeakerSummitAssistanceConfirmationRequestRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository;
|
||||
use Illuminate\Support\Facades\App;
|
||||
@ -272,5 +274,12 @@ final class RepositoriesProvider extends ServiceProvider
|
||||
return EntityManager::getRepository(SummitEventType::class);
|
||||
}
|
||||
);
|
||||
|
||||
App::singleton(
|
||||
IDefaultSummitEventTypeRepository::class,
|
||||
function(){
|
||||
return EntityManager::getRepository(DefaultSummitEventType::class);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php namespace App\Repositories\Summit;
|
||||
/**
|
||||
* Copyright 2018 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 App\Models\Foundation\Summit\Defaults\DefaultSummitEventType;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
|
||||
use App\Repositories\SilverStripeDoctrineRepository;
|
||||
/**
|
||||
* Class DoctrineDefaultSummitEventTypeRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
final class DoctrineDefaultSummitEventTypeRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements IDefaultSummitEventTypeRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return DefaultSummitEventType::class;
|
||||
}
|
||||
}
|
@ -49,4 +49,12 @@ interface ISummitEventTypeService
|
||||
*/
|
||||
public function deleteEventType(Summit $summit, $event_type_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return SummitEventType[]
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedDefaultEventTypes(Summit $summit);
|
||||
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Factories\SummitEventTypeFactory;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository;
|
||||
use App\Services\Model\ISummitEventTypeService;
|
||||
use libs\utils\ITransactionService;
|
||||
@ -36,19 +37,27 @@ final class SummitEventTypeService implements ISummitEventTypeService
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var IDefaultSummitEventTypeRepository
|
||||
*/
|
||||
private $default_event_types_repository;
|
||||
|
||||
/**
|
||||
* SummitEventTypeService constructor.
|
||||
* @param ISummitEventTypeRepository $repository
|
||||
* @param IDefaultSummitEventTypeRepository $default_event_types_repository
|
||||
* @param ITransactionService $tx_service
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ISummitEventTypeRepository $repository,
|
||||
IDefaultSummitEventTypeRepository $default_event_types_repository,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
{
|
||||
$this->tx_service = $tx_service;
|
||||
$this->repository = $repository;
|
||||
$this->tx_service = $tx_service;
|
||||
$this->repository = $repository;
|
||||
$this->default_event_types_repository = $default_event_types_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,4 +149,27 @@ final class SummitEventTypeService implements ISummitEventTypeService
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return SummitEventType[]
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedDefaultEventTypes(Summit $summit)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit){
|
||||
$added_types = [];
|
||||
$default_types = $this->default_event_types_repository->getAll();
|
||||
foreach ($default_types as $default_type){
|
||||
$former_type = $summit->getEventTypeByType($default_type->getType());
|
||||
if(!is_null($former_type)) continue;
|
||||
$new_type = $default_type->buildType($summit);
|
||||
$summit->addEventType($new_type);
|
||||
$added_types[] = $new_type;
|
||||
}
|
||||
|
||||
return $added_types;
|
||||
});
|
||||
}
|
||||
}
|
@ -581,8 +581,9 @@ final class SummitService implements ISummitService
|
||||
return false;
|
||||
}
|
||||
|
||||
$old_is_private = SummitEventType::isPrivate($old_event_type->getType());
|
||||
$new_is_private = SummitEventType::isPrivate($event_type->getType());
|
||||
$old_is_private = SummitEventType::isPrivateType($old_event_type->getType(), $old_event_type->getSummitId());
|
||||
$new_is_private = SummitEventType::isPrivateType($event_type->getType(), $event_type->getSummitId());
|
||||
|
||||
if((!$old_is_private && $new_is_private) || ($old_is_private && !$new_is_private))
|
||||
return false;
|
||||
|
||||
@ -660,7 +661,7 @@ final class SummitService implements ISummitService
|
||||
|
||||
// new event
|
||||
if (is_null($event))
|
||||
$event = SummitEventFactory::build($event_type);
|
||||
$event = SummitEventFactory::build($event_type, $summit);
|
||||
|
||||
// main data
|
||||
|
||||
|
@ -573,6 +573,15 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'seed-default-event-types',
|
||||
'route' => '/api/v1/summits/{id}/event-types/seed-defaults',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteEventTypeData, $current_realm),
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-event-type',
|
||||
'route' => '/api/v1/summits/{id}/event-types/{event_type_id}',
|
||||
|
@ -304,4 +304,32 @@ final class OAuth2EventTypesApiTest extends ProtectedApiTest
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testSeedDefaultEventTYpes($summit_id = 23){
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitsEventTypesApiController@seedDefaultEventTypesBySummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$event_types = json_decode($content);
|
||||
$this->assertTrue(!is_null($event_types));
|
||||
return $event_types;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user