Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ routes.txt
/ss.sql
phpunit.xml
.phpunit.result.cache
.phpunit.cache/
.phpunit.cache/
.claude
33 changes: 33 additions & 0 deletions app/Http/Controllers/Apis/Marketplace/TrainingApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2026 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\Http\Controllers\AbstractCompanyServiceApiController;
use App\Models\Foundation\Marketplace\ITrainingRepository;
use models\oauth2\IResourceServerContext;

class TrainingApiController extends AbstractCompanyServiceApiController
{
/**
* TrainingApiController constructor.
* @param ITrainingRepository $repository
*/
public function __construct(ITrainingRepository $repository, IResourceServerContext $resource_server_context)
{
parent::__construct($repository, $resource_server_context);
}

public function getAll()
{
return parent::getAll();
}
}
26 changes: 26 additions & 0 deletions app/ModelSerializers/Marketplace/ProjectSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use ModelSerializers\SilverStripeSerializer;
/**
* Class ProjectSerializer
* @package App\ModelSerializers\Marketplace
*/
final class ProjectSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
'Description' => 'description:json_string',
'Codename' => 'codename:json_string',
];
}
25 changes: 25 additions & 0 deletions app/ModelSerializers/Marketplace/TrainingCourseLevelSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCourseLevelSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCourseLevelSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Level' => 'level:json_string',
'Order' => 'order:json_int',
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCoursePrerequisiteSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCoursePrerequisiteSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 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\Marketplace\TrainingCourseSchedule;
use Libs\ModelSerializers\Many2OneExpandSerializer;
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCourseScheduleSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCourseScheduleSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'City' => 'city:json_string',
'State' => 'state:json_string',
'Country' => 'country:json_string',
];

protected static $allowed_relations = [
'times',
];

/**
* @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 = [])
{
$schedule = $this->object;
if (!$schedule instanceof TrainingCourseSchedule) return [];
$values = parent::serialize($expand, $fields, $relations, $params);

if (in_array('times', $relations) && !isset($values['times'])) {
$times = [];
foreach ($schedule->getTimes() as $t) {
$times[] = $t->getId();
}
$values['times'] = $times;
}

return $values;
}

protected static $expand_mappings = [
'times' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getTimes',
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Libs\ModelSerializers\One2ManyExpandSerializer;
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCourseScheduleTimeSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCourseScheduleTimeSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'StartDate' => 'start_date:datetime_epoch',
'EndDate' => 'end_date:datetime_epoch',
'Link' => 'link:json_string',
'LocationId' => 'location_id:json_int',
];

protected static $allowed_relations = [
'location',
];

protected static $expand_mappings = [
'location' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'location_id',
'getter' => 'getLocation',
'has' => 'hasLocation',
],
];
}
116 changes: 116 additions & 0 deletions app/ModelSerializers/Marketplace/TrainingCourseSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 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\Marketplace\TrainingCourse;
use Libs\ModelSerializers\Many2OneExpandSerializer;
use Libs\ModelSerializers\One2ManyExpandSerializer;
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCourseSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCourseSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
'Link' => 'link:json_string',
'Description' => 'description:json_string',
'Paid' => 'is_paid:json_boolean',
'Online' => 'is_online:json_boolean',
'TypeId' => 'type_id:json_int',
'LevelId' => 'level_id:json_int',
'TrainingServiceId' => 'training_service_id:json_int',
];

protected static $allowed_relations = [
'type',
'level',
'training_service',
'schedules',
'projects',
'prerequisites',
];

/**
* @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 = [])
{
$course = $this->object;
if (!$course instanceof TrainingCourse) return [];
$values = parent::serialize($expand, $fields, $relations, $params);

if (in_array('schedules', $relations) && !isset($values['schedules'])) {
$schedules = [];
foreach ($course->getSchedules() as $s) {
$schedules[] = $s->getId();
}
$values['schedules'] = $schedules;
}

if (in_array('projects', $relations) && !isset($values['projects'])) {
$projects = [];
foreach ($course->getProjects() as $p) {
$projects[] = $p->getId();
}
$values['projects'] = $projects;
}

if (in_array('prerequisites', $relations) && !isset($values['prerequisites'])) {
$prerequisites = [];
foreach ($course->getPrerequisites() as $p) {
$prerequisites[] = $p->getId();
}
$values['prerequisites'] = $prerequisites;
}

return $values;
}

protected static $expand_mappings = [
'type' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'type_id',
'getter' => 'getType',
'has' => 'hasType',
],
'level' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'level_id',
'getter' => 'getLevel',
'has' => 'hasLevel',
],
'training_service' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'training_service_id',
'getter' => 'getTrainingService',
'has' => 'hasTrainingService',
],
'schedules' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getSchedules',
],
'projects' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getProjects',
],
'prerequisites' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getPrerequisites',
],
];
}
24 changes: 24 additions & 0 deletions app/ModelSerializers/Marketplace/TrainingCourseTypeSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace App\ModelSerializers\Marketplace;
/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use ModelSerializers\SilverStripeSerializer;
/**
* Class TrainingCourseTypeSerializer
* @package App\ModelSerializers\Marketplace
*/
final class TrainingCourseTypeSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Type' => 'type:json_string',
];
}
Loading