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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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 CompanyServiceResourceSerializer
* @package App\ModelSerializers\Marketplace
*/
class CompanyServiceResourceSerializer extends SilverStripeSerializer
{
/**
* @var array
*/
protected static $array_mappings = [
'Name' => 'name:json_string',
'Uri' => 'uri:json_string',
'Order' => 'order:json_int',
];
}
41 changes: 40 additions & 1 deletion app/ModelSerializers/Marketplace/CompanyServiceSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class CompanyServiceSerializer extends SilverStripeSerializer

protected static $allowed_relations = [
'company',
'reviews',
'type',
'case_studies',
'videos',
'reviews',
'resources',
];

/**
Expand All @@ -54,6 +57,22 @@ public function serialize($expand = null, array $fields = [], array $relations =
if(!$company_service instanceof CompanyService) return [];
$values = parent::serialize($expand, $fields, $relations, $params);

if(in_array('case_studies', $relations) && !isset($values['case_studies'])) {
$case_studies = [];
foreach ($company_service->getCaseStudies() as $c) {
$case_studies[] = $c->getId();
}
$values['case_studies'] = $case_studies;
}

if(in_array('videos', $relations) && !isset($values['videos'])) {
$videos = [];
foreach ($company_service->getVideos() as $v) {
$videos[] = $v->getId();
}
$values['videos'] = $videos;
}

if(in_array('reviews', $relations) && !isset($values['reviews'])) {
$reviews = [];
foreach ($company_service->getApprovedReviews() as $r) {
Expand All @@ -62,14 +81,34 @@ public function serialize($expand = null, array $fields = [], array $relations =
$values['reviews'] = $reviews;
}

if(in_array('resources', $relations) && !isset($values['resources'])) {
$resources = [];
foreach ($company_service->getResources() as $r) {
$resources[] = $r->getId();
}
$values['resources'] = $resources;
}

return $values;
}

protected static $expand_mappings = [
'case_studies' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getCaseStudies',
],
'reviews' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getApprovedReviews',
],
'resources' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getResources',
],
'videos' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getVideos',
],
'company' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'company_id',
Expand Down
32 changes: 32 additions & 0 deletions app/ModelSerializers/Marketplace/CustomerCaseStudySerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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 CustomerCaseStudySerializer
* @package App\ModelSerializers\Marketplace
*/
class CustomerCaseStudySerializer extends SilverStripeSerializer
{
/**
* @var array
*/
protected static $array_mappings = [
'Name' => 'name:json_string',
'Uri' => 'uri:json_string',
'Order' => 'order:json_int',
];
}
45 changes: 24 additions & 21 deletions app/ModelSerializers/Marketplace/RegionalSupportSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
**/
use App\Models\Foundation\Marketplace\RegionalSupport;
use Libs\ModelSerializers\Many2OneExpandSerializer;
use Libs\ModelSerializers\One2ManyExpandSerializer;
use ModelSerializers\SerializerRegistry;
use ModelSerializers\SilverStripeSerializer;

Expand All @@ -23,8 +25,12 @@
*/
class RegionalSupportSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'RegionId' => 'region_id:json_int',
];

protected static $allowed_relations = [
'region',
'supported_channel_types',
];

