Skip to content

Commit f000716

Browse files
committed
Speakers Promo code fixes
* added debug info * fixed AssignedPromoCodeSpeaker repository Change-Id: I3bb952ab02ff7ac3031a0d07b16d32bda51ad3b5
1 parent 386e519 commit f000716

File tree

8 files changed

+104
-18
lines changed

8 files changed

+104
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ public function getDiscountCodeSpeakers($summit_id, $discount_code_id)
572572
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
573573
if (is_null($summit)) return $this->error404();
574574

575-
$discount_code = $this->repository->getById($discount_code_id);
575+
$discount_code = $this->repository->getById(intval($discount_code_id));
576576

577577
if (!$discount_code instanceof SpeakersRegistrationDiscountCode) {
578578
return $this->error404();
@@ -582,6 +582,7 @@ public function getDiscountCodeSpeakers($summit_id, $discount_code_id)
582582
function () {
583583
return [
584584
'email' => ['@@', '=@', '=='],
585+
'full_name' => ['@@', '=@', '=='],
585586
'first_name' => ['@@', '=@', '=='],
586587
'last_name' => ['@@', '=@', '=='],
587588
];

app/Models/Foundation/Summit/Registration/PromoCodes/Traits/SpeakersPromoCodeTrait.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,28 @@ private function isSpeakerAlreadyAssigned(PresentationSpeaker $speaker): bool
8585
*/
8686
public function assignSpeaker(PresentationSpeaker $speaker)
8787
{
88-
if ($this->isSpeakerAlreadyAssigned($speaker)) return $this;
88+
Log::debug
89+
(
90+
sprintf
91+
(
92+
"SpeakersPromoCodeTrait::assignSpeaker promo_code %s speaker %s",
93+
$this->getId(),
94+
$speaker->getId()
95+
)
96+
);
97+
98+
if ($this->isSpeakerAlreadyAssigned($speaker)) {
99+
Log::warning
100+
(
101+
sprintf
102+
(
103+
"SpeakersPromoCodeTrait::assignSpeaker promo_code %s speaker %s already assigned",
104+
$this->getId(),
105+
$speaker->getId()
106+
)
107+
);
108+
return $this;
109+
}
89110
$owner = new AssignedPromoCodeSpeaker();
90111
$owner->setSpeaker($speaker);
91112
$owner->setRegistrationPromoCode($this);

app/Models/Foundation/Summit/Repositories/ISpeakersRegistrationDiscountCodeRepository.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ interface ISpeakersRegistrationDiscountCodeRepository extends IBaseRepository
3232
* @param Order|null $order
3333
* @return PagingResponse
3434
*/
35-
public function getDiscountCodeSpeakers(
35+
public function getDiscountCodeSpeakers
36+
(
3637
SpeakersRegistrationDiscountCode $discount_code,
3738
PagingInfo $paging_info,
3839
Filter $filter = null,
39-
Order $order = null);
40+
Order $order = null
41+
);
4042
}

app/Models/Foundation/Summit/Summit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,15 +2093,17 @@ public function getSpeaker($speaker_id, $filter_published_events = true)
20932093
->setParameter('speaker_id', $speaker_id)
20942094
->getQuery()->getOneOrNullResult();
20952095

2096-
if (!is_null($speaker)) return $speaker;
2096+
if (!is_null($speaker))
2097+
return $speaker;
20972098

20982099
// attendance
20992100
$speaker = $this->buildSpeakerSummitAttendanceQuery()
21002101
->andWhere('ps.id = :speaker_id')
21012102
->setParameter('speaker_id', $speaker_id)
21022103
->getQuery()->getOneOrNullResult();
21032104

2104-
if (!is_null($speaker)) return $speaker;
2105+
if (!is_null($speaker))
2106+
return $speaker;
21052107

21062108
return null;
21072109
}

app/Repositories/Summit/DoctrineSpeakersRegistrationDiscountCodeRepository.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,25 @@ protected function getBaseEntity()
4343
protected function getFilterMappings(): array
4444
{
4545
return [
46-
'email' => new DoctrineFilterMapping("m.email :operator :value"),
47-
'full_name' => new DoctrineFilterMapping("concat(m.first_name, ' ', m.last_name) :operator :value"),
46+
'first_name' => new DoctrineFilterMapping(
47+
"( LOWER(m.first_name) :operator LOWER(:value) )".
48+
"OR ( LOWER(s.first_name) :operator LOWER(:value) )"
49+
),
50+
'last_name' => new DoctrineFilterMapping(
51+
"( LOWER(m.last_name) :operator LOWER(:value) )".
52+
" OR ( LOWER(s.last_name) :operator LOWER(:value) )"
53+
),
54+
'email' => [
55+
Filter::buildEmailField('m.email'),
56+
Filter::buildEmailField('m.second_email'),
57+
Filter::buildEmailField('m.third_email'),
58+
Filter::buildEmailField('rr.email'),
59+
],
60+
'full_name' => new DoctrineFilterMapping
61+
(
62+
"( CONCAT(LOWER(m.first_name), ' ', LOWER(m.last_name)) :operator LOWER(:value) )".
63+
" OR ( CONCAT(LOWER(s.first_name), ' ', LOWER(s.last_name)) :operator LOWER(:value) )"
64+
),
4865
];
4966
}
5067

@@ -61,7 +78,8 @@ public function getDiscountCodeSpeakers(
6178
->from(AssignedPromoCodeSpeaker::class, 'o')
6279
->join('o.registration_promo_code', 'd')
6380
->join('o.speaker', 's')
64-
->join('s.member', 'm')
81+
->leftJoin("s.registration_request", "rr")
82+
->leftJoin('s.member', 'm')
6583
->where("d.id = :discount_code")
6684
->setParameter("discount_code", $discount_code);
6785
},

app/Services/Model/Imp/SpeakerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ function($summit, $flow_event, $speaker_id, $test_email_recipient, $speaker_anno
12561256
$speaker = $this->speaker_repository->getByIdExclusiveLock(intval($speaker_id));
12571257

12581258
if (!$speaker instanceof PresentationSpeaker) {
1259-
throw new EntityNotFoundException('speaker not found!');
1259+
throw new EntityNotFoundException('Speaker not found');
12601260
}
12611261

12621262
// try to get or auto-build a promo code

app/Services/Model/Imp/SummitPromoCodeService.php

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,28 @@ private function getPromoCodeParams(Summit $summit, array $data)
191191
public function addPromoCode(Summit $summit, array $data, Member $current_user = null)
192192
{
193193
$promo_code = $this->tx_service->transaction(function () use ($summit, $data, $current_user) {
194-
Log::debug(sprintf("SummitPromoCodeService::addPromoCode summit %s data %s", $summit->getId(), json_encode($data)));
195194

196-
$code = trim($data['code']);
195+
Log::debug
196+
(
197+
sprintf
198+
(
199+
"SummitPromoCodeService::addPromoCode summit %s data %s",
200+
$summit->getId(),
201+
json_encode($data)
202+
)
203+
);
204+
205+
206+
$code = isset($data['code']) ? trim($data['code']) : null;
197207

198208
if (empty($code)) {
199-
throw new ValidationException("code can not be empty!");
209+
throw new ValidationException("Code can not be empty.");
200210
}
201211

202212
$old_promo_code = $summit->getPromoCodeByCode($code);
203213

204214
if (!is_null($old_promo_code))
205-
throw new ValidationException(sprintf("promo code %s already exits on summit id %s", trim($data['code']), $summit->getId()));
215+
throw new ValidationException(sprintf("Promo code %s already exits on Summit %s.", trim($data['code']), $summit->getId()));
206216

207217
$promo_code = SummitPromoCodeFactory::build($summit, $data, $this->getPromoCodeParams($summit, $data));
208218
if (is_null($promo_code))
@@ -213,15 +223,43 @@ public function addPromoCode(Summit $summit, array $data, Member $current_user =
213223

214224
$promo_code->setSourceAdmin();
215225

216-
if (isset($data['speaker_ids']) && ($promo_code->getClassName() == SpeakersSummitRegistrationPromoCode::ClassName ||
226+
if (isset($data['speaker_ids']) && (
227+
$promo_code->getClassName() == SpeakersSummitRegistrationPromoCode::ClassName ||
217228
$promo_code->getClassName() == SpeakersRegistrationDiscountCode::ClassName)) {
229+
Log::debug
230+
(
231+
sprintf
232+
(
233+
"SummitPromoCodeService::addPromoCode promo code %s is a speaker promo code",
234+
$promo_code->getId()
235+
)
236+
);
218237

219238
foreach ($data['speaker_ids'] as $speaker_id) {
239+
Log::debug
240+
(
241+
sprintf
242+
(
243+
"SummitPromoCodeService::addPromoCode promo code %s trying to assign to speaker %s",
244+
$promo_code->getId(),
245+
$speaker_id
246+
)
247+
);
248+
220249
$speaker = $summit->getSpeaker(intval($speaker_id), false);
221-
if(is_null($speaker))
222-
throw new EntityNotFoundException(sprintf("speaker %s not found", $speaker_id));
250+
251+
if(is_null($speaker)) {
252+
Log::warning
253+
(
254+
sprintf("SummitPromoCodeService::addPromoCode Speaker %s not found.", $speaker_id)
255+
);
256+
throw new EntityNotFoundException(sprintf("Speaker %s not found.", $speaker_id));
257+
}
258+
223259
$promo_code->assignSpeaker($speaker);
224260
}
261+
262+
$this->repository->add($promo_code, true);
225263
}
226264

227265
// tags

app/Services/Model/Strategies/PromoCodes/AutomaticMultiSpeakerPromoCodeStrategy.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
**/
1515
use App\Models\Foundation\Summit\Factories\SummitPromoCodeFactory;
16+
use Illuminate\Support\Facades\Log;
1617
use libs\utils\ITransactionService;
1718
use models\exceptions\EntityNotFoundException;
1819
use models\exceptions\ValidationException;
@@ -81,6 +82,7 @@ public function __construct(Summit $summit,
8182
* @throws ValidationException|\Exception
8283
*/
8384
public function getPromoCode(PresentationSpeaker $speaker): ?SummitRegistrationPromoCode {
85+
Log::debug(sprintf("AutomaticMultiSpeakerPromoCodeStrategy::getPromoCode speaker %s", $speaker->getId()));
8486
$code = null;
8587
do {
8688
$code = $this->code_generator->generate($this->summit);
@@ -89,11 +91,13 @@ public function getPromoCode(PresentationSpeaker $speaker): ?SummitRegistrationP
8991
$promo_code_spec = $this->data["promo_code_spec"];
9092
$promo_code_spec["code"] = $code;
9193
$promo_code_spec["speaker_ids"] = [$speaker->getId()];
94+
9295
$promo_code = $this->service->addPromoCode($this->summit, $promo_code_spec);
9396

9497
if (is_null($promo_code)) {
95-
throw new ValidationException('cannot build a valid promo code with the given specification');
98+
throw new ValidationException('Cannot build a valid promo code with the given specification.');
9699
}
100+
97101
return $promo_code;
98102
}
99103
}

0 commit comments

Comments
 (0)