Permalink
Browse files

Add doctrine fixtures plus several fixtures

  • Loading branch information...
1 parent 1f8f6c0 commit 27bd266dbee47ebe274be7c2c2927f8e85cb473c @Soulou committed Apr 26, 2012
View
@@ -15,6 +15,7 @@ public function registerBundles()
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
+ new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
View
@@ -25,7 +25,7 @@ twig:
assetic:
debug: %kernel.debug%
use_controller: false
- bundles: [ ]
+ bundles: [ UnsapaIPWBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
View
@@ -8,6 +8,7 @@
"symfony/symfony": "2.1.*",
"doctrine/orm": "2.2.0",
"doctrine/doctrine-bundle": "dev-master",
+ "doctrine/doctrine-fixtures-bundle" : "dev-master",
"twig/extensions": "dev-master",
"symfony/assetic-bundle": "dev-master",
"symfony/swiftmailer-bundle": "dev-master",
View
Oops, something went wrong.
Binary file not shown.
@@ -0,0 +1,144 @@
+<?php
+/**
+ * LoadExampleData.php
+ *
+ * @author Léo
+ * @date 2012/04/26
+ */
+
+namespace Unsapa\IPWBundle\DataFixtures\ORM;
+
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+use Doctrine\Common\Persistence\ObjectManager;
+use Doctrine\Common\DataFixtures\FixtureInterface;
+
+use FOS\UseBundle\Entity\UserManager;
+
+use Unsapa\IPWBundle\Entity\User;
+use Unsapa\IPWBundle\Entity\Exam;
+use Unsapa\IPWBundle\Entity\Promo;
+use Unsapa\IPWBundle\Entity\Record;
+
+class LoadUserData implements FixtureInterface, ContainerAwareInterface
+{
+ private $container;
+
+ public function setContainer(ContainerInterface $container = null)
+ {
+ $this->container = $container;
+ }
+
+ public function load(ObjectManager $manager)
+ {
+ $promo1 = new Promo();
+ $promo2 = new Promo();
+ $promo3 = new Promo();
+
+ $promo1->setName("2011");
+ $promo2->setName("2012");
+ $promo3->setName("2013");
+
+ $manager->persist($promo1);
+ $manager->persist($promo2);
+ $manager->persist($promo3);
+
+ $exam1_1 = new Exam();
+ $exam1_2 = new Exam();
+ $exam2 = new Exam();
+ $exam3 = new Exam();
+
+ $exam1_1->setPromo($promo1);
+ $exam1_2->setPromo($promo1);
+ $exam2->setPromo($promo2);
+ $exam3->setPromo($promo3);
+
+ $exam1_1->setTitle("MST");
+ $exam1_2->setTitle("MAN");
+ $exam2->setTitle("ILO");
+ $exam3->setTitle("OPT1");
+
+ $exam1_1->setExamDesc("Maths : Statistiques");
+ $exam1_2->setExamDesc("Maths : Analyse Numérique");
+ $exam2->setExamDesc("Informatique : Langage Object");
+ $exam3->setExamDesc("Option 1");
+
+ $exam1_1->setExamDate(new \DateTime("2012-05-12 14:00:00"));
+ $exam1_2->setExamDate(new \DateTime("2012-05-20 10:00:00"));
+ $exam2->setExamDate(new \DateTime("2011-12-15 15:00:00"));
+ $exam3->setExamDate(new \DateTime("2011-11-21 8:00:00"));
+
+ $exam1_1->setCoef(1.5);
+ $exam1_2->setCoef(0.5);
+ $exam2->setCoef(2);
+ $exam3->setCoef(1);
+
+ $manager->persist($exam1_1);
+ $manager->persist($exam1_2);
+ $manager->persist($exam2);
+ $manager->persist($exam3);
+
+ $manager->flush();
+
+ $userManager = $this->container->get('fos_user.user_manager');
+ $users = array();
+
+ for($i = 1; $i <= 10; $i++)
+ {
+ $newUser = $userManager->createUser();
+ $newUser->setUsername("user" . $i);
+ $newUser->setUsernameCanonical("user" . $i);
+ $encoder = $this->container->get('security.encoder_factory')->getEncoder($newUser);
+ $password = $encoder->encodePassword('user1' . $i, $newUser->getSalt());
+ $newUser->setPassword($password);
+ $newUser->setEmail("user" . $i . "@example.com");
+ $newUser->addRole("ROLE_STUDENT");
+ $newUser->setEnabled(true);
+ $newUser->setFirstname("User" . $i);
+ $newUser->setLastname("Test");
+ $newUser->setAddress($i . " 5th Avenue");
+ $newUser->setZipCode($i . $i . $i . "NY");
+ $newUser->setCity("New York City");
+ $manager->persist($newUser);
+ array_push($users, $newUser);
+ }
+ $manager->flush();
+
+ for($i = 1; $i <= 5; $i++)
+ {
+ $record = new Record();
+ $record->setStudent($users[$i-1]);
+ $record->setExam($exam1_1);
+ $record->setMark(rand(2,19));
+ $manager->persist($record);
+ }
+ for($i = 1; $i <= 5; $i++)
+ {
+ $record = new Record();
+ $record->setStudent($users[$i-1]);
+ $record->setExam($exam1_2);
+ $record->setMark(rand(2,19));
+ $manager->persist($record);
+ }
+ for($i = 1; $i <=3; $i++)
+ {
+ $record = new Record();
+ $record->setStudent($users[$i+4]);
+ $record->setExam($exam2);
+ $record->setMark(rand(2,19));
+ $manager->persist($record);
+ }
+ for($i = 1; $i <=2; $i++)
+ {
+ $record = new Record();
+ $record->setStudent($users[$i+7]);
+ $record->setExam($exam3);
+ $record->setMark(rand(2,19));
+ $manager->persist($record);
+ }
+ }
+}
+
+?>
+

0 comments on commit 27bd266

Please sign in to comment.