Added new Endpoint Create Speaker
POST api/v1/summits/{id}/speakers Change-Id: Ieab08014bc2f10236f6328c8bd5a089e18e542c2
This commit is contained in:
parent
0ce7492a6f
commit
cf9d1ca5a4
@ -17,12 +17,16 @@ use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use libs\utils\HTMLCleaner;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
use models\summit\IEventFeedbackRepository;
|
||||
use models\summit\ISpeakerRepository;
|
||||
use models\summit\ISummitEventRepository;
|
||||
use models\summit\ISummitRepository;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use services\model\ISpeakerService;
|
||||
use services\model\ISummitService;
|
||||
use utils\FilterParser;
|
||||
use utils\FilterParserException;
|
||||
@ -36,7 +40,7 @@ use utils\PagingInfo;
|
||||
final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
|
||||
{
|
||||
/**
|
||||
* @var ISummitService
|
||||
* @var ISpeakerService
|
||||
*/
|
||||
private $service;
|
||||
|
||||
@ -62,7 +66,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
|
||||
ISummitEventRepository $event_repository,
|
||||
ISpeakerRepository $speaker_repository,
|
||||
IEventFeedbackRepository $event_feedback_repository,
|
||||
ISummitService $service,
|
||||
ISpeakerService $service,
|
||||
IResourceServerContext $resource_server_context
|
||||
) {
|
||||
parent::__construct($resource_server_context);
|
||||
@ -251,4 +255,64 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
|
||||
}
|
||||
|
||||
|
||||
public function addSpeaker($summit_id){
|
||||
try {
|
||||
if(!Request::isJson()) return $this->error403();
|
||||
$data = Input::json();
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$rules = array
|
||||
(
|
||||
'title' => 'required|string|max:100',
|
||||
'first_name' => 'required|string|max:100',
|
||||
'last_name' => 'required|string|max:100',
|
||||
'bio' => 'sometimes|string',
|
||||
'irc' => 'sometimes|string|max:50',
|
||||
'twitter' => 'sometimes|string|max:50',
|
||||
'member_id' => 'sometimes|integer',
|
||||
'email' => 'sometimes|string|max:50',
|
||||
'on_site_phone' => 'sometimes|string|max:50',
|
||||
'registered' => 'sometimes|boolean',
|
||||
'confirmed' => 'sometimes|boolean',
|
||||
'checked_in' => 'sometimes|boolean',
|
||||
'registration_code' => 'sometimes|string',
|
||||
);
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($data->all(), $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'title',
|
||||
'bio',
|
||||
];
|
||||
|
||||
$speaker = $this->service->addSpeaker($summit, HTMLCleaner::cleanData($data->all(), $fields));
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($speaker)->serialize());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -183,6 +183,7 @@ Route::group([
|
||||
// speakers
|
||||
Route::group(array('prefix' => 'speakers'), function () {
|
||||
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitSpeakersApiController@addSpeaker']);
|
||||
Route::get('', 'OAuth2SummitSpeakersApiController@getSpeakers');
|
||||
|
||||
Route::group(array('prefix' => '{speaker_id}'), function () {
|
||||
|
@ -0,0 +1,100 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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\utils\SilverstripeBaseModel;
|
||||
use DateTime;
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="repositories\main\DoctrineEmailCreationRequestRepository")
|
||||
* @ORM\Table(name="EmailCreationRequest")
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
* @ORM\DiscriminatorMap({"EmailCreationRequest" = "EmailCreationRequest",
|
||||
* "SpeakerCreationEmailCreationRequest" = "SpeakerCreationEmailCreationRequest" })
|
||||
* Class EmailCreationRequest
|
||||
* @package models\main
|
||||
*/
|
||||
class EmailCreationRequest extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="TemplateName", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $template_name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Processed", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
protected $processed;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ProcessedDate", type="datetime")
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $processed_date;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateName()
|
||||
{
|
||||
return $this->template_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template_name
|
||||
*/
|
||||
public function setTemplateName($template_name)
|
||||
{
|
||||
$this->template_name = $template_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isProcessed()
|
||||
{
|
||||
return $this->processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $processed
|
||||
*/
|
||||
public function setProcessed($processed)
|
||||
{
|
||||
$this->processed = $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getProcessedDate()
|
||||
{
|
||||
return $this->processed_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $processed_date
|
||||
*/
|
||||
public function setProcessedDate($processed_date)
|
||||
{
|
||||
$this->processed_date = $processed_date;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->processed = false;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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\PresentationSpeaker;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SpeakerCreationEmailCreationRequest")
|
||||
* Class SpeakerCreationEmailCreationRequest
|
||||
* @package models\main
|
||||
*/
|
||||
class SpeakerCreationEmailCreationRequest extends EmailCreationRequest
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\summit\PresentationSpeaker")
|
||||
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
|
||||
* @var PresentationSpeaker
|
||||
*/
|
||||
protected $speaker;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->template_name = "presentation-speaker-creation";
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getSpeaker()
|
||||
{
|
||||
return $this->speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
*/
|
||||
public function setSpeaker($speaker)
|
||||
{
|
||||
$this->speaker = $speaker;
|
||||
}
|
||||
}
|
@ -60,12 +60,28 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
private $twitter_name;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="SpeakerRegistrationRequest")
|
||||
* @ORM\Column(name="CreatedFromAPI", type="boolean")
|
||||
*/
|
||||
private $created_from_api;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="SpeakerRegistrationRequest", cascade={"persist"})
|
||||
* @ORM\JoinColumn(name="RegistrationRequestID", referencedColumnName="ID")
|
||||
* @var SpeakerRegistrationRequest
|
||||
*/
|
||||
private $registration_request;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="PresentationSpeakerSummitAssistanceConfirmationRequest", mappedBy="speaker", cascade={"persist"})
|
||||
* @var PresentationSpeakerSummitAssistanceConfirmationRequest[]
|
||||
*/
|
||||
private $summit_assistances;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="SpeakerSummitRegistrationPromoCode", mappedBy="speaker", cascade={"persist"})
|
||||
* @var SpeakerSummitRegistrationPromoCode[]
|
||||
*/
|
||||
private $promo_codes;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\summit\Presentation", inversedBy="speakers")
|
||||
@ -86,7 +102,6 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
*/
|
||||
private $moderated_presentations;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File")
|
||||
* @ORM\JoinColumn(name="PhotoID", referencedColumnName="ID")
|
||||
@ -200,8 +215,11 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->presentations = new ArrayCollection;
|
||||
$this->moderated_presentations = new ArrayCollection;
|
||||
$this->summit_assistances = new ArrayCollection;
|
||||
$this->promo_codes = new ArrayCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,6 +229,16 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
$this->presentations->add($presentation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SpeakerSummitRegistrationPromoCode $code
|
||||
* @return $this
|
||||
*/
|
||||
public function addPromoCode(SpeakerSummitRegistrationPromoCode $code){
|
||||
$this->promo_codes->add($code);
|
||||
$code->setSpeaker($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $summit_id
|
||||
* @param bool|true $published_ones
|
||||
@ -317,6 +345,13 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
return $this->member;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $member
|
||||
*/
|
||||
public function setMember(Member $member){
|
||||
$this->member = $member;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -330,6 +365,7 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
public function getMemberId()
|
||||
{
|
||||
try{
|
||||
if(is_null($this->member)) return 0;
|
||||
return $this->member->getId();
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
@ -351,6 +387,7 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
public function setRegistrationRequest($registration_request)
|
||||
{
|
||||
$this->registration_request = $registration_request;
|
||||
$registration_request->setSpeaker($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,4 +401,50 @@ class PresentationSpeaker extends SilverstripeBaseModel
|
||||
}
|
||||
return $fullname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PresentationSpeakerSummitAssistanceConfirmationRequest[]
|
||||
*/
|
||||
public function getSummitAssistances()
|
||||
{
|
||||
return $this->summit_assistances;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeakerSummitAssistanceConfirmationRequest $assistance
|
||||
* @return $this
|
||||
*/
|
||||
public function addSummitAssistance(PresentationSpeakerSummitAssistanceConfirmationRequest $assistance){
|
||||
$this->summit_assistances->add($assistance);
|
||||
$assistance->setSpeaker($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCreatedFromApi()
|
||||
{
|
||||
return $this->created_from_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $created_from_api
|
||||
*/
|
||||
public function setCreatedFromApi($created_from_api)
|
||||
{
|
||||
$this->created_from_api = $created_from_api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return PresentationSpeakerSummitAssistanceConfirmationRequest
|
||||
*/
|
||||
public function buildAssistanceFor(Summit $summit)
|
||||
{
|
||||
$request = new PresentationSpeakerSummitAssistanceConfirmationRequest;
|
||||
$request->setSummit($summit);
|
||||
$request->setSpeaker($this);
|
||||
return $request;
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
* Class PresentationSpeakerSummitAssistanceConfirmationRequest
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="PresentationSpeakerSummitAssistanceConfirmationRequest")
|
||||
* @package models\summit
|
||||
*/
|
||||
class PresentationSpeakerSummitAssistanceConfirmationRequest extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="OnSitePhoneNumber", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $on_site_phone;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="RegisteredForSummit", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $registered;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="IsConfirmed", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $is_confirmed;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="CheckedIn", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
private $checked_in;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PresentationSpeaker")
|
||||
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
|
||||
* @var PresentationSpeaker
|
||||
*/
|
||||
private $speaker;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Summit")
|
||||
* @ORM\JoinColumn(name="SummitID", referencedColumnName="ID")
|
||||
* @var Summit
|
||||
*/
|
||||
private $summit;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOnSitePhone()
|
||||
{
|
||||
return $this->on_site_phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $on_site_phone
|
||||
*/
|
||||
public function setOnSitePhone($on_site_phone)
|
||||
{
|
||||
$this->on_site_phone = $on_site_phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRegistered()
|
||||
{
|
||||
return $this->registered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $registered
|
||||
*/
|
||||
public function setRegistered($registered)
|
||||
{
|
||||
$this->registered = $registered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isConfirmed()
|
||||
{
|
||||
return $this->is_confirmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_confirmed
|
||||
*/
|
||||
public function setIsConfirmed($is_confirmed)
|
||||
{
|
||||
$this->is_confirmed = $is_confirmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isCheckedIn()
|
||||
{
|
||||
return $this->checked_in;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $checked_in
|
||||
*/
|
||||
public function setCheckedIn($checked_in)
|
||||
{
|
||||
$this->checked_in = $checked_in;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getSpeaker()
|
||||
{
|
||||
return $this->speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
*/
|
||||
public function setSpeaker($speaker)
|
||||
{
|
||||
$this->speaker = $speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Summit
|
||||
*/
|
||||
public function getSummit()
|
||||
{
|
||||
return $this->summit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
*/
|
||||
public function setSummit($summit)
|
||||
{
|
||||
$this->summit = $summit;
|
||||
}
|
||||
}
|
@ -11,15 +11,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\main\Member;
|
||||
use models\utils\RandomGenerator;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* Class SpeakerRegistrationRequest
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSpeakerRegistrationRequestRepository")
|
||||
* @ORM\Table(name="SpeakerRegistrationRequest")
|
||||
* @package models\summit
|
||||
*/
|
||||
@ -49,7 +48,7 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
|
||||
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
|
||||
* @var PresentationSpeaker
|
||||
*/
|
||||
private $moderator;
|
||||
private $speaker;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member")
|
||||
@ -58,6 +57,17 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
|
||||
*/
|
||||
private $proposer;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ConfirmationHash", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $confirmation_hash;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@ -109,17 +119,17 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
|
||||
/**
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getModerator()
|
||||
public function getSpeaker()
|
||||
{
|
||||
return $this->moderator;
|
||||
return $this->speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $moderator
|
||||
* @param PresentationSpeaker $speaker
|
||||
*/
|
||||
public function setModerator($moderator)
|
||||
public function setSpeaker($speaker)
|
||||
{
|
||||
$this->moderator = $moderator;
|
||||
$this->speaker = $speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,4 +147,36 @@ class SpeakerRegistrationRequest extends SilverstripeBaseModel
|
||||
{
|
||||
$this->proposer = $proposer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function generateConfirmationToken() {
|
||||
$generator = new RandomGenerator();
|
||||
$this->is_confirmed = false;
|
||||
$this->confirmation_date = null;
|
||||
$this->token = $generator->randomToken();
|
||||
$this->confirmation_hash = self::HashConfirmationToken($this->token);
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
public static function HashConfirmationToken($token){
|
||||
return md5($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getConfirmationHash()
|
||||
{
|
||||
return $this->confirmation_hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use App\Events\SummitEventCreated;
|
||||
use App\Events\SummitEventDeleted;
|
||||
use App\Events\SummitEventUpdated;
|
||||
@ -23,13 +23,11 @@ use models\main\Member;
|
||||
use models\main\Tag;
|
||||
use models\utils\PreRemoveEventArgs;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Cocur\Slugify\Slugify;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSummitEventRepository")
|
||||
* @ORM\Table(name="SummitEvent")
|
||||
|
@ -0,0 +1,137 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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\main\Member;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="MemberSummitRegistrationPromoCode")
|
||||
* Class MemberSummitRegistrationPromoCode
|
||||
* @package models\summit
|
||||
*/
|
||||
class MemberSummitRegistrationPromoCode extends SummitRegistrationPromoCode
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="FirstName", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $first_name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="LastName", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $last_name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Email", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Type", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member")
|
||||
* @ORM\JoinColumn(name="OwnerID", referencedColumnName="ID")
|
||||
* @var Member
|
||||
*/
|
||||
protected $owner;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->first_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $first_name
|
||||
*/
|
||||
public function setFirstName($first_name)
|
||||
{
|
||||
$this->first_name = $first_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $last_name
|
||||
*/
|
||||
public function setLastName($last_name)
|
||||
{
|
||||
$this->last_name = $last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $email
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Member
|
||||
*/
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $owner
|
||||
*/
|
||||
public function setOwner($owner)
|
||||
{
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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;
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSpeakerSummitRegistrationPromoCodeRepository")
|
||||
* @ORM\Table(name="SpeakerSummitRegistrationPromoCode")
|
||||
* Class SpeakerSummitRegistrationPromoCode
|
||||
* @package models\summit
|
||||
*/
|
||||
class SpeakerSummitRegistrationPromoCode extends SummitRegistrationPromoCode
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="Type", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PresentationSpeaker")
|
||||
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
|
||||
* @var PresentationSpeaker
|
||||
*/
|
||||
protected $speaker;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getSpeaker()
|
||||
{
|
||||
return $this->speaker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
*/
|
||||
public function setSpeaker($speaker)
|
||||
{
|
||||
$this->speaker = $speaker;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->redeemed = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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\main\Company;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="SponsorSummitRegistrationPromoCode")
|
||||
* Class SponsorSummitRegistrationPromoCode
|
||||
* @package models\summit
|
||||
*/
|
||||
class SponsorSummitRegistrationPromoCode extends MemberSummitRegistrationPromoCode
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Company")
|
||||
* @ORM\JoinColumn(name="SponsorID", referencedColumnName="ID")
|
||||
* @var Company
|
||||
*/
|
||||
protected $sponsor;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return 'SPONSOR';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Company
|
||||
*/
|
||||
public function getSponsor()
|
||||
{
|
||||
return $this->sponsor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Company $sponsor
|
||||
*/
|
||||
public function setSponsor($sponsor)
|
||||
{
|
||||
$this->sponsor = $sponsor;
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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\main\Member;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSummitRegistrationPromoCodeRepository")
|
||||
* @ORM\Table(name="SummitRegistrationPromoCode")
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
* @ORM\DiscriminatorMap({"SummitRegistrationPromoCode" = "SummitRegistrationPromoCode",
|
||||
* "SpeakerSummitRegistrationPromoCode" = "SpeakerSummitRegistrationPromoCode",
|
||||
* "MemberSummitRegistrationPromoCode" = "MemberSummitRegistrationPromoCode",
|
||||
* "SponsorSummitRegistrationPromoCode" = "SponsorSummitRegistrationPromoCode"})
|
||||
* Class SummitRegistrationPromoCode
|
||||
* @package models\summit
|
||||
*/
|
||||
class SummitRegistrationPromoCode extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="Code", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="EmailSent", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
protected $email_sent;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Redeemed", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
protected $redeemed;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Source", type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
use SummitOwned;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member")
|
||||
* @ORM\JoinColumn(name="CreatorID", referencedColumnName="ID")
|
||||
* @var Member
|
||||
*/
|
||||
protected $creator;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmailSent()
|
||||
{
|
||||
return $this->email_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $email_sent
|
||||
*/
|
||||
public function setEmailSent($email_sent)
|
||||
{
|
||||
$this->email_sent = $email_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isRedeemed()
|
||||
{
|
||||
return $this->redeemed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $redeemed
|
||||
*/
|
||||
public function setRedeemed($redeemed)
|
||||
{
|
||||
$this->redeemed = $redeemed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
*/
|
||||
public function setSource($source)
|
||||
{
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Member
|
||||
*/
|
||||
public function getCreator()
|
||||
{
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $creator
|
||||
*/
|
||||
public function setCreator($creator)
|
||||
{
|
||||
$this->creator = $creator;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->email_sent = false;
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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 IEmailCreationRequestRepository
|
||||
* @package models\main
|
||||
*/
|
||||
interface IEmailCreationRequestRepository
|
||||
extends IBaseRepository
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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 ISpeakerRegistrationRequestRepository
|
||||
* @package models\summit
|
||||
*/
|
||||
interface ISpeakerRegistrationRequestRepository
|
||||
extends IBaseRepository
|
||||
{
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return bool
|
||||
*/
|
||||
public function existByHash($hash);
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return SpeakerRegistrationRequest
|
||||
*/
|
||||
public function getByHash($hash);
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return bool
|
||||
*/
|
||||
public function existByEmail($email);
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return SpeakerRegistrationRequest
|
||||
*/
|
||||
public function getByEmail($email);
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\main\Member;
|
||||
use utils\Order;
|
||||
use utils\PagingResponse;
|
||||
use utils\PagingInfo;
|
||||
@ -33,4 +34,10 @@ interface ISpeakerRepository extends IBaseRepository
|
||||
* @return PagingResponse
|
||||
*/
|
||||
public function getSpeakersBySummit(Summit $summit, PagingInfo $paging_info, Filter $filter = null, Order $order = null);
|
||||
|
||||
/**
|
||||
* @param Member $member
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getByMember(Member $member);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php namespace models\summit;
|
||||
/**
|
||||
* Copyright 2017 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 ISpeakerSummitRegistrationPromoCodeRepository
|
||||
* @package models\summit
|
||||
*/
|
||||
interface ISpeakerSummitRegistrationPromoCodeRepository
|
||||
extends IBaseRepository
|
||||
{
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getBySpeakerAndSummit(PresentationSpeaker $speaker, Summit $summit);
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return bool
|
||||
*/
|
||||
public function isAssignedCode($code, Summit $summit);
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getNotAssignedCode($code, Summit $summit);
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getAssignedCode($code, Summit $summit);
|
||||
}
|
84
app/Models/Utils/RandomGenerator.php
Normal file
84
app/Models/Utils/RandomGenerator.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php namespace models\utils;
|
||||
/**
|
||||
* Copyright 2017 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 Exception;
|
||||
/**
|
||||
* Class RandomGenerator
|
||||
* @package models\utils
|
||||
*/
|
||||
final class RandomGenerator {
|
||||
|
||||
/**
|
||||
* Note: Returned values are not guaranteed to be crypto-safe,
|
||||
* depending on the used retrieval method.
|
||||
*
|
||||
* @return string Returns a random series of bytes
|
||||
*/
|
||||
public function generateEntropy() {
|
||||
$isWin = preg_match('/WIN/', PHP_OS);
|
||||
|
||||
// TODO Fails with "Could not gather sufficient random data" on IIS, temporarily disabled on windows
|
||||
if(!$isWin) {
|
||||
if(function_exists('mcrypt_create_iv')) {
|
||||
$e = mcrypt_create_iv(64, MCRYPT_DEV_URANDOM);
|
||||
if($e !== false) return $e;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to SSL methods - may slow down execution by a few ms
|
||||
if (function_exists('openssl_random_pseudo_bytes')) {
|
||||
$e = openssl_random_pseudo_bytes(64, $strong);
|
||||
// Only return if strong algorithm was used
|
||||
if($strong) return $e;
|
||||
}
|
||||
|
||||
// Read from the unix random number generator
|
||||
if(!$isWin && !ini_get('open_basedir') && is_readable('/dev/urandom') && ($h = fopen('/dev/urandom', 'rb'))) {
|
||||
$e = fread($h, 64);
|
||||
fclose($h);
|
||||
return $e;
|
||||
}
|
||||
|
||||
// Warning: Both methods below are considered weak
|
||||
|
||||
// try to read from the windows RNG
|
||||
if($isWin && class_exists('COM')) {
|
||||
try {
|
||||
$comObj = new COM('CAPICOM.Utilities.1');
|
||||
|
||||
if(is_callable(array($comObj,'GetRandom'))) {
|
||||
return base64_decode($comObj->GetRandom(64, 0));
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to good old mt_rand()
|
||||
return uniqid(mt_rand(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random token that can be used for session IDs, CSRF tokens etc., based on
|
||||
* hash algorithms.
|
||||
*
|
||||
* If you are using it as a password equivalent (e.g. autologin token) do NOT store it
|
||||
* in the database as a plain text but encrypt it with Member::encryptWithUserSettings.
|
||||
*
|
||||
* @param String $algorithm Any identifier listed in hash_algos() (Default: whirlpool)
|
||||
*
|
||||
* @return String Returned length will depend on the used $algorithm
|
||||
*/
|
||||
public function randomToken($algorithm = 'whirlpool') {
|
||||
return hash($algorithm, $this->generateEntropy());
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php namespace repositories\main;
|
||||
/**
|
||||
* Copyright 2017 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\Repositories\SilverStripeDoctrineRepository;
|
||||
use models\main\EmailCreationRequest;
|
||||
use models\main\IEmailCreationRequestRepository;
|
||||
/**
|
||||
* Class DoctrineEmailCreationRequestRepository
|
||||
* @package repositories\main
|
||||
*/
|
||||
class DoctrineEmailCreationRequestRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements IEmailCreationRequestRepository
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return EmailCreationRequest::class;
|
||||
}
|
||||
}
|
@ -16,9 +16,11 @@ use Illuminate\Support\ServiceProvider;
|
||||
use LaravelDoctrine\ORM\Facades\EntityManager;
|
||||
use models\main\AssetsSyncRequest;
|
||||
use models\main\Company;
|
||||
use models\main\EmailCreationRequest;
|
||||
use models\main\File;
|
||||
use models\main\Group;
|
||||
|
||||
use models\summit\SpeakerRegistrationRequest;
|
||||
use models\summit\SpeakerSummitRegistrationPromoCode;
|
||||
/**
|
||||
* Class RepositoriesProvider
|
||||
* @package repositories
|
||||
@ -210,5 +212,24 @@ final class RepositoriesProvider extends ServiceProvider
|
||||
function(){
|
||||
return EntityManager::getRepository(Group::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'models\summit\ISpeakerRegistrationRequestRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(SpeakerRegistrationRequest::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'models\summit\ISpeakerSummitRegistrationPromoCodeRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(SpeakerSummitRegistrationPromoCode::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'models\main\IEmailCreationRequestRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(EmailCreationRequest::class);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -35,7 +35,15 @@ final class DoctrineMemberRepository
|
||||
*/
|
||||
public function getByEmail($email)
|
||||
{
|
||||
// TODO: Implement getByEmail() method.
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("m")
|
||||
->from(\models\main\Member::class, "m")
|
||||
->where("m.email = :email")
|
||||
->setParameter("email", trim($email))
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,86 @@
|
||||
<?php namespace App\Repositories\Summit;
|
||||
/**
|
||||
* Copyright 2017 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\Repositories\SilverStripeDoctrineRepository;
|
||||
use models\summit\ISpeakerRegistrationRequestRepository;
|
||||
use models\summit\SpeakerRegistrationRequest;
|
||||
|
||||
/**
|
||||
* Class DoctrineSpeakerRegistrationRequestRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
final class DoctrineSpeakerRegistrationRequestRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements ISpeakerRegistrationRequestRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return SpeakerRegistrationRequest::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return bool
|
||||
*/
|
||||
public function existByHash($hash)
|
||||
{
|
||||
return $this->getByHash($hash) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return SpeakerRegistrationRequest
|
||||
*/
|
||||
public function getByHash($hash)
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("r")
|
||||
->from(SpeakerRegistrationRequest::class, "r")
|
||||
->where("r.confirmation_hash = :confirmation_hash")
|
||||
->setParameter("confirmation_hash", trim($hash))
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return bool
|
||||
*/
|
||||
public function existByEmail($email)
|
||||
{
|
||||
return $this->getByEmail($email) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return SpeakerRegistrationRequest
|
||||
*/
|
||||
public function getByEmail($email)
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("r")
|
||||
->from(SpeakerRegistrationRequest::class, "r")
|
||||
->where("r.email = :email")
|
||||
->setParameter("email", trim($email))
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use models\main\Member;
|
||||
use models\summit\ISpeakerRepository;
|
||||
use models\summit\PresentationSpeaker;
|
||||
use models\summit\Summit;
|
||||
@ -22,7 +23,6 @@ use utils\Filter;
|
||||
use utils\Order;
|
||||
use utils\PagingInfo;
|
||||
use utils\PagingResponse;
|
||||
|
||||
/**
|
||||
* Class DoctrineSpeakerRepository
|
||||
* @package App\Repositories\Summit
|
||||
@ -355,4 +355,21 @@ SQL;
|
||||
{
|
||||
return PresentationSpeaker::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $member
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function getByMember(Member $member)
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("s")
|
||||
->from(PresentationSpeaker::class, "s")
|
||||
->where("s.member = :member")
|
||||
->setParameter("member", $member)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
<?php namespace App\Repositories\Summit;
|
||||
/**
|
||||
* Copyright 2017 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\summit\ISpeakerSummitRegistrationPromoCodeRepository;
|
||||
use models\summit\PresentationSpeaker;
|
||||
use models\summit\SpeakerSummitRegistrationPromoCode;
|
||||
use models\summit\Summit;
|
||||
|
||||
/**
|
||||
* Class DoctrineSpeakerSummitRegistrationPromoCodeRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
final class DoctrineSpeakerSummitRegistrationPromoCodeRepository
|
||||
extends DoctrineSummitRegistrationPromoCodeRepository
|
||||
implements ISpeakerSummitRegistrationPromoCodeRepository
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return SpeakerSummitRegistrationPromoCode::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getBySpeakerAndSummit(PresentationSpeaker $speaker, Summit $summit)
|
||||
{
|
||||
if($speaker->getId() == 0) return null;
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("c")
|
||||
->from(SpeakerSummitRegistrationPromoCode::class, "c")
|
||||
->where("c.speaker = :speaker")
|
||||
->andWhere("c.summit = :summit")
|
||||
->setParameter("speaker", $speaker)
|
||||
->setParameter("summit", $summit)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return bool
|
||||
*/
|
||||
public function isAssignedCode($code, Summit $summit)
|
||||
{
|
||||
return $this->getAssignedCode($code, $summit) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getAssignedCode($code, Summit $summit)
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("c")
|
||||
->from(SpeakerSummitRegistrationPromoCode::class, "c")
|
||||
->where("c.speaker is not null")
|
||||
->andWhere("c.summit = :summit")
|
||||
->andWhere("c.code = :code")
|
||||
->setParameter("summit", $summit)
|
||||
->setParameter("code", trim($code))
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Summit $summit
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
*/
|
||||
public function getNotAssignedCode($code, Summit $summit)
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->createQueryBuilder()
|
||||
->select("c")
|
||||
->from(SpeakerSummitRegistrationPromoCode::class, "c")
|
||||
->where("c.speaker is null")
|
||||
->andWhere("c.summit = :summit")
|
||||
->andWhere("c.code = :code")
|
||||
->setParameter("summit", $summit)
|
||||
->setParameter("code", trim($code))
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php namespace App\Repositories\Summit;
|
||||
/**
|
||||
* Copyright 2017 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\Repositories\SilverStripeDoctrineRepository;
|
||||
use models\summit\SummitRegistrationPromoCode;
|
||||
/**
|
||||
* Class DoctrineSummitRegistrationPromoCodeRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
class DoctrineSummitRegistrationPromoCodeRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return SummitRegistrationPromoCode::class;
|
||||
}
|
||||
}
|
@ -21,4 +21,7 @@ final class SummitScopes
|
||||
{
|
||||
const ReadSummitData = '%s/summits/read';
|
||||
const ReadAllSummitData = '%s/summits/read/all';
|
||||
|
||||
const WriteSummitData = '%s/summits/write';
|
||||
const WriteSpeakersData = '%s/speakers/write';
|
||||
}
|
40
app/Services/Model/ISpeakerService.php
Normal file
40
app/Services/Model/ISpeakerService.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php namespace services\model;
|
||||
/**
|
||||
* Copyright 2017 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\exceptions\ValidationException;
|
||||
use models\summit\PresentationSpeaker;
|
||||
use models\summit\SpeakerSummitRegistrationPromoCode;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Interface ISpeakerService
|
||||
* @package services\model
|
||||
*/
|
||||
interface ISpeakerService
|
||||
{
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return PresentationSpeaker
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addSpeaker(Summit $summit, array $data);
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @param Summit $summit
|
||||
* @param string $reg_code
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code);
|
||||
}
|
263
app/Services/Model/SpeakerService.php
Normal file
263
app/Services/Model/SpeakerService.php
Normal file
@ -0,0 +1,263 @@
|
||||
<?php namespace services\model;
|
||||
/**
|
||||
* Copyright 2017 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 libs\utils\ITransactionService;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\IEmailCreationRequestRepository;
|
||||
use models\main\IFolderRepository;
|
||||
use models\main\IMemberRepository;
|
||||
use models\main\SpeakerCreationEmailCreationRequest;
|
||||
use models\summit\ISpeakerRegistrationRequestRepository;
|
||||
use models\summit\ISpeakerRepository;
|
||||
use models\summit\ISpeakerSummitRegistrationPromoCodeRepository;
|
||||
use models\summit\PresentationSpeaker;
|
||||
use models\summit\SpeakerRegistrationRequest;
|
||||
use models\summit\SpeakerSummitRegistrationPromoCode;
|
||||
use models\summit\Summit;
|
||||
|
||||
/**
|
||||
* Class SpeakerService
|
||||
* @package services\model
|
||||
*/
|
||||
final class SpeakerService implements ISpeakerService
|
||||
{
|
||||
/**
|
||||
* @var ISpeakerRepository
|
||||
*/
|
||||
private $speaker_repository;
|
||||
|
||||
/**
|
||||
* @var IMemberRepository
|
||||
*/
|
||||
private $member_repository;
|
||||
|
||||
/**
|
||||
* @var IFolderRepository
|
||||
*/
|
||||
private $folder_repository;
|
||||
|
||||
/**
|
||||
* @var ISpeakerRegistrationRequestRepository
|
||||
*/
|
||||
private $speaker_registration_request_repository;
|
||||
|
||||
/**
|
||||
* @var ISpeakerSummitRegistrationPromoCodeRepository
|
||||
*/
|
||||
private $registration_code_repository;
|
||||
|
||||
/**
|
||||
* @var IEmailCreationRequestRepository
|
||||
*/
|
||||
private $email_creation_request_repository;
|
||||
/**
|
||||
* @var ITransactionService
|
||||
*/
|
||||
private $tx_service;
|
||||
|
||||
|
||||
public function __construct
|
||||
(
|
||||
ISpeakerRepository $speaker_repository,
|
||||
IMemberRepository $member_repository,
|
||||
ISpeakerRegistrationRequestRepository $speaker_registration_request_repository,
|
||||
ISpeakerSummitRegistrationPromoCodeRepository $registration_code_repository,
|
||||
IEmailCreationRequestRepository $email_creation_request_repository,
|
||||
IFolderRepository $folder_repository,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
{
|
||||
$this->speaker_repository = $speaker_repository;
|
||||
$this->member_repository = $member_repository;
|
||||
$this->folder_repository = $folder_repository;
|
||||
$this->speaker_registration_request_repository = $speaker_registration_request_repository;
|
||||
$this->registration_code_repository = $registration_code_repository;
|
||||
$this->email_creation_request_repository = $email_creation_request_repository;
|
||||
$this->tx_service = $tx_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @return PresentationSpeaker
|
||||
*/
|
||||
public function addSpeaker(Summit $summit, array $data){
|
||||
|
||||
return $this->tx_service->transaction(function() use($data, $summit){
|
||||
|
||||
$speaker = new PresentationSpeaker();
|
||||
$speaker->setCreatedFromApi(true);
|
||||
$member_id = 0;
|
||||
|
||||
if(!isset($data['email']) && !isset($data['member_id']))
|
||||
throw
|
||||
new ValidationException
|
||||
("you must provide an email or a member_id in order to create a speaker!");
|
||||
|
||||
if(isset($data['member_id']) && intval($data['member_id']) > 0){
|
||||
$member_id = intval($data['member_id']);
|
||||
$existent_speaker = $this->speaker_repository->getByMember($member_id);
|
||||
if(!is_null($existent_speaker))
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"member_id %s already has assigned an speaker!",
|
||||
$member_id
|
||||
)
|
||||
);
|
||||
|
||||
$member = $this->member_repository->getById($member_id);
|
||||
if(is_null($member))
|
||||
throw new EntityNotFoundException(sprintf("member id %s does not exists!", $member_id));
|
||||
$speaker->setMember($member);
|
||||
}
|
||||
|
||||
$this->updateSpeakerMainData($speaker, $data);
|
||||
|
||||
if($member_id === 0 && isset($data['email'])){
|
||||
$email = trim($data['email']);
|
||||
$member = $this->member_repository->getByEmail($email);
|
||||
if(is_null($member)){
|
||||
$this->registerSpeaker($speaker, $email);
|
||||
}
|
||||
else
|
||||
{
|
||||
$existent_speaker = $this->speaker_repository->getByMember($member);
|
||||
if(!is_null($existent_speaker))
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
(
|
||||
"member id %s already has assigned a speaker id %s!",
|
||||
$member->getIdentifier(),
|
||||
$existent_speaker->getIdentifier()
|
||||
)
|
||||
);
|
||||
$speaker->setMember($member);
|
||||
}
|
||||
}
|
||||
|
||||
$on_site_phone = isset($data['on_site_phone']) ? trim($data['on_site_phone']) : null;
|
||||
$registered = isset($data['registered']) ? 1 : 0;
|
||||
$checked_in = isset($data['checked_in']) ? 1 : 0;
|
||||
$confirmed = isset($data['confirmed']) ? 1 : 0;
|
||||
|
||||
$summit_assistance = $speaker->buildAssistanceFor($summit);
|
||||
$summit_assistance->setOnSitePhone($on_site_phone);
|
||||
$summit_assistance->setRegistered($registered);
|
||||
$summit_assistance->setIsConfirmed($confirmed);
|
||||
$summit_assistance->setCheckedIn($checked_in);
|
||||
|
||||
$speaker->addSummitAssistance($summit_assistance);
|
||||
|
||||
$reg_code = isset($data['registration_code']) ? trim($data['registration_code']) : null;
|
||||
if(!empty($reg_code)){
|
||||
$this->registerSummitPromoCodeByValue($speaker, $summit, $reg_code);
|
||||
}
|
||||
$this->speaker_repository->add($speaker);
|
||||
|
||||
$email_request = new SpeakerCreationEmailCreationRequest();
|
||||
$email_request->setSpeaker($speaker);
|
||||
$this->email_creation_request_repository->add($email_request);
|
||||
|
||||
return $speaker;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @param string $email
|
||||
* @return SpeakerRegistrationRequest
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function registerSpeaker(PresentationSpeaker $speaker, $email){
|
||||
|
||||
if($this->speaker_registration_request_repository->existByEmail($email))
|
||||
throw new ValidationException(sprintf("email %s already has a Speaker Registration Request", $email));
|
||||
|
||||
$registration_request = new SpeakerRegistrationRequest();
|
||||
$registration_request->setEmail($email);
|
||||
|
||||
do {
|
||||
$registration_request->generateConfirmationToken();
|
||||
}while($this->speaker_registration_request_repository->existByHash($registration_request->getConfirmationHash()));
|
||||
|
||||
$speaker->setRegistrationRequest($registration_request);
|
||||
return $registration_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationSpeaker $speaker
|
||||
* @param Summit $summit
|
||||
* @param string $reg_code
|
||||
* @return SpeakerSummitRegistrationPromoCode
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function registerSummitPromoCodeByValue(PresentationSpeaker $speaker, Summit $summit, $reg_code){
|
||||
|
||||
return $this->tx_service->transaction(function() use($speaker, $summit, $reg_code) {
|
||||
$existent_code = $this->registration_code_repository->getBySpeakerAndSummit($speaker, $summit);
|
||||
|
||||
// we are trying to update the promo code with another one ....
|
||||
if ($existent_code && $reg_code !== $existent_code->getCode()) {
|
||||
throw new ValidationException(sprintf(
|
||||
'speaker has been already assigned to another registration code (%s)', $existent_code->getCode()
|
||||
));
|
||||
}
|
||||
|
||||
if ($assigned_code = $this->registration_code_repository->getAssignedCode($reg_code, $summit)) {
|
||||
throw new ValidationException(sprintf(
|
||||
'there is another speaker with that code for this summit ( speaker id %s )', $assigned_code->getSpeaker()->getId()
|
||||
));
|
||||
}
|
||||
|
||||
$code = $this->registration_code_repository->getNotAssignedCode($reg_code, $summit);
|
||||
|
||||
if (is_null($code)) {
|
||||
//create it
|
||||
$code = new SpeakerSummitRegistrationPromoCode();
|
||||
$code->setSummit($summit);
|
||||
$code->setCode($reg_code);
|
||||
}
|
||||
|
||||
$speaker->addPromoCode($code);
|
||||
|
||||
return $code;
|
||||
});
|
||||
}
|
||||
|
||||
private function updateSpeakerMainData(PresentationSpeaker $speaker, array $data){
|
||||
if(isset($data['title']))
|
||||
$speaker->setTitle(trim($data['title']));
|
||||
|
||||
if(isset($data['bio']))
|
||||
$speaker->setBio(trim($data['bio']));
|
||||
|
||||
if(isset($data['first_name']))
|
||||
$speaker->setFirstName(trim($data['first_name']));
|
||||
|
||||
if(isset($data['last_name']))
|
||||
$speaker->setLastName(trim($data['last_name']));
|
||||
|
||||
if(isset($data['irc']))
|
||||
$speaker->setIrcHandle(trim($data['irc']));
|
||||
|
||||
if(isset($data['twitter']))
|
||||
$speaker->setTwitterName(trim($data['twitter']));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -79,6 +79,7 @@ final class SummitService implements ISummitService
|
||||
* minimun number of minutes that an event must last
|
||||
*/
|
||||
const MIN_EVENT_MINUTES = 5;
|
||||
|
||||
/**
|
||||
* @var ITransactionService
|
||||
*/
|
||||
@ -144,7 +145,6 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
private $company_repository;
|
||||
|
||||
|
||||
/**
|
||||
* @var IGroupRepository
|
||||
*/
|
||||
|
@ -53,6 +53,8 @@ class ServicesProvider extends ServiceProvider
|
||||
|
||||
App::singleton('services\model\ISummitService', 'services\model\SummitService');
|
||||
|
||||
App::singleton('services\model\ISpeakerService', 'services\model\SpeakerService');
|
||||
|
||||
App::singleton('services\model\IPresentationService', 'services\model\PresentationService');
|
||||
|
||||
App::singleton('services\model\IChatTeamService', 'services\model\ChatTeamService');
|
||||
|
@ -157,6 +157,14 @@ class ApiEndpointsSeeder extends Seeder
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
),
|
||||
array(
|
||||
'name' => 'add-speaker',
|
||||
'route' => '/api/v1/summits/{id}/speakers',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
|
||||
],
|
||||
),
|
||||
array(
|
||||
'name' => 'get-all-speakers',
|
||||
'route' => '/api/v1/speakers',
|
||||
|
@ -71,7 +71,7 @@ final class ApiScopesSeeder extends Seeder
|
||||
'description' => 'Allows to remove Summit events as favorite',
|
||||
),
|
||||
array(
|
||||
'name' => sprintf('%s/summits/write', $current_realm),
|
||||
'name' => sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
'short_description' => 'Write Summit Data',
|
||||
'description' => 'Grants write access for Summits Data',
|
||||
),
|
||||
@ -109,7 +109,12 @@ final class ApiScopesSeeder extends Seeder
|
||||
'name' => sprintf('%s/summits/read-notifications', $current_realm),
|
||||
'short_description' => 'Allow to read summit notifications',
|
||||
'description' => 'Allow to read summit notifications',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => sprintf(SummitScopes::WriteSpeakersData, $current_realm),
|
||||
'short_description' => 'Write Speakers Data',
|
||||
'description' => 'Grants write access for Speakers Data',
|
||||
),
|
||||
];
|
||||
|
||||
foreach ($scopes as $scope_info) {
|
||||
|
133
tests/OAuth2SpeakersApiTest.php
Normal file
133
tests/OAuth2SpeakersApiTest.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2017 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.
|
||||
**/
|
||||
class OAuth2SpeakersApiTest extends ProtectedApiTest
|
||||
{
|
||||
public function testPostSpeaker($summit_id = 23)
|
||||
{
|
||||
$params = [
|
||||
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
||||
'title' => 'Developer!',
|
||||
'first_name' => 'Sebastian',
|
||||
'last_name' => 'Marcet',
|
||||
'email' => 'sebastian.ge4.marcet@gmail.com'
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"POST",
|
||||
"OAuth2SummitSpeakersApiController@addSpeaker",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$this->assertResponseStatus(201);
|
||||
$content = $response->getContent();
|
||||
$speaker = json_decode($content);
|
||||
$this->assertTrue($speaker->id > 0);
|
||||
return $speaker;
|
||||
}
|
||||
|
||||
public function testPostSpeakerRegCode($summit_id = 23)
|
||||
{
|
||||
$params = [
|
||||
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
||||
'title' => 'Developer!',
|
||||
'first_name' => 'Sebastian',
|
||||
'last_name' => 'Marcet',
|
||||
'email' => 'sebastian.ge7.marcet@gmail.com',
|
||||
'registration_code' => 'SPEAKER_00001'
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"POST",
|
||||
"OAuth2SummitSpeakersApiController@addSpeaker",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$this->assertResponseStatus(201);
|
||||
$content = $response->getContent();
|
||||
$speaker = json_decode($content);
|
||||
$this->assertTrue($speaker->id > 0);
|
||||
return $speaker;
|
||||
}
|
||||
|
||||
public function testPostSpeakerExistent($summit_id = 23)
|
||||
{
|
||||
$params = [
|
||||
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
||||
'title' => 'Developer!',
|
||||
'first_name' => 'Sebastian',
|
||||
'last_name' => 'Marcet',
|
||||
'email' => 'sebastian@tipit.net',
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"POST",
|
||||
"OAuth2SummitSpeakersApiController@addSpeaker",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$this->assertResponseStatus(201);
|
||||
$content = $response->getContent();
|
||||
$speaker = json_decode($content);
|
||||
$this->assertTrue($speaker->id > 0);
|
||||
return $speaker;
|
||||
}
|
||||
}
|
@ -11,12 +11,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use models\oauth2\AccessToken;
|
||||
use App\Models\ResourceServer\IAccessTokenService;
|
||||
|
||||
use App\Security\SummitScopes;
|
||||
/**
|
||||
* Class AccessTokenServiceStub
|
||||
*/
|
||||
@ -57,6 +56,7 @@ class AccessTokenServiceStub implements IAccessTokenService
|
||||
$url . '/teams/write',
|
||||
$url . '/me/summits/events/favorites/add',
|
||||
$url . '/me/summits/events/favorites/delete',
|
||||
sprintf(SummitScopes::WriteSpeakersData, $url),
|
||||
);
|
||||
|
||||
return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, '1','11624', 3600, 'WEB_APPLICATION', '', '');
|
||||
@ -101,6 +101,7 @@ class AccessTokenServiceStub2 implements IAccessTokenService
|
||||
$url . '/teams/write',
|
||||
$url . '/me/summits/events/favorites/add',
|
||||
$url . '/me/summits/events/favorites/delete',
|
||||
sprintf(SummitScopes::WriteSpeakersData, $url),
|
||||
);
|
||||
|
||||
return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, null,null, 3600, 'SERVICE', '', '');
|
||||
|
Loading…
x
Reference in New Issue
Block a user