Пример #1
0
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             $item = [];
             $item['title'] = $fields['title']->getValue();
             $item['capacity'] = $fields['capacity']->getValue();
             $item['price'] = $fields['price']->getValue();
             $item['count'] = $fields['count']->getValue();
             $item['image'] = null;
             $item['hotel_id'] = $this->id;
             if ($fields['image']->isFilled()) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
                 // create folders if needed
                 $fs = new Filesystem();
                 $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128'));
                 $item['image'] = $fields['image']->getFileName(false) . '.' . $fields['image']->getExtension();
                 $i = 2;
                 while ($fs->exists($imagePath . '/source/' . $item['image'])) {
                     $item['image'] = $fields['image']->getFileName(false) . '(' . $i . ')' . '.' . $fields['image']->getExtension();
                     $i++;
                 }
                 // upload the image & generate thumbnails
                 $fields['image']->generateThumbnails($imagePath, $item['image']);
             }
             $item['id'] = BackendHotelsModel::insertRecord('hotels_rooms', $item);
             $this->redirect(BackendModel::createURLForAction('Rooms') . '&id=' . $this->id . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Пример #2
0
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendHotelsModel::exists('hotels_rooms', $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_rooms', $this->id);
         if ($this->record['image']) {
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
             BackendModel::deleteThumbnails($imagePath, $this->record['image']);
         }
         // delete item
         BackendHotelsModel::deleteRecord('hotels_rooms', $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Rooms') . '&report=deleted&var=' . urlencode($this->record['title'] . '&id=' . $this->record['id']);
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Rooms') . '&error=non-existing&id=' . $this->record['id']);
     }
 }
Пример #3
0
 private function getData()
 {
     $this->record = BackendHotelsModel::getRecord('hotels', $this->id);
 }