fixed speaker update endpoints

* refactoring
* adding missing relations
- other_presentation_links ( string array)
- languages ( int array)
- travel_preferences ( string array)
- areas_of_expertise ( string array)
- organizational_roles ( int array)
- other_organizational_rol ( field string)
- active_involvements ( int array )

Change-Id: I5f1093a43035aa2d6eadb6eea16bde250fb3d6a7
This commit is contained in:
Sebastian Marcet 2018-10-16 23:06:38 -03:00
parent 210c46e3ee
commit 63a1083a93
27 changed files with 865 additions and 441 deletions

View File

@ -505,6 +505,14 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
'willing_to_present_video' => 'sometimes|boolean',
'org_has_cloud' => 'sometimes|boolean',
'country' => 'sometimes|country_iso_alpha2_code',
// collections
'languages' => 'sometimes|int_array',
'areas_of_expertise' => 'sometimes|string_array',
'other_presentation_links' => 'sometimes|string_array',
'travel_preferences' => 'sometimes|string_array',
'organizational_roles' => 'sometimes|int_array',
'other_organizational_rol' => 'sometimes|string|max:255',
'active_involvements' => 'sometimes|int_array',
];
// Creates a Validator instance and validates the data.
@ -524,7 +532,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
'bio',
];
$speaker = $this->service->addSpeaker($summit, HTMLCleaner::cleanData($data->all(), $fields));
$speaker = $this->service->addSpeakerBySummit($summit, HTMLCleaner::cleanData($data->all(), $fields));
return $this->created(SerializerRegistry::getInstance()->getSerializer($speaker)->serialize());
} catch (ValidationException $ex1) {
@ -576,6 +584,14 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
'willing_to_present_video' => 'sometimes|boolean',
'org_has_cloud' => 'sometimes|boolean',
'country' => 'sometimes|country_iso_alpha2_code',
// collections
'languages' => 'sometimes|int_array',
'areas_of_expertise' => 'sometimes|string_array',
'other_presentation_links' => 'sometimes|string_array',
'travel_preferences' => 'sometimes|string_array',
'organizational_roles' => 'sometimes|int_array',
'other_organizational_rol' => 'sometimes|string|max:255',
'active_involvements' => 'sometimes|int_array',
];
// Creates a Validator instance and validates the data.
@ -610,6 +626,33 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
}
}
public function addMySpeakerPhoto(LaravelRequest $request){
try {
$current_member_id = $this->resource_server_context->getCurrentUserExternalId();
if (is_null($current_member_id))
return $this->error403();
$member = $this->member_repository->getById($current_member_id);
if (is_null($member))
return $this->error403();
$speaker = $this->speaker_repository->getByMember($member);
if (is_null($speaker)) return $this->error404();
return $this->addSpeakerPhoto($request, $speaker->getId());
} catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412($ex1->getMessages());
} catch (EntityNotFoundException $ex2) {
Log::warning($ex2);
return $this->error404(array('message' => $ex2->getMessage()));
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param LaravelRequest $request
* @param $speaker_id
@ -694,12 +737,20 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
'twitter' => 'sometimes|string|max:50',
'member_id' => 'sometimes|integer',
'email' => 'sometimes|string|max:50',
'available_for_bureau' => 'sometimes|boolean',
'funded_travel' => 'sometimes|boolean',
'willing_to_travel' => 'sometimes|boolean',
'willing_to_present_video' => 'sometimes|boolean',
'org_has_cloud' => 'sometimes|boolean',
'available_for_bureau' => 'sometimes|boolean',
'country' => 'sometimes|country_iso_alpha2_code',
// collections
'languages' => 'sometimes|int_array',
'areas_of_expertise' => 'sometimes|string_array',
'other_presentation_links' => 'sometimes|string_array',
'travel_preferences' => 'sometimes|string_array',
'organizational_roles' => 'sometimes|int_array',
'other_organizational_rol' => 'sometimes|string|max:255',
'active_involvements' => 'sometimes|int_array',
];
// Creates a Validator instance and validates the data.
@ -765,6 +816,14 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
'willing_to_present_video' => 'sometimes|boolean',
'org_has_cloud' => 'sometimes|boolean',
'country' => 'sometimes|country_iso_alpha2_code',
// collections
'languages' => 'sometimes|int_array',
'areas_of_expertise' => 'sometimes|string_array',
'other_presentation_links' => 'sometimes|string_array',
'travel_preferences' => 'sometimes|string_array',
'organizational_roles' => 'sometimes|int_array',
'other_organizational_rol' => 'sometimes|string|max:255',
'active_involvements' => 'sometimes|int_array',
];
// Creates a Validator instance and validates the data.

