Skip to content

Commit 7fd6111

Browse files
authored
added new signs metamodel (#135)
GET api/v1/summits/{summitid}/signs?filter=location_id==XYZ POST api/v1/summits/{summitid}/signs payload { location_id : XYZ , template: ''} PUT api/v1/summits/{summitid}/signs/{sign_id} Change-Id: I5602ed9c493b75111231b7a8bf8814c5819c77fb
1 parent 7c26d36 commit 7fd6111

File tree

18 files changed

+822
-31
lines changed

18 files changed

+822
-31
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php namespace App\Http\Controllers;
2+
3+
/*
4+
* Copyright 2023 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
16+
use App\Models\Foundation\Summit\Repositories\ISummitSignRepository;
17+
use App\Services\Model\ISummitSignService;
18+
use models\oauth2\IResourceServerContext;
19+
use models\summit\ISummitRepository;
20+
use models\summit\Summit;
21+
use models\utils\IEntity;
22+
23+
/**
24+
* Class OAuth2SummitSignApiController
25+
* @package App\Http\Controller
26+
*/
27+
final class OAuth2SummitSignApiController extends OAuth2ProtectedController
28+
{
29+
private $summit_repository;
30+
31+
private $service;
32+
33+
/**
34+
* @param ISummitSignRepository $repository
35+
* @param ISummitRepository $summit_repository
36+
* @param ISummitSignService $service
37+
* @param IResourceServerContext $resource_server_context
38+
*/
39+
public function __construct
40+
(
41+
ISummitSignRepository $repository,
42+
ISummitRepository $summit_repository,
43+
ISummitSignService $service,
44+
IResourceServerContext $resource_server_context
45+
)
46+
{
47+
parent::__construct($resource_server_context);
48+
$this->summit_repository = $summit_repository;
49+
$this->service = $service;
50+
$this->repository = $repository;
51+
}
52+
53+
use GetAllBySummit;
54+
55+
use GetSummitChildElementById;
56+
57+
use AddSummitChildElement;
58+
59+
use UpdateSummitChildElement;
60+
61+
protected function addChild(Summit $summit, array $payload): IEntity
62+
{
63+
return $this->service->add($summit, $payload);
64+
}
65+
66+
function getAddValidationRules(array $payload): array
67+
{
68+
return [
69+
'location_id' => 'required|integer',
70+
'template' => 'required|string'
71+
];
72+
}
73+
74+
protected function getSummitRepository(): ISummitRepository
75+
{
76+
return $this->summit_repository;
77+
}
78+
79+
protected function getChildFromSummit(Summit $summit, $child_id): ?IEntity
80+
{
81+
return $summit->getSignById(intval($child_id));
82+
}
83+
84+
function getUpdateValidationRules(array $payload): array
85+
{
86+
return [
87+
'template' => 'sometimes|string'
88+
];
89+
}
90+
91+
protected function updateChild(Summit $summit, int $child_id, array $payload): IEntity
92+
{
93+
return $this->service->update($summit, $child_id, $payload);
94+
}
95+
96+
protected function getFilterRules():array{
97+
return [
98+
'location_id' => ['=='],
99+
];
100+
}
101+
102+
/**
103+
* @return array
104+
*/
105+
protected function getFilterValidatorRules():array{
106+
return [
107+
'location_id' => 'sometimes|integer',
108+
];
109+
}
110+
/**
111+
* @return array
112+
*/
113+
protected function getOrderRules():array{
114+
return [
115+
'id'
116+
];
117+
}
118+
}

app/Http/Utils/Filters/FilterParser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public static function parse($filters, $allowed_fields = [])
102102
if (!isset($allowed_fields[$field])){
103103
throw new FilterParserException(sprintf("filter by field %s is not allowed", $field));
104104
}
105+
106+
if (!is_array($allowed_fields[$field])){
107+
throw new FilterParserException(sprintf("filter by field %s is not an array", $field));
108+
}
109+
105110
if (!in_array($op, $allowed_fields[$field])){
106111
throw new FilterParserException(sprintf("%s op is not allowed for filter by field %s",$op, $field));
107112

app/ModelSerializers/SerializerRegistry.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
use ModelSerializers\Locations\SummitVenueFloorSerializer;
115115
use ModelSerializers\Locations\SummitVenueRoomSerializer;
116116
use ModelSerializers\Locations\SummitVenueSerializer;
117-
117+
use App\ModelSerializers\Summit\SummitSignSerializer;
118118
/**
119119
* Class SerializerRegistry
120120
* @package ModelSerializers
@@ -249,6 +249,11 @@ private function __construct()
249249
$this->registry['TrackCheckBoxListQuestionTemplate'] = TrackMultiValueQuestionTemplateSerializer::class;
250250
$this->registry['TrackRadioButtonListQuestionTemplate'] = TrackMultiValueQuestionTemplateSerializer::class;
251251
$this->registry['TrackLiteralContentQuestionTemplate'] = TrackLiteralContentQuestionTemplateSerializer::class;
252+
253+
// signs
254+
255+
$this->registry['SummitSign'] = SummitSignSerializer::class;
256+
252257
// events
253258

254259
$this->registry['SummitEvent'] = [
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 2023 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+
16+
use ModelSerializers\SilverStripeSerializer;
17+
18+
/**
19+
* Class SummitSignSerializer
20+
* @package App\ModelSerializers\Summit
21+
*/
22+
final class SummitSignSerializer extends SilverStripeSerializer
23+
{
24+
protected static $array_mappings = [
25+
'Template' => 'template:json_string',
26+
'SummitId' => 'summit_id:json_int',
27+
'LocationId' => 'location_id:json_int',
28+
];
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php namespace App\Models\Foundation\Summit\Repositories;
2+
/*
3+
* Copyright 2023 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 models\utils\IBaseRepository;
16+
17+
/**
18+
* Interface ISummitSignRepository
19+
* @package App\Models\Foundation\Summit\Repositories
20+
*/
21+
interface ISummitSignRepository extends IBaseRepository
22+
{
23+
24+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php namespace App\Models\Foundation\Summit\Signs;
2+
/*
3+
* Copyright 2023 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 Doctrine\ORM\Mapping as ORM;
16+
use models\summit\SummitAbstractLocation;
17+
use models\summit\SummitOwned;
18+
use models\utils\One2ManyPropertyTrait;
19+
use models\utils\SilverstripeBaseModel;
20+
/**
21+
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrineSummitSignRepository")
22+
* @ORM\Table(name="SummitSign")
23+
* @ORM\AssociationOverrides({
24+
* @ORM\AssociationOverride(
25+
* name="summit",
26+
* inversedBy="signs"
27+
* )
28+
* })
29+
* Class SummitSign
30+
* @package App\Models\Foundation\Summit\Signs;
31+
*/
32+
class SummitSign extends SilverstripeBaseModel
33+
{
34+
35+
use One2ManyPropertyTrait;
36+
37+
protected $getIdMappings = [
38+
'getLocationId' => 'location',
39+
];
40+
41+
protected $hasPropertyMappings = [
42+
'hasLocation' => 'location',
43+
];
44+
45+
use SummitOwned;
46+
47+
/**
48+
* @ORM\Column(name="Template", type="string")
49+
* @var string
50+
*/
51+
private $template;
52+
53+
54+
/**
55+
* @ORM\OneToOne(targetEntity="models\summit\SummitAbstractLocation")
56+
* @ORM\JoinColumn(name="LocationID", referencedColumnName="ID")
57+
* @var SummitAbstractLocation
58+
*/
59+
private $location;
60+
61+
/**
62+
* @return string
63+
*/
64+
public function getTemplate(): ?string
65+
{
66+
return $this->template;
67+
}
68+
69+
/**
70+
* @param string $template
71+
*/
72+
public function setTemplate(string $template): void
73+
{
74+
$this->template = trim($template);
75+
}
76+
77+
/**
78+
* @return SummitAbstractLocation
79+
*/
80+
public function getLocation(): ?SummitAbstractLocation
81+
{
82+
return $this->location;
83+
}
84+
85+
/**
86+
* @param SummitAbstractLocation $location
87+
*/
88+
public function setLocation(SummitAbstractLocation $location): void
89+
{
90+
$this->location = $location;
91+
}
92+
93+
94+
}

app/Models/Foundation/Summit/Summit.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use App\Models\Foundation\Main\IGroup;
1616
use App\Models\Foundation\Main\OrderableChilds;
17-
use App\Models\Foundation\Summit\AllowedCurrencies;
1817
use App\Models\Foundation\Summit\EmailFlows\SummitEmailEventFlowType;
1918
use App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate;
2019
use App\Models\Foundation\Summit\ExtraQuestions\SummitSelectionPlanExtraQuestionType;
@@ -24,6 +23,7 @@
2423
use App\Models\Foundation\Summit\Registration\ISummitExternalRegistrationFeedType;
2524
use App\Models\Foundation\Summit\ScheduleEntity;
2625
use App\Models\Foundation\Summit\SelectionPlan;
26+
use App\Models\Foundation\Summit\Signs\SummitSign;
2727
use App\Models\Foundation\Summit\Speakers\FeaturedSpeaker;
2828
use App\Models\Foundation\Summit\TrackTagGroup;
2929
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
@@ -386,6 +386,11 @@ class Summit extends SilverstripeBaseModel
386386
*/
387387
private $locations;
388388

389+
/**
390+
* @ORM\OneToMany(targetEntity="App\Models\Foundation\Summit\Signs\SummitSign", mappedBy="summit", cascade={"persist","remove"}, orphanRemoval=true)
391+
*/
392+
private $signs;
393+
389394
/**
390395
* @ORM\OneToMany(targetEntity="SummitBookableVenueRoomAttributeType", mappedBy="summit", cascade={"persist","remove"}, orphanRemoval=true)
391396
*/
@@ -1128,6 +1133,7 @@ public function __construct()
11281133
$this->sponsorship_types = new ArrayCollection();
11291134
$this->selection_plan_extra_questions = new ArrayCollection();
11301135
$this->submission_invitations = new ArrayCollection();
1136+
$this->signs = new ArrayCollection();
11311137
}
11321138

11331139
/**
@@ -6341,4 +6347,46 @@ public function parseDateTime(int $epoch):?Datetime
63416347
$datetime->setTimezone($this->getTimeZone());
63426348
return $datetime;
63436349
}
6350+
6351+
/**
6352+
* @return ArrayCollection
6353+
*/
6354+
public function getSigns(): ArrayCollection
6355+
{
6356+
return $this->signs;
6357+
}
6358+
6359+
/**
6360+
* @param int $sign_id
6361+
* @return SummitSign|null
6362+
*/
6363+
public function getSignById(int $sign_id):?SummitSign{
6364+
$criteria = Criteria::create();
6365+
$criteria->where(Criteria::expr()->eq('id', $sign_id));
6366+
$sign = $this->signs->matching($criteria)->first();
6367+
return $sign === false ? null : $sign;
6368+
}
6369+
6370+
/**
6371+
* @param int $location_id
6372+
* @return SummitSign|null
6373+
*/
6374+
public function getSignByLocationId(int $location_id):?SummitSign{
6375+
$location = $this->getLocation($location_id);
6376+
if(is_null($location)) return null;
6377+
$criteria = Criteria::create();
6378+
$criteria->where(Criteria::expr()->eq('location', $location));
6379+
$sign = $this->signs->matching($criteria)->first();
6380+
return $sign === false ? null : $sign;
6381+
}
6382+
6383+
/**
6384+
* @param SummitSign $sign
6385+
* @return void
6386+
*/
6387+
public function addSign(SummitSign $sign):void{
6388+
if($this->signs->contains($sign)) return;
6389+
$this->signs->add($sign);
6390+
$sign->setSummit($this);
6391+
}
63446392
}

0 commit comments

Comments
 (0)