Prepare Front

This commit is contained in:
Michael RICOIS 2017-11-10 15:25:44 +01:00
parent df11669618
commit ab97adac66
9 changed files with 220 additions and 136 deletions

View File

@ -14,6 +14,7 @@ class AdminGuideCategories extends AdminTab
public function __construct()
{
global $cookie;
$this->maxImageBytes = (Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1000000);
$this->table = 'guide_category';
@ -56,12 +57,10 @@ class AdminGuideCategories extends AdminTab
);
if (isset($_GET['delete'.$this->table])) {
self::$current_category = new GuideCategory(
(int)(Tools::getValue('id_guide_category_parent', 0)));
self::$current_category = new GuideCategory((int)(Tools::getValue('id_guide_category_parent', 0)));
}
else {
self::$current_category = new GuideCategory((int)(Tools::getValue('id_guide_category',
Tools::getValue('id_guide_category_parent', 0))));
self::$current_category = new GuideCategory((int)(Tools::getValue('id_guide_category', Tools::getValue('id_guide_category_parent', 0))));
}
$this->_filter = 'AND a.`id_parent` = '.(int)(self::$current_category->id);
@ -70,6 +69,61 @@ class AdminGuideCategories extends AdminTab
parent::__construct();
}
protected function _displayEditLink($token = NULL, $id)
{
global $currentIndex;
$_cacheLang['Edit'] = $this->l('Edit');
echo '
<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.
'&token='.($token!=NULL ? $token : $this->token).
(self::$current_category->id==0 ? '' : '&id_guide_category_parent='.self::$current_category->id).'">
<img src="../img/admin/edit.gif" alt="" title="'.$_cacheLang['Edit'].'" /></a>';
}
protected function _displayDeleteLink($token = NULL, $id)
{
global $currentIndex;
$_cacheLang['Delete'] = $this->l('Delete');
$_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE);
echo '
<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'&id_guide_category_parent='.self::$current_category->id.'" onclick="return confirm(\''.$_cacheLang['DeleteItem'].$id.' ?'.
(!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : '').'\');">
<img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a>';
}
protected function _displayViewLink($token = NULL, $id)
{
$category = new GuideCategory($id);
if ($category->id_parent != 0) {
$this->_displayPostLink($token, $id);
}
global $currentIndex;
$_cacheLang['View'] = $this->l('View');
echo '
<a href="'._PS_BASE_URL_SSL_.'/modules/purchaseguide/post.php?cid='.$id.'" target="_blank">
<img src="../img/admin/details.gif" alt="'.$_cacheLang['View'].'" title="'.$_cacheLang['View'].'" /></a>';
}
protected function _displayPostLink($token = NULL, $id)
{
$_cacheLang['Post'] = $this->l('View Post');
$currentIndex = '?tab=AdminGuidePosts';
$token = Tools::getAdminTokenLite('AdminGuidePosts');
echo '
<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.
'&token='.($token!=NULL ? $token : $this->token).'">
<img src="../img/admin/arrow-right.png" alt="" title="'.$_cacheLang['Post'].'" /></a>';
}
public static function getCurrentCategory()
{
@ -81,9 +135,9 @@ class AdminGuideCategories extends AdminTab
global $currentIndex, $cookie, $smarty;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
if (!($obj = $this->loadObject(true))) {
return;
}
$langs = Language::getLanguages(false);
@ -97,14 +151,14 @@ class AdminGuideCategories extends AdminTab
'options_map' => ['id_guide_category', 'name', 'level'],
'empty_option' => ['value'=>'0', 'label'=>$this->l('No parent category')],
'initial_value' => $obj->id_parent?$obj->id_parent:self::$current_category->id
),
),
'id_category_family' => array(
'title' => $this->l('Famille'),
'type' => 'select',
'options_raw' => GuideCategory::findFamiliesTree($cookie->id_lang),
'options_map' => ['id_category_family', 'name', 'level'],
'initial_value' => $obj->id_category_family
),
),
'name' => array(
'title' => $this->l('Title'),
'type' => 'text',
@ -112,13 +166,13 @@ class AdminGuideCategories extends AdminTab
'translatable' => true,
'attrs' => [
'onkeyup' => 'copy2friendlyURL();'
]
),
]
),
'description' => array(
'title' => $this->l('Description'),
'type' => 'textarea',
'translatable' => true,
),
),
'image' => array(
'title' => $this->l('Image'),
'type' => 'file',
@ -127,29 +181,29 @@ class AdminGuideCategories extends AdminTab
'allowed_format' => 'JPEG',
'html_file' => "img",
'path' => $obj->getImageFileUrl().'?rand='.time()
]
),
]
),
'active' => array(
'title' => $this->l('Displayed'),
'type' => 'yesno',
'required' => true,
),
),
'link_rewrite' => array(
'title' => $this->l('Simplified URL'),
'type' => 'text',
'required' => true,
),
),
'meta_title' => array(
'title' => $this->l('Title (META)'),
'type' => 'text',
'translatable' => true,
),
),
'meta_description' => array(
'title' => $this->l('Description (META)'),
'type' => 'textarea',
'translatable' => true,
),
);
),
);
$form->setTitle($this->l('Purchase guide category'));
$form->setFields($this->fieldsForm);
@ -222,31 +276,6 @@ class AdminGuideCategories extends AdminTab
$this->includeSubTab('display');
}
protected function _displayEditLink($token = NULL, $id)
{
global $currentIndex;
$_cacheLang['Edit'] = $this->l('Edit');
echo '
<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&update'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'&id_guide_category_parent='.self::$current_category->id.'">
<img src="../img/admin/edit.gif" alt="" title="'.$_cacheLang['Edit'].'" /></a>';
}
protected function _displayDeleteLink($token = NULL, $id)
{
global $currentIndex;
$_cacheLang['Delete'] = $this->l('Delete');
$_cacheLang['DeleteItem'] = $this->l('Delete item #', __CLASS__, TRUE, FALSE);
echo '
<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&delete'.$this->table.'&token='.($token!=NULL ? $token : $this->token).'&id_guide_category_parent='.self::$current_category->id.'" onclick="return confirm(\''.$_cacheLang['DeleteItem'].$id.' ?'.
(!is_null($this->specificConfirmDelete) ? '\r'.$this->specificConfirmDelete : '').'\');">
<img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a>';
}
public function postProcess()
{
if (isset($_GET['delete'.$this->table]) ||
@ -254,6 +283,10 @@ class AdminGuideCategories extends AdminTab
$this->postProcessDelete();
return;
}
if (self::$current_category->id != 0) {
$this->noLink = true;
}
parent::postProcess();
}

View File

@ -18,50 +18,71 @@ class AdminGuidePosts extends AdminTab
$this->view = true;
$this->delete = true;
$this->fieldsDisplay = array(
'id_guide_post' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'name' => array(
'title' => $this->l('Category'),
'width' => 200,
),
'link_rewrite' => array(
'title' => $this->l('URL'),
'width' => 200
),
'meta_title' => array(
'title' => $this->l('Title'),
'width' => 300
),
'position' => array(
'title' => $this->l('Position'),
'width' => 40,
'filter_key' => 'position',
'align' => 'center',
'position' => 'position'
),
'active' => array(
'title' => $this->l('Enabled'),
'width' => 25,
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
)
);
$this->_select = 'a.position, gcl.name, a.id_guide_category ';
$this->_join = '
$this->identifiersDnd['id_guide_post'] = 'id_guide_post';
parent::__construct();
}
protected function _displayViewLink($token = null, $id)
{
$_cacheLang['View'] = $this->l('View');
echo '
<a href="'._PS_BASE_URL_SSL_.'/modules/purchaseguide/post.php?pid='.$id.'" target="_blank">
<img src="../img/admin/details.gif" alt="'.$_cacheLang['View'].'" title="'.$_cacheLang['View'].'" /></a>';
}
public function postProcess()
{
global $cookie, $currentIndex;
$this->fieldsDisplay = array(
'id_guide_post' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'name' => array(
'title' => $this->l('Category'),
'width' => 200,
),
'link_rewrite' => array(
'title' => $this->l('URL'),
'width' => 200
),
'meta_title' => array(
'title' => $this->l('Title'),
'width' => 300
),
'active' => array(
'title' => $this->l('Enabled'),
'width' => 25,
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
)
);
$this->_select = 'a.`position`, gcl.`name`, a.`id_guide_category` ';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'guide_category` gc
ON gc.`id_guide_category` = a.`id_guide_category`
LEFT JOIN `'._DB_PREFIX_.'guide_category_lang` gcl
ON (gcl.`id_guide_category` = gc.`id_guide_category` AND gcl.`id_lang` = '.(int)($cookie->id_lang).')';
$this->identifiersDnd['id_guide_post'] = 'id_guide_post';
parent::__construct();
if (Tools::getIsset('id_guide_category')) {
$this->fieldsDisplay['position'] = array(
'title' => $this->l('Position'),
'width' => 40,
'filter_key' => 'position',
'align' => 'center',
'position' => 'position'
);
$this->_where = ' AND a.`id_guide_category`='.(int)Tools::getValue('id_guide_category');
$currentIndex.= '&id_guide_category='.(int)Tools::getValue('id_guide_category');
}
parent::postProcess();
}
public function displayList()
@ -126,31 +147,4 @@ class AdminGuidePosts extends AdminTab
$form->display($smarty, $langs, $obj);
}
public function postProcess()
{
global $cookie, $currentIndex;
$link = new Link();
if (Tools::isSubmit('viewguide_post') AND ($id_guide_post = (int)(Tools::getValue('id_guide_post'))) AND $guide_post = new GuidePost($id_guide_post, (int)($cookie->id_lang)) AND Validate::isLoadedObject($guide_post))
{
$redir = $link->getGuideLink($guide_post, null, null,
$cookie->id_lang);
if (!$guide_post->active)
{
$admin_dir = dirname($_SERVER['PHP_SELF']);
$admin_dir = substr($admin_dir, strrpos($admin_dir,'/') + 1);
$redir .= '?adtoken='.Tools::encrypt('PreviewGuidePost'.$guide_post->id).'&ad='.$admin_dir;
}
Tools::redirectAdmin($redir);
}
else {
parent::postProcess();
}
}
}