View File

@ -606,6 +606,8 @@ Route::group([
Route::get('', 'OAuth2SummitSpeakersApiController@getMySpeaker');
Route::post('', 'OAuth2SummitSpeakersApiController@createMySpeaker');
Route::put('', 'OAuth2SummitSpeakersApiController@updateMySpeaker');
Route::post('/photo', 'OAuth2SummitSpeakersApiController@addMySpeakerPhoto');
Route::group(['prefix' => 'presentations'], function(){
Route::group(['prefix' => '{presentation_id}'], function(){

View File

@ -0,0 +1,26 @@
<?php namespace App\ModelSerializers;
/**
* 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 ModelSerializers\SilverStripeSerializer;
/**
* Class LanguageSerializer
* @package App\ModelSerializers
*/
final class LanguageSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
'IsoCode(' => 'iso_code:json_string',
];
}

View File

@ -12,6 +12,7 @@
* limitations under the License.
**/
use App\ModelSerializers\CCLA\TeamSerializer;
use App\ModelSerializers\LanguageSerializer;
use App\ModelSerializers\Marketplace\CloudServiceOfferedSerializer;
use App\ModelSerializers\Marketplace\ConfigurationManagementTypeSerializer;
use App\ModelSerializers\Marketplace\ConsultantClientSerializer;
@ -122,6 +123,7 @@ final class SerializerRegistry
$this->registry['PresentationCategoryGroup'] = PresentationCategoryGroupSerializer::class;
$this->registry['PrivatePresentationCategoryGroup'] = PrivatePresentationCategoryGroupSerializer::class;
$this->registry['Tag'] = TagSerializer::class;
$this->registry['Language'] = LanguageSerializer::class;
// track questions
$this->registry['TrackAnswer'] = TrackAnswerSerializer::class;
$this->registry['TrackQuestionValueTemplate'] = TrackQuestionValueTemplateSerializer::class;
@ -166,7 +168,6 @@ final class SerializerRegistry
$this->registry['RSVPDropDownQuestionTemplate'] = RSVPDropDownQuestionTemplateSerializer::class;
$this->registry['SpeakerExpertise'] = SpeakerExpertiseSerializer::class;
$this->registry['SpeakerLanguage'] = SpeakerLanguageSerializer::class;
$this->registry['SpeakerTravelPreference'] = SpeakerTravelPreferenceSerializer::class;
$this->registry['SpeakerPresentationLink'] = SpeakerPresentationLinkSerializer::class;
$this->registry['SpeakerActiveInvolvement'] = SpeakerActiveInvolvementSerializer::class;

View File

@ -78,42 +78,6 @@ final class AdminPresentationSpeakerSerializer extends PresentationSpeakerSerial
$values['all_moderated_presentations'] = $speaker->getAllModeratedPresentationIds( false);
}
$languages = [];
foreach ($speaker->getLanguages() as $language){
$languages[] = SerializerRegistry::getInstance()->getSerializer($language)->serialize();
}
$values['languages'] = $languages;
$other_presentation_links = [];
foreach ($speaker->getOtherPresentationLinks() as $link){
$other_presentation_links[] = SerializerRegistry::getInstance()->getSerializer($link)->serialize();
}
$values['other_presentation_links'] = $other_presentation_links;
$areas_of_expertise = [];
foreach ($speaker->getAreasOfExpertise() as $exp){
$areas_of_expertise[] = SerializerRegistry::getInstance()->getSerializer($exp)->serialize();
}
$values['areas_of_expertise'] = $areas_of_expertise;
$travel_preferences = [];
foreach ($speaker->getTravelPreferences() as $tp){
$travel_preferences[] = SerializerRegistry::getInstance()->getSerializer($tp)->serialize();
}
$values['travel_preferences'] = $travel_preferences;
$active_involvements = [];
foreach ($speaker->getActiveInvolvements() as $ai){
$active_involvements[] = SerializerRegistry::getInstance()->getSerializer($ai)->serialize();
}
$values['active_involvements'] = $active_involvements;
$organizational_roles = [];
foreach ($speaker->getOrganizationalRoles() as $or){
$organizational_roles[] = SerializerRegistry::getInstance()->getSerializer($or)->serialize();
}
$values['organizational_roles'] = $organizational_roles;
$affiliations = [];
if($speaker->hasMember()) {
$member = $speaker->getMember();

View File

@ -33,7 +33,6 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
'FundedTravel' => 'funded_travel:json_boolean',
'WillingToTravel' => 'willing_to_travel:json_boolean',
'WillingToPresentVideo' => 'willing_to_present_video:json_boolean',
];
protected static $allowed_relations = [
@ -45,8 +44,13 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
* @return null|string|string[]
*/
protected function getSpeakerEmail(PresentationSpeaker $speaker){
$speaker_email = $speaker->getEmail();
return preg_replace('/(?<=.).(?=.*.)/u','*', $speaker_email);
$email = $speaker->getEmail();
$em = explode("@", $email);
$name = implode(array_slice($em, 0, count($em) - 1), '@');
$len = floor(strlen($name) / 2);
$obfuscated_email = substr($name, 0, $len) . str_repeat('*', $len) . "@" . end($em);
return $obfuscated_email;
}
/**
@ -95,7 +99,6 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
$values['last_name'] = $last_name;
}
$affiliations = [];
if($speaker->hasMember()) {
$member = $speaker->getMember();
@ -105,6 +108,42 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
}
$values['affiliations'] = $affiliations;
$languages = [];
foreach ($speaker->getLanguages() as $language){
$languages[] = SerializerRegistry::getInstance()->getSerializer($language)->serialize();
}
$values['languages'] = $languages;
$other_presentation_links = [];
foreach ($speaker->getOtherPresentationLinks() as $link){
$other_presentation_links[] = SerializerRegistry::getInstance()->getSerializer($link)->serialize();
}
$values['other_presentation_links'] = $other_presentation_links;
$areas_of_expertise = [];
foreach ($speaker->getAreasOfExpertise() as $exp){
$areas_of_expertise[] = SerializerRegistry::getInstance()->getSerializer($exp)->serialize();
}
$values['areas_of_expertise'] = $areas_of_expertise;
$travel_preferences = [];
foreach ($speaker->getTravelPreferences() as $tp){
$travel_preferences[] = SerializerRegistry::getInstance()->getSerializer($tp)->serialize();
}
$values['travel_preferences'] = $travel_preferences;
$active_involvements = [];
foreach ($speaker->getActiveInvolvements() as $ai){
$active_involvements[] = SerializerRegistry::getInstance()->getSerializer($ai)->serialize();
}
$values['active_involvements'] = $active_involvements;
$organizational_roles = [];
foreach ($speaker->getOrganizationalRoles() as $or){
$organizational_roles[] = SerializerRegistry::getInstance()->getSerializer($or)->serialize();
}
$values['organizational_roles'] = $organizational_roles;
if (!empty($expand)) {
foreach (explode(',', $expand) as $relation) {
switch (trim($relation)) {

View File

@ -16,6 +16,6 @@ final class SpeakerOrganizationalRoleSerializer
{
protected static $array_mappings = [
'Role' => 'role:json_string',
'IsDefault' => 'is_default:json_boolean',
'Default' => 'is_default:json_boolean',
];
}

View File

@ -15,7 +15,8 @@ final class SpeakerTravelPreferenceSerializer
extends SilverStripeSerializer
{
protected static $array_mappings = [
'Country' => 'country:json_string',
'SpeakerId' => 'speaker_id:json_int',
'Country' => 'country_iso_code:json_string',
'CountryName' => 'country:json_string',
'SpeakerId' => 'speaker_id:json_int',
];
}

View File

@ -0,0 +1,52 @@
<?php namespace App\Models\Foundation\Main;
/**
* 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\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity(repositoryClass="App\Repositories\Main\DoctrineLanguageRepository")
* @ORM\Table(name="Language")
* Class Language
* @package App\Models\Foundation\Main
*/
final class Language extends SilverstripeBaseModel
{
/**
* @ORM\Column(name="Name", type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(name="IsoCode_639_1", type="string")
* @var string
*/
private $iso_code;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getIsoCode()
{
return $this->iso_code;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace ModelSerializers;
<?php namespace App\Models\Foundation\Main\Repositories;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -11,11 +11,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
final class SpeakerLanguageSerializer
extends SilverStripeSerializer
use models\utils\IBaseRepository;
/**
* Interface ILanguageRepository
* @package App\Models\Foundation\Main\Repositories
*/
interface ILanguageRepository extends IBaseRepository
{
protected static $array_mappings = [
'Language' => 'language:json_string',
'SpeakerId' => 'speaker_id:json_int',
];
}

View File

@ -38,6 +38,18 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
*/
private $speaker;
/**
* SpeakerPresentationLink constructor.
* @param string $link
* @param string|null $title
*/
public function __construct($link, $title = null)
{
parent::__construct();
$this->link = $link;
$this->title = $title;
}
/**
* @return string
*/
@ -97,4 +109,6 @@ class SpeakerPresentationLink extends SilverstripeBaseModel
return 0;
}
}
}

View File

@ -0,0 +1,22 @@
<?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 ISpeakerActiveInvolvementRepository
* @package App\Models\Foundation\Summit\Repositories
*/
interface ISpeakerActiveInvolvementRepository extends IBaseRepository
{
}

View File

@ -0,0 +1,27 @@
<?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\summit\SpeakerOrganizationalRole;
use models\utils\IBaseRepository;
/**
* Interface ISpeakerOrganizationalRoleRepository
* @package App\Models\Foundation\Summit\Repositories
*/
interface ISpeakerOrganizationalRoleRepository extends IBaseRepository
{
/**
* @param string $role
* @return SpeakerOrganizationalRole|null
*/
public function getByRole($role);
}

View File

@ -11,6 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Main\Language;
use App\Models\Foundation\Summit\SelectionPlan;
use Doctrine\ORM\Mapping AS ORM;
use App\Events\PresentationSpeakerCreated;
@ -179,8 +180,12 @@ class PresentationSpeaker extends SilverstripeBaseModel
private $travel_preferences;
/**
* @ORM\OneToMany(targetEntity="SpeakerLanguage", mappedBy="speaker", cascade={"persist"}, orphanRemoval=true)
* @var SpeakerLanguage[]
* @ORM\ManyToMany(targetEntity="App\Models\Foundation\Main\Language", cascade={"persist"})
* @ORM\JoinTable(name="PresentationSpeaker_Languages",
* joinColumns={@ORM\JoinColumn(name="PresentationSpeakerID", referencedColumnName="ID")},
* inverseJoinColumns={@ORM\JoinColumn(name="LanguageID", referencedColumnName="ID")}
* )
* @var Language[]
*/
private $languages;
@ -195,7 +200,7 @@ class PresentationSpeaker extends SilverstripeBaseModel
protected $organizational_roles;
/**
* @ORM\ManyToMany(targetEntity="SpeakerOrganizationalRole", cascade={"persist"})
* @ORM\ManyToMany(targetEntity="SpeakerActiveInvolvement", cascade={"persist"})
* @ORM\JoinTable(name="PresentationSpeaker_ActiveInvolvements",
* joinColumns={@ORM\JoinColumn(name="PresentationSpeakerID", referencedColumnName="ID")},
* inverseJoinColumns={@ORM\JoinColumn(name="SpeakerActiveInvolvementID", referencedColumnName="ID")}
@ -1387,6 +1392,10 @@ SQL;
return $this->areas_of_expertise;
}
public function clearAreasOfExpertise(){
$this->areas_of_expertise->clear();
}
/**
* @param SpeakerExpertise $area_of_expertise
*/
@ -1411,6 +1420,11 @@ SQL;
$link->setSpeaker($this);
}
public function clearOtherPresentationLinks(){
$this->other_presentation_links->clear();
}
/**
* @return SpeakerTravelPreference[]
*/
@ -1427,8 +1441,12 @@ SQL;
$travel_preference->setSpeaker($this);
}
public function clearTravelPreferences(){
$this->travel_preferences->clear();
}
/**
* @return SpeakerLanguage[]
* @return Language[]
*/
public function getLanguages()
{
@ -1436,11 +1454,18 @@ SQL;
}
/**
* @param SpeakerLanguage $language
* @param Language $language
*/
public function addLanguage(SpeakerLanguage $language){
public function addLanguage(Language $language){
if($this->languages->contains($language)) return;
$this->languages->add($language);
$language->setSpeaker($this);
}
/**
*
*/
public function clearLanguages(){
$this->languages->clear();
}
/**

View File

@ -14,7 +14,7 @@
use Doctrine\ORM\Mapping AS ORM;
use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSpeakerActiveInvolvementRepository")
* @ORM\Table(name="SpeakerActiveInvolvement")
* Class SpeakerActiveInvolvement
* @package models\summit

View File

@ -26,6 +26,16 @@ class SpeakerExpertise extends SilverstripeBaseModel
*/
private $expertise;
/**
* SpeakerExpertise constructor.
* @param string $expertise
*/
public function __construct($expertise)
{
parent::__construct();
$this->expertise = $expertise;
}
/**
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="areas_of_expertise")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")

View File

@ -1,79 +0,0 @@
<?php namespace models\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 Doctrine\ORM\Mapping AS ORM;
use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity
* @ORM\Table(name="SpeakerLanguage")
* Class SpeakerLanguage
* @package models\summit
*/
class SpeakerLanguage extends SilverstripeBaseModel
{
/**
* @ORM\Column(name="Language", type="string")
*/
private $language;
/**
* @ORM\ManyToOne(targetEntity="PresentationSpeaker", inversedBy="languages")
* @ORM\JoinColumn(name="SpeakerID", referencedColumnName="ID")
* @var PresentationSpeaker
*/
private $speaker;
/**
* @return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* @param string $language
*/
public function setLanguage($language)
{
$this->language = $language;
}
/**
* @return PresentationSpeaker
*/
public function getSpeaker()
{
return $this->speaker;
}
/**
* @param PresentationSpeaker $speaker
*/
public function setSpeaker($speaker)
{
$this->speaker = $speaker;
}
/**
* @return int
*/
public function getSpeakerId(){
try {
return !is_null($this->speaker) ? $this->speaker->getId() : 0;
}
catch(\Exception $ex){
return 0;
}
}
}

View File

@ -14,7 +14,7 @@
use Doctrine\ORM\Mapping AS ORM;
use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSpeakerOrganizationalRoleRepository")
* @ORM\Table(name="SpeakerOrganizationalRole")
* Class SpeakerOrganizationalRole
* @package models\summit
@ -31,6 +31,18 @@ class SpeakerOrganizationalRole extends SilverstripeBaseModel
*/
private $is_default;
/**
* SpeakerOrganizationalRole constructor.
* @param string $role
* @param bool $is_default
*/
public function __construct($role, $is_default = false)
{
parent::__construct();
$this->role = $role;
$this->is_default = $is_default;
}
/**
* @return mixed
*/

View File

@ -13,6 +13,7 @@
**/
use Doctrine\ORM\Mapping AS ORM;
use models\utils\SilverstripeBaseModel;
use App\Models\Foundation\Main\CountryCodes;
/**
* @ORM\Entity
* @ORM\Table(name="SpeakerTravelPreference")
@ -33,6 +34,16 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
*/
private $speaker;
/**
* SpeakerTravelPreference constructor.
* @param string $country
*/
public function __construct($country)
{
parent::__construct();
$this->country = $country;
}
/**
* @return int
*/
@ -53,6 +64,15 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
return $this->country;
}
/**
* @return string
*/
public function getCountryName(){
if(isset(CountryCodes::$iso_3166_countryCodes[$this->country]))
return CountryCodes::$iso_3166_countryCodes[$this->country];
return '';
}
/**
* @param string $country
*/
@ -76,4 +96,5 @@ class SpeakerTravelPreference extends SilverstripeBaseModel
{
$this->speaker = $speaker;
}
}

