Skip to content

Commit 63d2abf

Browse files
committed
feat: sponsor service statistics crud endpoints
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 2db6e9b commit 63d2abf

18 files changed

Lines changed: 573 additions & 14 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php namespace App\Http\Controllers;
2+
/**
3+
* Copyright 2026 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
use App\Http\ValidationRulesFactories\AbstractValidationRulesFactory;
15+
/**
16+
* Class SponsorServicesStatisticsValidationRulesFactory
17+
* @package App\Http\Controllers
18+
*/
19+
final class SponsorServicesStatisticsValidationRulesFactory extends AbstractValidationRulesFactory
20+
{
21+
public static function buildForAdd(array $payload = []): array
22+
{
23+
return [
24+
'forms_qty' => 'sometimes|integer',
25+
'purchases_qty' => 'sometimes|integer',
26+
'pages_qty' => 'sometimes|integer',
27+
'documents_qty' => 'sometimes|integer',
28+
];
29+
}
30+
31+
public static function buildForUpdate(array $payload = []): array
32+
{
33+
return self::buildForAdd();
34+
}
35+
}

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSponsorApiController.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,4 +4288,84 @@ public function updateLeadReportSettings($summit_id, $sponsor_id) {
42884288
);
42894289
});
42904290
}
4291+
4292+
#[OA\Put(
4293+
path: "/api/v1/summits/{id}/sponsors/{sponsor_id}/sponsorservices-statistics",
4294+
description: "required-groups " . IGroup::SuperAdmins . ", " . IGroup::Administrators . ", " . IGroup::SummitAdministrators,
4295+
summary: 'Upsert Sponsor Services Statistics',
4296+
operationId: 'updateSponsorServicesStatistics',
4297+
tags: ['Sponsors'],
4298+
x: [
4299+
'required-groups' => [
4300+
IGroup::SuperAdmins,
4301+
IGroup::Administrators,
4302+
IGroup::SummitAdministrators,
4303+
]
4304+
],
4305+
security: [
4306+
[
4307+
'summit_sponsor_oauth2' => [
4308+
SummitScopes::WriteSummitData,
4309+
]
4310+
]
4311+
],
4312+
parameters: [
4313+
new OA\Parameter(
4314+
name: 'id',
4315+
in: 'path',
4316+
required: true,
4317+
schema: new OA\Schema(type: 'integer'),
4318+
description: 'The summit id'
4319+
),
4320+
new OA\Parameter(
4321+
name: 'sponsor_id',
4322+
in: 'path',
4323+
required: true,
4324+
schema: new OA\Schema(type: 'integer'),
4325+
description: 'The sponsor id'
4326+
),
4327+
],
4328+
requestBody: new OA\RequestBody(
4329+
required: true,
4330+
content: new OA\JsonContent(ref: "#/components/schemas/SponsorServicesStatisticsUpsertRequest")
4331+
),
4332+
responses: [
4333+
new OA\Response(
4334+
response: Response::HTTP_CREATED,
4335+
description: 'Sponsor Services Statistics created/updated successfully'
4336+
),
4337+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
4338+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "Not Found"),
4339+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
4340+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error")
4341+
]
4342+
)]
4343+
/**
4344+
* @param $summit_id
4345+
* @param $sponsor_id
4346+
* @return mixed
4347+
*/
4348+
public function updateSponsorServicesStatistics($summit_id, $sponsor_id) {
4349+
return $this->processRequest(function () use ($summit_id, $sponsor_id) {
4350+
4351+
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
4352+
if (is_null($summit)) return $this->error404();
4353+
4354+
$sponsor = $summit->getSummitSponsorById(intval($sponsor_id));
4355+
if (is_null($sponsor)) return $this->error404();
4356+
4357+
$payload = $this->getJsonPayload(SponsorServicesStatisticsValidationRulesFactory::buildForUpdate(), true);
4358+
4359+
$statistics = $this->service->updateSponsorServicesStatistics($summit, $sponsor->getId(), $payload);
4360+
4361+
return $this->updated(SerializerRegistry::getInstance()
4362+
->getSerializer($statistics)
4363+
->serialize(
4364+
SerializerUtils::getExpand(),
4365+
SerializerUtils::getFields(),
4366+
SerializerUtils::getRelations()
4367+
)
4368+
);
4369+
});
4370+
}
42914371
}

app/ModelSerializers/SerializerRegistry.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
use App\ModelSerializers\Summit\SponsorMaterialSerializer;
109109
use App\ModelSerializers\Summit\SponsorSerializerV2;
110110
use App\ModelSerializers\Summit\SponsorSocialNetworkSerializer;
111+
use App\ModelSerializers\Summit\SponsorStatisticsSerializer;
111112
use App\ModelSerializers\Summit\SponsorUserInfoGrantSerializer;
112113
use App\ModelSerializers\Summit\StripePaymentProfileSerializer;
113114
use App\ModelSerializers\Summit\SummitAttendeeBadgeSerializer;
@@ -268,7 +269,7 @@ private function __construct()
268269
$this->registry['SummitSelectionPlanExtraQuestionType'] = SummitSelectionPlanExtraQuestionTypeSerializer::class;
269270
$this->registry['AssignedSelectionPlanExtraQuestionType'] = AssignedSelectionPlanExtraQuestionTypeSerializer::class;
270271
$this->registry['SelectionPlanAllowedMember'] = SelectionPlanAllowedMemberSerializer::class;
271-
272+
272273
$this->registry['SummitWIFIConnection'] = SummitWIFIConnectionSerializer::class;
273274
$this->registry['SummitType'] = SummitTypeSerializer::class;
274275
$this->registry['SummitEventType'] = SummitEventTypeSerializer::class;
@@ -602,6 +603,7 @@ private function __construct()
602603
$this->registry['SponsorAd'] = SponsorAdSerializer::class;
603604
$this->registry['SponsorMaterial'] = SponsorMaterialSerializer::class;
604605
$this->registry['SponsorSocialNetwork'] = SponsorSocialNetworkSerializer::class;
606+
$this->registry['SponsorStatistics'] = SponsorStatisticsSerializer::class;
605607

