Beispiel #1
0
 public function save(Recipe $recipe)
 {
     $now = new \DateTimeImmutable();
     if (null === $recipe->getDateCreated()) {
         $recipe->setDateCreated($now);
     }
     $recipe->setAuthor($this->authorizationService->getIdentity());
     $recipe->setDateUpdated($now);
     $this->objectManager->persist($recipe);
     $this->objectManager->flush();
 }
Beispiel #2
0
 public function load(ObjectManager $manager)
 {
     $recipeData = [['id' => Uuid::uuid4()->toString(), 'title' => 'Wiener Schnitzel', 'content' => 'Bei ALDI kaufen in die Pfanne hauen und gut ist!'], ['id' => Uuid::uuid4()->toString(), 'title' => 'Ravioli', 'content' => 'Dose aufmachen und Inhalt in einen Topf geben. Alternativ dose ins Lagerfeuer schmeißen.'], ['id' => Uuid::uuid4()->toString(), 'title' => 'Pizza', 'content' => 'Selber machen, hahhaa, der war gut!']];
     $counter = 0;
     $now = new \DateTimeImmutable();
     $map = ['a', 'b'];
     $iteration = true;
     foreach ($recipeData as $recipe) {
         $obj = new RecipeEntity();
         $obj->setId($recipe['id']);
         $obj->setTitle($recipe['title']);
         $obj->setContent($recipe['content']);
         $obj->setDateCreated($now);
         $obj->setDateUpdated($now);
         $obj->setPublished(true);
         $obj->setAuthor($this->getReference('user_' . $map[(int) $iteration]));
         $iteration = !$iteration;
         $manager->persist($obj);
         $this->addReference('recipe_' . ++$counter, $obj);
     }
     $manager->flush();
 }