View File

@ -0,0 +1,33 @@
<?php namespace App\Repositories\Main;
/**
* 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\Main\Language;
use App\Models\Foundation\Main\Repositories\ILanguageRepository;
use App\Repositories\SilverStripeDoctrineRepository;
/**
* Class DoctrineLanguageRepository
* @package App\Repositories\Main
*/
final class DoctrineLanguageRepository
extends SilverStripeDoctrineRepository
implements ILanguageRepository
{
/**
* @return string
*/
protected function getBaseEntity()
{
return Language::class;
}
}

View File

@ -11,6 +11,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Main\Language;
use App\Models\Foundation\Main\Repositories\ILanguageRepository;
use App\Models\Foundation\Summit\Defaults\DefaultSummitEventType;
use App\Models\Foundation\Summit\DefaultTrackTagGroup;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
@ -22,6 +24,8 @@ use App\Models\Foundation\Summit\Repositories\IPresentationCategoryGroupReposito
use App\Models\Foundation\Summit\Repositories\IPresentationSpeakerSummitAssistanceConfirmationRequestRepository;
use App\Models\Foundation\Summit\Repositories\IRSVPTemplateRepository;
use App\Models\Foundation\Summit\Repositories\ISelectionPlanRepository;
use App\Models\Foundation\Summit\Repositories\ISpeakerActiveInvolvementRepository;
use App\Models\Foundation\Summit\Repositories\ISpeakerOrganizationalRoleRepository;
use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository;
use App\Models\Foundation\Summit\Repositories\ISummitLocationBannerRepository;
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
@ -45,6 +49,8 @@ use models\summit\ISummitTicketTypeRepository;
use models\summit\PresentationCategory;
use models\summit\PresentationCategoryGroup;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
use models\summit\SpeakerActiveInvolvement;
use models\summit\SpeakerOrganizationalRole;
use models\summit\SpeakerRegistrationRequest;
use models\summit\SpeakerSummitRegistrationPromoCode;
use models\summit\SummitAbstractLocation;
@ -365,5 +371,26 @@ final class RepositoriesProvider extends ServiceProvider
}
);
App::singleton(
ILanguageRepository::class,
function(){
return EntityManager::getRepository(Language::class);
}
);
App::singleton(
ISpeakerOrganizationalRoleRepository::class,
function(){
return EntityManager::getRepository(SpeakerOrganizationalRole::class);
}
);
App::singleton(
ISpeakerActiveInvolvementRepository::class,
function(){
return EntityManager::getRepository(SpeakerActiveInvolvement::class);
}
);
}
}

