コード例 #1
0
ファイル: actions.class.php プロジェクト: pmoutet/navinum
 /**
  * Updates a Visite object
  * @param   sfWebRequest   $request a request object
  * @return  string
  */
 public function executeUpdate(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod(sfRequest::POST));
     $content = $request->getContent();
     // Restores backward compatibility. Content can be the HTTP request full body, or a form encoded "content" var.
     if (strpos($content, 'content=') === 0) {
         $content = $request->getParameter('content');
     }
     $parameters = $this->parsePayload($content, true);
     if (isset($parameters['connexion_id'])) {
         $connexion_id = $parameters['connexion_id'];
         unset($parameters['connexion_id']);
     }
     $is_ending = false;
     if (isset($parameters['is_ending'])) {
         $is_ending = $parameters['is_ending'];
         unset($parameters['is_ending']);
     }
     $navinum_id = $parameters['navinum_id'];
     $visiteur_id = $parameters['visiteur_id'];
     if (isset($parameters['parcours_id']) && !$parameters['parcours_id']) {
         unset($parameters['parcours_id']);
     }
     $serializer = $this->getSerializer();
     $content = $serializer->serialize($parameters);
     $request->setRequestFormat('html');
     try {
         $this->validateUpdate($content);
     } 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;
     }
     if ($navinum_id) {
         $q = Doctrine_Query::create()->from('Rfid rfid');
         $chaine = '';
         for ($i = 0; $i < strlen($navinum_id) - 1; $i += 2) {
             $chaine[] = $navinum_id[$i] . $navinum_id[$i + 1];
         }
         $inverted = implode("", array_reverse($chaine));
         $q->andWhere('(rfid.uid = ? OR rfid.uid = ? )', array($navinum_id, $inverted));
         $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
         if (count($result)) {
             $navinum_id = $result[0]['uid'];
             $this->getRequest()->setParameter('navinum_id', $navinum_id);
         } else {
             throw new sfException('Unknown rfid ' . $navinum_id);
         }
     }
     $this->object = Doctrine_Core::getTable($this->model)->createQuery('v')->where('v.navinum_id = ?', $navinum_id)->andWhere('v.visiteur_id = ?', $visiteur_id)->andWhere('v.guid != ""')->fetchOne();
     if (!$this->object) {
         $this->object = $this->createObject();
         $this->object->set('guid', Guid::generate());
     }
     if (isset($parameters['exposition_id']) && $this->object->getExpositionId() === null) {
         $this->object->set('exposition_id', $parameters['exposition_id']);
         $exposition = Doctrine_Core::getTable('Exposition')->findOneBy('guid', $parameters['exposition_id']);
         if ($exposition != false && $exposition->getUniversId() != null) {
             $univers_id = $exposition->getUniversId();
             $contexte_id = $exposition->getContexteId();
             // find visiteur medaille for univers
             $nb_visiteur_medailles = Doctrine_Core::getTable('VisiteurMedaille')->createQuery('vm')->select('count(*) count')->where('vm.univers_id = ?', $univers_id)->addWhere('vm.visiteur_id = ?', $visiteur_id)->count();
             if ($nb_visiteur_medailles == 0) {
                 // medaille first medaille to insert
                 $first_medaille = Doctrine_Core::getTable('UniversMedaille')->createQuery('um')->select('um.medaille_id')->leftJoin('um.Medaille m')->where('um.univers_id = ?', $univers_id)->andWhere('m.is_first_medaille = 1')->limit(1)->fetchOne();
                 if ($first_medaille != false && $first_medaille->getMedailleId() != null) {
                     // insert visiteur medaille
                     VisiteurMedailleTable::createVisiteurMedaille($visiteur_id, $first_medaille->getMedailleId(), $univers_id, $contexte_id);
                     $univers_status = Doctrine_Core::getTable('UniversStatus')->createQuery('us')->where('us.univers_id = ?', $univers_id)->orderBy('level asc')->limit(1)->fetchOne();
                     if ($univers_status != false && $univers_status->getGuid() != null) {
                         $gain_id = null;
                         $expiration_days = 0;
                         if ($univers_status->getGainId() != null) {
                             $gain_id = $univers_status->getGainId();
                             $expiration_days = $univers_status->getGain()->getExpirationDays();
                         }
                         VisiteurUniversStatusGainTable::setNewVisiteurUniversStatus($univers_status->getGuid(), $univers_id, $visiteur_id, $gain_id, $expiration_days, $contexte_id);
                     }
                 }
             }
         }
     }
     // update and save it
     $this->updateObjectFromRequest($content);
     $this->object->set('navinum_id', $navinum_id);
     $this->object->set('visiteur_id', $visiteur_id);
     // Is there rfidGroup
     if (!isset($parameters['groupe_id'])) {
         $groupe = Doctrine_Query::create()->select('rfgv.guid as groupe_visiteur_id, rfid.uid as navinum_id, rfg.guid as groupe_id')->from('Rfid rfid, RfidGroupe rfg, RfidGroupeVisiteur rfgv')->where('rfid.uid = ?', $navinum_id)->andWhere('rfid.groupe_id = rfg.guid')->andWhere('rfgv.rfid_groupe_id = rfg.guid')->orderBy('rfgv.created_at desc')->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
         if (is_array($groupe) && isset($groupe['groupe_visiteur_id']) && !empty($groupe['groupe_visiteur_id'])) {
             $this->object->set('groupe_id', $groupe['groupe_visiteur_id']);
         }
     }
     $response = $this->doSave();
     if (isset($connexion_id) && !empty($connexion_id)) {
         // Notify websocket server
         caNotificationsTools::getInstance()->notifyAuth($this->object['guid'], $connexion_id);
     }
     if (isset($is_ending) && $is_ending == true) {
         // Notify websocket server
         caNotificationsTools::getInstance()->notifyReset($this->object['guid']);
     }
     return $response;
 }
