callback = $callback; return $this; } /** * @return int */ public function getAmount(): int { return $this->amount; } public function setIsGlobal(bool $global): ActivityFixtures { $this->isGlobal = $global; return $this; } public function setIsVisible(bool $visible): ActivityFixtures { $this->isVisible = $visible; return $this; } public function setAmount(int $amount): ActivityFixtures { $this->amount = $amount; return $this; } /** * {@inheritdoc} */ public function load(ObjectManager $manager) { $projects = $this->getAllProjects($manager); $faker = Factory::create(); // random amount of timesheet entries for every user for ($i = 0; $i < $this->amount; $i++) { $project = null; if (false === $this->isGlobal) { $project = $projects[array_rand($projects)]; } $visible = 0 != $i % 3; if (null !== $this->isVisible) { $visible = $this->isVisible; } $activity = new Activity(); $activity ->setProject($project) ->setName($faker->bs . ($visible ? '' : ' (x)')) ->setComment($faker->text) ->setVisible($visible) ; if (null !== $this->callback) { call_user_func($this->callback, $activity); } $manager->persist($activity); } $manager->flush(); } /** * @param ObjectManager $manager * @return array */ protected function getAllProjects(ObjectManager $manager): array { $all = []; /** @var Project[] $entries */ $entries = $manager->getRepository(Project::class)->findAll(); foreach ($entries as $temp) { $all[$temp->getId()] = $temp; } return $all; } }