View File

@ -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\Repositories\ISpeakerActiveInvolvementRepository;
use App\Repositories\SilverStripeDoctrineRepository;
use models\summit\SpeakerActiveInvolvement;
/**
* Class DoctrineSpeakerActiveInvolvementRepository
* @package App\Repositories\Summit
*/
final class DoctrineSpeakerActiveInvolvementRepository
extends SilverStripeDoctrineRepository
implements ISpeakerActiveInvolvementRepository
{
/**
* @return string
*/
protected function getBaseEntity()
{
return SpeakerActiveInvolvement::class;
}
}

View File

@ -0,0 +1,54 @@
<?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\Repositories\ISpeakerOrganizationalRoleRepository;
use App\Repositories\SilverStripeDoctrineRepository;
use models\summit\SpeakerOrganizationalRole;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
/**
* Class DoctrineSpeakerOrganizationalRoleRepository
* @package App\Repositories\Summit
*/
final class DoctrineSpeakerOrganizationalRoleRepository
extends SilverStripeDoctrineRepository
implements ISpeakerOrganizationalRoleRepository
{
/**
* @return string
*/
protected function getBaseEntity()
{
return SpeakerOrganizationalRole::class;
}
/**
* @param string $role
* @return SpeakerOrganizationalRole|null
*/
public function getByRole($role)
{
$query = <<<SQL
select * from SpeakerOrganizationalRole where
Role = :role
SQL;
// build rsm here
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata(SpeakerOrganizationalRole::class, 'r');
$native_query = $this->_em->createNativeQuery($query, $rsm);
$native_query->setParameter("role", $role);
return $native_query->getOneOrNullResult();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -402,6 +402,14 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WriteMySpeakersData, $current_realm),
],
],
[
'name' => 'add-my-speaker-photo',
'route' => '/api/v1/speakers/me/photo',
'http_method' => 'POST',
'scopes' => [
sprintf(SummitScopes::WriteMySpeakersData, $current_realm),
],
],
[
'name' => 'merge-speakers',
'route' => '/api/v1/speakers/merge/{speaker_from_id}/{speaker_to_id}',

View File

@ -106,5 +106,13 @@ return [
'TrackQuestionTemplateService.addTrackQuestionValueTemplate.ValueAlreadyExist' => 'value :value already exists on track question template :track_question_template_id',
'TrackQuestionTemplateService.addTrackQuestionValueTemplate.LabelAlreadyExist' => 'label :label already exists on track question template :track_question_template_id',
'TrackQuestionTemplateService.updateTrackQuestionValueTemplate.ValueAlreadyExist' => 'value :value already exists on track question template :track_question_template_id',
'TrackQuestionTemplateService.updateTrackQuestionValueTemplate.LabelAlreadyExist' => 'label :label already exists on track question template :track_question_template_id'
'TrackQuestionTemplateService.updateTrackQuestionValueTemplate.LabelAlreadyExist' => 'label :label already exists on track question template :track_question_template_id',
// SpeakerService
'SpeakerService.addSpeaker.MissingMemberOrEmail' => "you must provide an email or a member_id in order to create a speaker!",
'SpeakerService.addSpeaker.MemberAlreadyAssigned2Speaker' => "member id :member_id already has assigned speaker :speaker_id!",
'SpeakerService.updateSpeaker.MemberAlreadyAssigned2Speaker' => "member id :member_id already has assigned speaker :speaker_id!",
"SpeakerService.updateSpeakerRelations.InvalidLanguage" => "language :lang_id does not exists!",
"SpeakerService.updateSpeakerRelations.InvalidCountryCode" => "country :country does not exists!",
"SpeakerService.updateSpeakerRelations.InvalidOrganizationRole" => "organization role :role does not exists!",
"SpeakerService.updateSpeakerRelations.InvalidActiveInvolvement" => "involvement :involvement_id does not exists!"
];

View File

@ -25,12 +25,21 @@ final class OAuth2SpeakersApiTest extends ProtectedApiTest
"CONTENT_TYPE" => "application/json"
];
$suffix = str_random(16);
$data = [
'title' => 'Developer!',
'first_name' => 'Sebastian',
'last_name' => 'Marcet',
'email' => 'sebastian.ge4.marcet@gmail.com'
'email' => "smarcet.{$suffix}@gmail.com",
'languages' => [1,2],
'other_presentation_links' => ["https://www.openstack.org"],
'travel_preferences' => ["AF"],
"areas_of_expertise" => ["testing"],
"active_involvements" => [1],
"organizational_roles" => [1],
"other_organizational_rol" => "no se",
];
$response = $this->action
@ -45,8 +54,8 @@ final class OAuth2SpeakersApiTest extends ProtectedApiTest
json_encode($data)
);
$this->assertResponseStatus(201);
$content = $response->getContent();
$this->assertResponseStatus(201);
$speaker = json_decode($content);
$this->assertTrue($speaker->id > 0);
return $speaker;