Esempio n. 1
0
 public function actionIndex()
 {
     // redirect to poll list
     $this->redirect($this->url('poll.index'));
     return;
     $html = Application::getTemplateEngine()->render('home/index.html', array('link' => $this->url('poll.index')));
     echo $html;
 }
Esempio n. 2
0
 public function updateStat()
 {
     $app = Application::getInstance();
     $dql = "SELECT COUNT(a.answer) AS total, SUM(a.answer) as chosen FROM Answer a WHERE a.variant=:variant";
     $query = $app['entityManager']->createQuery($dql)->setParameter('variant', $this);
     $result = $query->getResult();
     $this->_total = $result[0]['total'];
     $this->_chosen = is_null($result[0]['chosen']) ? 0 : $result[0]['chosen'];
 }
Esempio n. 3
0
 public function actionIndex()
 {
     // message for modelless controller
     if (empty($this->_modelName)) {
         echo get_class($this) . '->actionIndex(): controller without model';
         return;
     }
     // get models list
     $app = Application::getInstance();
     $items = Application::getEntityManager()->findAll();
     // render model view (if it exists) or default view
     $html = Application::getTemplateEngine()->render(strtolower($this->_modelName) . '/index.html', array('items' => $items));
     if ($html === null) {
         // fall to default index view
         $html = $app['templateEngine']->render('default/index.html', array('items' => $items, 'model' => $this->_modelName));
     }
     echo $html;
 }
Esempio n. 4
0
 public function actionStat($id)
 {
     $poll = Poll::findById($id);
     // update statistic for all variants
     foreach ($poll->questions as $question) {
         foreach ($question->variants as $variant) {
             $variant->updateStat();
         }
     }
     $pollObj = $poll->formStdObject();
     $html = Application::getTemplateEngine()->render('poll/stat.html', array('poll' => $pollObj, 'indexUrl' => $this->url('poll.index'), 'showUrl' => $this->url('poll.show', array('id' => $poll->id))));
     echo $html;
 }
Esempio n. 5
0
 public function url($name, $params = array())
 {
     return Application::getRouter()->url($name, $params);
 }
Esempio n. 6
0
<?php

use PollExample\Config;
use PollExample\Application;
require __DIR__ . '/vendor/autoload.php';
// get config
$configArray = (require __DIR__ . '/app/config.php');
$configArray['appDir'] = __DIR__;
$config = Config::getInstance($configArray);
// set debug messages
if (!empty($config['debug'])) {
    error_reporting(E_ALL);
}
$app = Application::getInstance($config);
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($app['entityManager']);