Skip to content

Commit fb8131c

Browse files
committed
fix: review changes
Signed-off-by: romanetar <[email protected]>
1 parent ed361cd commit fb8131c

File tree

7 files changed

+64
-9
lines changed

7 files changed

+64
-9
lines changed

app/Jobs/Emails/Registration/PromoCodes/SponsorPromoCodeEmail.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ public function __construct
5454
$summit = $promo_code->getSummit();
5555
$payload = [];
5656
$sponsor = $promo_code->getSponsor();
57-
$sponsorships = $sponsor->getSponsorships();
58-
$sponsor_tier_names = [];
59-
foreach ($sponsorships as $sponsorship) {
60-
$sponsor_tier_names[] = $sponsorship->getType()->getType()->getName();
61-
}
62-
$payload[IMailTemplatesConstants::sponsor_tier_name] = implode(',', $sponsor_tier_names);
57+
$payload[IMailTemplatesConstants::sponsor_tier_name] = implode(',', $sponsor->getSponsorshipTierNames());
6358
$payload[IMailTemplatesConstants::promo_code] = $promo_code->getCode();
6459
$payload[IMailTemplatesConstants::company_name] = '';
6560
$company = $sponsor->getCompany();

app/ModelSerializers/SerializerRegistry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
use App\ModelSerializers\Summit\SummitScheduleConfigSerializer;
116116
use App\ModelSerializers\Summit\SummitSchedulePreFilterElementConfigSerializer;
117117
use App\ModelSerializers\Summit\SummitSignSerializer;
118+
use App\ModelSerializers\Summit\SummitSponsorshipSerializer;
118119
use App\ModelSerializers\Summit\SummitSponsorshipTypeSerializer;
119120
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupAllowedTagSerializer;
120121
use App\ModelSerializers\Summit\TrackTagGroups\TrackTagGroupSerializer;
@@ -566,6 +567,7 @@ private function __construct()
566567
// summit sponsors
567568

568569
$this->registry['SponsorshipType'] = SponsorshipTypeSerializer::class;
570+
$this->registry['SummitSponsorship'] = SummitSponsorshipSerializer::class;
569571
$this->registry['SummitSponsorshipType'] = SummitSponsorshipTypeSerializer::class;
570572
$this->registry['Sponsor'] = SponsorSerializer::class;
571573
$this->registry['SponsorAd'] = SponsorAdSerializer::class;

app/ModelSerializers/Summit/SponsorSerializer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function serialize($expand = null, array $fields = [], array $relations =
8383
if (in_array('sponsorships', $relations)) {
8484
$sponsorships = [];
8585
foreach ($sponsor->getSponsorships() as $sponsorship) {
86-
$sponsorships[] = $sponsorship->getType()->getId();
86+
$sponsorships[] = $sponsorship->getId();
8787
}
8888
$values['sponsorships'] = $sponsorships;
8989
}
@@ -178,7 +178,7 @@ public function serialize($expand = null, array $fields = [], array $relations =
178178
unset($values['sponsorships']);
179179
$sponsorship_types = [];
180180
foreach ($sponsorships as $sponsorship) {
181-
$sponsorship_types[] = SerializerRegistry::getInstance()->getSerializer($sponsorship->getType())->serialize
181+
$sponsorship_types[] = SerializerRegistry::getInstance()->getSerializer($sponsorship)->serialize
182182
(
183183
AbstractSerializer::filterExpandByPrefix($expand, $relation),
184184
AbstractSerializer::filterFieldsByPrefix($fields, $relation),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php namespace App\ModelSerializers\Summit;
2+
use Libs\ModelSerializers\Many2OneExpandSerializer;
3+
use Libs\ModelSerializers\One2ManyExpandSerializer;
4+
use ModelSerializers\SilverStripeSerializer;
5+
6+
/**
7+
* Copyright 2025 OpenStack Foundation
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
**/
18+
19+
/**
20+
* Class SummitSponsorshipSerializer
21+
* @package ModelSerializers
22+
*/
23+
final class SummitSponsorshipSerializer extends SilverStripeSerializer
24+
{
25+
protected static $array_mappings = [
26+
'Id' => 'id:json_int',
27+
'SponsorID' => 'sponsor_id:json_int',
28+
'TypeID' => 'type_id:json_int'
29+
];
30+
31+
protected static $expand_mappings = [
32+
'add_ons' => [
33+
'type' => Many2OneExpandSerializer::class,
34+
'getter' => 'getAddOns',
35+
],
36+
'type' => [
37+
'type' => One2ManyExpandSerializer::class,
38+
'original_attribute' => 'type_id',
39+
'getter' => 'getType',
40+
'has' => 'hasType'
41+
],
42+
];
43+
}

app/Models/Foundation/Summit/Factories/SponsorFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public static function build(array $data):Sponsor{
3232
* @param Sponsor $sponsor
3333
* @param array $data
3434
* @return Sponsor
35-
* @throws ValidationException
3635
*/
3736
public static function populate(Sponsor $sponsor, array $data):Sponsor{
3837

app/Models/Foundation/Summit/Sponsor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,4 +976,12 @@ public function clearSponsorships(): void
976976
$this->sponsorships->clear();
977977
$this->sponsorships = null;
978978
}
979+
980+
/**
981+
* @return array
982+
*/
983+
public function getSponsorshipTierNames(): array
984+
{
985+
return array_map(fn($sponsorship) => $sponsorship->getType()->getType()->getName(), $this->sponsorships);
986+
}
979987
}

app/Models/Foundation/Summit/SummitSponsorship.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class SummitSponsorship extends SilverstripeBaseModel
2727
{
2828
use One2ManyPropertyTrait;
2929

30+
protected $getIdMappings = [
31+
'getTypeId' => 'type',
32+
];
33+
34+
protected $hasPropertyMappings = [
35+
'hasType' => 'type',
36+
];
37+
3038
/**
3139
* @var Sponsor
3240
*/

0 commit comments

Comments
 (0)