View File

@ -304,6 +304,17 @@ class GuideCategory extends ObjectModel
return $position;
}
public function findByCategoryFamily($id, $id_lang)
{
$sql = "SELECT gc.*, gcl.name FROM `"._DB_PREFIX_."guide_category` gc, `"._DB_PREFIX_."guide_category_lang` gcl
WHERE gc.id_guide_category=gcl.id_guide_category AND gcl.id_lang=".$id_lang.
" AND gc.id_category_family=".$id;
$row = Db::getInstance()->getRow($sql);
return $row;
}
public function getLinkRewrite()
{
if ($this->id) {
@ -317,6 +328,32 @@ class GuideCategory extends ObjectModel
public function getLinkRewriteUrl(){}
public function getTree($id_lang, $active = 1)
{
return $this->recurseData(0, $id_lang, $active);
}
protected function recurseData($id_category, $id_lang, $active = 1)
{
$data = array();
$sql = "SELECT gc.*, gcl.name FROM `"._DB_PREFIX_."guide_category` gc, `"._DB_PREFIX_."guide_category_lang` gcl
WHERE gc.id_guide_category=gcl.id_guide_category AND gcl.id_lang=".$id_lang.
" AND gc.id_parent=".$id_category." ORDER BY position ASC";
$result = Db::getInstance()->ExecuteS($sql);
if (count($result) > 0) {
foreach ($result as $c) {
$item = array(
'id_guide_category' => $c['id_guide_category'],
'name' => $c['name'],
'children' => $this->recurseData($c['id_guide_category'], $id_lang),
);
$data[] = $item;
}
}
return $data;
}
public function getParent(){}
public function getMainStruct()

View File

@ -1,13 +1,9 @@
<?php
class CategoryController extends FrontController
{
//public function init(){}
//public function preProcess(){}
//public function displayHeader(){}
public function process()
public function preProcess()
{
parent::process();
parent::preProcess();
$id_lang = self::$cookie->id_lang;
$id_category = Tools::getValue('cid', 0);

View File

@ -1,9 +1,11 @@
<?php
require_once(__DIR__.'/../../classes/GuideCategory.php');
class PostController extends FrontController
{
public function process()
public function preProcess()
{
parent::process();
parent::preProcess();
$id_lang = self::$cookie->id_lang;
@ -106,6 +108,12 @@ class PostController extends FrontController
'postLink' => '',
));
$metaTags = Tools::completeMetaTags(array(
'meta_description' => '',
'meta_keywords' => '',
), $content['meta_title']);
self::$smarty->assign($metaTags);
}
public function displayContent()

View File

@ -1,6 +1,6 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
exit;
}
require_once(__DIR__.'/classes/GuideCategory.php');
@ -243,14 +243,28 @@ class PurchaseGuide extends Module
');
}
public function hookDisplayNavTop(){}
public function hookDisplayNavLeft(){}
public function hookRightColumn(){}
public function hookTopMenuLink($params)
{
global $cookie, $smarty;
$id_category_family = $params['id_category_family'];
$loadedCategory = GuideCategory::findByCategoryFamily($id_category_family, $cookie->id_lang);
$category = new GuideCategory($loadedCategory['id_guide_category']);
$rewrite = $category->getLinkRewrite();
$smarty->assign(array(
'link_rewrite' => '#',
));
return $this->display(dirname(__FILE__), '/views/templates/hook/topmenulink.tpl');
}
public function hookLeftColumn($params)
{
global $cookie, $smarty;
// id_category, id_subcategory
$id_category = Tools::getValue('cid', 0);
$id_subcategory = Tools::getValue('sid', 0);
@ -260,13 +274,13 @@ class PurchaseGuide extends Module
}*/
// Récup de l'arbre en fonction des catégories
$model = new GuideCategory();
$tree = $model->getTree($cookie->id_lang);
return $this->display(__FILE__, '/views/templates/front/leftcolumn.tpl');
$smarty->assign(array(
'menu' => $tree,
));
return $this->display(__FILE__, '/views/templates/hook/leftcolumn.tpl');
}
public function displayCategory(){}
public function displayContent(){}
}