Expand All @@ -37,34 +43,31 @@ class RegionalSupportSerializer extends SilverStripeSerializer
*/
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
{

$regional_support = $this->object;
if(!$regional_support instanceof RegionalSupport) return [];
$values = parent::serialize($expand, $fields, $relations, $params);

if(in_array('supported_channel_types', $relations)){
$res = [];
foreach ($regional_support->getSupportedChannelTypes() as $channel_type){
$res[] = SerializerRegistry::getInstance()
->getSerializer($channel_type)
->serialize();
if(in_array('supported_channel_types', $relations) && !isset($values['supported_channel_types'])) {
$supported_channel_types = [];
foreach ($regional_support->getSupportedChannelTypes() as $c) {
$supported_channel_types[] = $c->getId();
}
$values['supported_channel_types'] = $res;
$values['supported_channel_types'] = $supported_channel_types;
}

if (!empty($expand)) {
$exp_expand = explode(',', $expand);
foreach ($exp_expand as $relation) {
switch (trim($relation)) {
case 'region':
unset($values['region_id']);
$values['region'] = SerializerRegistry::getInstance()
->getSerializer($regional_support->getRegion())
->serialize();
break;
}
}
}
return $values;
}

protected static $expand_mappings = [
'supported_channel_types' => [
'type' => Many2OneExpandSerializer::class,
'getter' => 'getSupportedChannelTypes',
],
'region' => [
'type' => One2ManyExpandSerializer::class,
'original_attribute' => 'region_id',
'getter' => 'getRegion',
'has' => 'hasRegion'
],
];
}
6 changes: 6 additions & 0 deletions app/ModelSerializers/SerializerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
use App\ModelSerializers\Locations\SummitRoomReservationSerializer;
use App\ModelSerializers\Marketplace\ApplianceSerializer;
use App\ModelSerializers\Marketplace\CloudServiceOfferedSerializer;
use App\ModelSerializers\Marketplace\CompanyServiceResourceSerializer;
use App\ModelSerializers\Marketplace\CompanyServiceSerializer;
use App\ModelSerializers\Marketplace\ConfigurationManagementTypeSerializer;
use App\ModelSerializers\Marketplace\ConsultantClientSerializer;
use App\ModelSerializers\Marketplace\ConsultantSerializer;
use App\ModelSerializers\Marketplace\ConsultantServiceOfferedTypeSerializer;
use App\ModelSerializers\Marketplace\CustomerCaseStudySerializer;
use App\ModelSerializers\Marketplace\DataCenterLocationSerializer;
use App\ModelSerializers\Marketplace\DataCenterRegionSerializer;
use App\ModelSerializers\Marketplace\DistributionSerializer;
Expand Down Expand Up @@ -636,8 +639,11 @@ private function __construct()
$this->registry['RegionalSupport'] = RegionalSupportSerializer::class;
$this->registry['SupportChannelType'] = SupportChannelTypeSerializer::class;
$this->registry['Office'] = OfficeSerializer::class;
$this->registry['CompanyService'] = CompanyServiceSerializer::class;
$this->registry['CompanyServiceResource'] = CompanyServiceResourceSerializer::class;
$this->registry['Consultant'] = ConsultantSerializer::class;
$this->registry['ConsultantClient'] = ConsultantClientSerializer::class;
$this->registry['CustomerCaseStudy'] = CustomerCaseStudySerializer::class;
$this->registry['SpokenLanguage'] = SpokenLanguageSerializer::class;
$this->registry['ConfigurationManagementType'] = ConfigurationManagementTypeSerializer::class;
$this->registry['ServiceOfferedType'] = ServiceOfferedTypeSerializer::class;
Expand Down
18 changes: 16 additions & 2 deletions app/Models/Foundation/Marketplace/CompanyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ class CompanyService extends SilverstripeBaseModel

/**
* @ORM\OneToMany(targetEntity="CompanyServiceResource", mappedBy="company_service", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "order"})
* @ORM\OrderBy({"order" = "ASC"})
* @var CompanyServiceResource[]
*/
protected $resources;


/**
* @ORM\OneToMany(targetEntity="CustomerCaseStudy", mappedBy="company_service", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"order" = "ASC"})
* @var CustomerCaseStudy[]
*/
protected $case_studies;

use One2ManyPropertyTrait;

Expand All @@ -128,6 +133,7 @@ public function __construct()
$this->reviews = new ArrayCollection();
$this->videos = new ArrayCollection();
$this->resources = new ArrayCollection();
$this->case_studies = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -226,4 +232,12 @@ public function getResources()
{
return $this->resources->toArray();
}

/**
* @return CustomerCaseStudy[]
*/
public function getCaseStudies()
{
return $this->case_studies->toArray();
}
}
108 changes: 108 additions & 0 deletions app/Models/Foundation/Marketplace/CustomerCaseStudy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php namespace App\Models\Foundation\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 models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(
* name="CustomerCaseStudy",
* uniqueConstraints={
* @ORM\UniqueConstraint(
* name="owner_name",
* columns={"Name", "OwnerID"}
* )
* }
* )
* Class CustomerCaseStudy
* @package App\Models\Foundation\Marketplace
*/
class CustomerCaseStudy extends SilverstripeBaseModel
{
const ClassName = 'CustomerCaseStudy';

/**
* @ORM\Column(name="Name", type="string", length=250)
* @var string
*/
private $name;

/**
* @ORM\Column(name="Uri", type="string", length=250, nullable=true)
* @var string
*/
private $uri;

/**
* @ORM\Column(name="`Order`", type="integer")
* @var int
*/
private $order;

/**
* @ORM\ManyToOne(targetEntity="CompanyService", inversedBy="case_studies", fetch="LAZY")
* @ORM\JoinColumn(name="OwnerID", referencedColumnName="ID", nullable=false, onDelete="CASCADE")
* @var CompanyService
*/
private $company_service;

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): self
{
$this->name = trim($name);
return $this;
}

public function getUri(): ?string
{
return $this->uri;
}

public function setUri(?string $uri): self
{
$this->uri = $uri !== null ? trim($uri) : null;
return $this;
}

public function getOrder(): int
{
return $this->order;
}

public function setOrder(int $order): self
{
$this->order = $order;
return $this;
}

/**
* @return CompanyService
*/
public function getOwner(): CompanyService
{
return $this->company_service;
}

public function setOwner(CompanyService $new_owner): self
{
$this->company_service = $new_owner;
return $this;
}
}
Loading