public static function hasNewStatus($visiteur_id, $medaille_id, $contexte_id = null)
 {
     $visiteur_medailles = VisiteurTable::getMedaillesByUnivers($visiteur_id);
     foreach ($visiteur_medailles as $univers_id => $visiteur_medaille) {
         //print_r($visiteur_medaille);
         // exit;
         if (in_array($medaille_id, $visiteur_medaille['Medailles'])) {
             $count_medaille = count($visiteur_medaille['Medailles']);
             foreach ($visiteur_medaille['VisiteurStatus'] as $visiteur_status) {
                 if (isset($visiteur_status['UniversStatus']) && count($visiteur_status['UniversStatus'])) {
                     //$nb_min = $visiteur_status['UniversStatus']['nombre_min'];
                     $nb_max = $visiteur_status['UniversStatus']['nb_medaille'];
                     $current_level = $visiteur_status['UniversStatus']['level'];
                     $next_univers_status = Doctrine_Core::getTable("UniversStatus")->createQuery('us')->where('us.univers_id = ?', $univers_id)->andWhere('us.level = ?', $current_level + 1)->limit(1)->fetchOne();
                     if ($next_univers_status !== false && $count_medaille >= $next_univers_status->getNbMedaille()) {
                         $gain_id = $next_univers_status->getGainId();
                         $expiration_days = 0;
                         if ($gain_id) {
                             $expiration_days = $next_univers_status->getGain()->getExpirationDays();
                         }
                         self::setNewVisiteurUniversStatus($next_univers_status->getGuid(), $univers_id, $visiteur_id, $gain_id, $expiration_days, $contexte_id);
                     }
                 }
                 break;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Retrieves a  collection of Visiteur objects
  * @param   sfWebRequest   $request a request object
  * @return  string
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod(sfRequest::GET));
     $params = $request->getParameterHolder()->getAll();
     //$params['is_active'] = true;
     // notify an event before the action's body starts
     $this->dispatcher->notify(new sfEvent($this, 'sfDoctrineRestGenerator.get.pre', array('params' => $params)));
     $request->setRequestFormat('html');
     $params = $this->cleanupParameters($params);
     try {
         if (empty($params)) {
             throw new sfException("the service must have at least one parameter");
         }
         $format = $this->getFormat();
         $this->validateIndex($params);
     } catch (Exception $e) {
         $this->getResponse()->setStatusCode(406);
         $serializer = $this->getSerializer();
         $this->getResponse()->setContentType($serializer->getContentType());
         $error = $e->getMessage();
         // event filter to enable customisation of the error message.
         $result = $this->dispatcher->filter(new sfEvent($this, 'sfDoctrineRestGenerator.filter_error_output'), $error)->getReturnValue();
         if ($error === $result) {
             $error = array(array('message' => $error));
             $this->output = $serializer->serialize($error, 'error');
         } else {
             $this->output = $serializer->serialize($result);
         }
         return sfView::SUCCESS;
     }
     $isset_pk = (!isset($isset_pk) || $isset_pk) && isset($params['guid']);
     if (!$isset_pk) {
         $params['is_active'] = true;
     }
     $this->queryExecute($params);
     foreach ($this->objects as &$objects) {
         if ($objects['has_photo'] != true) {
             $objects['has_photo'] = false;
         }
         if ($objects['date_naissance'] == '0000-00-00') {
             $objects['date_naissance'] = '';
         }
         //unset($objects['VisiteurMedaille']);
         if ($request->getParameter('with_univers', '0') == '1') {
             $objects['VisiteurUnivers'] = VisiteurTable::getMedaillesByUnivers($objects['guid']);
         }
         // XP
         if ($request->getParameter('with_xp', '0') == '1') {
             $objects['Xp'] = Doctrine_Query::create()->select('xp.score, xp.typologie_id, typo.libelle, xp.updated_at')->from('Xp xp')->leftJoin('xp.Typologie typo')->where('xp.visiteur_id = ?', $objects['guid'])->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
         }
         if ($request->getParameter('with_lastLogVisite', '0') == '1') {
             $logVisite = Doctrine_Query::create()->from('LogVisite lv')->where('lv.visiteur_id = ?', $objects['guid'])->limit(1)->orderBy('lv.created_at desc')->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
             unset($logVisite['updated_at'], $logVisite['is_tosync']);
             $objects['LastLogVisite'] = $logVisite;
             if ($logVisite) {
                 if (isset($logVisite['exposition_id']) && $logVisite['exposition_id'] != null) {
                     $last_univers = Doctrine_Query::create()->select('e.univers_id')->from('Exposition e')->where('e.guid = ?', $logVisite['exposition_id'])->limit(1)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
                     $last_univers = $last_univers['univers_id'];
                 } else {
                     $last_univers = sfConfig::get('app_cyou_univers_id', 'CE81341D20E16C61E60DB52BF5F466D1');
                 }
                 $objects['last_visited_univers_id'] = $last_univers;
             }
         }
     }
     // configure the fields of the returned objects and eventually hide some
     $this->setFieldVisibility();
     $this->configureFields();
     $serializer = $this->getSerializer();
     $this->getResponse()->setContentType($serializer->getContentType());
     $this->output = $serializer->serialize($this->objects, $this->model);
     unset($this->objects);
 }