View File

@ -1,5 +1,7 @@
{include file="$tpl_dir./breadcrumb.tpl"}
<h1>Guide d'achat</h1>
<div class="rte{if $content_only} content_only{/if}">

View File

@ -11,12 +11,12 @@
</div>
</div>
<div>
<img alt="" src="{$subcategoryImg}"/>
<img alt="" src="{$subcategoryImg}"/>
</div>
</div>
<div class="clear">
<div style="width:50%; float:left; border:1px solid #cccccc;">
<div style="width:24%; float:left; border:1px solid #cccccc;">
<ul>
{foreach from=$postList item=p}
<li><a href="{$base_dir_ssl}guide/{$categoryRewrite}/{$subcategoryRewrite}/{$p.id_guide_post}-{$p.link_rewrite}">{$p.meta_title}</a></li>
@ -24,7 +24,7 @@
</ul>
</div>
<div style="width:50%; float:right; border:1px solid #cccccc;">
<div style="width:75%; float:right; border:1px solid #cccccc;">
<h3>{$postTitle}</h3>
<p>{$postContent}</p>
</div>

View File

@ -397,7 +397,7 @@ class FrontController extends FrontControllerCore {
'module-paypal-express_checkout-payment',
'module-paymentinfo-manage',
'module-purchaseguide-category', 'rubrique',
'module-purchaseguide-content', 'post',
'module-purchaseguide-post', 'post',
);
$displayRight = array(