bootstrap = true; $this->table = 'room_type_selling_object'; $this->className = 'RoomTypeSellingObject'; $this->identifier = 'id_room_type_selling_object'; $this->lang = true; $this->context = Context::getContext(); $this->toolbar_title = $this->l('Room Type Selling Objects'); parent::__construct(); $this->fields_list = array( 'id_room_type_selling_object' => array( 'title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs', ), 'name' => array( 'title' => $this->l('Name'), 'align' => 'left', ), 'plural_name' => array( 'title' => $this->l('Plural Name'), 'align' => 'left', ), 'active' => array( 'title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, ), ); $this->addRowAction('edit'); $this->addRowAction('delete'); $this->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash', ), ); } public function initPageHeaderToolbar() { if (!$this->display || $this->display == 'list') { $this->page_header_toolbar_btn['new_room_selling_type'] = array( 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, 'desc' => $this->l('Add new Selling Object', null, null, false), 'icon' => 'process-icon-new', ); } parent::initPageHeaderToolbar(); } public function renderForm() { if (!$this->loadObject(true)) { return; } $this->fields_form = array( 'legend' => array( 'title' => $this->l('Room Type Selling Object'), 'icon' => 'icon-tags', ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'lang' => true, 'required' => true, 'hint' => $this->l('Displayed name for this room type selling object.'), ), array( 'type' => 'text', 'label' => $this->l('Plural Name'), 'name' => 'plural_name', 'lang' => true, 'required' => true, 'hint' => $this->l('Displayed name when more than one is booked.'), ), array( 'type' => 'switch', 'label' => $this->l('Enabled'), 'name' => 'active', 'is_bool' => true, 'default_value' => 1, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled'), ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'), ), ), ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( 'save-and-stay' => array( 'title' => $this->l('Save and stay'), 'name' => 'submitAdd'.$this->table.'AndStay', 'type' => 'submit', 'class' => 'btn btn-default pull-right', 'icon' => 'process-icon-save', ), ), ); return parent::renderForm(); } public function postProcess() { if (Tools::isSubmit('submitAdd'.$this->table) || Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { $languages = Language::getLanguages(false); $defaultLangId = Configuration::get('PS_LANG_DEFAULT'); $objDefaultLanguage = Language::getLanguage((int) $defaultLangId); $idSellingObject = Tools::getValue($this->identifier); if (!trim(Tools::getValue('name_'.$defaultLangId))) { $this->errors[] = $this->l('Name is required at least in ').$objDefaultLanguage['name']; } else { foreach ($languages as $lang) { if (trim(Tools::getValue('name_'.$lang['id_lang']))) { if (!Validate::isGenericName(Tools::getValue('name_'.$lang['id_lang']))) { $this->errors[] = $this->l('Invalid Name in ').$lang['name']; } } } } if (!trim(Tools::getValue('plural_name_'.$defaultLangId))) { $this->errors[] = $this->l('Plural Name is required at least in ').$objDefaultLanguage['name']; } else { foreach ($languages as $lang) { if (trim(Tools::getValue('plural_name_'.$lang['id_lang']))) { if (!Validate::isGenericName(Tools::getValue('plural_name_'.$lang['id_lang']))) { $this->errors[] = $this->l('Invalid Plural Name in ').$lang['name']; } } } } $this->display = $idSellingObject ? 'edit' : 'add'; if (!$this->errors) { parent::postProcess(); } } else { parent::postProcess(); } } public function processDelete() { $object = $this->loadObject(); if (!$this->checkDeletion($object)) { return false; } return parent::processDelete(); } protected function processBulkDelete() { if (is_array($this->boxes) && !empty($this->boxes)) { foreach ($this->boxes as $idSellingObject) { $object = new RoomTypeSellingObject((int) $idSellingObject); if (!$this->checkDeletion($object)) { return false; } } } return parent::processBulkDelete(); } protected function checkDeletion($object) { if (Validate::isLoadedObject($object)) { if ($object->isUsed()) { $this->errors[] = $this->l('You cannot delete this room type selling object because it is currently assigned to one or more room types.'); } else { return true; } } else { $this->errors[] = Tools::displayError('An error occurred while deleting the object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } return false; } }