public function actionAdd($id, $access_code = null)
 {
     $session = new Session();
     if (!($ticket = Ticket::findOne($id))) {
         $session->addError(Yii::t('app', 'Ticket does not exist'));
         return $this->redirect('index');
     }
     if ($ticket->requires_access_code && (count($ticket->accessCodes) == 0 || $access_code == null)) {
         $session->addError(Yii::t('app', 'Access code required'));
         return $this->redirect('index');
     } else {
         if ($ticket->requires_access_code) {
             $code_match = false;
             foreach ($ticket->accessCodes as $code) {
                 if ($code->access_code == $access_code) {
                     $code_match = true;
                     break;
                 }
             }
             if (!$code_match) {
                 $session->addError(Yii::t('app', 'Valid access code required'));
                 return $this->redirect('index');
             }
         }
     }
     $cart = Cart::getCurrentCart();
     $cart->addItem($id);
     $session->addSuccess(Yii::t('app', 'Ticket added'));
     return $this->redirect('index');
 }
 /**
  * Finds the Ticket model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ticket the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Ticket::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 public function cleanUp()
 {
     $items = $this->getItems()->all();
     $items_removed = false;
     foreach ($items as $item) {
         $ticket = Ticket::findOne($item->ticket_id);
         if (!$ticket->isAvailable()) {
             $this->removeItem($item->ticket_id);
             $items_removed = true;
         } else {
             if ($ticket->getAvailableQuantity() !== false && $item->quantity > $ticket->getAvailableQuantity()) {
                 $this->updateItem($item->ticket_id, $ticket->getAvailableQuantity());
                 $items_removed = true;
             }
         }
     }
     if ($items_removed) {
         $session = new Session();
         $session->addError(Yii::t('app', 'Unavailable tickets removed'));
     }
 }
 /**
  * Finds the Ticket model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $idTicket
  * @param integer $MotivoTicket_idMotivoTicket
  * @param integer $RRHH_idRRHH
  * @param integer $tiporrhh_idTipoRRHH
  * @param integer $Transporte_idTransporte
  * @param integer $Transporte_TIpoTransporte_idTIpoTransporte
  * @param integer $Transporte_RRHH_idRRHH
  * @param integer $Transporte_tiporrhh_idTipoRRHH
  * @return Ticket the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($idTicket, $MotivoTicket_idMotivoTicket, $RRHH_idRRHH, $tiporrhh_idTipoRRHH, $Transporte_idTransporte, $Transporte_TIpoTransporte_idTIpoTransporte, $Transporte_RRHH_idRRHH, $Transporte_tiporrhh_idTipoRRHH)
 {
     if (($model = Ticket::findOne(['idTicket' => $idTicket, 'MotivoTicket_idMotivoTicket' => $MotivoTicket_idMotivoTicket, 'RRHH_idRRHH' => $RRHH_idRRHH, 'tiporrhh_idTipoRRHH' => $tiporrhh_idTipoRRHH, 'Transporte_idTransporte' => $Transporte_idTransporte, 'Transporte_TIpoTransporte_idTIpoTransporte' => $Transporte_TIpoTransporte_idTIpoTransporte, 'Transporte_RRHH_idRRHH' => $Transporte_RRHH_idRRHH, 'Transporte_tiporrhh_idTipoRRHH' => $Transporte_tiporrhh_idTipoRRHH])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }