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']; }
public function refresh($entity = null) { $app = Application::getInstance(); try { $app['entityManager']->refresh(empty($entity) ? $this : $entity); } catch (Exception $e) { echo $e->getMessage(); exit; } }
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; }
<?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']);