606608
// locations
607609

@@ -804,4 +806,4 @@ public function serialize($expand = null, array $fields = [], array $relations =
804806

805807
return $res;
806808
}
807-
}
809+
}

app/ModelSerializers/Summit/SponsorBaseSerializer.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ abstract class SponsorBaseSerializer extends SilverStripeSerializer
5050
'CarouselAdvertiseImageAltText' => 'carousel_advertise_image_alt_text:json_string',
5151
'ShowLogoInEventPage' => 'show_logo_in_event_page:json_boolean',
5252
'LeadReportSettingId' => 'lead_report_setting_id:json_int',
53+
'SponsorServicesStatisticsId' => 'sponsorservices_statistics_id:json_int',
5354
];
5455

5556

@@ -193,5 +194,11 @@ public function serialize($expand = null, array $fields = [], array $relations =
193194
'getter' => 'getLeadReportSetting',
194195
'has' => 'hasLeadReportSetting'
195196
],
197+
'sponsorservices_statistics' => [
198+
'type' => One2ManyExpandSerializer::class,
199+
'original_attribute' => 'sponsorservices_statistics_id',
200+
'getter' => 'getSponsorServicesStatistics',
201+
'has' => 'hasSponsorServicesStatistics'
202+
],
196203
];
197-
}
204+
}

app/ModelSerializers/Summit/SponsorSerializer.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
use App\ModelSerializers\Summit\SponsorBaseSerializer;
1616
use Libs\ModelSerializers\AbstractSerializer;
17-
use Libs\ModelSerializers\Many2OneExpandSerializer;
18-
use Libs\ModelSerializers\One2ManyExpandSerializer;
1917
use models\summit\Sponsor;
2018

2119
/**
@@ -63,11 +61,26 @@ public function serialize($expand = null, array $fields = [], array $relations =
6361
}
6462
}
6563
break;
64+
case 'sponsorservices_statistics':
65+
{
66+
if ($sponsor->hasStatistics()) {
67+
unset($values['sponsorservices_statistics_id']);
68+
$statistics = $sponsor->getStatistics();
69+
$values['sponsorservices_statistics'] = SerializerRegistry::getInstance()->getSerializer($statistics)->serialize
70+
(
71+
AbstractSerializer::filterExpandByPrefix($expand, $relation),
72+
AbstractSerializer::filterFieldsByPrefix($fields, $relation),
73+
AbstractSerializer::filterFieldsByPrefix($relations, $relation),
74+
$params
75+
);
76+
}
77+
}
78+
break;
6679
}
6780
}
6881
}
6982

7083
return $values;
7184
}
7285

73-
}
86+
}

app/ModelSerializers/Summit/SponsorSerializerV2.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class SponsorSerializerV2 extends SponsorBaseSerializer
2323
{
2424
protected static $allowed_relations = [
2525
'sponsorships',
26+
'statistics',
2627
];
2728

2829
/**
@@ -53,6 +54,6 @@ public function serialize($expand = null, array $fields = [], array $relations =
5354
'sponsorships' => [
5455
'type' => Many2OneExpandSerializer::class,
5556
'getter' => 'getSponsorships',
56-
],
57+
]
5758
];
58-
}
59+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php namespace App\ModelSerializers\Summit;
2+
/*
3+
* Copyright 2026 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use ModelSerializers\SilverStripeSerializer;
16+
17+
/**
18+
* Class SponsorStatisticsSerializer
19+
* @package App\ModelSerializers\Summit
20+
*/
21+
final class SponsorStatisticsSerializer extends SilverStripeSerializer
22+
{
23+
protected static $array_mappings = [
24+
'FormsQty' => 'forms_qty:json_int',
25+
'PurchasesQty' => 'purchases_qty:json_int',
26+
'PagesQty' => 'pages_qty:json_int',
27+
'DocumentsQty' => 'documents_qty:json_int',
28+
];
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace App\Models\Foundation\Summit\Factories;
2+
/*
3+
* Copyright 2026 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use App\Models\Foundation\Summit\SponsorStatistics;
16+
17+
/**
18+
* Class SponsorServicesStatisticsFactory
19+
* @package App\Models\Foundation\Summit\Factories
20+
*/
21+
final class SponsorServicesStatisticsFactory
22+
{
23+
/**
24+
* @param array $data
25+
* @return SponsorStatistics
26+
*/
27+
public static function build(array $data): SponsorStatistics
28+
{
29+
return self::populate(self::getNewEntity(), $data);
30+
}
31+
32+
/**
33+
* @param SponsorStatistics $settings
34+
* @param array $data
35+
* @return SponsorStatistics
36+
*/
37+
public static function populate(SponsorStatistics $statistics, array $data): SponsorStatistics
38+
{
39+
$statistics->setFormsQty($data['forms_qty']);
40+
$statistics->setPurchasesQty($data['purchases_qty']);
41+
$statistics->setPagesQty($data['pages_qty']);
42+
$statistics->setDocumentsQty($data['documents_qty']);
43+
return $statistics;
44+
}
45+
46+
protected static function getNewEntity(): SponsorStatistics
47+
{
48+
return new SponsorStatistics;
49+
}
50+
}

0 commit comments

Comments
 (0)