/**
  * Class constructor
  * 
  * @param string $action
  * @param mixed $urlvalues
  */
 public function __construct($action, $urlvalues)
 {
     $this->action = $action;
     $this->urlvalues = $urlvalues;
     // initialize the entityManage to be use by all child classes(Controller)
     $this->entityManager = Doctrine::getEntityManager();
 }
Example #2
0
 /**
  * Возвращает EntityManager
  * @param bool $smart
  * @param string $path_to_entity
  * @param string $proxyPath
  * @param string $proxyNamespace
  * @return \Doctrine\ORM\EntityManager
  */
 public static function getEntityManager($smart = FALSE, $path_to_entity = null, $proxyPath = null, $proxyNamespace = null)
 {
     return Doctrine::getEntityManager($smart, $path_to_entity, $proxyPath, $proxyNamespace);
 }
Example #3
0
 /**
  * Получает следующий вопрос, жаль что приходится в этом случае использовать нативный sql, но без него нормально не сделать
  * @param Request $request
  * @param Doctrine $doctrine
  * @return array | bool true если вопросы закончились
  */
 public static function getNextQuestion($request, $doctrine)
 {
     $session = $request->getSession();
     $n = $session->get(self::CURRENT_QUESTION);
     //если заданы все вопросы, вернуть true
     if ($n == self::QUESTIONS_LIMIT) {
         return true;
     }
     $result = array();
     $notIn = $session->get(self::LAST_QUESTIONS, array(0));
     $sNotIn = join(',', $notIn);
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('SkyengTT\\SkyengTTBundle\\Entity\\Vocabulary', 'v');
     $rsm->addFieldResult('v', 'id', 'id');
     $rsm->addFieldResult('v', 'eng_word', 'eng_word');
     $rsm->addFieldResult('v', 'rus_word', 'rus_word');
     $rsm->addFieldResult('v', 'answer_id', 'answer_id');
     $questionResult = $doctrine->getEntityManager()->createNativeQuery("SELECT v.id, v.eng_word, v.rus_word, v.answer_id FROM vocabulary AS v WHERE v.id NOT IN ({$sNotIn}) ORDER BY RANDOM() LIMIT 1", $rsm)->getResult();
     $answerLangWord = 'getRusWord';
     $questionLangWord = 'getEngWord';
     if (rand(0, 1000) % 2 != 0) {
         $buf = $answerLangWord;
         $answerLangWord = $questionLangWord;
         $questionLangWord = $buf;
     }
     if ($questionResult) {
         $question = current($questionResult);
         $questionId = $question->getId();
         $notIn[$questionId] = $questionId;
         $session->set(self::LAST_QUESTIONS, $notIn);
         $answerResult = $doctrine->getEntityManager()->createNativeQuery("SELECT v.id, v.eng_word, v.rus_word, v.answer_id FROM vocabulary AS v WHERE id != {$questionId} ORDER BY RANDOM() LIMIT 4", $rsm)->getResult();
         $result['answers'] = array();
         $result['question'] = array('id' => $question->getId(), 'word' => $question->{$questionLangWord}());
         foreach ($answerResult as $item) {
             if ($item->getId() != $question->getId()) {
                 $result['answers'][] = array('word' => $item->{$answerLangWord}(), 'id' => $item->getAnswerId());
             }
         }
         $k = rand(0, 3);
         $result['answers'][$k] = array('word' => $question->{$answerLangWord}(), 'id' => $question->getAnswerId());
     }
     $session->set(self::CURRENT_QUESTION, $n + 1);
     return $result;
 }
 public function __construct(Doctrine $doctrine)
 {
     $this->em = $doctrine->getEntityManager();
 }
 /**
  * Creates pager from query builder or query
  *
  * @param QueryBuilder $qb
  * @param ParameterBag $params
  * 
  * @return Pager
  */
 public function fromQuery(QueryBuilder $qb, ParameterBag $params)
 {
     return $this->getNewPager($params, $this->doctrine->getEntityManager())->setQueryBuilder($qb);
 }