push block publicite

This commit is contained in:
Florent C 2015-08-13 12:41:23 +02:00
parent f29b4a08ea
commit cabf5b8a36
10 changed files with 321 additions and 71 deletions

View File

@ -147,19 +147,48 @@ class Blockadshooks extends Module
Tools::redirectAdmin($this->context->link->getAdminLink('AdminAds'));
}
public function getIdByPageName($page_name)
{
switch($page_name)
{
case 'postcms':
return Context::getContext()->controller->postcms->id;
break;
case 'postedito':
return Context::getContext()->controller->postedito->id;
break;
case 'categorycms':
return Context::getContext()->controller->categorycms->id;
break;
default: return null; break;
}
}
public function runByHook($hook_name)
{
$page_name = Dispatcher::getInstance()->getController();
return BlockAds::getContentByHook(
$hook_name,
$page_name,
new DateTime(),
$this->getIdByPageName($page_name),
Context::getContext()->language->id
);
}
public function hookDisplayBoxPartenaire1($params)
{
return $this->runByHook('displayBoxPartenaire1');
}
public function hookDisplayBoxPartenaire2($params)
{
return $this->runByHook('displayBoxPartenaire2');
}
public function hookDisplayBoxPartenaire3($params)
{
return $this->runByHook('displayBoxPartenaire3');
}
}

View File

@ -30,4 +30,89 @@ class BlockAds extends ObjectModel
),
);
public function getPublicationsIds($page_name, DateTime $date, $id = null)
{
$sql = 'SELECT ap.id_publication
FROM '._DB_PREFIX_.'ads_publication ap
INNER JOIN '._DB_PREFIX_.'ads_publication_page app
ON ap.id_publication = app.id_publication
AND app.page_name = "'.pSQL($page_name).'"
WHERE ap.id_block_ads = '.(int)$this->id.'
AND ( date_from = "0000-00-00 00:00:00"
OR date_from <= "'.$date->format('Y-m-d H:i:s').'")
AND ( date_to = "0000-00-00 00:00:00"
OR date_to >= "'.$date->format('Y-m-d H:i:s').'")
AND active = 1
GROUP BY ap.id_publication';
$publications = Db::getInstance()->executeS($sql);
if(empty($publications)
|| count($publications) == 0)
{
return array();
}
$publications = array_map(function($line){ return $line['id_publication']; }, $publications);
if(empty($id))
return $publications;
$sql = 'SELECT id_publication, id_free
FROM '._DB_PREFIX_.'ads_publication_other
WHERE page_name = "'.pSQL($page_name).'"
AND id_publication IN ('.implode(',', $publications).')';
$ids_free = Db::getInstance()->executeS($sql);
$publications = array();
foreach($ids_free as $line)
if($line['id_free'] == $id)
{
$publications[$line['id_publication']] = $line['id_publication'];
}
return $publications;
}
public function getPublications($page_name, DateTime $date, $id = null, $id_lang = null)
{
if(empty($id_lang))
$id_lang = Context::getContext()->language->id;
$ids_publications = $this->getPublicationsIds($page_name, $date, $id);
if(count($ids_publications) == 0)
return array();
$collection = new Collection('Publication', $id_lang);
$collection->where('id_publication', 'in', $ids_publications);
return $collection->getResults();
}
public function getContent($page_name, DateTime $date, $id = null, $id_lang = null)
{
if(empty($id_lang))
$id_lang = Context::getContext()->language->id;
$publications = $this->getPublications($page_name, $date, $id, $id_lang = null);
if(count($publications) > 0)
return $publications[0]->content;
return $this->content;
}
public static function getContentByHook($hook_name, $page_name, DateTime $date = null, $id = null, $id_lang = null)
{
if(empty($id_lang))
$id_lang = Context::getContext()->language->id;
$collection = new Collection('BlockAds', $id_lang);
$collection->where('hook_name', '=', $hook_name);
$ads = $collection->getFirst();
if(empty($ads))
return '';
if(empty($date))
$date = new DateTime();
return $ads->getContent($page_name, $date, $id, $id_lang);
}
}

View File

