diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 94ec953d..a0f6cf64 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -51,6 +51,7 @@ class Kernel extends ConsoleKernel 7, //BCN 22, //Boston 23, //Sydney + 24, //Vancouver BC ]; foreach ($summit_ids as $summit_id) diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitLocationValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitLocationValidationRulesFactory.php index 4993b973..9beda48c 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitLocationValidationRulesFactory.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitLocationValidationRulesFactory.php @@ -53,10 +53,10 @@ final class SummitLocationValidationRulesFactory } break; case SummitExternalLocation::ClassName: { - return array_merge(SummitExternalLocationValidationRulesFactory::build($data, $update)); + return array_merge($base_rules, SummitExternalLocationValidationRulesFactory::build($data, $update)); } case SummitVenueRoom::ClassName: { - return array_merge(SummitVenueRoomValidationRulesFactory::build($data, $update)); + return array_merge($base_rules, SummitVenueRoomValidationRulesFactory::build($data, $update)); } break; default:{ diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPLiteralContentQuestionTemplateValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPLiteralContentQuestionTemplateValidationRulesFactory.php new file mode 100644 index 00000000..a8768a33 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPLiteralContentQuestionTemplateValidationRulesFactory.php @@ -0,0 +1,32 @@ + 'sometimes|string']; + } + return ['content' => 'required|string']; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPMultiValueQuestionTemplateValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPMultiValueQuestionTemplateValidationRulesFactory.php new file mode 100644 index 00000000..5a91f386 --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPMultiValueQuestionTemplateValidationRulesFactory.php @@ -0,0 +1,32 @@ + 'sometimes|string']; + } + return ['empty_string' => 'required|string']; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPTemplateQuestionValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPTemplateQuestionValidationRulesFactory.php new file mode 100644 index 00000000..1ca010fe --- /dev/null +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitRSVPTemplateQuestionValidationRulesFactory.php @@ -0,0 +1,119 @@ + sprintf('required|in:%s', implode(",", SummitRSVPTemplateQuestionConstants::$valid_class_names)) + ]; + + if($update){ + $base_rules = array_merge($base_rules, [ + 'name' => 'sometimes|alpha_dash|max:255', + 'label' => 'sometimes|string', + 'is_mandatory' => 'sometimes|boolean', + 'order' => 'sometimes|int|min:1', + 'is_read_only;' => 'sometimes|boolean', + ]); + } + 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', + ]); + } + + switch($data['class_name']){ + case RSVPMemberEmailQuestionTemplate::ClassName: { + return $base_rules; + } + break; + case RSVPMemberFirstNameQuestionTemplate::ClassName: { + return $base_rules; + } + break; + case RSVPMemberLastNameQuestionTemplate::ClassName: { + return $base_rules; + } + break; + case RSVPTextBoxQuestionTemplate::ClassName: { + return array_merge($base_rules, ['initial_value' => 'string|sometimes']); + } + break; + case RSVPTextAreaQuestionTemplate::ClassName: { + return array_merge($base_rules, ['initial_value' => 'string|sometimes']); + } + break; + case RSVPCheckBoxListQuestionTemplate::ClassName: { + return array_merge($base_rules, SummitRSVPMultiValueQuestionTemplateValidationRulesFactory::build($data, $update)); + } + break; + case RSVPRadioButtonListQuestionTemplate::ClassName: { + return array_merge($base_rules, SummitRSVPMultiValueQuestionTemplateValidationRulesFactory::build($data, $update)); + } + break; + case RSVPDropDownQuestionTemplate::ClassName: { + return array_merge + ( + $base_rules, + SummitRSVPMultiValueQuestionTemplateValidationRulesFactory::build($data, $update), + [ + 'is_multiselect' => 'sometimes|boolean', + 'is_country_selector' => 'sometimes|boolean', + 'use_chosen_plugin' => 'sometimes|boolean', + ] + ); + } + break; + case RSVPLiteralContentQuestionTemplate::ClassName: { + return array_merge($base_rules, SummitRSVPLiteralContentQuestionTemplateValidationRulesFactory::build($data, $update)); + } + break; + default:{ + throw new ValidationException(sprintf('invalid class_name param (%s)', implode(",", SummitRSVPTemplateQuestionConstants::$valid_class_names))); + } + break; + } + + return []; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php index d6da8e56..0e379c8d 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php @@ -11,13 +11,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ - -use App\Http\Utils\FilterAvailableSummitsStrategy; use Exception; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Validator; -use Illuminate\Support\Facades\Input; use models\exceptions\EntityNotFoundException; use models\exceptions\ValidationException; use models\oauth2\IResourceServerContext; @@ -29,7 +26,6 @@ use models\summit\ISummitRepository; use ModelSerializers\SerializerRegistry; use services\model\ISummitService; use utils\PagingResponse; - /** * Class OAuth2SummitApiController * @package App\Http\Controllers @@ -88,7 +84,7 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController $summits = []; - foreach($this->_getSummits() as $summit){ + foreach($this->repository->getAvailables() as $summit){ $summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize($expand, $fields, $relations); } @@ -110,11 +106,39 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController } /** - * @return \models\summit\Summit[] + * @return mixed */ - private function _getSummits(){ - return FilterAvailableSummitsStrategy::shouldReturnAllSummits($this->resource_server_context) ? - $this->repository->getAllOrderedByBeginDate():$this->repository->getAvailables(); + public function getAllSummits(){ + try { + + $expand = Request::input('expand', ''); + $fields = Request::input('fields', ''); + $relations = Request::input('relations', ''); + + $relations = !empty($relations) ? explode(',', $relations) : []; + $fields = !empty($fields) ? explode(',', $fields) : []; + + $summits = []; + + foreach($this->repository->getAllOrderedByBeginDate()as $summit){ + $summits[] = SerializerRegistry::getInstance()->getSerializer($summit)->serialize($expand, $fields, $relations); + } + + $response = new PagingResponse + ( + count($summits), + count($summits), + 1, + 1, + $summits + ); + + return $this->ok($response->toArray()); + } + catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } } /** diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php index bd79695b..267be4cb 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php @@ -232,4 +232,54 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro return $this->error500($ex); } } + + /** + * Questions endpoints + */ + + /** + * @param $summit_id + * @param $template_id + * @return mixed + */ + public function addRSVPTemplateQuestion($summit_id, $template_id){ + try { + + if(!Request::isJson()) return $this->error400(); + $payload = Input::json()->all(); + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $rules = SummitRSVPTemplateQuestionValidationRulesFactory::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->rsvp_template_service->addQuestion($summit, $template_id, $payload); + + return $this->created(SerializerRegistry::getInstance()->getSerializer($question)->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); + } + } } \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 0cdcbfb1..9377cdb3 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -161,15 +161,18 @@ Route::group([ Route::group(array('prefix' => 'summits'), function () { Route::get('', [ 'middleware' => 'cache:'.Config::get('cache_api_response.get_summits_response_lifetime', 600), 'uses' => 'OAuth2SummitApiController@getSummits']); - - Route::group(array('prefix' => '{id}'), function () { + Route::get('all', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitApiController@getAllSummits']); + Route::group(['prefix' => '{id}'], function () { // rsvp templates - Route::group(array('prefix' => 'rsvp-templates'), function () { + Route::group(['prefix' => 'rsvp-templates'], function () { Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@getAllBySummit']); - Route::group(array('prefix' => '{template_id}'), function () { + Route::group(['prefix' => '{template_id}'], function () { Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@getRSVPTemplate']); Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@deleteRSVPTemplate']); + Route::group(['prefix' => 'questions'], function () { + Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitRSVPTemplatesApiController@addRSVPTemplateQuestion']); + }); }); }); diff --git a/app/ModelSerializers/SerializerRegistry.php b/app/ModelSerializers/SerializerRegistry.php index 25e18d21..1aa4f6a9 100644 --- a/app/ModelSerializers/SerializerRegistry.php +++ b/app/ModelSerializers/SerializerRegistry.php @@ -36,6 +36,7 @@ use App\ModelSerializers\Marketplace\SpokenLanguageSerializer; use App\ModelSerializers\Marketplace\SupportChannelTypeSerializer; use App\ModelSerializers\Software\OpenStackComponentSerializer; use App\ModelSerializers\Software\OpenStackReleaseSerializer; +use App\ModelSerializers\Summit\RSVP\Templates\RSVPDropDownQuestionTemplateSerializer; use App\ModelSerializers\Summit\RSVP\Templates\RSVPMultiValueQuestionTemplateSerializer; use App\ModelSerializers\Summit\RSVP\Templates\RSVPQuestionValueTemplateSerializer; use App\ModelSerializers\Summit\RSVP\Templates\RSVPSingleValueTemplateQuestionSerializer; @@ -126,6 +127,7 @@ final class SerializerRegistry $this->registry['RSVPCheckBoxListQuestionTemplate'] = RSVPMultiValueQuestionTemplateSerializer::class; $this->registry['RSVPRadioButtonListQuestionTemplate'] = RSVPMultiValueQuestionTemplateSerializer::class; + $this->registry['RSVPDropDownQuestionTemplate'] = RSVPDropDownQuestionTemplateSerializer::class; $this->registry['SpeakerExpertise'] = SpeakerExpertiseSerializer::class; $this->registry['SpeakerLanguage'] = SpeakerLanguageSerializer::class; diff --git a/app/ModelSerializers/Summit/RSVP/Templates/RSVPDropDownQuestionTemplateSerializer.php b/app/ModelSerializers/Summit/RSVP/Templates/RSVPDropDownQuestionTemplateSerializer.php new file mode 100644 index 00000000..a11dc0bd --- /dev/null +++ b/app/ModelSerializers/Summit/RSVP/Templates/RSVPDropDownQuestionTemplateSerializer.php @@ -0,0 +1,62 @@ + 'is_country_selector:json_boolean', + 'UseChosenPlugin' => 'use_chosen_plugin:json_boolean', + 'Multiselect' => 'is_multiselect:json_boolean', + ]; + + /** + * @param null $expand + * @param array $fields + * @param array $relations + * @param array $params + * @return array + */ + public function serialize($expand = null, array $fields = [], array $relations = [], array $params = []) + { + $question = $this->object; + if(! $question instanceof RSVPDropDownQuestionTemplate) return []; + $values = parent::serialize($expand, $fields, $relations, $params); + + if($question->isCountrySelector()) { + $question_values = []; + $extra_options = [ + + 'Worldwide' => 'Worldwide', + 'Prefer not to say' => 'Prefer not to say', + 'Too many to list' => 'Too many to list', + ]; + + $options = array_merge($extra_options, CountryCodes::$iso_3166_countryCodes); + foreach($options as $k => $v) + { + $question_values[] = [ + 'id' => $k, + 'value' => $v + ]; + } + $values['values'] = $question_values; + } + return $values; + } +} \ No newline at end of file diff --git a/app/Models/Foundation/Main/CountryCodes.php b/app/Models/Foundation/Main/CountryCodes.php new file mode 100644 index 00000000..f51c1d2e --- /dev/null +++ b/app/Models/Foundation/Main/CountryCodes.php @@ -0,0 +1,274 @@ + "Afghanistan", + 'AX' => "Aland Islands", + 'AL' => "Albania", + 'DZ' => "Algeria", + 'AS' => "American Samoa", + 'AD' => "Andorra", + 'AO' => "Angola", + 'AI' => "Anguilla", + 'AQ' => "Antarctica", + 'AG' => "Antigua and Barbuda", + 'AR' => "Argentina", + 'AM' => "Armenia", + 'AW' => "Aruba", + 'AU' => "Australia", + 'AT' => "Austria", + 'AZ' => "Azerbaijan", + 'BS' => "Bahamas", + 'BH' => "Bahrain", + 'BD' => "Bangladesh", + 'BB' => "Barbados", + 'BY' => "Belarus", + 'BE' => "Belgium", + 'BZ' => "Belize", + 'BJ' => "Benin", + 'BM' => "Bermuda", + 'BT' => "Bhutan", + 'BO' => "Bolivia, Plurinational State of", + 'BQ' => "Bonaire, Sint Eustatius and Saba", + 'BA' => "Bosnia and Herzegovina", + 'BW' => "Botswana", + 'BV' => "Bouvet Island", + 'BR' => "Brazil", + 'IO' => "British Indian Ocean Territory", + 'BN' => "Brunei Darussalam", + 'BG' => "Bulgaria", + 'BF' => "Burkina Faso", + 'BI' => "Burundi", + 'KH' => "Cambodia", + 'CM' => "Cameroon", + 'CA' => "Canada", + 'CV' => "Cape Verde", + 'KY' => "Cayman Islands", + 'CF' => "Central African Republic", + 'TD' => "Chad", + 'CL' => "Chile", + 'CN' => "China", + 'CX' => "Christmas Island", + 'CC' => "Cocos (Keeling) Islands", + 'CO' => "Colombia", + 'KM' => "Comoros", + 'CG' => "Congo", + 'CD' => "Congo, the Democratic Republic of the", + 'CK' => "Cook Islands", + 'CR' => "Costa Rica", + 'CI' => "Côte d'Ivoire", + 'HR' => "Croatia", + 'CU' => "Cuba", + 'CW' => "Curaçao", + 'CY' => "Cyprus", + 'CZ' => "Czech Republic", + 'DK' => "Denmark", + 'DJ' => "Djibouti", + 'DM' => "Dominica", + 'DO' => "Dominican Republic", + 'EC' => "Ecuador", + 'EG' => "Egypt", + 'SV' => "El Salvador", + 'GQ' => "Equatorial Guinea", + 'ER' => "Eritrea", + 'EE' => "Estonia", + 'ET' => "Ethiopia", + 'FK' => "Falkland Islands (Malvinas)", + 'FO' => "Faroe Islands", + 'FJ' => "Fiji", + 'FI' => "Finland", + 'FR' => "France", + 'FX' => "France, Metropolitan", + 'GF' => "French Guiana", + 'PF' => "French Polynesia", + 'TF' => "French Southern Territories", + 'GA' => "Gabon", + 'GM' => "Gambia", + 'GE' => "Georgia", + 'DE' => "Germany", + 'GH' => "Ghana", + 'GI' => "Gibraltar", + 'GR' => "Greece", + 'GL' => "Greenland", + 'GD' => "Grenada", + 'GP' => "Guadeloupe", + 'GU' => "Guam", + 'GT' => "Guatemala", + 'GG' => "Guernsey", + 'GN' => "Guinea", + 'GW' => "Guinea-Bissau", + 'GY' => "Guyana", + 'HT' => "Haiti", + 'HM' => "Heard Island and McDonald Islands", + 'VA' => "Holy See (Vatican City State)", + 'HN' => "Honduras", + 'HK' => "Hong Kong", + 'HU' => "Hungary", + 'IS' => "Iceland", + 'IN' => "India", + 'ID' => "Indonesia", + 'IR' => "Iran, Islamic Republic of", + 'IQ' => "Iraq", + 'IE' => "Ireland", + 'IM' => "Isle of Man", + 'IL' => "Israel", + 'IT' => "Italy", + 'JM' => "Jamaica", + 'JP' => "Japan", + 'JE' => "Jersey", + 'JO' => "Jordan", + 'KZ' => "Kazakhstan", + 'KE' => "Kenya", + 'KI' => "Kiribati", + 'KP' => "Korea, Democratic People's Republic of", + 'KR' => "Korea, Republic of", + 'KW' => "Kuwait", + 'KG' => "Kyrgyzstan", + 'LA' => "Lao People's Democratic Republic", + 'LV' => "Latvia", + 'LB' => "Lebanon", + 'LS' => "Lesotho", + 'LR' => "Liberia", + 'LY' => "Libya", + 'LI' => "Liechtenstein", + 'LT' => "Lithuania", + 'LU' => "Luxembourg", + 'MO' => "Macao", + 'MK' => "Macedonia, the former Yugoslav Republic of", + 'MG' => "Madagascar", + 'MW' => "Malawi", + 'MY' => "Malaysia", + 'MV' => "Maldives", + 'ML' => "Mali", + 'MT' => "Malta", + 'MH' => "Marshall Islands", + 'MQ' => "Martinique", + 'MR' => "Mauritania", + 'MU' => "Mauritius", + 'YT' => "Mayotte", + 'MX' => "Mexico", + 'FM' => "Micronesia, Federated States of", + 'MD' => "Moldova, Republic of", + 'MC' => "Monaco", + 'MN' => "Mongolia", + 'ME' => "Montenegro", + 'MS' => "Montserrat", + 'MA' => "Morocco", + 'MZ' => "Mozambique", + 'MM' => "Myanmar", + 'NA' => "Namibia", + 'NR' => "Nauru", + 'NP' => "Nepal", + 'NL' => "Netherlands", + 'NC' => "New Caledonia", + 'NZ' => "New Zealand", + 'NI' => "Nicaragua", + 'NE' => "Niger", + 'NG' => "Nigeria", + 'NU' => "Niue", + 'NF' => "Norfolk Island", + 'MP' => "Northern Mariana Islands", + 'NO' => "Norway", + 'OM' => "Oman", + 'PK' => "Pakistan", + 'PW' => "Palau", + 'PS' => "Palestine", + 'PA' => "Panama", + 'PG' => "Papua New Guinea", + 'PY' => "Paraguay", + 'PE' => "Peru", + 'PH' => "Philippines", + 'PN' => "Pitcairn", + 'PL' => "Poland", + 'PT' => "Portugal", + 'PR' => "Puerto Rico", + 'QA' => "Qatar", + 'RE' => "Réunion", + 'RO' => "Romania", + 'RU' => "Russian Federation", + 'RW' => "Rwanda", + 'BL' => "Saint Barthélemy", + 'SH' => "Saint Helena, Ascension and Tristan da Cunha", + 'KN' => "Saint Kitts and Nevis", + 'LC' => "Saint Lucia", + 'MF' => "Saint Martin (French part)", + 'PM' => "Saint Pierre and Miquelon", + 'VC' => "Saint Vincent and the Grenadines", + 'WS' => "Samoa", + 'SM' => "San Marino", + 'ST' => "Sao Tome and Principe", + 'SA' => "Saudi Arabia", + 'SN' => "Senegal", + 'RS' => "Serbia", + 'SC' => "Seychelles", + 'SL' => "Sierra Leone", + 'SG' => "Singapore", + 'SX' => "Sint Maarten (Dutch part)", + 'SK' => "Slovakia", + 'SI' => "Slovenia", + 'SB' => "Solomon Islands", + 'SO' => "Somalia", + 'ZA' => "South Africa", + 'GS' => "South Georgia and the South Sandwich Islands", + 'SS' => "South Sudan", + 'ES' => "Spain", + 'LK' => "Sri Lanka", + 'SD' => "Sudan", + 'SR' => "Suriname", + 'SJ' => "Svalbard and Jan Mayen", + 'SZ' => "Swaziland", + 'SE' => "Sweden", + 'CH' => "Switzerland", + 'SY' => "Syrian Arab Republic", + 'TW' => "Taiwan", + 'TJ' => "Tajikistan", + 'TZ' => "Tanzania, United Republic of", + 'TH' => "Thailand", + 'TL' => "Timor-Leste", + 'TG' => "Togo", + 'TK' => "Tokelau", + 'TO' => "Tonga", + 'TT' => "Trinidad and Tobago", + 'TN' => "Tunisia", + 'TR' => "Turkey", + 'TM' => "Turkmenistan", + 'TC' => "Turks and Caicos Islands", + 'TV' => "Tuvalu", + 'UG' => "Uganda", + 'UA' => "Ukraine", + 'AE' => "United Arab Emirates", + 'GB' => "United Kingdom", + 'US' => "United States", + 'UM' => "United States Minor Outlying Islands", + 'UY' => "Uruguay", + 'UZ' => "Uzbekistan", + 'VU' => "Vanuatu", + 'VE' => "Venezuela, Bolivarian Republic of", + 'VN' => "Viet Nam", + 'VG' => "Virgin Islands, British", + 'VI' => "Virgin Islands, U.S.", + 'WF' => "Wallis and Futuna", + 'EH' => "Western Sahara", + 'YE' => "Yemen", + 'ZM' => "Zambia", + 'ZW' => "Zimbabwe" + ]; +} \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPCheckBoxListQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPCheckBoxListQuestionTemplate.php index 1db9330f..2da571af 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPCheckBoxListQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPCheckBoxListQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPCheckBoxListQuestionTemplate extends RSVPMultiValueQuestionTemplate { + const ClassName = 'RSVPCheckBoxListQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPCheckBoxListQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPDropDownQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPDropDownQuestionTemplate.php new file mode 100644 index 00000000..f527c1fd --- /dev/null +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPDropDownQuestionTemplate.php @@ -0,0 +1,105 @@ +is_multiselect; + } + + /** + * @param bool $is_multiselect + */ + public function setIsMultiselect($is_multiselect) + { + $this->is_multiselect = $is_multiselect; + } + + /** + * @return bool + */ + public function isCountrySelector() + { + return $this->is_country_selector; + } + + /** + * @param bool $is_country_selector + */ + public function setIsCountrySelector($is_country_selector) + { + $this->is_country_selector = $is_country_selector; + } + + /** + * @return bool + */ + public function getUseChosenPlugin() + { + return $this->use_chosen_plugin; + } + + /** + * @param bool $use_chosen_plugin + */ + public function setUseChosenPlugin($use_chosen_plugin) + { + $this->use_chosen_plugin = $use_chosen_plugin; + } + + public function __construct() + { + parent::__construct(); + $this->use_chosen_plugin = false; + $this->is_multiselect = false; + $this->is_country_selector = false; + } +} \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPLiteralContentQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPLiteralContentQuestionTemplate.php index f9aba6cc..c0d56af2 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPLiteralContentQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPLiteralContentQuestionTemplate.php @@ -20,6 +20,7 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPLiteralContentQuestionTemplate extends RSVPQuestionTemplate { + const ClassName = 'RSVPLiteralContentQuestionTemplate'; /** * @ORM\Column(name="Content", type="string") * @var string @@ -30,7 +31,7 @@ class RSVPLiteralContentQuestionTemplate extends RSVPQuestionTemplate * @return string */ public function getClassName(){ - return 'RSVPLiteralContentQuestionTemplate'; + return self::ClassName; } /** diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberEmailQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberEmailQuestionTemplate.php index 884842d4..ded09c19 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberEmailQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberEmailQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPMemberEmailQuestionTemplate extends RSVPTextBoxQuestionTemplate { + const ClassName = 'RSVPMemberEmailQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPMemberEmailQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberFirstNameQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberFirstNameQuestionTemplate.php index 8f719373..00ec1fbe 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberFirstNameQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberFirstNameQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPMemberFirstNameQuestionTemplate extends RSVPTextBoxQuestionTemplate { + const ClassName = 'RSVPMemberFirstNameQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPMemberFirstNameQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberLastNameQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberLastNameQuestionTemplate.php index ed871ab1..a13e491e 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberLastNameQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPMemberLastNameQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPMemberLastNameQuestionTemplate extends RSVPTextBoxQuestionTemplate { + const ClassName = 'RSVPMemberLastNameQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPMemberLastNameQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPQuestionTemplate.php index 7c7de07d..bf1ea746 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPQuestionTemplate.php @@ -29,7 +29,8 @@ use models\utils\SilverstripeBaseModel; * "RSVPMemberFirstNameQuestionTemplate" = "RSVPMemberFirstNameQuestionTemplate", * "RSVPMemberLastNameQuestionTemplate" = "RSVPMemberLastNameQuestionTemplate", * "RSVPCheckBoxListQuestionTemplate" = "RSVPCheckBoxListQuestionTemplate", - * "RSVPRadioButtonListQuestionTemplate" = "RSVPRadioButtonListQuestionTemplate" + * "RSVPRadioButtonListQuestionTemplate" = "RSVPRadioButtonListQuestionTemplate", + * "RSVPDropDownQuestionTemplate" = "RSVPDropDownQuestionTemplate" * }) * Class RSVPQuestionTemplate * @package App\Models\Foundation\Summit\Events\RSVP @@ -183,4 +184,16 @@ class RSVPQuestionTemplate extends SilverstripeBaseModel return 'RSVPQuestionTemplate'; } + public function clearTemplate(){ + $this->template = null; + } + + public function __construct() + { + parent::__construct(); + $this->is_mandatory = false; + $this->is_read_only = false; + $this->order = 0; + } + } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPRadioButtonListQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPRadioButtonListQuestionTemplate.php index d2bdc048..3bc68428 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPRadioButtonListQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPRadioButtonListQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPRadioButtonListQuestionTemplate extends RSVPMultiValueQuestionTemplate { + const ClassName = 'RSVPRadioButtonListQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPRadioButtonListQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTemplate.php index fb802813..90f605d9 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTemplate.php @@ -143,4 +143,48 @@ class RSVPTemplate extends SilverstripeBaseModel $this->questions = $questions; } + /** + * @param string $name + * @return RSVPQuestionTemplate + */ + public function getQuestionByName($name){ + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('name', trim($name))); + $res = $this->questions->matching($criteria)->first(); + return $res ? $res : null; + } + + /** + * @param int $id + * @return RSVPQuestionTemplate + */ + public function getQuestionById($id){ + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('id', intval($id))); + $res = $this->questions->matching($criteria)->first(); + return $res ? $res : null; + } + + /** + * @param RSVPQuestionTemplate $question + * @return $this + */ + public function addQuestion(RSVPQuestionTemplate $question){ + $questions = $this->getQuestions(); + $this->questions->add($question); + $question->setTemplate($this); + $question->setOrder(count($questions) + 1); + return $this; + } + + /** + * @param RSVPQuestionTemplate $question + * @return $this + */ + public function removeQuestion(RSVPQuestionTemplate $question){ + $this->questions->removeElement($question); + $question->clearTemplate(); + return $this; + } + } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextAreaQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextAreaQuestionTemplate.php index a28f33bf..56b61df5 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextAreaQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextAreaQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPTextAreaQuestionTemplate extends RSVPSingleValueTemplateQuestion { + const ClassName = 'RSVPTextAreaQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPTextAreaQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextBoxQuestionTemplate.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextBoxQuestionTemplate.php index a3d7da47..d1c384b9 100644 --- a/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextBoxQuestionTemplate.php +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/RSVPTextBoxQuestionTemplate.php @@ -20,10 +20,11 @@ use Doctrine\ORM\Mapping AS ORM; */ class RSVPTextBoxQuestionTemplate extends RSVPSingleValueTemplateQuestion { + const ClassName = 'RSVPTextBoxQuestionTemplate'; /** * @return string */ public function getClassName(){ - return 'RSVPTextBoxQuestionTemplate'; + return self::ClassName; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Events/RSVP/Templates/SummitRSVPTemplateQuestionConstants.php b/app/Models/Foundation/Summit/Events/RSVP/Templates/SummitRSVPTemplateQuestionConstants.php new file mode 100644 index 00000000..d4a092a7 --- /dev/null +++ b/app/Models/Foundation/Summit/Events/RSVP/Templates/SummitRSVPTemplateQuestionConstants.php @@ -0,0 +1,40 @@ +setInitialValue(trim($data['initial_value'])); + + $question = self::populateRSVPQuestionTemplate($question, $data); + + return $question; + } + + /** + * @param RSVPQuestionTemplate $question + * @param array $data + * @return RSVPQuestionTemplate + */ + private static function populateRSVPQuestionTemplate(RSVPQuestionTemplate $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 RSVPMultiValueQuestionTemplate $question + * @param array $data + * @return RSVPMultiValueQuestionTemplate + */ + private static function populateRSVPMultiValueQuestionTemplate(RSVPMultiValueQuestionTemplate $question, array $data){ + + if(isset($data['empty_string'])) + $question->setEmptyString(trim($data['empty_string'])); + + return $question; + } + + /** + * @param RSVPDropDownQuestionTemplate $question + * @param array $data + * @return RSVPDropDownQuestionTemplate + */ + private static function populateRSVPDropDownQuestionTemplate(RSVPDropDownQuestionTemplate $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'])); + + if(isset($data['use_chosen_plugin'])) + $question->setUseChosenPlugin(boolval($data['use_chosen_plugin'])); + + return $question; + } + + /** + * @param RSVPLiteralContentQuestionTemplate $question + * @param array $data + * @return RSVPLiteralContentQuestionTemplate + */ + private static function populateRSVPLiteralContentQuestionTemplate(RSVPLiteralContentQuestionTemplate $question, array $data){ + if(isset($data['content'])) + $question->setContent(trim($data['content'])); + return $question; + } + + /** + * @param RSVPQuestionTemplate $question + * @param array $data + * @return RSVPQuestionTemplate + */ + public static function populate(RSVPQuestionTemplate $question, array $data){ + + if($question instanceof RSVPMemberEmailQuestionTemplate){ + return self::populateRSVPSingleValueTemplateQuestion($question, $data); + } + + if($question instanceof RSVPMemberFirstNameQuestionTemplate){ + return self::populateRSVPSingleValueTemplateQuestion($question, $data); + } + + if($question instanceof RSVPMemberLastNameQuestionTemplate){ + return self::populateRSVPSingleValueTemplateQuestion($question, $data); + } + + if($question instanceof RSVPTextBoxQuestionTemplate){ + return self::populateRSVPSingleValueTemplateQuestion($question, $data); + } + + if($question instanceof RSVPTextAreaQuestionTemplate){ + return self::populateRSVPSingleValueTemplateQuestion($question, $data); + } + + if($question instanceof RSVPCheckBoxListQuestionTemplate){ + return self::populateRSVPMultiValueQuestionTemplate($question, $data); + } + + if($question instanceof RSVPRadioButtonListQuestionTemplate){ + return self::populateRSVPMultiValueQuestionTemplate($question, $data); + } + + if($question instanceof RSVPDropDownQuestionTemplate){ + return self::populateRSVPDropDownQuestionTemplate($question, $data); + } + + if($question instanceof RSVPLiteralContentQuestionTemplate){ + return self::populateRSVPLiteralContentQuestionTemplate($question, $data); + } + + return $question; + } +} \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Summit.php b/app/Models/Foundation/Summit/Summit.php index fdf7335c..1ce20e56 100644 --- a/app/Models/Foundation/Summit/Summit.php +++ b/app/Models/Foundation/Summit/Summit.php @@ -148,34 +148,34 @@ class Summit extends SilverstripeBaseModel private $time_zone_id; /** - * @ORM\OneToMany(targetEntity="SummitAbstractLocation", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="SummitAbstractLocation", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") */ private $locations; /** - * @ORM\OneToMany(targetEntity="SummitEvent", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="SummitEvent", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") */ private $events; /** - * @ORM\OneToMany(targetEntity="App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") */ private $rsvp_templates; /** - * @ORM\OneToMany(targetEntity="SummitWIFIConnection", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="SummitWIFIConnection", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") * @var SummitWIFIConnection[] */ private $wifi_connections; /** - * @ORM\OneToMany(targetEntity="SummitRegistrationPromoCode", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="SummitRegistrationPromoCode", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") * @var SummitRegistrationPromoCode[] */ private $promo_codes; /** - * @ORM\OneToMany(targetEntity="PresentationSpeakerSummitAssistanceConfirmationRequest", mappedBy="summit") + * @ORM\OneToMany(targetEntity="PresentationSpeakerSummitAssistanceConfirmationRequest", mappedBy="summit", fetch="EXTRA_LAZY") * @var PresentationSpeakerSummitAssistanceConfirmationRequest[] */ private $speaker_assistances; @@ -188,30 +188,30 @@ class Summit extends SilverstripeBaseModel private $logo; /** - * @ORM\OneToMany(targetEntity="models\summit\SummitEventType", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="models\summit\SummitEventType", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") */ private $event_types; /** - * @ORM\OneToMany(targetEntity="models\summit\PresentationCategory", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="models\summit\PresentationCategory", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") * @var PresentationCategory[] */ private $presentation_categories; /** - * @ORM\OneToMany(targetEntity="models\summit\SummitAttendee", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="models\summit\SummitAttendee", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") * @var SummitAttendee[] */ private $attendees; /** - * @ORM\OneToMany(targetEntity="models\summit\PresentationCategoryGroup", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="models\summit\PresentationCategoryGroup", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") * @var PresentationCategoryGroup[] */ private $category_groups; /** - * @ORM\OneToMany(targetEntity="models\summit\SummitTicketType", mappedBy="summit", cascade={"persist"}, orphanRemoval=true) + * @ORM\OneToMany(targetEntity="models\summit\SummitTicketType", mappedBy="summit", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY") */ private $ticket_types; diff --git a/app/Security/SummitScopes.php b/app/Security/SummitScopes.php index fc7263d0..e57cc8e6 100644 --- a/app/Security/SummitScopes.php +++ b/app/Security/SummitScopes.php @@ -41,6 +41,8 @@ final class SummitScopes const WriteLocationsData = '%s/locations/write'; + const WriteRSVPTemplateData = '%s/rsvp-templates/write'; + const WriteLocationBannersData = '%s/locations/banners/write'; const WriteSummitSpeakerAssistanceData = '%s/summit-speaker-assistance/write'; diff --git a/app/Services/Model/IRSVPTemplateService.php b/app/Services/Model/IRSVPTemplateService.php index eb9d5628..8bde02ba 100644 --- a/app/Services/Model/IRSVPTemplateService.php +++ b/app/Services/Model/IRSVPTemplateService.php @@ -11,6 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +use App\Models\Foundation\Summit\Events\RSVP\RSVPQuestionTemplate; use models\exceptions\EntityNotFoundException; use models\exceptions\ValidationException; use models\summit\Summit; @@ -28,4 +29,14 @@ interface IRSVPTemplateService * @throws ValidationException */ public function deleteTemplate(Summit $summit, $template_id); + + /** + * @param Summit $summit + * @param $template_id + * @param array $payload + * @return RSVPQuestionTemplate + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addQuestion(Summit $summit, $template_id, array $payload); } \ No newline at end of file diff --git a/app/Services/Model/RSVPTemplateService.php b/app/Services/Model/RSVPTemplateService.php index 72960213..1ea986bf 100644 --- a/app/Services/Model/RSVPTemplateService.php +++ b/app/Services/Model/RSVPTemplateService.php @@ -11,6 +11,8 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +use App\Models\Foundation\Summit\Events\RSVP\RSVPQuestionTemplate; +use App\Models\Foundation\Summit\Factories\SummitRSVPTemplateQuestionFactory; use App\Models\Foundation\Summit\Repositories\IRSVPTemplateRepository; use libs\utils\ITransactionService; use models\exceptions\EntityNotFoundException; @@ -65,4 +67,54 @@ final class RSVPTemplateService implements IRSVPTemplateService $summit->removeRSVPTemplate($template); }); } + + /** + * @param Summit $summit + * @param $template_id + * @param array $data + * @return RSVPQuestionTemplate + * @throws EntityNotFoundException + * @throws ValidationException + */ + public function addQuestion(Summit $summit, $template_id, array $data) + { + return $this->tx_service->transaction(function() use($summit, $template_id, $data){ + + $template = $summit->getRSVPTemplateById($template_id); + + if(is_null($template)) + throw new EntityNotFoundException + ( + trans + ( + '', + [ + 'summit_id' => $summit->getId(), + 'template_id' => $template_id, + ] + ) + ); + + $former_question = $template->getQuestionByName($data['name']); + if(!is_null($former_question)){ + throw new ValidationException + ( + trans + ( + '', + [ + 'template_id' => $template_id, + 'name' => $data['name'] + ] + ) + ); + } + + $question = SummitRSVPTemplateQuestionFactory::build($data); + + $template->addQuestion($question); + + return $question; + }); + } } \ No newline at end of file diff --git a/app/Services/Model/LocationService.php b/app/Services/Model/SummitLocationService.php similarity index 99% rename from app/Services/Model/LocationService.php rename to app/Services/Model/SummitLocationService.php index 328d0ee8..eb0398b4 100644 --- a/app/Services/Model/LocationService.php +++ b/app/Services/Model/SummitLocationService.php @@ -48,10 +48,10 @@ use models\summit\SummitVenue; use models\summit\SummitVenueFloor; use models\summit\SummitVenueRoom; /** - * Class LocationService + * Class SummitLocationService * @package App\Services\Model */ -final class LocationService implements ILocationService +final class SummitLocationService implements ILocationService { /** * @var ISummitLocationRepository diff --git a/app/Services/ServicesProvider.php b/app/Services/ServicesProvider.php index 745eeb39..ddeabd48 100644 --- a/app/Services/ServicesProvider.php +++ b/app/Services/ServicesProvider.php @@ -22,7 +22,7 @@ use App\Services\Model\IMemberService; use App\Services\Model\IRSVPTemplateService; use App\Services\Model\ISummitEventTypeService; use App\Services\Model\ISummitTrackService; -use App\Services\Model\LocationService; +use App\Services\Model\SummitLocationService; use App\Services\Model\MemberService; use App\Services\Model\RSVPTemplateService; use App\Services\Model\SummitPromoCodeService; @@ -174,7 +174,7 @@ final class ServicesProvider extends ServiceProvider App::singleton ( ILocationService::class, - LocationService::class + SummitLocationService::class ); App::singleton diff --git a/database/seeds/ApiEndpointsSeeder.php b/database/seeds/ApiEndpointsSeeder.php index 577053f3..99b60295 100644 --- a/database/seeds/ApiEndpointsSeeder.php +++ b/database/seeds/ApiEndpointsSeeder.php @@ -73,16 +73,23 @@ class ApiEndpointsSeeder extends Seeder $this->seedApiEndpoints('summits', [ // summits - array( + [ 'name' => 'get-summits', 'route' => '/api/v1/summits', 'http_method' => 'GET', 'scopes' => [ sprintf(SummitScopes::ReadSummitData, $current_realm), + ], + ], + [ + 'name' => 'get-summits-all', + 'route' => '/api/v1/summits/all', + 'http_method' => 'GET', + 'scopes' => [ sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), - array( + ], + [ 'name' => 'get-summit', 'route' => '/api/v1/summits/{id}', 'http_method' => 'GET', @@ -90,8 +97,8 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), - array( + ], + [ 'name' => 'get-summit-entity-events', 'route' => '/api/v1/summits/{id}/entity-events', 'http_method' => 'GET', @@ -99,9 +106,9 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), + ], // attendees - array( + [ 'name' => 'get-attendees', 'route' => '/api/v1/summits/{id}/attendees', 'http_method' => 'GET', @@ -109,8 +116,8 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), - array( + ], + [ 'name' => 'get-own-attendee', 'route' => '/api/v1/summits/{id}/attendees/me', 'http_method' => 'GET', @@ -118,8 +125,8 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), - array( + ], + [ 'name' => 'get-attendee', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}', 'http_method' => 'GET', @@ -127,23 +134,23 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadSummitData, $current_realm), sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], - ), - array( + ], + [ 'name' => 'delete-attendee', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}', 'http_method' => 'DELETE', 'scopes' => [ sprintf(SummitScopes::WriteAttendeesData, $current_realm), ], - ), - array( + ], + [ 'name' => 'update-attendee', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}', 'http_method' => 'PUT', 'scopes' => [ sprintf(SummitScopes::WriteAttendeesData, $current_realm), ], - ), + ], array( 'name' => 'get-attendee-schedule', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule', @@ -705,13 +712,103 @@ class ApiEndpointsSeeder extends Seeder sprintf(SummitScopes::ReadAllSummitData, $current_realm) ], ], + [ + 'name' => 'add-rsvp-template', + 'route' => '/api/v1/summits/{id}/rsvp-templates', + 'http_method' => 'POST', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + [ + 'name' => 'update-rsvp-template', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], [ 'name' => 'delete-rsvp-template', 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}', 'http_method' => 'DELETE', 'scopes' => [ sprintf(SummitScopes::WriteSummitData, $current_realm), - sprintf(SummitScopes::WriteLocationsData, $current_realm) + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + // rsvp template questions + [ + 'name' => 'get-rsvp-template-question', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'add-rsvp-template-question', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions', + 'http_method' => 'POST', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + [ + 'name' => 'update-rsvp-template-question', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + [ + 'name' => 'delete-rsvp-template-question', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + // multi value questions + [ + 'name' => 'add-rsvp-template-question-value', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}/values', + 'http_method' => 'POST', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + [ + 'name' => 'get-rsvp-template-question-value', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}/values/{value_id}', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadAllSummitData, $current_realm) + ], + ], + [ + 'name' => 'update-rsvp-template-question-value', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}/values/{value_id}', + 'http_method' => 'PUT', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) + ], + ], + [ + 'name' => 'delete-rsvp-template-question-value', + 'route' => '/api/v1/summits/{id}/rsvp-templates/{template_id}/questions/{question_id}/values/{value_id}', + 'http_method' => 'DELETE', + 'scopes' => [ + sprintf(SummitScopes::WriteSummitData, $current_realm), + sprintf(SummitScopes::WriteRSVPTemplateData, $current_realm) ], ], // rooms diff --git a/tests/OAuth2SummitApiTest.php b/tests/OAuth2SummitApiTest.php index 1463eb49..c2181199 100644 --- a/tests/OAuth2SummitApiTest.php +++ b/tests/OAuth2SummitApiTest.php @@ -45,6 +45,35 @@ final class OAuth2SummitApiTest extends ProtectedApiTest $this->assertResponseStatus(200); } + public function testGetAllSummits() + { + + $start = time(); + $params = [ + 'relations'=>'none', + 'expand' => 'none', + ]; + + $headers = ["HTTP_Authorization" => " Bearer " . $this->access_token]; + $response = $this->action( + "GET", + "OAuth2SummitApiController@getAllSummits", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $summits = json_decode($content); + $end = time(); + $delta = $end - $start; + echo "execution call " . $delta . " seconds ..."; + $this->assertTrue(!is_null($summits)); + $this->assertResponseStatus(200); + } + public function testGetSummit($summit_id = 22) { diff --git a/tests/OAuth2SummitRSVPTemplateApiTest.php b/tests/OAuth2SummitRSVPTemplateApiTest.php index 68dd00da..3533a45b 100644 --- a/tests/OAuth2SummitRSVPTemplateApiTest.php +++ b/tests/OAuth2SummitRSVPTemplateApiTest.php @@ -113,4 +113,92 @@ final class OAuth2SummitRSVPTemplateApiTest extends ProtectedApiTest $this->assertResponseStatus(204); } + + public function testAddRSVPTemplateQuestionRSVPTextBoxQuestionTemplate($summit_id = 24){ + + $templates_response = $this->testGetSummitRSVPTemplates($summit_id); + $templates = $templates_response->data; + + $params = [ + 'id' => $summit_id, + 'template_id' => $templates[0]->id + ]; + + $name = str_random(16).'_rsvp_question'; + $data = [ + 'name' => $name, + 'label' => 'test label', + 'initial_value' => 'test initial value', + 'is_mandatory' => true, + 'class_name' => \App\Models\Foundation\Summit\Events\RSVP\RSVPTextBoxQuestionTemplate::ClassName, + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitRSVPTemplatesApiController@addRSVPTemplateQuestion", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + + $question = json_decode($content); + $this->assertTrue(!is_null($question)); + $this->assertTrue($question->initial_value == 'test initial value'); + return $question; + } + + public function testAddRSVPTemplateQuestionRSVPDropDownQuestionTemplate($summit_id = 24){ + + $templates_response = $this->testGetSummitRSVPTemplates($summit_id); + $templates = $templates_response->data; + + $params = [ + 'id' => $summit_id, + 'template_id' => $templates[0]->id + ]; + + $name = str_random(16).'_rsvp_question'; + $data = [ + 'name' => $name, + 'label' => 'test dropdown', + 'is_mandatory' => true, + 'is_country_selector' => true, + 'empty_string' => '--select a value', + 'class_name' => \App\Models\Foundation\Summit\Events\RSVP\RSVPDropDownQuestionTemplate::ClassName, + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitRSVPTemplatesApiController@addRSVPTemplateQuestion", + $params, + [], + [], + [], + $headers, + json_encode($data) + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + + $question = json_decode($content); + $this->assertTrue(!is_null($question)); + return $question; + } } \ No newline at end of file