Track Extra Questions Endpoints
Get all track questions GET /api/v1/track-question-templates params 'page' => 'integer|min:1' 'per_page' => 'required_with:page|integer|min:5|max:100' filter 'name' => ['=@', '=='] 'label' => ['=@', '=='] 'class_name' => ['=='] order * id * name * label expand * tracks scopes %s/summits/read/all Add track question POST /api/v1/track-question-templates payload 'name' => 'sometimes|alpha_dash|max:255' 'label' => 'sometimes|string' 'is_mandatory' => 'sometimes|boolean' 'is_read_only' => 'sometimes|boolean' 'tracks' => 'sometimes|int_array' for TrackCheckBoxQuestionTemplate and TrackTextBoxQuestionTemplate 'initial_value' => 'string|sometimes' for TrackDropDownQuestionTemplate 'is_multiselect' => 'sometimes|boolean' 'is_country_selector' => 'sometimes|boolean' scopes %s/summits/write %s/track-question-templates/write PUT /api/v1/track-question-templates/{track_question_template_id} payload same as POST scopes %s/summits/write %s/track-question-templates/write delete track question DELETE /api/v1/track-question-templates/{track_question_template_id} scopes %s/summits/write %s/track-question-templates/write get track question metadata GET /api/v1/track-question-templates/metadata scopes %s/summits/read/all add track question value POST /api/v1/track-question-templates/{track_question_template_id}/values payload 'value' => 'required|string|max:255' 'label' => 'required|string' scopes %s/summits/write %s/track-question-templates/write update track question value /api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id} payload 'value' => 'sometimes|string|max:255' 'label' => 'sometimes|string' 'order' => 'sometimes|integer|min:1' delete track question value DELETE /api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id} scopes %s/summits/write %s/track-question-templates/write get track question template value GET /api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id} scopes '%s/summits/read/all' Change-Id: I663bccf3987cb0b7e337e0fe5b92f3723fac5cd6
This commit is contained in:
parent
6a01b46a72
commit
10e1b1c424
|
@ -1,4 +1,4 @@
|
|||
<?php namespace App\Models\Foundation;
|
||||
<?php namespace App\Http\Controllers;
|
||||
/**
|
||||
* Copyright 2018 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -12,19 +12,22 @@
|
|||
* limitations under the License.
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* Interface IOrderableEntity
|
||||
* @package App\Models\Foundation
|
||||
* Class TrackLiteralContentQuestionTemplateValidationRulesFactory
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
interface IOrderableEntity
|
||||
final class TrackLiteralContentQuestionTemplateValidationRulesFactory
|
||||
{
|
||||
/**
|
||||
* @return int
|
||||
* @param array $data
|
||||
* @param bool $update
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder();
|
||||
|
||||
/**
|
||||
* @param int $order
|
||||
*/
|
||||
public function setOrder($order);
|
||||
public static function build(array $data, $update = false){
|
||||
if($update){
|
||||
return ['content' => 'sometimes|string'];
|
||||
}
|
||||
return ['content' => 'required|string'];
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?php namespace App\Models;
|
||||
<?php namespace App\Http\Controllers;
|
||||
/**
|
||||
* Copyright 2018 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,19 +11,27 @@
|
|||
* 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
|
||||
* Class TrackMultiValueQuestionTemplateValidationRulesFactory
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
interface IRecalculateOrderStrategy
|
||||
final class TrackMultiValueQuestionTemplateValidationRulesFactory
|
||||
{
|
||||
/**
|
||||
* @param array $collection
|
||||
* @param IOrderableEntity $entity
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
* @param array $data
|
||||
* @param bool $update
|
||||
* @return array
|
||||
*/
|
||||
public function recalculateOrder(array $collection , IOrderableEntity $entity, $new_order);
|
||||
public static function build(array $data, $update = false){
|
||||
if($update){
|
||||
return [
|
||||
'empty_string' => 'sometimes|string',
|
||||
'default_value' => 'sometimes|integer',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'empty_string' => 'required|string'
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php namespace App\Http\Controllers;
|
||||
|
||||
/**
|
||||
* 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\Events\Presentations\TrackQuestions\TrackCheckBoxListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackCheckBoxQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackDropDownQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackLiteralContentQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplateConstants;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackRadioButtonListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Class TrackQuestionTemplateValidationRulesFactory
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
final class TrackQuestionTemplateValidationRulesFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @param bool $update
|
||||
* @return array
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public static function build(array $data, $update = false)
|
||||
{
|
||||
|
||||
if (!isset($data['class_name']))
|
||||
throw new ValidationException('class_name is required');
|
||||
|
||||
$base_rules = [
|
||||
'class_name' => sprintf('required|in:%s', implode(",", TrackQuestionTemplateConstants::$valid_class_names))
|
||||
];
|
||||
|
||||
if ($update) {
|
||||
$base_rules = array_merge($base_rules, [
|
||||
'name' => 'sometimes|alpha_dash|max:255',
|
||||
'label' => 'sometimes|string',
|
||||
'is_mandatory' => 'sometimes|boolean',
|
||||
'is_read_only' => 'sometimes|boolean',
|
||||
'tracks' => 'sometimes|int_array',
|
||||
]);
|
||||
} else {
|
||||
$base_rules = array_merge($base_rules, [
|
||||
'name' => 'required|alpha_dash|max:255',
|
||||
'label' => 'required|string',
|
||||
'is_mandatory' => 'sometimes|boolean',
|
||||
'is_read_only' => 'sometimes|boolean',
|
||||
'tracks' => 'sometimes|int_array',
|
||||
]);
|
||||
}
|
||||
|
||||
switch ($data['class_name']) {
|
||||
case TrackTextBoxQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge($base_rules, ['initial_value' => 'string|sometimes']);
|
||||
}
|
||||
break;
|
||||
case TrackCheckBoxQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge($base_rules, ['initial_value' => 'string|sometimes']);
|
||||
}
|
||||
break;
|
||||
case TrackCheckBoxListQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge
|
||||
(
|
||||
$base_rules,
|
||||
TrackMultiValueQuestionTemplateValidationRulesFactory::build($data, $update)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case TrackRadioButtonListQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge
|
||||
(
|
||||
$base_rules,
|
||||
TrackMultiValueQuestionTemplateValidationRulesFactory::build($data, $update)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case TrackDropDownQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge
|
||||
(
|
||||
$base_rules,
|
||||
TrackMultiValueQuestionTemplateValidationRulesFactory::build($data, $update),
|
||||
[
|
||||
'is_multiselect' => 'sometimes|boolean',
|
||||
'is_country_selector' => 'sometimes|boolean',
|
||||
]
|
||||
);
|
||||
}
|
||||
break;
|
||||
case TrackLiteralContentQuestionTemplate::ClassName:
|
||||
{
|
||||
return array_merge(
|
||||
$base_rules,
|
||||
TrackLiteralContentQuestionTemplateValidationRulesFactory::build($data, $update)
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
throw new ValidationException(sprintf('invalid class_name param (%s)', implode(",", TrackQuestionTemplateConstants::$valid_class_names)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php namespace App\Http\Controllers;
|
||||
/**
|
||||
* 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 TrackQuestionValueTemplateValidationRulesFactory
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
final class TrackQuestionValueTemplateValidationRulesFactory
|
||||
{
|
||||
public static function build(array $data, $update = false){
|
||||
if($update){
|
||||
return [
|
||||
'value' => 'sometimes|string|max:255',
|
||||
'label' => 'sometimes|string',
|
||||
'order' => 'sometimes|integer|min:1',
|
||||
];
|
||||
}
|
||||
return [
|
||||
'value' => 'required|string|max:255',
|
||||
'label' => 'required|string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -683,7 +683,7 @@ final class OAuth2SummitAttendeesApiController extends OAuth2ProtectedController
|
|||
$other_member = $this->member_repository->getById($other_member_id);
|
||||
if(is_null($other_member)) return $this->error404();
|
||||
|
||||
$ticket = $this->attendee_service->reassignAttendeeTicket($summit, $attendee, $other_member_id, $ticket_id);
|
||||
$ticket = $this->attendee_service->reassignAttendeeTicket($summit, $attendee, $other_member, $ticket_id);
|
||||
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($ticket)->serialize());
|
||||
}
|
||||
|
|
|
@ -643,7 +643,7 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro
|
|||
|
||||
$value = $this->rsvp_template_service->updateQuestionValue($summit, $template_id, $question_id, $value_id, $payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($value)->serialize());
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($value)->serialize());
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
|
|
|
@ -0,0 +1,477 @@
|
|||
<?php namespace App\Http\Controllers;
|
||||
/**
|
||||
* 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\Events\Presentations\TrackQuestions\TrackMultiValueQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplateConstants;
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackQuestionTemplateRepository;
|
||||
use App\Services\Model\ITrackQuestionTemplateService;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use Exception;
|
||||
use models\oauth2\IResourceServerContext;
|
||||
use ModelSerializers\SerializerRegistry;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use utils\Filter;
|
||||
use utils\FilterParser;
|
||||
use utils\OrderParser;
|
||||
use utils\PagingInfo;
|
||||
/**
|
||||
* Class OAuth2TrackQuestionsTemplateApiController
|
||||
* @package App\Http\Controllers
|
||||
*/
|
||||
final class OAuth2TrackQuestionsTemplateApiController extends OAuth2ProtectedController
|
||||
{
|
||||
/**
|
||||
* @var ITrackQuestionTemplateService
|
||||
*/
|
||||
private $track_question_template_service;
|
||||
|
||||
/**
|
||||
* @var ITrackQuestionTemplateRepository
|
||||
*/
|
||||
private $track_question_template_repository;
|
||||
|
||||
/**
|
||||
* OAuth2TrackQuestionsTemplateApiController constructor.
|
||||
* @param ITrackQuestionTemplateService $track_question_template_service
|
||||
* @param ITrackQuestionTemplateRepository $track_question_template_repository
|
||||
* @param IResourceServerContext $resource_server_context
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ITrackQuestionTemplateService $track_question_template_service,
|
||||
ITrackQuestionTemplateRepository $track_question_template_repository,
|
||||
IResourceServerContext $resource_server_context
|
||||
)
|
||||
{
|
||||
parent::__construct($resource_server_context);
|
||||
$this->track_question_template_repository = $track_question_template_repository;
|
||||
$this->track_question_template_service = $track_question_template_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackQuestionTemplates(){
|
||||
$values = Input::all();
|
||||
$rules = [
|
||||
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => 'required_with:page|integer|min:5|max:100',
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
$validation = Validator::make($values, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$ex = new ValidationException();
|
||||
throw $ex->setMessages($validation->messages()->toArray());
|
||||
}
|
||||
|
||||
// default values
|
||||
$page = 1;
|
||||
$per_page = 5;
|
||||
|
||||
if (Input::has('page')) {
|
||||
$page = intval(Input::get('page'));
|
||||
$per_page = intval(Input::get('per_page'));
|
||||
}
|
||||
|
||||
$filter = null;
|
||||
|
||||
if (Input::has('filter')) {
|
||||
$filter = FilterParser::parse(Input::get('filter'), [
|
||||
'name' => ['=@', '=='],
|
||||
'label' => ['=@', '=='],
|
||||
'class_name' => ['=='],
|
||||
]);
|
||||
}
|
||||
|
||||
if(is_null($filter)) $filter = new Filter();
|
||||
|
||||
$filter->validate([
|
||||
'class_name' => sprintf('sometimes|in:%s',implode(',', TrackQuestionTemplateConstants::$valid_class_names)),
|
||||
'name' => 'sometimes|string',
|
||||
'label' => 'sometimes|string',
|
||||
], [
|
||||
'class_name.in' => sprintf
|
||||
(
|
||||
":attribute has an invalid value ( valid values are %s )",
|
||||
implode(", ", TrackQuestionTemplateConstants::$valid_class_names)
|
||||
),
|
||||
]);
|
||||
|
||||
$order = null;
|
||||
|
||||
if (Input::has('order'))
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
|
||||
'id',
|
||||
'name',
|
||||
'label',
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $this->track_question_template_repository->getAllByPage(new PagingInfo($page, $per_page), $filter, $order);
|
||||
|
||||
return $this->ok
|
||||
(
|
||||
$data->toArray
|
||||
(
|
||||
Request::input('expand', ''),
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array( $ex1->getMessage()));
|
||||
}
|
||||
catch (EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message' => $ex2->getMessage()));
|
||||
}
|
||||
catch(\HTTP401UnauthorizedException $ex3)
|
||||
{
|
||||
Log::warning($ex3);
|
||||
return $this->error401();
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTrackQuestionTemplate(){
|
||||
try {
|
||||
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
|
||||
$rules = TrackQuestionTemplateValidationRulesFactory::build($payload);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$question = $this->track_question_template_service->addTrackQuestionTemplate($payload);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($question)->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 $track_question_template_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackQuestionTemplate($track_question_template_id){
|
||||
try {
|
||||
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
if (is_null($track_question_template)) return $this->error404();
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($track_question_template)->serialize());
|
||||
}
|
||||
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 $track_question_template_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateTrackQuestionTemplate($track_question_template_id){
|
||||
try {
|
||||
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
|
||||
$rules = TrackQuestionTemplateValidationRulesFactory::build($payload, true);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$question = $this->track_question_template_service->updateTrackQuestionTemplate($track_question_template_id, $payload);
|
||||
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($question)->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 $track_question_template_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteTrackQuestionTemplate($track_question_template_id){
|
||||
try {
|
||||
|
||||
$this->track_question_template_service->deleteTrackQuestionTemplate($track_question_template_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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackQuestionTemplateMetadata(){
|
||||
return $this->ok
|
||||
(
|
||||
$this->track_question_template_repository->getQuestionsMetadata()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* values endpoints
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $track_question_template_id
|
||||
* @param $track_question_template_value_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){
|
||||
try {
|
||||
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
if (is_null($track_question_template)) return $this->error404();
|
||||
|
||||
if (!$track_question_template instanceof TrackMultiValueQuestionTemplate) return $this->error404();
|
||||
|
||||
$value = $track_question_template->getValueById($track_question_template_value_id);
|
||||
if (is_null($value)) return $this->error404();
|
||||
|
||||
return $this->ok(SerializerRegistry::getInstance()->getSerializer($value)->serialize());
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $track_question_template_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function addTrackQuestionTemplateValue($track_question_template_id){
|
||||
try {
|
||||
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
|
||||
$rules = TrackQuestionValueTemplateValidationRulesFactory::build($payload);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$value = $this->track_question_template_service->addTrackQuestionValueTemplate
|
||||
(
|
||||
$track_question_template_id,
|
||||
$payload
|
||||
);
|
||||
|
||||
return $this->created(SerializerRegistry::getInstance()->getSerializer($value)->serialize(
|
||||
Request::input('expand', '')
|
||||
));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $track_question_template_id
|
||||
* @param $track_question_template_value_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){
|
||||
try {
|
||||
|
||||
if(!Request::isJson()) return $this->error400();
|
||||
$payload = Input::json()->all();
|
||||
|
||||
$rules = TrackQuestionValueTemplateValidationRulesFactory::build($payload, true);
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($payload, $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$value = $this->track_question_template_service->updateTrackQuestionValueTemplate
|
||||
(
|
||||
$track_question_template_id,
|
||||
$track_question_template_value_id,
|
||||
$payload
|
||||
);
|
||||
|
||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($value)->serialize(
|
||||
Request::input('expand', '')
|
||||
));
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $track_question_template_id
|
||||
* @param $track_question_template_value_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteTrackQuestionTemplateValue($track_question_template_id, $track_question_template_value_id){
|
||||
try {
|
||||
$this->track_question_template_service->deleteTrackQuestionValueTemplate
|
||||
(
|
||||
$track_question_template_id,
|
||||
$track_question_template_value_id
|
||||
);
|
||||
return $this->deleted();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -531,6 +531,7 @@ Route::group([
|
|||
});
|
||||
});
|
||||
|
||||
// track tag groups
|
||||
Route::group(['prefix' => 'track-tag-groups'], function(){
|
||||
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
|
@ -539,7 +540,7 @@ Route::group([
|
|||
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',
|
||||
Route::post('seed-defaults', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@seedDefaultTrackTagGroups']);
|
||||
|
||||
Route::group(['prefix' => '{track_tag_group_id}'], function(){
|
||||
|
@ -601,6 +602,47 @@ Route::group([
|
|||
Route::post('/photo', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSpeakersApiController@addSpeakerPhoto']);
|
||||
});
|
||||
});
|
||||
|
||||
// track question templates
|
||||
Route::group(['prefix' => 'track-question-templates'], function () {
|
||||
|
||||
Route::get('', [
|
||||
'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplates']);
|
||||
Route::get('metadata', [
|
||||
'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplateMetadata'
|
||||
]);
|
||||
|
||||
Route::post('', [
|
||||
'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplate']);
|
||||
|
||||
Route::group(['prefix' => '{track_question_template_id}'], function () {
|
||||
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplate']);
|
||||
|
||||
Route::put('', [
|
||||
'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplate']);
|
||||
|
||||
Route::delete('', [
|
||||
'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplate']);
|
||||
|
||||
// multi values questions
|
||||
Route::group(['prefix' => 'values'], function () {
|
||||
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplateValue']);
|
||||
Route::group(['prefix' => '{track_question_template_value_id}'], function () {
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplateValue']);
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplateValue']);
|
||||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplateValue']);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//OAuth2 Protected API V2
|
||||
|
|
|
@ -11,7 +11,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
interface IOrderable
|
||||
use models\utils\IEntity;
|
||||
/**
|
||||
* Interface IOrderable
|
||||
* @package App\Models\Foundation\Main
|
||||
*/
|
||||
interface IOrderable extends IEntity
|
||||
{
|
||||
/**
|
||||
* @param int $order
|
||||
|
|
|
@ -20,42 +20,52 @@ use models\exceptions\ValidationException;
|
|||
*/
|
||||
trait OrderableChilds
|
||||
{
|
||||
/**
|
||||
* @param array $collection
|
||||
* @param IOrderable $entity
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private static function recalculateOrderForCollection(array $collection , IOrderable $entity, $new_order){
|
||||
|
||||
$former_order = 1;
|
||||
|
||||
foreach ($collection as $e){
|
||||
if($e->getId() == $entity->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param Selectable $collection
|
||||
* @param IOrderable $element
|
||||
* @param $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private static function recalculateOrderFor(Selectable $collection, IOrderable $element, $new_order){
|
||||
private static function recalculateOrderForSelectable(Selectable $collection, IOrderable $element, $new_order){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->orderBy(['order'=> 'ASC']);
|
||||
|
||||
$elements = $collection->matching($criteria)->toArray();
|
||||
$elements = array_slice($elements,0, count($elements), false);
|
||||
$max_order = count($elements);
|
||||
$former_order = 1;
|
||||
|
||||
foreach ($elements as $e){
|
||||
if($e->getId() == $element->getId()) break;
|
||||
$former_order++;
|
||||
}
|
||||
|
||||
if($new_order > $max_order)
|
||||
throw new ValidationException(sprintf("max order is %s", $max_order));
|
||||
|
||||
unset($elements[$former_order - 1]);
|
||||
|
||||
$elements = array_merge
|
||||
(
|
||||
array_slice($elements, 0, $new_order -1 , true) ,
|
||||
[$element] ,
|
||||
array_slice($elements, $new_order -1 , count($elements), true)
|
||||
);
|
||||
|
||||
$order = 1;
|
||||
foreach($elements as $e){
|
||||
$e->setOrder($order);
|
||||
$order++;
|
||||
}
|
||||
self::recalculateOrderForCollection( $collection->matching($criteria)->toArray(), $element, $new_order);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
<?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++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -173,6 +173,33 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
return $this->extra_questions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionTemplate $extra_question
|
||||
* @return $this
|
||||
*/
|
||||
public function addExtraQuestion(TrackQuestionTemplate $extra_question){
|
||||
if($this->extra_questions->contains($extra_question)) return $this;
|
||||
$this->extra_questions->add($extra_question);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionTemplate $extra_question
|
||||
* @return $this
|
||||
*/
|
||||
public function removeExtraQuestion(TrackQuestionTemplate $extra_question){
|
||||
if(!$this->extra_questions->contains($extra_question)) return $this;
|
||||
$this->extra_questions->removeElement($extra_question);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function clearExtraQuestions(){
|
||||
$this->extra_questions->clear();
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param int $id
|
||||
* @return TrackQuestionTemplate|null
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Main\OrderableChilds;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use models\exceptions\ValidationException;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
|
@ -29,7 +32,7 @@ class TrackMultiValueQuestionTemplate extends TrackQuestionTemplate
|
|||
protected $empty_string;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="TrackQuestionValueTemplate", mappedBy="owner", cascade={"persist"})
|
||||
* @ORM\OneToMany(targetEntity="TrackQuestionValueTemplate", mappedBy="owner", cascade={"persist"}, orphanRemoval=true)
|
||||
* @var TrackQuestionValueTemplate[]
|
||||
*/
|
||||
protected $values;
|
||||
|
@ -131,4 +134,70 @@ class TrackMultiValueQuestionTemplate extends TrackQuestionTemplate
|
|||
return array_merge(TrackQuestionTemplate::getMetadata(), self::$metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return TrackQuestionValueTemplate
|
||||
*/
|
||||
public function getValueById($id){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('id', intval($id)));
|
||||
$res = $this->values->matching($criteria)->first();
|
||||
return $res ? $res : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return TrackQuestionValueTemplate
|
||||
*/
|
||||
public function getValueByValue($value){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('value', strtolower(trim($value))));
|
||||
$res = $this->values->matching($criteria)->first();
|
||||
return $res ? $res : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @return TrackQuestionValueTemplate
|
||||
*/
|
||||
public function getValueByLabel($label){
|
||||
$criteria = Criteria::create();
|
||||
$criteria->where(Criteria::expr()->eq('label', strtolower(trim($label))));
|
||||
$res = $this->values->matching($criteria)->first();
|
||||
return $res ? $res : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionValueTemplate $value
|
||||
* @return $this
|
||||
*/
|
||||
public function addValue(TrackQuestionValueTemplate $value){
|
||||
$values = $this->getValues();
|
||||
$this->values->add($value);
|
||||
$value->setOwner($this);
|
||||
$value->setOrder(count($values));
|
||||
return $this;
|
||||
}
|
||||
|
||||
use OrderableChilds;
|
||||
|
||||
/**
|
||||
* @param TrackQuestionValueTemplate $value
|
||||
* @param int $new_order
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateValueOrder(TrackQuestionValueTemplate $value, $new_order){
|
||||
self::recalculateOrderForSelectable($this->values, $value, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionValueTemplate $value
|
||||
* @return $this
|
||||
*/
|
||||
public function removeValue(TrackQuestionValueTemplate $value){
|
||||
$this->values->removeElement($value);
|
||||
$value->clearOwner();
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use models\summit\PresentationCategory;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineTrackQuestionTemplateRepository")
|
||||
* @ORM\Table(name="TrackQuestionTemplate")
|
||||
* @ORM\InheritanceType("JOINED")
|
||||
* @ORM\DiscriminatorColumn(name="ClassName", type="string")
|
||||
|
@ -66,7 +66,6 @@ class TrackQuestionTemplate extends SilverstripeBaseModel
|
|||
*/
|
||||
protected $after_question;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="models\summit\PresentationCategory", mappedBy="extra_questions")
|
||||
* @var PresentationCategory[]
|
||||
|
@ -210,6 +209,42 @@ class TrackQuestionTemplate extends SilverstripeBaseModel
|
|||
$this->tracks = $tracks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function clearTracks(){
|
||||
|
||||
foreach($this->tracks as $track)
|
||||
$track->removeExtraQuestion($this);
|
||||
$this->tracks->clear();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategory $track
|
||||
* @return $this
|
||||
*/
|
||||
public function addTrack(PresentationCategory $track){
|
||||
|
||||
if($this->tracks->contains($track))
|
||||
return $this;
|
||||
$this->tracks->add($track);
|
||||
$track->addExtraQuestion($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategory $track
|
||||
* @return $this
|
||||
*/
|
||||
public function removeTrack(PresentationCategory $track){
|
||||
if(!$this->tracks->contains($track))
|
||||
return $this;
|
||||
$track->removeExtraQuestion($this);
|
||||
$this->tracks->removeElement($track);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TrackAnswer[]
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php namespace App\Models\Foundation\Summit\Events\Presentations\TrackQuestions;
|
||||
/**
|
||||
* 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 TrackQuestionTemplateConstants
|
||||
* @package App\Models\Foundation\Summit\Events\Presentations\TrackQuestions
|
||||
*/
|
||||
final class TrackQuestionTemplateConstants
|
||||
{
|
||||
public static $valid_class_names = [
|
||||
TrackCheckBoxListQuestionTemplate::ClassName,
|
||||
TrackCheckBoxQuestionTemplate::ClassName,
|
||||
TrackDropDownQuestionTemplate::ClassName,
|
||||
TrackLiteralContentQuestionTemplate::ClassName,
|
||||
TrackRadioButtonListQuestionTemplate::ClassName,
|
||||
TrackTextBoxQuestionTemplate::ClassName,
|
||||
];
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\Main\IOrderable;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
/**
|
||||
|
@ -19,7 +20,7 @@ use models\utils\SilverstripeBaseModel;
|
|||
* Class TrackQuestionValueTemplate
|
||||
* @package App\Models\Foundation\Summit\Events\Presentations\TrackQuestions
|
||||
*/
|
||||
class TrackQuestionValueTemplate extends SilverstripeBaseModel
|
||||
class TrackQuestionValueTemplate extends SilverstripeBaseModel implements IOrderable
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="Value", type="string")
|
||||
|
@ -34,7 +35,7 @@ class TrackQuestionValueTemplate extends SilverstripeBaseModel
|
|||
private $label;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Order", type="integer")
|
||||
* @ORM\Column(name="`Order`", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $order;
|
||||
|
@ -110,6 +111,10 @@ class TrackQuestionValueTemplate extends SilverstripeBaseModel
|
|||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
public function clearOwner(){
|
||||
$this->owner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
|
|
@ -184,7 +184,7 @@ class RSVPMultiValueQuestionTemplate extends RSVPQuestionTemplate
|
|||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateValueOrder(RSVPQuestionValueTemplate $value, $new_order){
|
||||
self::recalculateOrderFor($this->values, $value, $new_order);
|
||||
self::recalculateOrderForSelectable($this->values, $value, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -187,7 +187,7 @@ class RSVPTemplate extends SilverstripeBaseModel
|
|||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateQuestionOrder(RSVPQuestionTemplate $question, $new_order){
|
||||
self::recalculateOrderFor($this->questions, $question, $new_order);
|
||||
self::recalculateOrderForSelectable($this->questions, $question, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,59 +37,45 @@ final class SummitRSVPTemplateQuestionFactory
|
|||
*/
|
||||
public static function build(array $data){
|
||||
if(!isset($data['class_name'])) throw new ValidationException("missing class_name param");
|
||||
$location = null;
|
||||
$question = null;
|
||||
switch($data['class_name']){
|
||||
case RSVPMemberEmailQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberEmailQuestionTemplate, $data);
|
||||
$question = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberEmailQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPMemberFirstNameQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberFirstNameQuestionTemplate, $data);
|
||||
$question = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberFirstNameQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPMemberLastNameQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberLastNameQuestionTemplate, $data);
|
||||
$question = self::populateRSVPSingleValueTemplateQuestion(new RSVPMemberLastNameQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPTextBoxQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPSingleValueTemplateQuestion(new RSVPTextBoxQuestionTemplate, $data);
|
||||
$question = self::populateRSVPSingleValueTemplateQuestion(new RSVPTextBoxQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPTextAreaQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPSingleValueTemplateQuestion(new RSVPTextAreaQuestionTemplate, $data);
|
||||
$question = self::populateRSVPSingleValueTemplateQuestion(new RSVPTextAreaQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPCheckBoxListQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPMultiValueQuestionTemplate(new RSVPCheckBoxListQuestionTemplate, $data);
|
||||
$question = self::populateRSVPMultiValueQuestionTemplate(new RSVPCheckBoxListQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPRadioButtonListQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPMultiValueQuestionTemplate(new RSVPRadioButtonListQuestionTemplate, $data);
|
||||
$question = self::populateRSVPMultiValueQuestionTemplate(new RSVPRadioButtonListQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPDropDownQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPDropDownQuestionTemplate(new RSVPDropDownQuestionTemplate, $data);
|
||||
$question = self::populateRSVPDropDownQuestionTemplate(new RSVPDropDownQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case RSVPLiteralContentQuestionTemplate::ClassName :{
|
||||
$location = self::populateRSVPLiteralContentQuestionTemplate(new RSVPLiteralContentQuestionTemplate, $data);
|
||||
$question = self::populateRSVPLiteralContentQuestionTemplate(new RSVPLiteralContentQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RSVPSingleValueTemplateQuestion $question
|
||||
* @param array $data
|
||||
* @return RSVPQuestionTemplate
|
||||
*/
|
||||
private static function populateRSVPSingleValueTemplateQuestion(RSVPSingleValueTemplateQuestion $question, array $data){
|
||||
if(isset($data['initial_value']))
|
||||
$question->setInitialValue(trim($data['initial_value']));
|
||||
|
||||
$question = self::populateRSVPQuestionTemplate($question, $data);
|
||||
|
||||
return $question;
|
||||
}
|
||||
|
||||
|
@ -115,23 +101,35 @@ final class SummitRSVPTemplateQuestionFactory
|
|||
return $question;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RSVPSingleValueTemplateQuestion $question
|
||||
* @param array $data
|
||||
* @return RSVPQuestionTemplate
|
||||
*/
|
||||
private static function populateRSVPSingleValueTemplateQuestion(RSVPSingleValueTemplateQuestion $question, array $data){
|
||||
if(isset($data['initial_value']))
|
||||
$question->setInitialValue(trim($data['initial_value']));
|
||||
|
||||
return self::populateRSVPQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RSVPMultiValueQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return RSVPMultiValueQuestionTemplate
|
||||
* @return RSVPQuestionTemplate
|
||||
*/
|
||||
private static function populateRSVPMultiValueQuestionTemplate(RSVPMultiValueQuestionTemplate $question, array $data){
|
||||
|
||||
if(isset($data['empty_string']))
|
||||
$question->setEmptyString(trim($data['empty_string']));
|
||||
|
||||
return $question;
|
||||
return self::populateRSVPQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RSVPDropDownQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return RSVPDropDownQuestionTemplate
|
||||
* @return RSVPQuestionTemplate
|
||||
*/
|
||||
private static function populateRSVPDropDownQuestionTemplate(RSVPDropDownQuestionTemplate $question, array $data){
|
||||
|
||||
|
@ -144,18 +142,18 @@ final class SummitRSVPTemplateQuestionFactory
|
|||
if(isset($data['use_chosen_plugin']))
|
||||
$question->setUseChosenPlugin(boolval($data['use_chosen_plugin']));
|
||||
|
||||
return $question;
|
||||
return self::populateRSVPMultiValueQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RSVPLiteralContentQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return RSVPLiteralContentQuestionTemplate
|
||||
* @return RSVPQuestionTemplate
|
||||
*/
|
||||
private static function populateRSVPLiteralContentQuestionTemplate(RSVPLiteralContentQuestionTemplate $question, array $data){
|
||||
if(isset($data['content']))
|
||||
$question->setContent(trim($data['content']));
|
||||
return $question;
|
||||
return self::populateRSVPQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
<?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\Events\Presentations\TrackQuestions\TrackCheckBoxListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackCheckBoxQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackDropDownQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackLiteralContentQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackMultiValueQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackRadioButtonListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackSingleValueTemplateQuestion;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Class TrackQuestionTemplateFactory
|
||||
* @package App\Models\Foundation\Summit\Factories
|
||||
*/
|
||||
final class TrackQuestionTemplateFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate|null
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public static function build(array $data)
|
||||
{
|
||||
if (!isset($data['class_name'])) throw new ValidationException("missing class_name param");
|
||||
$track_question_template = null;
|
||||
switch ($data['class_name']) {
|
||||
case TrackTextBoxQuestionTemplate::ClassName:
|
||||
{
|
||||
$track_question_template = self::populateTrackSingleValueTemplateQuestion(new TrackTextBoxQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case TrackCheckBoxQuestionTemplate::ClassName:
|
||||
{
|
||||
$track_question_template = self::populateTrackSingleValueTemplateQuestion(new TrackCheckBoxQuestionTemplate(), $data);
|
||||
}
|
||||
break;
|
||||
case TrackCheckBoxListQuestionTemplate::ClassName :
|
||||
{
|
||||
$track_question_template = self::populateTrackMultiValueQuestionTemplate(new TrackCheckBoxListQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case TrackRadioButtonListQuestionTemplate::ClassName :
|
||||
{
|
||||
$track_question_template = self::populateTrackMultiValueQuestionTemplate(new TrackRadioButtonListQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case TrackDropDownQuestionTemplate::ClassName :
|
||||
{
|
||||
$track_question_template = self::populateTrackDropDownQuestionTemplate(new TrackDropDownQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
case TrackLiteralContentQuestionTemplate::ClassName :
|
||||
{
|
||||
$track_question_template = self::populateTrackLiteralContentQuestionTemplate(new TrackLiteralContentQuestionTemplate, $data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $track_question_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackSingleValueTemplateQuestion $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
private static function populateTrackSingleValueTemplateQuestion(TrackSingleValueTemplateQuestion $question, array $data)
|
||||
{
|
||||
if (isset($data['initial_value']))
|
||||
$question->setInitialValue(trim($data['initial_value']));
|
||||
|
||||
return self::populateTrackQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackMultiValueQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
private static function populateTrackMultiValueQuestionTemplate(TrackMultiValueQuestionTemplate $question, array $data)
|
||||
{
|
||||
|
||||
if (isset($data['empty_string']))
|
||||
$question->setEmptyString(trim($data['empty_string']));
|
||||
|
||||
return self::populateTrackQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
private static function populateTrackQuestionTemplate(TrackQuestionTemplate $question, array $data)
|
||||
{
|
||||
|
||||
if (isset($data['name']))
|
||||
$question->setName(trim($data['name']));
|
||||
|
||||
if (isset($data['label']))
|
||||
$question->setLabel(trim($data['label']));
|
||||
|
||||
if (isset($data['is_mandatory']))
|
||||
$question->setIsMandatory(boolval($data['is_mandatory']));
|
||||
|
||||
if (isset($data['is_read_only']))
|
||||
$question->setIsReadOnly(boolval($data['is_read_only']));
|
||||
|
||||
return $question;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackDropDownQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
private static function populateTrackDropDownQuestionTemplate(TrackDropDownQuestionTemplate $question, array $data)
|
||||
{
|
||||
|
||||
if (isset($data['is_multiselect']))
|
||||
$question->setIsMultiselect(boolval($data['is_multiselect']));
|
||||
|
||||
if (isset($data['is_country_selector']))
|
||||
$question->setIsCountrySelector(boolval($data['is_country_selector']));
|
||||
|
||||
return self::populateTrackMultiValueQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackLiteralContentQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
private static function populateTrackLiteralContentQuestionTemplate(TrackLiteralContentQuestionTemplate $question, array $data)
|
||||
{
|
||||
if (isset($data['content']))
|
||||
$question->setContent(trim($data['content']));
|
||||
return self::populateTrackQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionTemplate $question
|
||||
* @param array $data
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
public static function populate(TrackQuestionTemplate $question, array $data){
|
||||
if($question instanceof TrackTextBoxQuestionTemplate){
|
||||
return self::populateTrackSingleValueTemplateQuestion($question, $data);
|
||||
}
|
||||
if($question instanceof TrackCheckBoxQuestionTemplate){
|
||||
return self::populateTrackSingleValueTemplateQuestion($question, $data);
|
||||
}
|
||||
if($question instanceof TrackCheckBoxListQuestionTemplate){
|
||||
return self::populateTrackMultiValueQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
if($question instanceof TrackRadioButtonListQuestionTemplate){
|
||||
return self::populateTrackMultiValueQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
if($question instanceof TrackDropDownQuestionTemplate){
|
||||
return self::populateTrackDropDownQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
if($question instanceof TrackLiteralContentQuestionTemplate){
|
||||
return self::populateTrackLiteralContentQuestionTemplate($question, $data);
|
||||
}
|
||||
|
||||
return $question;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php namespace App\Models\Foundation\Summit\Factories;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionValueTemplate;
|
||||
|
||||
/**
|
||||
* 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 TrackQuestionValueTemplateFactory
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
*/
|
||||
public static function build(array $data){
|
||||
return self::populate(new TrackQuestionValueTemplate, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TrackQuestionValueTemplate $value
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
*/
|
||||
public static function populate(TrackQuestionValueTemplate $value, array $data){
|
||||
|
||||
if(isset($data['value']))
|
||||
$value->setValue(trim($data['value']));
|
||||
|
||||
if(isset($data['label']))
|
||||
$value->setLabel(trim($data['label']));
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
|
@ -11,7 +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\Main\IOrderable;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\ScheduledSummitLocationBanner;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
@ -38,7 +38,7 @@ use Doctrine\ORM\Mapping AS ORM;
|
|||
* Class SummitAbstractLocation
|
||||
* @package models\summit
|
||||
*/
|
||||
class SummitAbstractLocation extends SilverstripeBaseModel implements IOrderableEntity
|
||||
class SummitAbstractLocation extends SilverstripeBaseModel implements IOrderable
|
||||
{
|
||||
const TypeExternal = 'External';
|
||||
const TypeInternal = 'Internal';
|
||||
|
|
|
@ -79,7 +79,7 @@ class SummitVenue extends SummitGeoLocatedLocation
|
|||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
self::recalculateOrderFor($this->rooms, $room, $new_order);
|
||||
self::recalculateOrderForSelectable($this->rooms, $room, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
use App\Models\Foundation\Main\OrderableChilds;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\File;
|
||||
|
@ -214,7 +213,7 @@ class SummitVenueFloor extends SilverstripeBaseModel
|
|||
* @throws ValidationException
|
||||
*/
|
||||
public function recalculateRoomsOrder(SummitVenueRoom $room, $new_order){
|
||||
self::recalculateOrderFor($this->rooms, $room, $new_order);
|
||||
self::recalculateOrderForSelectable($this->rooms, $room, $new_order);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?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 App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use models\utils\IBaseRepository;
|
||||
/**
|
||||
* Interface ITrackQuestionTemplateRepository
|
||||
* @package App\Models\Foundation\Summit\Repositories
|
||||
*/
|
||||
interface ITrackQuestionTemplateRepository extends IBaseRepository
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
public function getByName($name);
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
public function getByLabel($label);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getQuestionsMetadata();
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
**/
|
||||
use App\Http\Utils\DateUtils;
|
||||
use App\Models\Foundation\RecalculateOrderStrategy;
|
||||
use App\Models\Foundation\Main\OrderableChilds;
|
||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||
use App\Models\Foundation\Summit\SelectionPlan;
|
||||
use App\Models\Foundation\Summit\TrackTagGroup;
|
||||
|
@ -22,7 +22,6 @@ use App\Models\Utils\TimeZoneEntity;
|
|||
use DateTime;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Query\Expr\Select;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\Company;
|
||||
use models\main\File;
|
||||
|
@ -1728,6 +1727,8 @@ SQL;
|
|||
return $this;
|
||||
}
|
||||
|
||||
use OrderableChilds;
|
||||
|
||||
/**
|
||||
* @param SummitAbstractLocation $location
|
||||
* @param int $new_order
|
||||
|
@ -1744,8 +1745,7 @@ SQL;
|
|||
$filtered_locations[] = $l;
|
||||
}
|
||||
|
||||
$strategy = new RecalculateOrderStrategy();
|
||||
$strategy->recalculateOrder($filtered_locations, $location, $new_order);
|
||||
self::recalculateOrderForCollection($filtered_locations, $location, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2350,11 +2350,7 @@ SQL;
|
|||
* @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);
|
||||
self::recalculateOrderForSelectable($this->track_tag_groups, $track_tag_group, $new_order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
use App\Models\Foundation\IOrderableEntity;
|
||||
use App\Models\Foundation\Main\IOrderable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Cache;
|
||||
use models\main\Tag;
|
||||
use models\summit\SummitOwned;
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
|
@ -24,7 +23,7 @@ use Doctrine\ORM\Mapping AS ORM;
|
|||
* Class TrackTagGroup
|
||||
* @package models\summit\TrackTagGroup
|
||||
*/
|
||||
class TrackTagGroup extends SilverstripeBaseModel implements IOrderableEntity
|
||||
class TrackTagGroup extends SilverstripeBaseModel implements IOrderable
|
||||
{
|
||||
use SummitOwned;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
**/
|
||||
use App\Models\Foundation\Summit\Defaults\DefaultSummitEventType;
|
||||
use App\Models\Foundation\Summit\DefaultTrackTagGroup;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
|
||||
use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner;
|
||||
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
|
||||
|
@ -25,6 +26,7 @@ use App\Models\Foundation\Summit\Repositories\ISummitEventTypeRepository;
|
|||
use App\Models\Foundation\Summit\Repositories\ISummitLocationBannerRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitLocationRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitTrackRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackQuestionTemplateRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackTagGroupAllowedTagsRepository;
|
||||
use App\Models\Foundation\Summit\SelectionPlan;
|
||||
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
|
||||
|
@ -355,5 +357,13 @@ final class RepositoriesProvider extends ServiceProvider
|
|||
}
|
||||
);
|
||||
|
||||
|
||||
App::singleton(
|
||||
ITrackQuestionTemplateRepository::class,
|
||||
function(){
|
||||
return EntityManager::getRepository(TrackQuestionTemplate::class);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
<?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\Events\Presentations\TrackQuestions\TrackCheckBoxListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackCheckBoxQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackDropDownQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackLiteralContentQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackRadioButtonListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackQuestionTemplateRepository;
|
||||
use App\Repositories\SilverStripeDoctrineRepository;
|
||||
use utils\DoctrineInstanceOfFilterMapping;
|
||||
|
||||
/**
|
||||
* Class DoctrineTrackQuestionTemplateRepository
|
||||
* @package App\Repositories\Summit
|
||||
*/
|
||||
final class DoctrineTrackQuestionTemplateRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements ITrackQuestionTemplateRepository
|
||||
{
|
||||
|
||||
protected function getFilterMappings()
|
||||
{
|
||||
return [
|
||||
'name' => 'e.name:json_string',
|
||||
'label' => 'e.label:json_string',
|
||||
'class_name' => new DoctrineInstanceOfFilterMapping
|
||||
(
|
||||
"e",
|
||||
[
|
||||
TrackLiteralContentQuestionTemplate::ClassName => TrackLiteralContentQuestionTemplate::class,
|
||||
TrackRadioButtonListQuestionTemplate::ClassName => TrackRadioButtonListQuestionTemplate::class,
|
||||
TrackCheckBoxListQuestionTemplate::ClassName => TrackCheckBoxListQuestionTemplate::class,
|
||||
TrackDropDownQuestionTemplate::ClassName => TrackDropDownQuestionTemplate::class,
|
||||
TrackTextBoxQuestionTemplate::ClassName => TrackTextBoxQuestionTemplate::class,
|
||||
TrackCheckBoxQuestionTemplate::ClassName => TrackCheckBoxQuestionTemplate::class,
|
||||
]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOrderMappings()
|
||||
{
|
||||
return [
|
||||
'name' => 'e.name',
|
||||
'label' => 'e.name',
|
||||
'id' => 'e.id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return TrackQuestionTemplate::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
public function getByName($name)
|
||||
{
|
||||
return $this->getEntityManager()->createQueryBuilder()
|
||||
->select("g")
|
||||
->from(TrackQuestionTemplate::class, "g")
|
||||
->where('LOWER(g.name) = :name')
|
||||
->setParameter('name', strtolower(trim($name)))
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
* @return TrackQuestionTemplate
|
||||
*/
|
||||
public function getByLabel($label)
|
||||
{
|
||||
return $this->getEntityManager()->createQueryBuilder()
|
||||
->select("g")
|
||||
->from(TrackQuestionTemplate::class, "g")
|
||||
->where('LOWER(g.label) = :label')
|
||||
->setParameter('label', strtolower(trim($label)))
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getQuestionsMetadata()
|
||||
{
|
||||
return [
|
||||
TrackTextBoxQuestionTemplate::getMetadata(),
|
||||
TrackCheckBoxQuestionTemplate::getMetadata(),
|
||||
TrackLiteralContentQuestionTemplate::getMetadata(),
|
||||
TrackRadioButtonListQuestionTemplate::getMetadata(),
|
||||
TrackCheckBoxListQuestionTemplate::getMetadata(),
|
||||
TrackDropDownQuestionTemplate::getMetadata(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ final class SummitScopes
|
|||
const WriteSummitData = '%s/summits/write';
|
||||
const WriteSpeakersData = '%s/speakers/write';
|
||||
const WriteTrackTagGroupsData = '%s/track-tag-groups/write';
|
||||
const WriteTrackQuestionTemplateData = '%s/track-question-templates/write';
|
||||
const WriteMySpeakersData = '%s/speakers/write/me';
|
||||
|
||||
const PublishEventData = '%s/summits/publish-event';
|
||||
|
|
|
@ -316,14 +316,11 @@ final class AttendeeService extends AbstractService implements IAttendeeService
|
|||
$new_owner = SummitAttendeeFactory::build($summit, $other_member, []);
|
||||
$this->attendee_repository->add($new_owner);
|
||||
}
|
||||
if($new_owner->hasTickets()){
|
||||
throw new ValidationException('This member is already assigned to another ticket');
|
||||
}
|
||||
$new_owner->addTicket($ticket);
|
||||
$attendee->removeTicket($ticket);
|
||||
if(!$attendee->hasTickets()){
|
||||
$this->attendee_repository->delete($attendee);
|
||||
}
|
||||
$new_owner->addTicket($ticket);
|
||||
return $ticket;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<?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\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionValueTemplate;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Interface ITrackQuestionTemplate
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
interface ITrackQuestionTemplateService
|
||||
{
|
||||
/**
|
||||
* @param array $payload
|
||||
* @return TrackQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addTrackQuestionTemplate(array $payload);
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param array $payload
|
||||
* @return TrackQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackQuestionTemplate($track_question_template_id, array $payload);
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function deleteTrackQuestionTemplate($track_question_template_id);
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addTrackQuestionValueTemplate($track_question_template_id, $data);
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param int $track_question_value_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackQuestionValueTemplate($track_question_template_id, $track_question_value_template_id, $data);
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param int $track_question_value_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteTrackQuestionValueTemplate($track_question_template_id, $track_question_value_template_id);
|
||||
}
|
|
@ -251,6 +251,23 @@ final class RSVPTemplateService
|
|||
)
|
||||
);
|
||||
|
||||
$class_name = $data['class_name'];
|
||||
$reflect = new \ReflectionClass($question);
|
||||
if ($reflect->getShortName() !== $class_name) {
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.RSVPTemplateService.updateQuestion.QuestionNotFound',
|
||||
[
|
||||
'summit_id' => $summit->getId(),
|
||||
'template_id' => $template_id,
|
||||
'question_id' => $question_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(isset($data['name'])) {
|
||||
$former_question = $template->getQuestionByName($data['name']);
|
||||
if (!is_null($former_question) && $former_question->getId() != $question_id) {
|
||||
|
|
|
@ -0,0 +1,412 @@
|
|||
<?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\Events\Presentations\TrackQuestions\TrackMultiValueQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionValueTemplate;
|
||||
use App\Models\Foundation\Summit\Factories\TrackQuestionTemplateFactory;
|
||||
use App\Models\Foundation\Summit\Factories\TrackQuestionValueTemplateFactory;
|
||||
use App\Models\Foundation\Summit\Repositories\ISummitTrackRepository;
|
||||
use App\Models\Foundation\Summit\Repositories\ITrackQuestionTemplateRepository;
|
||||
use libs\utils\ITransactionService;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
/**
|
||||
* Class TrackQuestionTemplateService
|
||||
* @package App\Services\Model
|
||||
*/
|
||||
final class TrackQuestionTemplateService
|
||||
extends AbstractService
|
||||
implements ITrackQuestionTemplateService
|
||||
{
|
||||
/**
|
||||
* @var ITrackQuestionTemplateRepository
|
||||
*/
|
||||
private $track_question_template_repository;
|
||||
|
||||
/**
|
||||
* @var ISummitTrackRepository
|
||||
*/
|
||||
private $track_repository;
|
||||
|
||||
/**
|
||||
* TrackQuestionTemplateService constructor.
|
||||
* @param ITrackQuestionTemplateRepository $track_question_template_repository
|
||||
* @param ISummitTrackRepository $track_repository
|
||||
* @param ITransactionService $tx_service
|
||||
*/
|
||||
public function __construct
|
||||
(
|
||||
ITrackQuestionTemplateRepository $track_question_template_repository,
|
||||
ISummitTrackRepository $track_repository,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
{
|
||||
parent::__construct($tx_service);
|
||||
$this->track_repository = $track_repository;
|
||||
$this->track_question_template_repository = $track_question_template_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $payload
|
||||
* @return TrackQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addTrackQuestionTemplate(array $payload)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($payload){
|
||||
$former_track_question_template = $this->track_question_template_repository->getByName($payload["name"]);
|
||||
if(!is_null($former_track_question_template)){
|
||||
throw new ValidationException(
|
||||
trans(
|
||||
"validation_errors.TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateLabelAlreadyExist"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_track_question_template = $this->track_question_template_repository->getByLabel($payload["label"]);
|
||||
if(!is_null($former_track_question_template)){
|
||||
throw new ValidationException(
|
||||
trans(
|
||||
"validation_errors.TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateNameAlreadyExist"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$track_question_template = TrackQuestionTemplateFactory::build($payload);
|
||||
|
||||
if(isset($payload['tracks'])){
|
||||
foreach($payload['tracks'] as $track_id){
|
||||
$track = $this->track_repository->getById($track_id);
|
||||
if(is_null($track))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
"not_found_errors.TrackQuestionTemplateService.addTrackQuestionTemplate.TrackNotFound"
|
||||
,['track_id' => $track_id])
|
||||
);
|
||||
$track_question_template->addTrack($track);
|
||||
}
|
||||
}
|
||||
|
||||
$this->track_question_template_repository->add($track_question_template);
|
||||
|
||||
return $track_question_template;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param array $payload
|
||||
* @return TrackQuestionTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackQuestionTemplate($track_question_template_id, array $payload)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($payload, $track_question_template_id){
|
||||
$former_track_question_template = $this->track_question_template_repository->getByName($payload["name"]);
|
||||
if(!is_null($former_track_question_template) && $former_track_question_template->getId() != $track_question_template_id){
|
||||
throw new ValidationException(
|
||||
trans(
|
||||
"validation_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateLabelAlreadyExist"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_track_question_template = $this->track_question_template_repository->getByLabel($payload["label"]);
|
||||
if(!is_null($former_track_question_template) && $former_track_question_template->getId() != $track_question_template_id){
|
||||
throw new ValidationException(
|
||||
trans(
|
||||
"validation_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNameAlreadyExist"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
|
||||
if(is_null($track_question_template))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
'not_found_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id
|
||||
]
|
||||
)
|
||||
);
|
||||
$class_name = $payload['class_name'];
|
||||
|
||||
$reflect = new \ReflectionClass($track_question_template);
|
||||
if ($reflect->getShortName() !== $class_name) {
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
'not_found_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(isset($payload['tracks'])){
|
||||
$track_question_template->clearTracks();
|
||||
foreach($payload['tracks'] as $track_id){
|
||||
$track = $this->track_repository->getById($track_id);
|
||||
if(is_null($track))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
"not_found_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackNotFound"
|
||||
,['track_id' => $track_id])
|
||||
);
|
||||
$track_question_template->addTrack($track);
|
||||
}
|
||||
}
|
||||
|
||||
if($track_question_template instanceof TrackMultiValueQuestionTemplate){
|
||||
if(isset($payload['default_value'])){
|
||||
$default_value = $track_question_template->getValueById(intval($payload['default_value']));
|
||||
if(is_null($default_value))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
"not_found_errors.TrackQuestionTemplateService.updateTrackQuestionTemplate.DefaultValueNotFound"
|
||||
,
|
||||
[
|
||||
'default_value' => $payload['default_value']
|
||||
]
|
||||
)
|
||||
);
|
||||
$track_question_template->setDefaultValue($default_value);
|
||||
}
|
||||
}
|
||||
|
||||
return TrackQuestionTemplateFactory::populate($track_question_template, $payload);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function deleteTrackQuestionTemplate($track_question_template_id){
|
||||
return $this->tx_service->transaction(function() use($track_question_template_id){
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
|
||||
if(is_null($track_question_template))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
'not_found_errors.TrackQuestionTemplateService.deleteTrackQuestionTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->track_question_template_repository->delete($track_question_template);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addTrackQuestionValueTemplate($track_question_template_id, $data){
|
||||
return $this->tx_service->transaction(function() use($track_question_template_id, $data){
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
|
||||
if(is_null($track_question_template))
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
if(!$track_question_template instanceof TrackMultiValueQuestionTemplate){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.TrackQuestionTemplateService.addTrackQuestionValueTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_value = $track_question_template->getValueByValue($data['value']);
|
||||
if(!is_null($former_value)){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.TrackQuestionTemplateService.addTrackQuestionValueTemplate.ValueAlreadyExist',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
'value' => $data['value']
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$former_value = $track_question_template->getValueByLabel($data['label']);
|
||||
if(!is_null($former_value)){
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.TrackQuestionTemplateService.addTrackQuestionValueTemplate.LabelAlreadyExist',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
'label' => $data['label']
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$value = TrackQuestionValueTemplateFactory::build($data);
|
||||
|
||||
$track_question_template->addValue($value);
|
||||
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param int $track_question_value_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function updateTrackQuestionValueTemplate($track_question_template_id, $track_question_value_template_id, $data){
|
||||
return $this->tx_service->transaction(function() use($track_question_template_id, $track_question_value_template_id, $data){
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
|
||||
if(is_null($track_question_template))
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
if(!$track_question_template instanceof TrackMultiValueQuestionTemplate){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.TrackQuestionTemplateService.updateTrackQuestionValueTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(isset($data['value'])) {
|
||||
$former_value = $track_question_template->getValueByValue($data['value']);
|
||||
if (!is_null($former_value) && $former_value->getId() != $track_question_value_template_id) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.TrackQuestionTemplateService.updateTrackQuestionValueTemplate.ValueAlreadyExist',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
'value' => $data['value']
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['label'])) {
|
||||
$former_value = $track_question_template->getValueByLabel($data['label']);
|
||||
if (!is_null($former_value) && $former_value->getId() != $track_question_value_template_id) {
|
||||
throw new ValidationException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'validation_errors.TrackQuestionTemplateService.updateTrackQuestionValueTemplate.LabelAlreadyExist',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
'label' => $data['label']
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$value = $track_question_template->getValueById($track_question_value_template_id);
|
||||
if(is_null($value))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
'not_found_errors.TrackQuestionTemplateService.updateTrackQuestionValueTemplate.TrackQuestionTemplateValueNotFound',
|
||||
[
|
||||
'track_question_value_template_id' => $track_question_value_template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
TrackQuestionValueTemplateFactory::populate($value, $data);
|
||||
|
||||
if (isset($data['order']) && intval($data['order']) != $value->getOrder()) {
|
||||
// request to update order
|
||||
$track_question_template->recalculateValueOrder($value, intval($data['order']));
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $track_question_template_id
|
||||
* @param int $track_question_value_template_id
|
||||
* @param array $data
|
||||
* @return TrackQuestionValueTemplate
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function deleteTrackQuestionValueTemplate($track_question_template_id, $track_question_value_template_id){
|
||||
return $this->tx_service->transaction(function() use($track_question_template_id, $track_question_value_template_id){
|
||||
$track_question_template = $this->track_question_template_repository->getById($track_question_template_id);
|
||||
|
||||
if(is_null($track_question_template))
|
||||
throw new EntityNotFoundException();
|
||||
|
||||
if(!$track_question_template instanceof TrackMultiValueQuestionTemplate){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans
|
||||
(
|
||||
'not_found_errors.TrackQuestionTemplateService.deleteTrackQuestionValueTemplate.TrackQuestionTemplateNotFound',
|
||||
[
|
||||
'track_question_template_id' => $track_question_template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$value = $track_question_template->getValueById($track_question_value_template_id);
|
||||
if(is_null($value))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
'not_found_errors.TrackQuestionTemplateService.deleteTrackQuestionValueTemplate.TrackQuestionTemplateValueNotFound',
|
||||
[
|
||||
'track_question_value_template_id' => $track_question_value_template_id,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$track_question_template->removeValue($value);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ use App\Services\Model\ISummitSelectionPlanService;
|
|||
use App\Services\Model\ISummitTicketTypeService;
|
||||
use App\Services\Model\ISummitTrackService;
|
||||
use App\Services\Model\ISummitTrackTagGroupService;
|
||||
use App\Services\Model\ITrackQuestionTemplateService;
|
||||
use App\Services\Model\OrganizationService;
|
||||
use App\Services\Model\PresentationCategoryGroupService;
|
||||
use App\Services\Model\SummitLocationService;
|
||||
|
@ -42,6 +43,7 @@ use App\Services\Model\SummitSelectionPlanService;
|
|||
use App\Services\Model\SummitTicketTypeService;
|
||||
use App\Services\Model\SummitTrackService;
|
||||
use App\Services\Model\SummitTrackTagGroupService;
|
||||
use App\Services\Model\TrackQuestionTemplateService;
|
||||
use App\Services\SummitEventTypeService;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
@ -250,5 +252,10 @@ final class ServicesProvider extends ServiceProvider
|
|||
ISummitTrackTagGroupService::class,
|
||||
SummitTrackTagGroupService::class
|
||||
);
|
||||
|
||||
App::singleton(
|
||||
ITrackQuestionTemplateService::class,
|
||||
TrackQuestionTemplateService::class
|
||||
);
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ class ApiEndpointsSeeder extends Seeder
|
|||
$this->seedCompaniesEndpoints();
|
||||
$this->seedGroupsEndpoints();
|
||||
$this->seedOrganizationsEndpoints();
|
||||
$this->seedTrackQuestionTemplateEndpoints();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1799,7 +1800,7 @@ class ApiEndpointsSeeder extends Seeder
|
|||
[
|
||||
'name' => 'seed-default-track-tag-groups',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/seed-defaults',
|
||||
'http_method' => 'PUT',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
|
@ -2078,4 +2079,91 @@ class ApiEndpointsSeeder extends Seeder
|
|||
);
|
||||
}
|
||||
|
||||
public function seedTrackQuestionTemplateEndpoints(){
|
||||
$current_realm = Config::get('app.url');
|
||||
|
||||
$this->seedApiEndpoints('track-question-templates', [
|
||||
// track question templates
|
||||
[
|
||||
'name' => 'get-track-question-templates',
|
||||
'route' => '/api/v1/track-question-templates',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-track-question-templates',
|
||||
'route' => '/api/v1/track-question-templates',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-track-question-templates',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-track-question-templates',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-track-question-templates-metadata',
|
||||
'route' => '/api/v1/track-question-templates/metadata',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'add-track-question-template-value',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}/values',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'update-track-question-template-value',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'delete-track-question-template-value',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'get-track-question-template-value',
|
||||
'route' => '/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -150,6 +150,11 @@ final class ApiScopesSeeder extends Seeder
|
|||
'short_description' => 'Write Summit Track Tag Groups Data',
|
||||
'description' => 'Grants write access for Summit Track Tag Groups Data',
|
||||
],
|
||||
[
|
||||
'name' => sprintf(SummitScopes::WriteTrackQuestionTemplateData, $current_realm),
|
||||
'short_description' => 'Write Summit Track Question Template Data',
|
||||
'description' => 'Grants write access for Summit Track Question Template Data',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($scopes as $scope_info) {
|
||||
|
|
|
@ -109,5 +109,16 @@ final class ApiSeeder extends Seeder
|
|||
|
||||
EntityManager::flush();
|
||||
|
||||
// track question templates
|
||||
|
||||
$api = new Api();
|
||||
$api->setName('track-question-templates');
|
||||
$api->setActive(true);
|
||||
$api->setDescription('Track Question Templates API');
|
||||
|
||||
EntityManager::persist($api);
|
||||
|
||||
EntityManager::flush();
|
||||
|
||||
}
|
||||
}
|
|
@ -89,5 +89,16 @@ return [
|
|||
'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'
|
||||
'SummitTrackTagGroupService.deleteTrackTagGroup.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id',
|
||||
// track question templates
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.deleteTrackQuestionTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.addTrackQuestionValueTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionValueTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionValueTemplate.TrackQuestionTemplateValueNotFound' => 'track question template value :track_question_value_template_id not found',
|
||||
'TrackQuestionTemplateService.deleteTrackQuestionValueTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.deleteTrackQuestionValueTemplate.TrackQuestionTemplateValueNotFound' => 'track question template value :track_question_value_template_id not found',
|
||||
'TrackQuestionTemplateService.addTrackQuestionTemplate.TrackNotFound' => 'track :track_id not found',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackNotFound' => 'track :track_id not found',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.DefaultValueNotFound' => 'default value :default_value not found'
|
||||
];
|
|
@ -90,4 +90,13 @@ return [
|
|||
'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',
|
||||
// track question templates
|
||||
'TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateLabelAlreadyExist' => 'track question template label already exists',
|
||||
'TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateNameAlreadyExist' => 'track question template name already exists',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateLabelAlreadyExist' => 'track question template label already exists',
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNameAlreadyExist' => 'track question template name already exists',
|
||||
'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'
|
||||
];
|
|
@ -137,7 +137,7 @@ final class OAuth2SelectionPlansApiTest extends ProtectedApiTest
|
|||
|
||||
$params = [
|
||||
'status' => $status,
|
||||
'expand' => 'summit,track_groups'
|
||||
'expand' => 'track_groups,summit'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
|
|
@ -460,10 +460,10 @@ final class OAuth2SummitLocationsApiTest extends ProtectedApiTest
|
|||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'address1' => 'Nazar 612',
|
||||
'address_1' => 'Nazar 612',
|
||||
'city' => 'Lanus',
|
||||
'state' => 'Buenos Aires',
|
||||
'country' => 'Argentina',
|
||||
'country' => 'AR',
|
||||
'class_name' => \models\summit\SummitVenue::ClassName,
|
||||
'description' => 'test location',
|
||||
];
|
||||
|
|
|
@ -0,0 +1,331 @@
|
|||
<?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.
|
||||
**/
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackRadioButtonListQuestionTemplate;
|
||||
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackDropDownQuestionTemplate;
|
||||
/**
|
||||
* Class OAuth2TrackQuestionsTemplateTest
|
||||
*/
|
||||
final class OAuth2TrackQuestionsTemplateTest
|
||||
extends ProtectedApiTest
|
||||
{
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function testGetTrackQuestionTemplateByClassName()
|
||||
{
|
||||
|
||||
$params = [
|
||||
'expand' => 'tracks',
|
||||
'filter' => 'class_name==TrackTextBoxQuestionTemplate',
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplates",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$track_question_templates = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_question_templates));
|
||||
$this->assertResponseStatus(200);
|
||||
return $track_question_templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function testAddTrackQuestionTemplate(
|
||||
$class_name = TrackTextBoxQuestionTemplate::ClassName, $extra_data = []){
|
||||
$params = [
|
||||
'expand' => 'tracks'
|
||||
];
|
||||
|
||||
$name = str_random(16).'_track_question_template_name';
|
||||
$label = str_random(16).'_track_question_template_label';
|
||||
$initial_value = str_random(16).'_initial_value';
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'class_name' => $class_name,
|
||||
'initial_value' => $initial_value,
|
||||
'is_mandatory' => true,
|
||||
'is_read_only' => true,
|
||||
'tracks' => [1, 2 , 3]
|
||||
];
|
||||
|
||||
if(count($extra_data) > 0){
|
||||
$data = array_merge($data, $extra_data);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplate",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
|
||||
$track_question_template = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_question_template));
|
||||
$this->assertTrue($track_question_template->name == $name);
|
||||
$this->assertTrue($track_question_template->label == $label);
|
||||
|
||||
return $track_question_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function testUpdateTrackQuestionTemplate(){
|
||||
|
||||
$new_track_question_template = $this->testAddTrackQuestionTemplate();
|
||||
|
||||
$params = [
|
||||
'track_question_template_id' => $new_track_question_template->id,
|
||||
'expand' => 'tracks'
|
||||
];
|
||||
|
||||
$name = str_random(16).'_track_question_template_name_update';
|
||||
$label = str_random(16).'_track_question_template_label_update';
|
||||
$initial_value = str_random(16).'_initial_value_update';
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'label' => $label,
|
||||
'class_name' => \App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate::ClassName,
|
||||
'initial_value' => $initial_value,
|
||||
'is_mandatory' => false,
|
||||
'is_read_only' => false,
|
||||
'tracks' => [1, 3]
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplate",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
|
||||
$track_question_template = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_question_template));
|
||||
$this->assertTrue($track_question_template->name == $name);
|
||||
$this->assertTrue($track_question_template->label == $label);
|
||||
|
||||
return $track_question_template;
|
||||
}
|
||||
|
||||
|
||||
public function testDeleteTrackQuestionTemplate(){
|
||||
$new_track_question_template = $this->testAddTrackQuestionTemplate();
|
||||
|
||||
$params = [
|
||||
'track_question_template_id' => $new_track_question_template->id,
|
||||
];
|
||||
|
||||
$headers =
|
||||
[
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"DELETE",
|
||||
"OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplate",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
|
||||
public function testGetTrackQuestionTemplateMetadata(){
|
||||
$params = [
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"GET",
|
||||
"OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplateMetadata",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$metadata = json_decode($content);
|
||||
$this->assertTrue(!is_null($metadata));
|
||||
$this->assertResponseStatus(200);
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
public function testAddTrackQuestionTemplateValue(){
|
||||
|
||||
$new_track_question_template = $this->testAddTrackQuestionTemplate(
|
||||
TrackDropDownQuestionTemplate::ClassName,
|
||||
[
|
||||
'empty_string' => '-- select a value --'
|
||||
]
|
||||
);
|
||||
$params = [
|
||||
'expand' => 'tracks',
|
||||
'track_question_template_id' => $new_track_question_template->id
|
||||
];
|
||||
|
||||
$value = str_random(16).'_track_question_template_value_value';
|
||||
$label = str_random(16).'_track_question_template_value_label';
|
||||
$data = [
|
||||
'value' => $value,
|
||||
'label' => $label,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplateValue",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
|
||||
$track_question_template_value = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_question_template_value));
|
||||
$this->assertTrue($track_question_template_value->value == $value);
|
||||
$this->assertTrue($track_question_template_value->label == $label);
|
||||
|
||||
return $track_question_template_value;
|
||||
}
|
||||
|
||||
public function testUpdateTrackQuestionTemplateValue(){
|
||||
|
||||
$new_track_question_template_value = $this->testAddTrackQuestionTemplateValue();
|
||||
$params = [
|
||||
'expand' => 'tracks',
|
||||
'track_question_template_id' => $new_track_question_template_value->owner_id,
|
||||
'track_question_template_value_id' => $new_track_question_template_value->id
|
||||
];
|
||||
|
||||
$value = str_random(16).'_track_question_template_value_value_update';
|
||||
$label = str_random(16).'_track_question_template_value_label_update';
|
||||
$data = [
|
||||
'value' => $value,
|
||||
'label' => $label,
|
||||
'order' => 1
|
||||
];
|
||||
|
||||
$headers = [
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action(
|
||||
"PUT",
|
||||
"OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplateValue",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(201);
|
||||
|
||||
$track_question_template_value = json_decode($content);
|
||||
$this->assertTrue(!is_null($track_question_template_value));
|
||||
$this->assertTrue($track_question_template_value->value == $value);
|
||||
$this->assertTrue($track_question_template_value->label == $label);
|
||||
|
||||
return $track_question_template_value;
|
||||
}
|
||||
|
||||
public function testDeleteTrackQuestionTemplateValue(){
|
||||
$new_track_question_template_value = $this->testAddTrackQuestionTemplateValue();
|
||||
|
||||
$params = [
|
||||
'track_question_template_id' => $new_track_question_template_value->owner_id,
|
||||
'track_question_template_value_id' => $new_track_question_template_value->id
|
||||
];
|
||||
|
||||
$headers =
|
||||
[
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"DELETE",
|
||||
"OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplateValue",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue