distribute scheduled nodes evenly by filling days sequentially
This commit is contained in:
parent
358694e7e3
commit
49663d70d9
2 changed files with 52 additions and 1 deletions
|
|
@ -82,8 +82,9 @@ class CreatePlan
|
||||||
$currentDate = $currentDate->modify('+1 day');
|
$currentDate = $currentDate->modify('+1 day');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nodesPerDay = (int) ceil(count($nodesOfText) / count($dates));
|
||||||
foreach ($nodesOfText as $index => $node) {
|
foreach ($nodesOfText as $index => $node) {
|
||||||
$dateIndex = $index % count($dates);
|
$dateIndex = (int) floor($index / $nodesPerDay);
|
||||||
$scheduledDate = $dates[$dateIndex];
|
$scheduledDate = $dates[$dateIndex];
|
||||||
|
|
||||||
$this->createScheduledNode->execute(
|
$this->createScheduledNode->execute(
|
||||||
|
|
|
||||||
|
|
@ -270,4 +270,54 @@ class CreatePlanTest extends TestCase
|
||||||
$childTwo->getDate()
|
$childTwo->getDate()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_more_scheduled_nodes_than_days(): void
|
||||||
|
{
|
||||||
|
$text = $this->textRepo->find(0);
|
||||||
|
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
|
||||||
|
text: $text,
|
||||||
|
title: 'root node',
|
||||||
|
parentNode: null,
|
||||||
|
));
|
||||||
|
$this->nodeRepo->create(new CreateNodeDto(
|
||||||
|
text: $text,
|
||||||
|
title: 'child 1',
|
||||||
|
parentNode: $rootNode,
|
||||||
|
));
|
||||||
|
$this->nodeRepo->create(new CreateNodeDto(
|
||||||
|
text: $text,
|
||||||
|
title: 'child 2',
|
||||||
|
parentNode: $rootNode,
|
||||||
|
));
|
||||||
|
$this->nodeRepo->create(new CreateNodeDto(
|
||||||
|
text: $text,
|
||||||
|
title: 'child 3',
|
||||||
|
parentNode: $rootNode,
|
||||||
|
));
|
||||||
|
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||||
|
userId: 0,
|
||||||
|
name: 'testPlan',
|
||||||
|
textId: 0,
|
||||||
|
dateStart: '2025-01-01',
|
||||||
|
dateEnd: '2025-01-02',
|
||||||
|
));
|
||||||
|
$childOne = $this->scheduledNodeRepo->find(0);
|
||||||
|
$childTwo = $this->scheduledNodeRepo->find(1);
|
||||||
|
$childThree = $this->scheduledNodeRepo->find(2);
|
||||||
|
$this->assertNotNull($childOne);
|
||||||
|
$this->assertNotNull($childTwo);
|
||||||
|
$this->assertNotNull($childThree);
|
||||||
|
$this->assertEquals(
|
||||||
|
new DateTimeImmutable('2025-01-01'),
|
||||||
|
$childOne->getDate()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new DateTimeImmutable('2025-01-01'),
|
||||||
|
$childTwo->getDate()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
new DateTimeImmutable('2025-01-02'),
|
||||||
|
$childThree->getDate()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue