Added new endpoints for Track Tag Groups
* get track tag groups per summit GET /api/v1/summits/{id}/track-tag-groups params expand: allowed_tags,tag scopes %s/summits/read/all * get track tag group by id GET /api/v1/summits/{id}/track-tag-groups/{track_tag_group_id} params expand: allowed_tags,tag scopes %s/summits/read/all * seed default track tag groups on summit PUT /api/v1/summits/{id}/track-tag-groups/seed-defaults scopes %s/summits/write %s/track-tag-groups/write * add track tag groups POST /api/v1/summits/{id}/track-tag-groups payload 'name' => 'required|string|max:50', 'label' => 'required|string|max:50', 'is_mandatory' => 'required|boolean', 'allowed_tags' => 'sometimes|string_array' scopes %s/summits/write %s/track-tag-groups/write * update track tag group PUT /api/v1/summits/{id}/track-tag-groups/{track_tag_group_id} payload 'name' => 'sometimes|string|max:50', 'label' => 'sometimes|string|max:50', 'is_mandatory' => 'sometimes|boolean', 'order' => 'sometimes|integer|min:1', 'allowed_tags' => 'sometimes|string_array', scopes %s/summits/write %s/track-tag-groups/write * delete track tag group by id DELETE /api/v1/summits/{id}/track-tag-groups/{track_tag_group_id} scopes %s/summits/write %s/track-tag-groups/write Change-Id: Ieef974863c19b41655888cbbd8e29215f4724127
This commit is contained in:
parent
8cf26d9f11
commit
e193e866cd
@ -12,9 +12,11 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackTagGroupAllowedTagsRepository;
|
||||
use App\Services\Model\ISummitTrackTagGroupService;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use utils\Filter;
|
||||
use utils\FilterParser;
|
||||
use utils\FilterParserException;
|
||||
@ -25,6 +27,8 @@ use utils\PagingInfo;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\ISummitRepository;
|
||||
use utils\PagingResponse;
|
||||
|
||||
/**
|
||||
* Class OAuth2SummitTrackTagGroupsApiController
|
||||
* @package App\Http\Controllers
|
||||
@ -36,33 +40,87 @@ final class OAuth2SummitTrackTagGroupsApiController extends OAuth2ProtectedContr
|
||||
*/
|
||||
private $summit_repository;
|
||||
|
||||
/**
|
||||
* @var ISummitTrackTagGroupService
|
||||
*/
|
||||
private $track_tag_group_service;
|
||||
|
||||
/**
|
||||
* OAuth2SummitTrackTagGroupsApiController constructor.
|
||||
* @param ISummitRepository $summit_repository
|
||||
* @param ITrackTagGroupAllowedTagsRepository $repository
|
||||
* @param ISummitTrackTagGroupService $track_tag_group_service
|
||||
* @param IResourceServerContext $resource_server_context
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ISummitRepository $summit_repository,
|
||||
ITrackTagGroupAllowedTagsRepository $repository,
|
||||
ISummitTrackTagGroupService $track_tag_group_service,
|
||||
IResourceServerContext $resource_server_context
|
||||
)
|
||||
{
|
||||
parent::__construct($resource_server_context);
|
||||
|
||||
$this->summit_repository = $summit_repository;
|
||||
$this->track_tag_group_service = $track_tag_group_service;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackTagGroupsBySummit($summit_id){
|
||||
try {
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$track_tag_groups = $summit->getTrackTagGroups()->toArray();
|
||||
|
||||
$response = new PagingResponse
|
||||
(
|
||||
count($track_tag_groups),
|
||||
count($track_tag_groups),
|
||||
1,
|
||||
1,
|
||||
$track_tag_groups
|
||||
);
|
||||
|
||||
return $this->ok($response->toArray($expand = Input::get('expand','')));
|
||||
}
|
||||
|
||||
catch (EntityNotFoundException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error404();
|
||||
}
|
||||
catch (ValidationException $ex2) {
|
||||
Log::warning($ex2);
|
||||
return $this->error412($ex2->getMessages());
|
||||
}
|
||||
catch(FilterParserException $ex3){
|
||||
Log::warning($ex3);
|
||||
return $this->error412($ex3->getMessages());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAllowedTags($summit_id){
|
||||
|
||||
$values = Input::all();
|
||||
|
||||
$rules = array
|
||||
(
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => 'required_with:page|integer|min:5|max:100',
|
||||
);
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
@ -141,4 +199,192 @@ final class OAuth2SummitTrackTagGroupsApiController extends OAuth2ProtectedContr
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTrackTagGroup($summit_id){
|
||||
try {
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$data = Input::json();
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$rules = [
|
||||
'name' => 'required|string|max:50',
|
||||
'label' => 'required|string|max:50',
|
||||
'is_mandatory' => 'required|boolean',
|
||||
'allowed_tags' => 'sometimes|string_array',
|
||||
];
|
||||
|
||||
// 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
|
||||
);
|
||||
}
|
||||
|
||||
$track_tag_group = $this->track_tag_group_service->addTrackTagGroup($summit, $data->all());
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($track_tag_group)->serialize(Request::input('expand', '')));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $track_tag_group_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateTrackTagGroup($summit_id, $track_tag_group_id){
|
||||
try {
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$data = Input::json();
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$rules = [
|
||||
'name' => 'sometimes|string|max:50',
|
||||
'label' => 'sometimes|string|max:50',
|
||||
'is_mandatory' => 'sometimes|boolean',
|
||||
'order' => 'sometimes|integer|min:1',
|
||||
'allowed_tags' => 'sometimes|string_array',
|
||||
];
|
||||
|
||||
// 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
|
||||
);
|
||||
}
|
||||
|
||||
$track_tag_group = $this->track_tag_group_service->updateTrackTagGroup($summit, $track_tag_group_id, $data->all());
|
||||
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($track_tag_group)->serialize(Request::input('expand', '')));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $track_tag_group_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackTagGroup($summit_id, $track_tag_group_id){
|
||||
try{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$track_tag_group = $summit->getTrackTagGroup(intval($track_tag_group_id));
|
||||
if(is_null($track_tag_group))
|
||||
return $this->error404();
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($track_tag_group)->serialize(Request::input('expand', '')));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $track_tag_group_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteTrackTagGroup($summit_id, $track_tag_group_id){
|
||||
try {
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$this->track_tag_group_service->deleteTrackTagGroup($summit, $track_tag_group_id);
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function seedDefaultTrackTagGroups($summit_id){
|
||||
try{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$this->track_tag_group_service->seedDefaultTrackTagGroups($summit);
|
||||
return $this->updated();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -528,6 +528,26 @@ Route::group([
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'track-tag-groups'], function(){
|
||||
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@getTrackTagGroupsBySummit']);
|
||||
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@addTrackTagGroup']);
|
||||
|
||||
Route::put('seed-defaults', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@seedDefaultTrackTagGroups']);
|
||||
|
||||
Route::group(['prefix' => '{track_tag_group_id}'], function(){
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@getTrackTagGroup']);
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@updateTrackTagGroup']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@deleteTrackTagGroup']);
|
||||
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'all'], function(){
|
||||
Route::group(['prefix' => 'allowed-tags'], function(){
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
@ -601,7 +621,6 @@ Route::group([
|
||||
Route::put('/feedback', 'OAuth2SummitEventsApiController@updateEventFeedbackByMember');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
@ -43,7 +43,6 @@ use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackDropDownQuestio
|
||||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackMultiValueQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackQuestionValueTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackQuestions\TrackSingleValueTemplateQuestionSerializer;
|
||||
use App\ModelSerializers\Summit\Presentation\TrackTagGroupSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPDropDownQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPLiteralContentQuestionTemplateSerializer;
|
||||
use App\ModelSerializers\Summit\RSVP\Templates\RSVPMultiValueQuestionTemplateSerializer;
|
||||
@ -54,6 +53,7 @@ use App\ModelSerializers\Summit\ScheduledSummitLocationBannerSerializer;
|
||||
use App\ModelSerializers\Summit\SelectionPlanSerializer;
|
||||
use App\ModelSerializers\Summit\SummitLocationBannerSerializer;
|
||||
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupAllowedTagSerializer;
|
||||
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupSerializer;
|
||||
use Libs\ModelSerializers\IModelSerializer;
|
||||
use ModelSerializers\ChatTeams\ChatTeamInvitationSerializer;
|
||||
use ModelSerializers\ChatTeams\ChatTeamMemberSerializer;
|
||||
@ -188,7 +188,7 @@ final class SerializerRegistry
|
||||
$this->registry['SummitLocationImage'] = SummitLocationImageSerializer::class;
|
||||
$this->registry['SummitLocationBanner'] = SummitLocationBannerSerializer::class;
|
||||
$this->registry['ScheduledSummitLocationBanner'] = ScheduledSummitLocationBannerSerializer::class;
|
||||
// track tag grousp
|
||||
// track tag groups
|
||||
$this->registry['TrackTagGroup'] = TrackTagGroupSerializer::class;
|
||||
$this->registry['TrackTagGroupAllowedTag'] = TrackTagGroupAllowedTagSerializer::class;
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use ModelSerializers\SilverStripeSerializer;
|
||||
|
||||
/**
|
||||
@ -38,6 +40,30 @@ final class TrackTagGroupSerializer extends SilverStripeSerializer
|
||||
{
|
||||
$values = parent::serialize($expand, $fields, $relations, $params);
|
||||
$track_tag_group = $this->object;
|
||||
if (!$track_tag_group instanceof TrackTagGroup) return [];
|
||||
$allowed_tags = [];
|
||||
foreach($track_tag_group->getAllowedTags() as $allowed_tag){
|
||||
$allowed_tags[] = $allowed_tag->getId();
|
||||
}
|
||||
$values['allowed_tags'] = $allowed_tags;
|
||||
|
||||
if (!empty($expand)) {
|
||||
$relations = explode(',', $expand);
|
||||
foreach ($relations as $relation) {
|
||||
switch (trim($relation)) {
|
||||
|
||||
case 'allowed_tags':{
|
||||
unset($values['allowed_tags']);
|
||||
$allowed_tags = [];
|
||||
foreach($track_tag_group->getAllowedTags() as $allowed_tag){
|
||||
$allowed_tags[] = SerializerRegistry::getInstance()->getSerializer($allowed_tag)->serialize($expand);
|
||||
}
|
||||
$values['allowed_tags'] = $allowed_tags;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<?php namespace App\ModelSerializers\Summit\Presentation;
|
||||
<?php namespace App\Models\Foundation;
|
||||
/**
|
||||
* Copyright 2018 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -11,19 +11,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use ModelSerializers\SilverStripeSerializer;
|
||||
|
||||
/**
|
||||
* Class TrackTagGroupSerializer
|
||||
* @package App\ModelSerializers\Summit\Presentation
|
||||
* Interface IOrderableEntity
|
||||
* @package App\Models\Foundation
|
||||
*/
|
||||
final class TrackTagGroupSerializer extends SilverStripeSerializer
|
||||
interface IOrderableEntity
|
||||
{
|
||||
protected static $array_mappings = array
|
||||
(
|
||||
'Name' => 'name:json_text',
|
||||
'Label' => 'label:json_text',
|
||||
'Mandatory' => 'is_mandatory:json_boolean',
|
||||
'Order' => 'order:json_int',
|
||||
'SummitId' => 'summit_id:json_int',
|
||||
);
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder();
|
||||
|
||||
/**
|
||||
* @param int $order
|
||||
*/
|
||||
public function setOrder($order);
|
||||
}
|
29
app/Models/Foundation/IRecalculateOrderStrategy.php
Normal file
29
app/Models/Foundation/IRecalculateOrderStrategy.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php namespace App\Models;
|
||||
/**
|
||||
* 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\IOrderableEntity;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Interface IRecalculateOrderStrategy
|
||||
* @package App\Models
|
||||
*/
|
||||
interface IRecalculateOrderStrategy
|
||||
{
|
||||
/**
|
||||
* @param array $collection
|
||||
* @param IOrderableEntity $entity
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateOrder(array $collection , IOrderableEntity $entity, $new_order);
|
||||
}
|
53
app/Models/Foundation/RecalculateOrderStrategy.php
Normal file
53
app/Models/Foundation/RecalculateOrderStrategy.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php namespace App\Models\Foundation;
|
||||
/**
|
||||
* 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\IRecalculateOrderStrategy;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Class RecalculateOrderStrategy
|
||||
* @package App\Models\Foundation
|
||||
*/
|
||||
final class RecalculateOrderStrategy implements IRecalculateOrderStrategy
|
||||
{
|
||||
/**
|
||||
* @param array $collection
|
||||
* @param IOrderableEntity $entity
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateOrder(array $collection , IOrderableEntity $entity, $new_order){
|
||||
|
||||
$former_order = $entity->getOrder();
|
||||
|
||||
$collection = array_slice($collection,0, count($collection), false);
|
||||
$max_order = count($collection);
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($collection[$former_order - 1]);
|
||||
|
||||
$collection = array_merge
|
||||
(
|
||||
array_slice($collection, 0, $new_order-1 , true) ,
|
||||
[$entity] ,
|
||||
array_slice($collection, $new_order -1 , count($collection), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($collection as $e){
|
||||
$e->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
}
|
||||
}
|
142
app/Models/Foundation/Summit/DefaultTrackTagGroup.php
Normal file
142
app/Models/Foundation/Summit/DefaultTrackTagGroup.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php namespace App\Models\Foundation\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\Common\Collections\ArrayCollection;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineDefaultTrackTagGroupRepository")
|
||||
* @ORM\Table(name="DefaultTrackTagGroup")
|
||||
* Class DefaultTrackTagGroup
|
||||
* @package models\summit\DefaultTrackTagGroup
|
||||
*/
|
||||
class DefaultTrackTagGroup extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="Name", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Label", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="`Order`", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Mandatory", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="DefaultTrackTagGroupAllowedTag", mappedBy="track_tag_group", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var DefaultTrackTagGroupAllowedTag[]
|
||||
*/
|
||||
private $allowed_tags;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*/
|
||||
public function setLabel($label)
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order
|
||||
*/
|
||||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isMandatory()
|
||||
{
|
||||
return $this->is_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_mandatory
|
||||
*/
|
||||
public function setIsMandatory($is_mandatory)
|
||||
{
|
||||
$this->is_mandatory = $is_mandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DefaultTrackTagGroupAllowedTag[]
|
||||
*/
|
||||
public function getAllowedTags()
|
||||
{
|
||||
return $this->allowed_tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DefaultTrackTagGroupAllowedTag[] $allowed_tags
|
||||
*/
|
||||
public function setAllowedTags($allowed_tags)
|
||||
{
|
||||
$this->allowed_tags = $allowed_tags;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->allowed_tags = new ArrayCollection;
|
||||
$this->is_mandatory = false;
|
||||
}
|
||||
|
||||
}
|
118
app/Models/Foundation/Summit/DefaultTrackTagGroupAllowedTag.php
Normal file
118
app/Models/Foundation/Summit/DefaultTrackTagGroupAllowedTag.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php namespace App\Models\Foundation\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\Utils\BaseEntity;
|
||||
use models\main\Tag;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="DefaultTrackTagGroup_AllowedTags")
|
||||
* Class DefaultTrackTagGroupAllowedTag
|
||||
* @package models\summit\DefaultTrackTagGroupAllowedTag
|
||||
*/
|
||||
|
||||
class DefaultTrackTagGroupAllowedTag extends BaseEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="IsDefault", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_default;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Tag")
|
||||
* @ORM\JoinColumn(name="TagID", referencedColumnName="ID")
|
||||
* @var Tag
|
||||
*/
|
||||
private $tag;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="DefaultTrackTagGroup", inversedBy="allowed_tags")
|
||||
* @ORM\JoinColumn(name="TrackTagGroupID", referencedColumnName="ID")
|
||||
* @var DefaultTrackTagGroup
|
||||
*/
|
||||
private $track_tag_group;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTrackTagGroupId(){
|
||||
try {
|
||||
return is_null($this->track_tag_group) ? 0 : $this->track_tag_group->getId();
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTagId(){
|
||||
try {
|
||||
return is_null($this->tag) ? 0 : $this->tag->getId();
|
||||
}
|
||||
catch(\Exception $ex){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefault()
|
||||
{
|
||||
return $this->is_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $is_default
|
||||
*/
|
||||
public function setIsDefault($is_default)
|
||||
{
|
||||
$this->is_default = $is_default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tag
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*/
|
||||
public function setTag(Tag $tag)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DefaultTrackTagGroup
|
||||
*/
|
||||
public function getTrackTagGroup()
|
||||
{
|
||||
return $this->track_tag_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DefaultTrackTagGroup $track_tag_group
|
||||
*/
|
||||
public function setTrackTagGroup(DefaultTrackTagGroup $track_tag_group)
|
||||
{
|
||||
$this->track_tag_group = $track_tag_group;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php namespace App\Models\Foundation\Summit\Factories;
|
||||
/**
|
||||
* 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\TrackTagGroup;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Class TrackTagGroupFactory
|
||||
* @package App\Models\Foundation\Summit\Factories
|
||||
*/
|
||||
final class TrackTagGroupFactory
|
||||
{
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return TrackTagGroup|null
|
||||
*/
|
||||
public static function build(Summit $summit, array $data){
|
||||
$track_tag_group = new TrackTagGroup();
|
||||
if(is_null($track_tag_group)) return null;
|
||||
return self::populate($track_tag_group, $summit, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackTagGroup $track_tag_group
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return TrackTagGroup
|
||||
*/
|
||||
public static function populate(TrackTagGroup $track_tag_group, Summit $summit, array $data){
|
||||
|
||||
if(isset($data['name']))
|
||||
$track_tag_group->setName(trim($data['name']));
|
||||
|
||||
if(isset($data['label']))
|
||||
$track_tag_group->setLabel(trim($data['label']));
|
||||
|
||||
if(isset($data['is_mandatory'])){
|
||||
$track_tag_group->setIsMandatory(boolval($data['is_mandatory']));
|
||||
}
|
||||
|
||||
return $track_tag_group;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\IOrderableEntity;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\ScheduledSummitLocationBanner;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
@ -37,7 +38,7 @@ use Doctrine\ORM\Mapping AS ORM;
|
||||
* Class SummitAbstractLocation
|
||||
* @package models\summit
|
||||
*/
|
||||
class SummitAbstractLocation extends SilverstripeBaseModel
|
||||
class SummitAbstractLocation extends SilverstripeBaseModel implements IOrderableEntity
|
||||
{
|
||||
const TypeExternal = 'External';
|
||||
const TypeInternal = 'Internal';
|
||||
|
@ -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 IDefaultTrackTagGroup
|
||||
* @package App\Models\Foundation\Summit\Repositories
|
||||
*/
|
||||
interface IDefaultTrackTagGroupRepository extends IBaseRepository
|
||||
{
|
||||
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Http\Utils\DateUtils;
|
||||
use App\Models\Foundation\RecalculateOrderStrategy;
|
||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||
use App\Models\Foundation\Summit\SelectionPlan;
|
||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||
@ -1734,7 +1735,6 @@ SQL;
|
||||
*/
|
||||
public function recalculateLocationOrder(SummitAbstractLocation $location, $new_order){
|
||||
|
||||
$former_order = $location->getOrder();
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$filtered_locations = [];
|
||||
@ -1744,26 +1744,8 @@ SQL;
|
||||
$filtered_locations[] = $l;
|
||||
}
|
||||
|
||||
$filtered_locations = array_slice($filtered_locations,0, count($filtered_locations), false);
|
||||
$max_order = count($filtered_locations);
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($filtered_locations[$former_order - 1]);
|
||||
|
||||
$filtered_locations = array_merge
|
||||
(
|
||||
array_slice($filtered_locations, 0, $new_order -1 , true) ,
|
||||
[$location] ,
|
||||
array_slice($filtered_locations, $new_order -1 , count($filtered_locations), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($filtered_locations as $l){
|
||||
$l->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
$strategy = new RecalculateOrderStrategy();
|
||||
$strategy->recalculateOrder($filtered_locations, $location, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2299,4 +2281,91 @@ SQL;
|
||||
$res = $native_query->getResult();
|
||||
return count($res) > 0 ? $res[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return null|TrackTagGroup
|
||||
*/
|
||||
public function getTrackTagGroupByName($name){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('name', $name));
|
||||
$track_tag_group = $this->track_tag_groups->matching($criteria)->first();
|
||||
return !$track_tag_group ? null : $track_tag_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TrackTagGroup[]|ArrayCollection
|
||||
*/
|
||||
public function getTrackTagGroups(){
|
||||
return $this->track_tag_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @return null|TrackTagGroup
|
||||
*/
|
||||
public function getTrackTagGroupByLabel($label){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('label', $label));
|
||||
$track_tag_group = $this->track_tag_groups->matching($criteria)->first();
|
||||
return !$track_tag_group ? null : $track_tag_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackTagGroup $track_tag_group
|
||||
* @return $this
|
||||
*/
|
||||
public function addTrackTagGroup(TrackTagGroup $track_tag_group)
|
||||
{
|
||||
if($this->track_tag_groups->contains($track_tag_group)) return $this;
|
||||
$this->track_tag_groups->add($track_tag_group);
|
||||
$track_tag_group->setSummit($this);
|
||||
$track_tag_group->setOrder($this->getTrackTagGroupMaxOrder() + 1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackTagGroup $track_tag_group
|
||||
* @return $this
|
||||
*/
|
||||
public function removeTrackTagGroup(TrackTagGroup $track_tag_group){
|
||||
if(!$this->track_tag_groups->contains($track_tag_group)) return $this;
|
||||
$this->track_tag_groups->removeElement($track_tag_group);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
private function getTrackTagGroupMaxOrder(){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order' => 'DESC']);
|
||||
$group = $this->track_tag_groups->matching($criteria)->first();
|
||||
return $group === false ? 0 : $group->getOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackTagGroup $track_tag_group
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateTrackTagGroupOrder(TrackTagGroup $track_tag_group, $new_order){
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
$strategy = new RecalculateOrderStrategy();
|
||||
$strategy->recalculateOrder($this->track_tag_groups->matching($criteria)->toArray(), $track_tag_group, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_tag_group_id
|
||||
* @return TrackTagGroup|null
|
||||
*/
|
||||
public function getTrackTagGroup($track_tag_group_id)
|
||||
{
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('id', intval($track_tag_group_id)));
|
||||
$track_tag_group = $this->track_tag_groups->matching($criteria)->first();
|
||||
return $track_tag_group === false ? null : $track_tag_group;
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\IOrderableEntity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Cache;
|
||||
use models\main\Tag;
|
||||
use models\summit\SummitOwned;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
@ -22,8 +24,40 @@ use Doctrine\ORM\Mapping AS ORM;
|
||||
* Class TrackTagGroup
|
||||
* @package models\summit\TrackTagGroup
|
||||
*/
|
||||
class TrackTagGroup extends SilverstripeBaseModel
|
||||
class TrackTagGroup extends SilverstripeBaseModel implements IOrderableEntity
|
||||
{
|
||||
use SummitOwned;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Name", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Label", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="`Order`", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Mandatory", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="TrackTagGroupAllowedTag", mappedBy="track_tag_group", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var TrackTagGroupAllowedTag[]
|
||||
*/
|
||||
private $allowed_tags;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -104,42 +138,29 @@ class TrackTagGroup extends SilverstripeBaseModel
|
||||
$this->allowed_tags = $allowed_tags;
|
||||
}
|
||||
|
||||
use SummitOwned;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Name", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Label", type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Order", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Mandatory", type="boolean")
|
||||
* @var boolean
|
||||
*/
|
||||
private $is_mandatory;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="TrackTagGroupAllowedTag", mappedBy="track_tag_group", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var TrackTagGroupAllowedTag[]
|
||||
*/
|
||||
private $allowed_tags;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->allowed_tags = new ArrayCollection;
|
||||
$this->is_mandatory = false;
|
||||
}
|
||||
|
||||
public function clearAllowedTags()
|
||||
{
|
||||
$this->allowed_tags->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param bool $is_default
|
||||
*/
|
||||
public function addTag(Tag $tag, $is_default = false)
|
||||
{
|
||||
$allowed_tag = new TrackTagGroupAllowedTag();
|
||||
$allowed_tag->setTag($tag);
|
||||
$allowed_tag->setTrackTagGroup($this);
|
||||
$allowed_tag->setIsDefault($is_default);
|
||||
$this->allowed_tags->add($allowed_tag);
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ class TrackTagGroupAllowedTag extends BaseEntity
|
||||
private $is_default;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Tag")
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Tag", cascade={"persist"})
|
||||
* @ORM\JoinColumn(name="TagID", referencedColumnName="ID")
|
||||
* @var Tag
|
||||
*/
|
||||
|
@ -12,9 +12,11 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Defaults\DefaultSummitEventType;
|
||||
use App\Models\Foundation\Summit\DefaultTrackTagGroup;
|
||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultTrackTagGroupRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\IPresentationCategoryGroupRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\IPresentationSpeakerSummitAssistanceConfirmationRequestRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\IRSVPTemplateRepository;
|
||||
@ -346,5 +348,12 @@ final class RepositoriesProvider extends ServiceProvider
|
||||
}
|
||||
);
|
||||
|
||||
App::singleton(
|
||||
IDefaultTrackTagGroupRepository::class,
|
||||
function(){
|
||||
return EntityManager::getRepository(DefaultTrackTagGroup::class);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?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\DefaultTrackTagGroup;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultTrackTagGroupRepository;
|
||||
use App\Repositories\SilverStripeDoctrineRepository;
|
||||
/**
|
||||
* Class DoctrineDefaultTrackTagGroupRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
final class DoctrineDefaultTrackTagGroupRepository extends SilverStripeDoctrineRepository
|
||||
implements IDefaultTrackTagGroupRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return DefaultTrackTagGroup::class;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ final class SummitScopes
|
||||
|
||||
const WriteSummitData = '%s/summits/write';
|
||||
const WriteSpeakersData = '%s/speakers/write';
|
||||
const WriteTrackTagGroupsData = '%s/track-tag-groups/write';
|
||||
const WriteMySpeakersData = '%s/speakers/write/me';
|
||||
|
||||
const PublishEventData = '%s/summits/publish-event';
|
||||
|
59
app/Services/Model/ISummitTrackTagGroupService.php
Normal file
59
app/Services/Model/ISummitTrackTagGroupService.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php namespace App\Services\Model;
|
||||
/**
|
||||
* 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\TrackTagGroup;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\summit\Summit;
|
||||
|
||||
/**
|
||||
* Interface ISummitTrackTagGroupService
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
interface ISummitTrackTagGroupService
|
||||
{
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return TrackTagGroup
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addTrackTagGroup(Summit $summit, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @param array $data
|
||||
* @return TrackTagGroup
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackTagGroup(Summit $summit, $track_tag_group_id, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteTrackTagGroup(Summit $summit, $track_tag_group_id);
|
||||
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return void
|
||||
*/
|
||||
public function seedDefaultTrackTagGroups(Summit $summit);
|
||||
}
|
235
app/Services/Model/SummitTrackTagGroupService.php
Normal file
235
app/Services/Model/SummitTrackTagGroupService.php
Normal file
@ -0,0 +1,235 @@
|
||||
<?php namespace App\Services\Model;
|
||||
/**
|
||||
* 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\Factories\TrackTagGroupFactory;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultTrackTagGroupRepository;
|
||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
|
||||
use libs\utils\ITransactionService;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\ITagRepository;
|
||||
use models\main\Tag;
|
||||
use models\summit\Summit;
|
||||
/**
|
||||
* Class SummitTrackTagGroupService
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
final class SummitTrackTagGroupService extends AbstractService
|
||||
implements ISummitTrackTagGroupService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ITagRepository
|
||||
*/
|
||||
private $tag_repository;
|
||||
|
||||
/**
|
||||
* @var IDefaultTrackTagGroupRepository
|
||||
*/
|
||||
private $default_track_tag_group_repository;
|
||||
|
||||
/**
|
||||
* SummitTrackTagGroupService constructor.
|
||||
* @param ITagRepository $tag_repository
|
||||
* @param IDefaultTrackTagGroupRepository $default_track_tag_group_repository
|
||||
* @param ITransactionService $tx_service
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ITagRepository $tag_repository,
|
||||
IDefaultTrackTagGroupRepository $default_track_tag_group_repository,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
{
|
||||
parent::__construct($tx_service);
|
||||
$this->tag_repository = $tag_repository;
|
||||
$this->default_track_tag_group_repository = $default_track_tag_group_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @return TrackTagGroup
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addTrackTagGroup(Summit $summit, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $data) {
|
||||
|
||||
if(isset($data['label'])){
|
||||
$former_group = $summit->getTrackTagGroupByLabel(trim($data['label']));
|
||||
if(!is_null($former_group)){
|
||||
throw new ValidationException(trans
|
||||
(
|
||||
'validation_errors.SummitTrackTagGroupService.addTrackTagGroup.TrackTagGroupLabelAlreadyExists',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['name'])){
|
||||
$former_group = $summit->getTrackTagGroupByName(trim($data['name']));
|
||||
if(!is_null($former_group)){
|
||||
throw new ValidationException(trans
|
||||
(
|
||||
'validation_errors.SummitTrackTagGroupService.addTrackTagGroup.TrackTagGroupNameAlreadyExists',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$track_tag_group = TrackTagGroupFactory::build($summit, $data);
|
||||
|
||||
if (isset($data['allowed_tags'])) {
|
||||
$track_tag_group->clearAllowedTags();
|
||||
foreach ($data['allowed_tags'] as $str_tag) {
|
||||
$tag = $this->tag_repository->getByTag($str_tag);
|
||||
if($tag == null) $tag = new Tag($str_tag);
|
||||
$track_tag_group->addTag($tag);
|
||||
}
|
||||
}
|
||||
|
||||
$summit->addTrackTagGroup($track_tag_group);
|
||||
|
||||
return $track_tag_group;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @param array $data
|
||||
* @return TrackTagGroup
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackTagGroup(Summit $summit, $track_tag_group_id, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $track_tag_group_id, $data) {
|
||||
|
||||
if(isset($data['label'])){
|
||||
$former_group = $summit->getTrackTagGroupByLabel(trim($data['label']));
|
||||
if(!is_null($former_group) && $former_group->getId() != $track_tag_group_id ){
|
||||
throw new ValidationException(trans
|
||||
(
|
||||
'validation_errors.SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupLabelAlreadyExists',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['name'])){
|
||||
$former_group = $summit->getTrackTagGroupByName(trim($data['name']));
|
||||
if(!is_null($former_group) && $former_group->getId() != $track_tag_group_id ){
|
||||
throw new ValidationException(trans
|
||||
(
|
||||
'validation_errors.SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNameAlreadyExists',
|
||||
[
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$track_tag_group = $summit->getTrackTagGroup($track_tag_group_id);
|
||||
|
||||
if(is_null($track_tag_group)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans("not_found_errors.SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNotFound", [
|
||||
'summit_id' => $summit->getId(),
|
||||
'track_tag_group_id' => $track_tag_group_id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['allowed_tags'])) {
|
||||
$track_tag_group->clearAllowedTags();
|
||||
foreach ($data['allowed_tags'] as $str_tag) {
|
||||
$tag = $this->tag_repository->getByTag($str_tag);
|
||||
if($tag == null) $tag = new Tag($str_tag);
|
||||
$track_tag_group->addTag($tag);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['order']) && intval($data['order']) != $track_tag_group->getOrder()) {
|
||||
// request to update order
|
||||
$summit->recalculateTrackTagGroupOrder($track_tag_group, intval($data['order']));
|
||||
}
|
||||
|
||||
return $track_tag_group;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteTrackTagGroup(Summit $summit, $track_tag_group_id)
|
||||
{
|
||||
$this->tx_service->transaction(function() use($summit, $track_tag_group_id) {
|
||||
$track_tag_group = $summit->getTrackTagGroup($track_tag_group_id);
|
||||
|
||||
if(is_null($track_tag_group)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans("not_found_errors.SummitTrackTagGroupService.deleteTrackTagGroup.TrackTagGroupNotFound", [
|
||||
'summit_id' => $summit->getId(),
|
||||
'track_tag_group_id' => $track_tag_group_id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$summit->removeTrackTagGroup($track_tag_group);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return void
|
||||
*/
|
||||
public function seedDefaultTrackTagGroups(Summit $summit)
|
||||
{
|
||||
$this->tx_service->transaction(function() use($summit) {
|
||||
$default_groups = $this->default_track_tag_group_repository->getAll();
|
||||
foreach($default_groups as $default_track_tag_group){
|
||||
// if already exists ...
|
||||
if($summit->getTrackTagGroupByLabel($default_track_tag_group->getLabel()))
|
||||
continue;
|
||||
|
||||
$new_group = new TrackTagGroup();
|
||||
$new_group->setName($default_track_tag_group->getName());
|
||||
$new_group->setLabel($default_track_tag_group->getLabel());
|
||||
$new_group->setOrder($default_track_tag_group->getOrder());
|
||||
$new_group->setIsMandatory($default_track_tag_group->isMandatory());
|
||||
$summit->addTrackTagGroup($new_group);
|
||||
|
||||
foreach ($default_track_tag_group->getAllowedTags() as $default_allowed_tag){
|
||||
$new_group->addTag($default_allowed_tag->getTag());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ use App\Services\Model\ISummitPushNotificationService;
|
||||
use App\Services\Model\ISummitSelectionPlanService;
|
||||
use App\Services\Model\ISummitTicketTypeService;
|
||||
use App\Services\Model\ISummitTrackService;
|
||||
use App\Services\Model\ISummitTrackTagGroupService;
|
||||
use App\Services\Model\OrganizationService;
|
||||
use App\Services\Model\PresentationCategoryGroupService;
|
||||
use App\Services\Model\SummitLocationService;
|
||||
@ -40,6 +41,7 @@ use App\Services\Model\SummitPushNotificationService;
|
||||
use App\Services\Model\SummitSelectionPlanService;
|
||||
use App\Services\Model\SummitTicketTypeService;
|
||||
use App\Services\Model\SummitTrackService;
|
||||
use App\Services\Model\SummitTrackTagGroupService;
|
||||
use App\Services\SummitEventTypeService;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
@ -243,5 +245,10 @@ final class ServicesProvider extends ServiceProvider
|
||||
IOrganizationService::class,
|
||||
OrganizationService::class
|
||||
);
|
||||
|
||||
App::singleton(
|
||||
ISummitTrackTagGroupService::class,
|
||||
SummitTrackTagGroupService::class
|
||||
);
|
||||
}
|
||||
}
|
@ -1758,6 +1758,14 @@ class ApiEndpointsSeeder extends Seeder
|
||||
],
|
||||
],
|
||||
// track tag groups
|
||||
[
|
||||
'name' => 'get-track-tag-groups',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-track-tag-groups-allowed-tags',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/all/allowed-tags',
|
||||
@ -1765,6 +1773,50 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-track-tag-group',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/{track_tag_group_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'seed-default-track-tag-groups',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/seed-defaults',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-track-tag-group',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-track-tag-group',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/{track_tag_group_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'delete-track-tag-group',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/{track_tag_group_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
@ -145,6 +145,11 @@ final class ApiScopesSeeder extends Seeder
|
||||
'short_description' => 'Write Summit Location Banners Data',
|
||||
'description' => 'Grants write access for Summit Location Banners Data',
|
||||
],
|
||||
[
|
||||
'name' => sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm),
|
||||
'short_description' => 'Write Summit Track Tag Groups Data',
|
||||
'description' => 'Grants write access for Summit Track Tag Groups Data',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($scopes as $scope_info) {
|
||||
|
@ -87,4 +87,7 @@ return [
|
||||
'PresentationService.saveOrUpdatePresentation.trackNotFound' => 'track :track_id not found.',
|
||||
'PresentationService.submitPresentation.eventTypeNotFound' => 'event type :type_id not found.',
|
||||
'PresentationService.saveOrUpdatePresentation.trackQuestionNotFound' => 'extra question :question_id not found.',
|
||||
// track tag groups
|
||||
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id',
|
||||
'SummitTrackTagGroupService.deleteTrackTagGroup.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id'
|
||||
];
|
@ -85,4 +85,9 @@ return [
|
||||
'PresentationService.submitPresentation.limitReached' => 'You reached the limit :limit of presentations.',
|
||||
// organizations
|
||||
'OrganizationService.addOrganization.alreadyExistName' => 'Organization name :name already exists!',
|
||||
// track tag groups
|
||||
'SummitTrackTagGroupService.addTrackTagGroup.TrackTagGroupLabelAlreadyExists' => 'track tag group label already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.addTrackTagGroup.TrackTagGroupNameAlreadyExists' => 'track tag group name already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupLabelAlreadyExists' => 'track tag group label already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNameAlreadyExists' => 'track tag group name already exist on summit :summit_id',
|
||||
];
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Class OAuth2SummitTrackTagGroupsApiControllerTest
|
||||
*/
|
||||
final class OAuth2SummitTrackTagGroupsApiControllerTest extends ProtectedApiTest
|
||||
{
|
||||
public function testGetTags($summit_id = 25)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
//AND FILTER
|
||||
'filter' => ['tag=@101'],
|
||||
'order' => '+id',
|
||||
'expand' => 'tag,track_tag_group'
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitTrackTagGroupsApiController@getAllowedTags",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$tags = json_decode($content);
|
||||
$this->assertTrue(!is_null($tags));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
}
|
209
tests/OAuth2TrackTagGroupsApiTest.php
Normal file
209
tests/OAuth2TrackTagGroupsApiTest.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
final class OAuth2TrackTagGroupsApiTest extends ProtectedApiTest
|
||||
{
|
||||
public function testGetTrackTagGroups($summit_id = 25)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'expand' => 'allowed_tags,tag',
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitTrackTagGroupsApiController@getTrackTagGroupsBySummit",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$groups = json_decode($content);
|
||||
$this->assertTrue(!is_null($groups));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testAddTrackTagGroup($summit_id = 25){
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'expand' => 'allowed_tags,tag'
|
||||
];
|
||||
|
||||
$name = str_random(16).'_track_tag_group_name';
|
||||
$label = str_random(16).'_track_tag_group_label';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'is_mandatory' => false,
|
||||
'allowed_tags' => ['101','Case Study', 'Demo'],
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitTrackTagGroupsApiController@addTrackTagGroup",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$track_tag_group = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_tag_group));
|
||||
return $track_tag_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testUpdateTrackTagGroup($summit_id = 25){
|
||||
$new_track_tag_group = $this->testAddTrackTagGroup($summit_id);
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_tag_group_id' => $new_track_tag_group->id,
|
||||
'expand' => 'allowed_tags,tag'
|
||||
];
|
||||
|
||||
$name = str_random(16).'_track_tag_group_name_update';
|
||||
$label = str_random(16).'_track_tag_group_label_update';
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'order' => 1,
|
||||
'allowed_tags' => ['101','Case Study', 'Demo', 'Demo2'],
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2SummitTrackTagGroupsApiController@updateTrackTagGroup",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
$track_tag_group = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_tag_group));
|
||||
$this->assertTrue($track_tag_group->order == 1);
|
||||
return $track_tag_group;
|
||||
}
|
||||
|
||||
public function testDeleteTrackTagGroup($summit_id = 25){
|
||||
$new_track_tag_group = $this->testAddTrackTagGroup($summit_id);
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_tag_group_id' => $new_track_tag_group->id,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"DELETE",
|
||||
"OAuth2SummitTrackTagGroupsApiController@deleteTrackTagGroup",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testGetTrackTagGroupById($summit_id = 25){
|
||||
$new_track_tag_group = $this->testAddTrackTagGroup($summit_id);
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_tag_group_id' => $new_track_tag_group->id,
|
||||
'expand' => 'allowed_tags,tag'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitTrackTagGroupsApiController@getTrackTagGroup",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
public function testGetTags($summit_id = 25)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
//AND FILTER
|
||||
'filter' => ['tag=@101'],
|
||||
'order' => '+id',
|
||||
'expand' => 'tag,track_tag_group'
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2SummitTrackTagGroupsApiController@getAllowedTags",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$tags = json_decode($content);
|
||||
$this->assertTrue(!is_null($tags));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user