Example #1
0
 public function updateAction()
 {
     $tripForm = new Admin_Form_Trip();
     $tripForm->setAction('/admin/trip/update')->setMethod('post');
     // add route element
     $routeModel = new Admin_Model_Route();
     $routes = $routeModel->getRouteIDRouteNameMap();
     $tripForm->addRouteElement($routes);
     // add bus element
     $busModel = new Admin_Model_Bus();
     $buses = $busModel->getBusIDBusRegNumberMap();
     $tripForm->addBusElement($buses);
     if ($this->_request->isPost()) {
         // get trip ID from $_POST
         $id = $this->_request->getParam('tripID');
         $routeID = $this->_request->getParam('route');
         $busID = $this->_request->getParam('bus');
         if ($tripForm->isValid($_POST)) {
             $data = $tripForm->getValues();
             $tripModel = new Admin_Model_Trip();
             // convert from Vietnamese date format to MySQL date format
             $departureTime = TBB_Utility_Date::formatDateTime($data['departureTime'], 'dd-MM-y HH:mm:ss', 'y-MM-dd HH:mm:ss');
             $arrivalTime = TBB_Utility_Date::formatDateTime($data['arrivalTime'], 'dd-MM-y HH:mm:ss', 'y-MM-dd HH:mm:ss');
             $tripModel->updateTrip($data['tripID'], $routeID, $busID, $departureTime, $arrivalTime, $data['fare']);
             $this->_redirect('/admin/trip/list');
         }
     } else {
         // get trip ID from URL
         $id = $this->_request->getParam('id');
     }
     // populate form
     $tripModel = new Admin_Model_Trip();
     $tripRow = $tripModel->find($id)->current();
     if ($tripRow) {
         $tripForm->getElement('tripID')->setValue($tripRow->trip_id);
         // convert from MySQL date format to Vietnamese date format
         $departureTime = TBB_Utility_Date::formatDateTime($tripRow->departure_time);
         $arrivalTime = TBB_Utility_Date::formatDateTime($tripRow->arrival_time);
         $tripForm->setRouteValue($tripRow->route_id);
         $tripForm->setBusValue($tripRow->bus_id);
         $tripForm->getElement('departureTime')->setValue($departureTime);
         $tripForm->getElement('arrivalTime')->setValue($arrivalTime);
         $tripForm->getElement('fare')->setValue($tripRow->fare);
     }
     $this->view->form = $tripForm;
 }
Example #2
0
 public function deleteAction()
 {
     $id = $this->_request->getParam('id');
     $routeModel = new Admin_Model_Route();
     try {
         $routeModel->deleteRoute($id);
     } catch (Exception $e) {
         return TBB_Utility_Redirector::redirect($e->getMessage(), 'admin', 'error', 'fatal-error');
     }
     return $this->_redirect('/admin/route/list');
 }