Exemple #1
0
 /**
  * Entrem a la sessió i guardem un estat si és correcte.
  * Passem una id de sessió o 0 si és nova
  **/
 public function getSessioToEdit()
 {
     $request = $this->getAjaxData();
     $idS = $request['idSessio'];
     $idE = $request['idEspectacle'];
     $EM = new EspectaclesModel();
     //Un espectacle Nou
     if ($idS == 0 && $idE == 0) {
         $ETO = new EspectacleTableObject(null, EspectacleTableObject::FROM_EMPTY);
         $ETO->newBlankEspectacle();
         $STO = new SessioTableObject(null, SessioTableObject::FROM_EMPTY);
         $STO->newBlankSession($ETO);
         $RET = array('Espectacle' => $ETO, 'Sessio' => $STO);
         echo json_encode($RET);
         //Una sessió nova
     } elseif ($idS == 0 && $idE > 0) {
         $ETO = new EspectacleTableObject(null, EspectacleTableObject::FROM_EMPTY);
         $ETO->loadById($idE);
         $STO = new SessioTableObject(null, SessioTableObject::FROM_EMPTY);
         $STO->newBlankSession($ETO);
         $RET = array('Espectacle' => $ETO, 'Sessio' => $STO);
         echo json_encode($RET);
         //Edito una sessió actual
     } elseif ($idS > 0 && $idE > 0) {
         $ETO = new EspectacleTableObject(null, EspectacleTableObject::FROM_EMPTY);
         $ETO->loadById($idE);
         $STO = new SessioTableObject(null, SessioTableObject::FROM_EMPTY);
         $STO->loadById($idS);
         $RET = array('Espectacle' => $ETO, 'Sessio' => $STO);
         echo json_encode($RET);
         //Hi ha hagut un error
     } else {
         throw new MyException("Vols fer una acció que no conec.");
     }
 }