table = 'advreassurance'; $this->className = 'AdvRea'; $this->identifier = 'id_reassurance'; $this->lang = TRUE; $this->deleted = FALSE; $this->bootstrap = TRUE; $this->fieldImageSettings = array( 'name' => 'image', 'dir' => 'reassurance' ); $this->position_identifier = 'id_reassurance'; $this->_defaultOrderBy = 'position'; parent::__construct(); $this->actions = array('edit', 'delete'); $this->fields_list = array( 'id_reassurance' => array( 'title' => 'ID', 'width' => 25 ), 'image' => array( 'title' => $this->module->l('Image'), 'image' => $this->fieldImageSettings['dir'], 'width' => 75 ), 'title' => array( 'title' => $this->module->l('Titre'), ), 'subtitle' => array( 'title' => $this->module->l('Sout-titre'), ), 'url' => array( 'title' => $this->module->l('Url'), 'width' => 45, ), 'position' => array( 'title' => $this->l('Position'), 'align' => 'center', 'position' => 'position', 'filter_key' => 'a!position' ) ); if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL){ $this->_join .= 'JOIN `'._DB_PREFIX_.'advreassurance_shop` as ashop ON a.`id_reassurance` = ashop.`id_reassurance` AND ashop.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') '; $this->_group .= 'GROUP BY ashop.`id_reassurance`'; } } public function initPageHeaderToolbar() { parent::initPageHeaderToolbar(); if ($this->display != 'edit' && $this->display != 'add') { $this->page_header_toolbar_btn['new_link'] = array( 'href' => self::$currentIndex.'&id_parent='.(int)Tools::getValue('id_reassurance').'&addadvreassurance&token='.$this->token, 'desc' => $this->l('Ajouter un nouveau block', NULL, NULL, FALSE), 'icon' => 'process-icon-new' ); } } public function renderView() { return $this->renderList(); } public function renderForm() { $this->fields_form = array( 'tinymce' => TRUE, 'legend' => array( 'title' => $this->className, ), 'submit' => array( 'name' => 'submitAdvReassurancer', 'title' => $this->l('Save'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Titre'), 'name' => 'title', 'lang' => TRUE, ), array( 'type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'subtitle', 'autoload_rte' => TRUE, 'cols' => 100, 'rows' => 6, 'lang' => TRUE, ), array( 'type' => 'text', 'label' => $this->l('Lien'), 'name' => 'url', 'lang' => TRUE ), array( 'type' => 'switch', 'label' => $this->l('Activé'), 'name' => 'active', 'required' => FALSE, 'is_bool' => TRUE, 'default' => 1, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'shop', 'label' => $this->l('Shop'), 'form_group_class' => 'fieldhide input_association', 'name' => 'checkBoxShopAsso_advreassurance' ) ) ); $obj = $this->loadObject(TRUE); $image = FALSE; $image_url = ''; $image_size = ''; if($obj) { $image = _PS_IMG_DIR_ . 'reassurance/' . $obj->id.'.jpg'; $image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350, $this->imageType, TRUE, TRUE); $image_size = file_exists($image) ? filesize($image) / 1000 : FALSE; } $this->fields_form['input'][] = array( 'type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'display_image' => TRUE, 'lang' => TRUE, 'image' => $image_url, 'size' => $image_size, 'delete_url' => self::$currentIndex.'&'.$this->identifier.'='.$this->object->id.'&token='.$this->token.'&deleteImage=1' ); return parent::renderForm(); } protected function copyFromPost(&$object, $table) { parent::copyFromPost($object, $table); if(Shop::isFeatureActive()) { $object->id_shop_list = array(); foreach (Tools::getValue('checkBoxShopAsso_advreassurance') as $id_shop => $value) $object->id_shop_list[] = $id_shop; } } public function postProcess() { if (Tools::getValue('deleteImage')) { $this->processForceDeleteImage(); $this->refreshPreview(); } return parent::postProcess(); } public function processForceDeleteImage() { $link = $this->loadObject(TRUE); if (Validate::isLoadedObject($link)) { $link->deleteImage(TRUE); } } protected function postImage($id) { $ret = parent::postImage($id); $this->refreshPreview(); if (isset($_FILES) && count($_FILES) && $_FILES['image']['name'] != NULL && !empty($this->object->id) ) { return TRUE; } return TRUE; } public function refreshPreview() { $current_preview = _PS_TMP_IMG_DIR_.'advreassurance_mini_'.$this->object->id_reassurance.'_'.$this->context->shop->id.'.jpg'; if (file_exists($current_preview)) { unlink($current_preview); } } public function ajaxProcessUpdatePositions() { $way = (int)(Tools::getValue('way')); $id = (int)(Tools::getValue('id')); $positions = Tools::getValue('slide'); $obj = 'advreassurance'; if (is_array($positions)){ foreach ($positions as $position => $value) { $pos = explode('_', $value); if (isset($pos[2]) && (int)$pos[2] === $id) { $menu_obj = new AdvRea((int)$pos[2]); if (Validate::isLoadedObject($menu_obj)) if (isset($position) && $menu_obj->updatePosition($way, $position)) { echo 'ok position '.(int)$position.' for '.$obj.' '.(int)$pos[2]."\r\n"; } else echo '{"hasError" : true, "errors" : "Can not update '.$obj.' '.(int)$id.' to position '.(int)$position.' "}'; else echo '{"hasError" : true, "errors" : "This '.$obj.' ('.(int)$id.') cannot be loaded"}'; break; } } } } }