Example #1
0
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendHotelsModel::exists('hotels', $this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get data
         $this->record = (array) BackendHotelsModel::getRecord('hotels', $this->id);
         if ($this->record['image']) {
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/hotels/images';
             BackendModel::deleteThumbnails($imagePath, $this->record['image']);
         }
         $rooms = BackendHotelsModel::getRecords('hotels_rooms', $this->id, 'hotel_id = ?');
         foreach ($rooms as $room) {
             $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
             BackendModel::deleteThumbnails($imagePath, $room['image']);
         }
         // delete rooms
         BackendHotelsModel::deleteRecord('hotels_rooms', $this->id, 'hotel_id = ?');
         // delete item
         BackendHotelsModel::deleteRecord('hotels', $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']);
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
 }