@ -8,6 +8,8 @@ class Publication extends ObjectModel
public $id_block_ads;
public $id_shop;
public $content;
public $active;
public $date_from;
public $date_to;
public $date_add;
@ -21,10 +23,12 @@ class Publication extends ObjectModel
'primary' => 'id_publication',
'multilang' => true,
'fields' => array(
'id_block_ads' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'content' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isAnything'),
'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),

View File

@ -1,6 +1,6 @@
<?php
require(dirname(__FILE__).'/../../blockadshooks.php');
require_once(dirname(__FILE__).'/../../blockadshooks.php');
class AdminAdsController extends ModuleAdminController {
@ -28,6 +28,9 @@ class AdminAdsController extends ModuleAdminController {
),
'label' => array(
'title' => $this->l('Label'),
),
'hook_name' => array(
'title' => $this->l('Hook'),
)
);
@ -46,12 +49,17 @@ class AdminAdsController extends ModuleAdminController {
'title' => $this->l('Save'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Label'),
'name' => 'label',
),
array(
'type' => 'text',
'label' => $this->l('Nom du hook'),
'name' => 'hook_name',
'disabled' => Validate::isLoadedObject($this->object)
),
array(
'type' => 'text',
'label' => $this->l('Width'),
@ -71,66 +79,25 @@ class AdminAdsController extends ModuleAdminController {
)
);
return parent::renderForm();
}
public function renderView()
{
$helper = new HelperList();
if (empty($this->toolbar_title))
$this->initToolbarTitle();
// tocheck
if ($this->object && $this->object->id)
$helper->id = $this->object->id;
// @todo : move that in Helper
$helper->title = $this->l('Liste des publications liées');
$helper->toolbar_btn = array('new' => array(
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
'desc' => $this->l('Add new')
));
$helper->show_toolbar = true;
$helper->toolbar_scroll = false;
$helper->override_folder = $this->tpl_folder;
$helper->actions = array('edit');
$helper->simple_header = $this->list_simple_header;
$helper->bulk_actions = $this->bulk_actions;
$helper->currentIndex = self::$currentIndex;
$helper->className = $this->className;
$helper->table = $this->table;
$helper->name_controller = Tools::getValue('controller');
$helper->orderBy = $this->_orderBy;
$helper->orderWay = $this->_orderWay;
$helper->listTotal = $this->_listTotal;
$helper->shopLink = $this->shopLink;
$helper->shopLinkType = $this->shopLinkType;
$helper->identifier = $this->identifier;
$helper->token = $this->token;
$helper->languages = $this->_languages;
$helper->specificConfirmDelete = $this->specificConfirmDelete;
$helper->imageType = $this->imageType;
$helper->no_link = $this->list_no_link;
$helper->colorOnBackground = $this->colorOnBackground;
$helper->ajax_params = (isset($this->ajax_params) ? $this->ajax_params : null);
$helper->default_form_language = $this->default_form_language;
$helper->allow_employee_form_lang = $this->allow_employee_form_lang;
$helper->multiple_fieldsets = $this->multiple_fieldsets;
$helper->row_hover = $this->row_hover;
$helper->position_identifier = $this->position_identifier;
$helper->position_group_identifier = $this->position_group_identifier;
$helper->controller_name = $this->controller_name;
$helper->list_id = isset($this->list_id) ? $this->list_id : $this->table;
$helper->bootstrap = $this->bootstrap;
// For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions;
$this->helper = $helper;
require(_PS_MODULE_DIR_.'blockadshooks/controllers/admin/AdminAdsPublication.php');
$controller = new AdminAdsPublicationController();
$controller->listByAds(array($this->object->id));
$controller->toolbar_title = $this->l('Liste des publications');
$controller->toolbar_btn['new'] = array(
'href' => Context::getContext()->link->getAdminLink('AdminAdsPublication', true).'&id_default_ads='.$this->object->id.'&addads_publication',
'desc' => $this->l('Add new')
);
$this->context->smarty->assign(array(
'publications_list' => array();
'ads' => $this->object,
'publications_list' => $controller->renderList()
));
return parent::renderView();

View File

@ -1,6 +1,6 @@
<?php
require(dirname(__FILE__).'/../../blockadshooks.php');
require_once(dirname(__FILE__).'/../../blockadshooks.php');
class AdminAdsPublicationController extends ModuleAdminController {
@ -13,6 +13,7 @@ class AdminAdsPublicationController extends ModuleAdminController {
$this->bootstrap = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->_group .= ' GROUP BY app.id_publication';
$this->_select .= ' GROUP_CONCAT(app.page_name) as page_list';
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'ads_publication_page` app ON (app.`id_publication` = a.`id_publication`)';
@ -39,6 +40,14 @@ class AdminAdsPublicationController extends ModuleAdminController {
'date_to' => array(
'title' => $this->l('Date fin'),
),
'active' => array(
'title' => $this->l('Actif'),
'align' => 'text-center',
'active' => 'status',
'type' => 'bool',
'orderby' => false,
'filter_key' => 'a!active'
),
'page_list' => array(
'title' => 'list des pages',
'callback' => 'cleanPageList'
@ -58,20 +67,20 @@ class AdminAdsPublicationController extends ModuleAdminController {
return $content;
}
public function postProcess()
public function processSave()
{
parent::postProcess();
parent::processSave();
if(Tools::isSubmit('submitAddads_publication'))
if (empty($this->errors))
{
$pages = Tools::getValue('pages');
$this->object->setPages($pages);
foreach($pages as $page)
{
$this->object->setPageInfo($page, Tools::getValue('input-'.$page.'', array()));
}
}
}
}
}
public function renderForm()
{
@ -84,7 +93,7 @@ class AdminAdsPublicationController extends ModuleAdminController {
);
}
if(Validate::isLoadedObject($this))
if(Validate::isLoadedObject($this->object))
{
$this->fields_value['pages[]'] = $this->object->getSelectedPages();
}
@ -100,19 +109,43 @@ class AdminAdsPublicationController extends ModuleAdminController {
),
'input' => array(
array(
'type' => 'free',
'name' => 'ads',
'label' => $this->l('Publicité')
),
array(
'type' => 'switch',
'name' => 'active',
'label' => $this->l('Activé'),
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'textarea',
'label' => $this->l('Contenu de la publicité'),
'name' => 'content',
'lang' => true
),
),
array(
'type' => 'date',
'type' => 'datetime',
'label' => $this->l('Date de début'),
'name' => 'date_from',
),
array(
'type' => 'date',
'type' => 'datetime',
'label' => $this->l('Date de fin'),
'name' => 'date_to',
),
@ -155,7 +188,68 @@ class AdminAdsPublicationController extends ModuleAdminController {
)
);
$tpl = $this->createTemplate('input-ads.tpl');
$id_ads = Tools::getValue('id_default_ads', $this->object->id_block_ads);
$ads = null;
if(!empty($id_ads))
$ads = new BlockAds($id_ads, Context::getContext()->language->id);
$tpl->assign(array(
'ads' => $ads
));
$this->fields_value['ads'] = $tpl->fetch();
return parent::renderForm();
}
public function delete()
{
$id = $this->id;
$res = parent::delete();
if($res)
{
Db::getInstance()->delete('ads_publication_page', 'id_publication = '.$id);
Db::getInstance()->delete('ads_publication_other', 'id_publication = '.$id);
}
return $res;
}
public function displayEditLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_edit.tpl');
$tpl->assign(array(
'href' => Context::getContext()->link->getAdminLink('AdminAdsPublication', true).'&'.$this->identifier.'='.$id.'&update'.$this->table,
'action' => $this->l('Modifier'),
));
return $tpl->fetch();
}
public function displayDeleteLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_delete.tpl');
$tpl->assign(array(
'href' => Context::getContext()->link->getAdminLink('AdminAdsPublication', true).'&'.$this->identifier.'='.$id.'&delete'.$this->table,
'action' => $this->l('Supprimer'),
));
return $tpl->fetch();
}
public function setHelperDisplay(Helper $helper)
{
$helper = parent::setHelperDisplay($helper);
return $helper;
}
public function listByAds( $ads_id = array() )
{
if(count($ads_id) == 0)
return;
$this->_where .= ' AND a.id_block_ads IN ('.implode(',', $ads_id).')';
}
}

