Skip to content

Commit 30f1c64

Browse files
authored
Merge pull request #323 from crf-devs/add-fixture-slot-comments
Add fixtures slot comments
2 parents 115e6c0 + a2d1bef commit 30f1c64

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/DataFixtures/ApplicationFixtures.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,16 @@ private function loadResourcesAvailabilities(ObjectManager $manager, array $reso
302302
$resourcePartiallyAvailable = \array_slice($resourcesRandom, $index, (int) ($resourceCount * $percentPartiallyAvailable));
303303

304304
// Creating slots locked
305-
$data = $this->createAvailabilities($resourceLocked, $today, AvailabilityInterface::STATUS_LOCKED);
305+
$data = $this->createAvailabilities($resourceLocked, $today, AvailabilityInterface::STATUS_LOCKED, false, 'Raison médicale');
306306

307307
// Creating slots available
308308
$data = array_merge($data, $this->createAvailabilities($resourceAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE));
309309

310310
// Creating slots partially available
311-
$data = array_merge($data, $this->createAvailabilities($resourcePartiallyAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE, true));
311+
$data = array_merge($data, $this->createAvailabilities($resourcePartiallyAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE, true, 'Alpha '.random_int(1, 8)));
312312

313313
$insert = sprintf(
314-
'INSERT INTO %s (id, %s, start_time, end_time, status, created_at, updated_at, planning_agent_id) VALUES %s',
314+
'INSERT INTO %s (id, %s, start_time, end_time, status, created_at, updated_at, planning_agent_id, comment) VALUES %s',
315315
$manager->getClassMetadata($class)->getTableName(),
316316
UserAvailability::class === $class ? 'user_id' : 'asset_id',
317317
implode(', ', $data)
@@ -327,7 +327,7 @@ private function loadResourcesAvailabilities(ObjectManager $manager, array $reso
327327
$manager->getConnection()->exec(sprintf('SELECT setval(\''.$sequence.'\', %d, true)', $this->availabilitiesId));
328328
}
329329

330-
private function createAvailabilities(array $objects, \DateTimeInterface $thisWeek, string $globalStatus, bool $partiallyAvailable = false): array
330+
private function createAvailabilities(array $objects, \DateTimeInterface $thisWeek, string $globalStatus, bool $partiallyAvailable = false, string $defaultComment = ''): array
331331
{
332332
$data = [];
333333

@@ -360,14 +360,18 @@ private function createAvailabilities(array $objects, \DateTimeInterface $thisWe
360360
$organizationId = $this->getRandomOrganization();
361361
}
362362

363-
$data[] = '('.$this->availabilitiesId++.','.
364-
$object->getId().','.
365-
"'".$slot->format('Y-m-d H:i:s')."',".
366-
"'".$this->closeInterval($slot)->format('Y-m-d H:i:s')."',".
367-
"'".$status."',".
368-
"'".date('Y-m-d H:i:s')."',".
369-
"'".date('Y-m-d H:i:s')."',".
370-
($organizationId ?: 'NULL').')';
363+
$data[] = sprintf(
364+
"(%d,%d,'%s','%s','%s','%s','%s',%s, '%s')",
365+
$this->availabilitiesId++,
366+
$object->getId(),
367+
$slot->format('Y-m-d H:i:s'),
368+
$this->closeInterval($slot)->format('Y-m-d H:i:s'),
369+
$status,
370+
date('Y-m-d H:i:s'),
371+
date('Y-m-d H:i:s'),
372+
$organizationId ?: 'NULL',
373+
AvailabilityInterface::STATUS_AVAILABLE !== $status ? $defaultComment : '',
374+
);
371375
}
372376

373377
$slot = $slot->add(new \DateInterval(self::SLOT_INTERVAL));

src/DataFixtures/SlotAvailabilityGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SlotAvailabilityGuesser
2020

2121
public function guessAvailableSlot(\DateTimeImmutable $slot): bool
2222
{
23-
$rand = rand(1, 100);
23+
$rand = random_int(1, 100);
2424
$chance = $this->getSlotChances($slot);
2525

2626
if ($this->availableSlotCount > 0) {

src/DataFixtures/SlotBookingGuesser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class SlotBookingGuesser
1515

1616
public function guessBookedSlot(\DateTimeImmutable $slot): bool
1717
{
18-
$rand = mt_rand(1, 100);
18+
$rand = random_int(1, 100);
1919

20-
if ($this->isPreviousSlotBooked($slot)) {
20+
if ($this->isPreviousSlotBooked()) {
2121
if ($rand <= $this->bookedSlotPercentageWithPrevious) {
2222
//Decreasing chances of being booked
2323
$this->bookedSlotPercentageWithPrevious -= self::RATE_OF_BOOKED_PERCENTAGE;
@@ -52,7 +52,7 @@ public function resetGuesser(int $resetLastBookedSlot = 1): void
5252
$this->bookedSlotPercentageWithPrevious = 100;
5353
}
5454

55-
private function isPreviousSlotBooked(\DateTimeImmutable $slot): bool
55+
private function isPreviousSlotBooked(): bool
5656
{
5757
if (0 === $this->bookedSlotCount) {
5858
return false;

0 commit comments

Comments
 (0)