reassurance

This commit is contained in:
Nolwenn 2016-06-08 17:11:44 +02:00
parent 6c7a4b5a5f
commit 5a27c87b0e
14 changed files with 695 additions and 1 deletions

View File

@ -0,0 +1,134 @@
<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__) . '/classes/AdvRea.php');
class AdvReassurance extends Module
{
public function __construct()
{
$this->name = 'advreassurance';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Reassurance avancé');
$this->description = $this->l('Gestion des blocks reassurance');
}
public function install()
{
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance` (
`id_reassurance` int(10) unsigned NOT NULL auto_increment,
`position` INT(11) UNSIGNED NOT NULL default 0,
`active` INT(11) UNSIGNED NOT NULL default 1,
PRIMARY KEY (`id_reassurance`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance_lang` (
`id_reassurance` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`subtitle` varchar(255) NOT NULL,
`url` varchar(255),
PRIMARY KEY (`id_reassurance`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance_shop` (
`id_reassurance` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_reassurance`, `id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$tab = new Tab();
$tab->class_name = 'AdminAdvReassurance';
$tab->id_parent = Tab::getCurrentParentId();
$tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$tab->name[$language['id_lang']] = 'Reassurance';
}
$img_dir = _PS_IMG_DIR_ . 'reassurance';
$folder = is_dir($img_dir);
if (!$folder)
{
$folder = mkdir($img_dir, 0755, true);
}
return parent::install() && $tab->add() && $this->registerHook('displayReassurance') && $this->registerHook('actionRefreshReassurance') && $folder;
}
public function uninstall()
{
$sql = 'DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'advreassurance_lang`,
`' . _DB_PREFIX_ . 'advreassurance_shop`,
`' . _DB_PREFIX_ . 'advreassurance`
';
Db::getInstance()->Execute($sql);
$idTab = Tab::getIdFromClassName('AdminAdvReassurance');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
return parent::uninstall();
}
public function assignBlocks()
{
$blocks = AdvRea::getBlocks();
if (!$blocks)
{
return false;
}
$this->smarty->assign('blocks', $blocks);
}
public function hookDisplayReassurance($params)
{
if (!$this->isCached('advreassurance.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance.tpl', $this->getCacheId());
}
public function hookDisplayReassuranceBottom($params)
{
if (!$this->isCached('advreassurance-bottom.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance-bottom.tpl', $this->getCacheId());
}
public function hookActionRefreshReassurance()
{
$this->_clearCache('advreassurance');
}
}

View File

@ -0,0 +1,133 @@
<?php
class AdvRea extends ObjectModel {
public $id_reassurance;
public $position;
public $active;
public $title;
public $subtitle;
public $url;
public static $definition = array(
'table' => 'advreassurance',
'primary' => 'id_reassurance',
'multilang' => TRUE,
'fields' => array(
'id_reassurance' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
// Lang fields
'title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'size' => 255),
'subtitle' => array('type' => self::TYPE_HTML, 'lang' => TRUE, 'validate' => 'isCleanHtml'),
'url' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isUrl', 'size' => 255)
)
);
public function __construct($id = NULL, $id_lang = NULL, $id_shop = NULL) {
parent::__construct($id, $id_lang, $id_shop);
$this->image_dir = _PS_IMG_DIR_ . 'reassurance/';
}
public function add($null_values = false, $autodate = true)
{
$result = parent::add($null_values, $autodate);
Hook::exec('actionRefreshReassurance');
return $result;
}
public function update($null_values = FALSE) {
$result = parent::update($null_values);
Hook::exec('actionRefreshReassurance');
return $result;
}
public function delete($null_values = FALSE) {
$result = parent::delete($null_values);
Hook::exec('actionRefreshReassurance');
return $result;
}
public static function getBlocks()
{
$context = Context::getContext();
$reassurances = Db::getInstance()->executeS('
SELECT *
FROM `'._DB_PREFIX_.'advreassurance` adv
JOIN `'._DB_PREFIX_.'advreassurance_lang` advl ON adv.`id_reassurance` = advl.`id_reassurance` AND id_lang = '. (int)$context->language->id . '
WHERE adv.`active` = 1
ORDER BY `position` ASC
');
return $reassurances;
}
public function cleanPositions(){
return Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'advreassurance`
SET `position`= `position` - 1
WHERE `id_reassurance` = '.(int)$this->id_reassurance.'
AND `position` > '.(int)$this->position);
}
public function updatePosition($way, $position)
{
$sql = 'SELECT `position`, `id_reassurance`
FROM `'._DB_PREFIX_.'advreassurance`
ORDER BY `position` ASC';
if (!$res = Db::getInstance()->executeS($sql))
return false;
foreach ($res as $row)
if ((int)$row['id_reassurance'] == (int)$this->id_reassurance)
$moved_row = $row;
if (!isset($moved_row) || !isset($position))
return false;
// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
$res = Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'advreassurance`
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
AND `position`
'.($way
? '> '.(int)$moved_row['position'].' AND `position` <= '.(int)$position
: '< '.(int)$moved_row['position'].' AND `position` >= '.(int)$position)
)
&& Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'advreassurance`
SET `position` = '.(int)$position.'
WHERE `id_reassurance`='.(int)$moved_row['id_reassurance']
);
$this->refreshPositions();
Hook::exec('actionRefreshReassurance');
return $res;
}
public function refreshPositions(){
$sql = 'SELECT `id_reassurance`
FROM `'._DB_PREFIX_.'advreassurance`
ORDER BY `position` ASC';
if (!$blocks = Db::getInstance()->executeS($sql))
return false;
$pos=0;
foreach ($blocks as $block) {
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'advreassurance`
SET `position` = '.(int)$pos.'
WHERE `id_reassurance`='.(int)$block['id_reassurance']);
$pos++;
}
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>advreassurance</name>
<displayName><![CDATA[Reassurance avanc&eacute;]]></displayName>
<version><![CDATA[1.0]]></version>
<description><![CDATA[Gestion des blocks reassurance]]></description>
<author><![CDATA[Antadis]]></author>
<tab><![CDATA[front_office_features]]></tab>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>

View File

@ -0,0 +1,243 @@
<?php
include_once dirname(__FILE__).'/../../classes/AdvRea.php';
class AdminAdvReassuranceController extends ModuleAdminController {
public function __construct() {
$this->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'),
),
'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;
}
}
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -0,0 +1,3 @@
<!-- Block Advmenu module -->
<!-- /Block Advmenu module -->

View File

@ -2344,7 +2344,7 @@ main#categorycms { margin-bottom: 30px }
font-family: 'pompiere_regular';
}
#reassurance_home_store {
/*#reassurance_home_store {
padding: 15px 0;
background: url('../img/bg_reassurance_store.jpg') no-repeat top center;
-webkit-background-size: contain;
@ -2374,8 +2374,85 @@ main#categorycms { margin-bottom: 30px }
}
#reassurance_home_store .bloc1 {
padding-top: 15px;
}*/
/*************************************************************************************************************
************************************* #REASSURANCE ****************************************
**************************************************************************************************************/
#advReassurance {
margin-top: 50px;
}
#advReassurance .ctn {
padding-right: 15px;
padding-left: 15px;
}
#advReassurance li {
padding-left: 85px;
text-align: left;
background-position: 15px 0px;
background-repeat: no-repeat;
font-size: 15px;
}
#advReassurance span.title {
font-weight: 200;
display: inline-block;
width: auto;
font-size: 22px;
line-height: 26px;
text-transform: none;
padding-top: 0;
padding-bottom: 5px;
background: none;
font-family: "pompiere_regular";
color: #4d4d4d;
text-align: left;
height: auto;
text-transform: uppercase;
}
#footer #advReassurance .title { padding-bottom: 15px; }
#advReassurance .subtitle {
display: block;
line-height: 18px;
font-size: 15px;
text-align: left;
width: auto;
}
#index main #advReassurance .subtitle { color: #666; }
#footer #advReassurance .subtitle { line-height: 21px; }
@media(max-width: 1170px) and (min-width: 990px) {
#footer #advReassurance .title { height: 50px; }
}
@media(max-width: 990px) and (min-width: 767px) {
#advReassurance .title { font-size: 18px; }
#advReassurance .subtitle { font-size: 13px; }
#footer #advReassurance .title { height: 50px; }
}
@media(max-width: 480px) {
#advReassurance span p { font-size: 13px; }
#advReassurance li { padding-bottom: 5px; background-position: 10px 0px; padding-top: 0; padding-left: 80px; text-align: left; line-height: 17px; }
#advReassurance .subtitle { padding-bottom: 15px; }
#advReassurance { padding-top: 30px; }
#footer #advReassurance .subtitle { line-height: 18px;}
#footer #advReassurance .title { padding-bottom: 3px;}
}
/*************************************************************************************************************
************************************* #manufacturers ****************************************
**************************************************************************************************************/
#manufacturers > div {
margin: 5px 0;
}