View File

@ -27,6 +27,7 @@ $sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ads_publication` (
`id_shop` int(11) NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME NOT NULL,
`active` int(11) NOT NULL,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL,
PRIMARY KEY (`id_publication`)

View File

@ -1,7 +1,14 @@
<div class="panel col-lg-12">
<div class="panel-heading">
{l s='Publicité :'} {$ads->label}
</div>
<p>
{l s='Nom technique de la publicité :'} {$ads->hook_name} <br />
{l s='Dimension de la publicité :'} {$ads->width}x{$ads->height}<br />
{l s='Contenu de la publicité : '} {if empty($ads->content[Context::getContext()->language->id])}{l s='Aucun contenu n a été saisi'}{else}<pre>{$ads->content[Context::getContext()->language->id]}</pre>{/if}
<br />
<a href="{$link->getAdminLink('AdminAds', true)}&id_block_ads={$ads->id}&updateads">{l s='Modifier la publicité'}</a>
</p>
</div>
</div>
{$publications_list}

View File

@ -0,0 +1,9 @@
{if empty($ads)}
<p>{l s="Cette publication n'a été reliée à aucun bloc de publicité, merci de saisir ci-dessous l'identifiant de la publicité"}</p>
{l s='identifiant de la publicité :'} <input type="text" name="id_block_ads" value="{Tools::getValue('id_block_ads')}">
{else}
<p>{l s="Cette publication est reliée à la publicité"} <strong>{$ads->label}</strong> ( <a href="{$link->getAdminLink('AdminAds', true)}&id_block_ads={$ads->id}&viewads">{l s='Aller à la publicité'}</a> )
<br />
{l s='Dimension de la publicité :'} {$ads->width}x{$ads->height}
</p>
{/if}

View File

@ -11,6 +11,57 @@ class AdminController extends AdminControllerCore {
parent::setMedia();
$this->addJS(_PS_JS_DIR_.'admin/search.js');
}
public function refresh($file_to_refresh, $external_file)
{
if (self::$is_prestashop_up && $content = Tools::file_get_contents($external_file))
return (bool)@file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content);
self::$is_prestashop_up = false;
return false;
}
protected function filterTabModuleList()
{
static $list_is_filtered = null;
if ($list_is_filtered !== null)
return;
if (!$this->isFresh(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 86400))
file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native'));
if (!$this->isFresh(Module::CACHE_FILE_ALL_COUNTRY_MODULES_LIST, 86400))
file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_ALL_COUNTRY_MODULES_LIST, Tools::addonsRequest('native_all'));
if (!$this->isFresh(Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, 86400))
@file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, Tools::addonsRequest('must-have'));
libxml_use_internal_errors(true);
$country_module_list = @file_get_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
$must_have_module_list = @file_get_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_MUST_HAVE_MODULES_LIST);
$all_module_list = array();
if (!empty($country_module_list) && $country_module_list_xml = simplexml_load_string($country_module_list))
{
$country_module_list_array = array();
if (is_object($country_module_list_xml->module))
foreach ($country_module_list_xml->module as $k => $m)
$all_module_list[] = (string)$m->name;
}
if (!empty($must_have_module_list) && $must_have_module_list_xml = simplexml_load_string($must_have_module_list))
{
$must_have_module_list_array = array();
if (is_object($country_module_list_xml->module))
foreach ($must_have_module_list_xml->module as $l => $mo)
$all_module_list[] = (string)$mo->name;
}
$this->tab_modules_list['slider_list'] = array_intersect($this->tab_modules_list['slider_list'], $all_module_list);
$list_is_filtered = true;
}
}
?>

View File

@ -7,14 +7,17 @@
{hook h='displayPubliciteFooter'}
<div class="col-md-4">
<div class="pub" style="padding: 20px; background:#f1f1f1; margin-bottom:30px;">
{hook h='displayBoxPartenaire1'}
</div>
</div>
<div class="col-md-4">
<div class="pub" style="padding: 20px; background:#f1f1f1; margin-bottom:30px;">
{hook h='displayBoxPartenaire2'}
</div>
</div>
<div class="col-md-4">
<div class="pub" style="padding: 20px; background:#f1f1f1; margin-bottom:30px;">
{hook h='displayBoxPartenaire3'}
</div>
</div>
</div>