コード例 #2
0
ファイル: Visiteur.class.php プロジェクト: pmoutet/navinum
 public function setFirstUniversStatus()
 {
     if ($univers_id = sfConfig::get('app_cyou_univers_id', 'CE81341D20E16C61E60DB52BF5F466D1')) {
         // medaille first medaille to insert
         $first_medaille = Doctrine_Core::getTable('UniversMedaille')->createQuery('um')->select('um.medaille_id')->leftJoin('um.Medaille m')->where('um.univers_id = ?', $univers_id)->andWhere('m.is_first_medaille = 1')->limit(1)->fetchOne();
         if ($first_medaille !== false && $first_medaille->getMedailleId() !== null) {
             // insert visiteur medaille
             VisiteurMedailleTable::createVisiteurMedaille($this->getGuid(), $first_medaille->getMedailleId(), $univers_id, $this->getContexteCreationId());
             $univers_status = Doctrine_Core::getTable('UniversStatus')->createQuery('us')->where('us.univers_id = ?', $univers_id)->orderBy('level asc')->limit(1)->fetchOne();
             if ($univers_status !== false && $univers_status->getGuid() !== null) {
                 $gain_id = null;
                 $expiration_days = 0;
                 if ($univers_status->getGainId() != null) {
                     $gain_id = $univers_status->getGainId();
                     $expiration_days = $univers_status->getGain()->getExpirationDays();
                 }
                 VisiteurUniversStatusGainTable::setNewVisiteurUniversStatus($univers_status->getGuid(), $univers_id, $this->getGuid(), $gain_id, $expiration_days, $this->getContexteCreationId());
                 //LogVisiteTable::createLogVisite($this->getGuid(), '999', $this->getContexteCreationId());
                 XpTable::createXp(XpTable::TYPO_CONNAISSANCE, $this->getGuid(), '333');
                 XpTable::createXp(XpTable::TYPO_PLAISIR, $this->getGuid(), '333');
                 XpTable::createXp(XpTable::TYPO_ECHANGE, $this->getGuid(), '333');
             }
         }
     }
 }