View File

@ -1,3 +1,8 @@
<div class="container">
<div >
{hook h="displayReassurance"}
</div>
</div>
{if !isset($content_only) || !$content_only}
{if $page_name != 'order'}
<div class="container">

View File

@ -0,0 +1,16 @@
<!-- Block Advmenu module -->
{if $blocks}
<ul class="row">
{foreach from=$blocks item=block key=key}
<li class="md3 sm6 xs6 xxs6">
<span class="title">{$block.title}</span>
<span class="subtitle">{$block.subtitle}</span>
</li>
{/foreach}
<li class="md3 sm6 xs6 xxs6">
<span class="title hidden-lg hidden-md hidden-sm">{l s='Reviews' mod='advreassurance'}</span>
<img src="{$base_dir}img/verified-reviews.png" alt="">
</li>
</ul>
{/if}
<!-- /Block Advmenu module -->

View File

@ -0,0 +1,17 @@
<!-- Block Advreassurance module -->
<div id="advReassurance" class="reassurance">
<div class="inner">
{if $blocks}
<ul class="row">
{foreach from=$blocks item=block key=key}
<li class="col-lg-3 col-md-3 col-sm-6 col-xs-6 col-xxs-12" style="background-image: url({$base_dir}img/reassurance/{$block.id_reassurance}.jpg);">
<span class="title">{$block.title}<br/></span>
<span class="subtitle">{$block.subtitle}</span>
</li>
{/foreach}
</ul>
{/if}
</div>
</div>
<!-- /Block Advreassurance module -->

View File

@ -0,0 +1,5 @@
<?php
global $_MODULE;
$_MODULE = array();
$_MODULE['<{advreassurance}pierimport>advreassurance-bottom_34e80a799d144cfe4af46815e103f017'] = 'Avis client';