Exemple #1
0
 /**
  *  Retrieve array ( options => hits ) 
  * 
  * @param Poll $poll
  * @return array
  */
 public function getResult(Poll $poll)
 {
     $result = array();
     $em = $this->getEntityManager();
     $_results = $em->createQuery(' SELECT o, COUNT(h) AS hits FROM  Desarrolla2\\PollBundle\\Entity\\PollOption o ' . ' LEFT JOIN  o.hits h JOIN o.poll p WHERE p.id = :poll_id ' . ' GROUP BY o ORDER BY hits DESC')->setParameter('poll_id', $poll->getId())->getResult();
     foreach ($_results as $_result) {
         array_push($result, array('id' => $_result[0]->getId(), 'title' => $_result[0]->getTitle(), 'hits' => $_result['hits']));
     }
     return $result;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 10; $i++) {
         $p = new Poll();
         $p->setTitle('Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
         $p->setBody('Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.');
         $p->setIsActive(round(rand(0, 1)));
         $manager->persist($p);
         $o = new PollOption();
         $o->setPoll($p);
         $o->setTitle('Contrary to popular belief.');
         $manager->persist($o);
         $o = new PollOption();
         $o->setPoll($p);
         $o->setTitle('Lorem Ipsum is not simply random text.');
         $manager->persist($o);
         $o = new PollOption();
         $o->setPoll($p);
         $o->setTitle('It has roots in a piece of classical ');
         $manager->persist($o);
     }
     $manager->flush();
 }