Advertisement
Guest User

fixture

a guest
Nov 19th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. namespace dn\AnkieterBundle\DataFixtures\ORM;
  4.  
  5. use Doctrine\Common\DataFixtures\FixtureInterface;
  6.  
  7. use dn\AnkieterBundle\Entity\Inquiry;
  8. use dn\AnkieterBundle\Entity\Question;
  9. use dn\AnkieterBundle\Entity\Answer;
  10.  
  11. class LoadTestInquiryData implements FixtureInterface
  12. {
  13.     public function load($manager)
  14.     {
  15.         // creating inquiry:
  16.         $inquiry = new Inquiry();
  17.         $inquiry->setName('Testowe badanie');
  18.         $inquiry->setDescription('Jakiś opis badania…');
  19.         $manager->persist($inquiry);
  20.  
  21.         // creating questions for the inquiry:
  22.         for ($i = 1; $i <= 5; $i++) {
  23.             $question = new Question();
  24.             $question->setPosition($i);
  25.             $question->setContent('Pytanie nr '.$i);
  26.             $question->setInquiry($inquiry);
  27.             $manager->persist($question);
  28.  
  29.             // creating answers for questions:
  30.             for ($j = 1; $j <= 5; $j++) {
  31.                 $answer = new Answer();
  32.                 $answer->setPosition($j);
  33.                 $answer->setContent('Odpowiedź nr '.$j);
  34.                 $answer->setQuestion($question);
  35.                 $manager->persist($answer);
  36.             }
  37.         }
  38.  
  39.         $manager->flush();
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement