table = 'advsitereviews'; $this->className = 'AdvSiteReview'; $this->identifier = 'id_comment'; $this->lang = true; $this->deleted = false; $this->bootstrap = true; $this->position_identifier = 'id_comment'; $this->_defaultOrderBy = 'position'; $this->fieldImageSettings = array( 'name' => 'image', 'dir' => 'sitereviews' ); parent::__construct(); $this->actions = array('edit', 'delete'); $this->fields_list = array( 'id_comment' => array( 'title' => 'ID', 'width' => 25 ), 'firstname' => array( 'title' => $this->module->l('Prénom'), ), 'lastname' => array( 'title' => $this->module->l('Nom'), ), 'rank' => array( 'title' => $this->module->l('Note'), ), 'content' => array( 'title' => $this->module->l('Contenu'), 'width' => 45, ), 'position' => array( 'title' => $this->l('Position'), 'position' => 'position', 'filter_key' => 'a!position' ), 'active' => array( 'title' => $this->l('Validé'), 'active' => 'status', 'type' => 'bool', 'align' => 'center', 'orderby' => false ) ); if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL){ $this->_join .= 'JOIN `'._DB_PREFIX_.'advsitereviews_shop` as ashop ON a.`id_comment` = ashop.`id_comment` AND ashop.`id_shop` IN ('.implode(', ', Shop::getContextListShopID()).') '; $this->_group .= 'GROUP BY ashop.`id_comment`'; } } public function renderView() { return $this->renderList(); } public function renderForm() { $obj = $this->loadObject(TRUE); $image = FALSE; $image_url = ''; $image_size = ''; if($obj) { $image = _PS_IMG_DIR_ . 'sitereviews/' . $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 = array( 'tinymce' => TRUE, 'legend' => array( 'title' => $this->className, ), 'submit' => array( 'name' => 'submitAdvSlider', 'title' => $this->l('Save'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Prénom'), 'name' => 'firstname', 'lang' => TRUE, ), array( 'type' => 'text', 'label' => $this->l('Nom'), 'name' => 'lastname', 'lang' => TRUE, ), array( 'type' => 'text', 'label' => $this->l('Note'), 'name' => 'rank', ), array( 'type' => 'text', 'label' => $this->module->l('Titre'), 'name' => 'title', 'lang' => TRUE, ), array( 'type' => 'text', 'label' => $this->module->l('Lieu'), 'name' => 'place', 'lang' => TRUE, ), array( 'type' => 'text', 'label' => $this->module->l('Date'), 'name' => 'date', 'lang' => TRUE, ), array( 'type' => 'textarea', 'label' => $this->l('Contenu'), 'name' => 'content', 'autoload_rte' => TRUE, 'lang' => TRUE ), 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' ), array( 'type' => 'switch', 'label' => $this->l('Validé ?'), 'name' => 'active', 'required' => FALSE, 'is_bool' => TRUE, 'default' => 1, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('No'), ) ), ), array( 'type' => 'shop', 'label' => $this->l('Shop'), 'form_group_class' => 'fieldhide input_association', 'name' => 'checkBoxShopAsso_advsitereviews' ) ) ); return parent::renderForm(); } public function postProcess() { if (Tools::getValue('deleteImage')) { $this->processForceDeleteImage(); $this->refreshPreview(); } return parent::postProcess(); } public function refreshPreview() { $current_preview = _PS_TMP_IMG_DIR_.'advsitereviews_'.$this->object->id.'.jpg'; if (file_exists($current_preview)) { unlink($current_preview); } } 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 ajaxProcessUpdatePositions() { $way = (int)(Tools::getValue('way')); $id = (int)(Tools::getValue('id')); $positions = Tools::getValue('review'); $obj = 'advsitereviews'; if (is_array($positions)){ foreach ($positions as $position => $value) { $pos = explode('_', $value); if (isset($pos[2]) && (int)$pos[2] === $id) { $menu_obj = new AdvSiteReview((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; } } } } }