Prepare Front

This commit is contained in:
Michael RICOIS 2017-11-09 15:53:45 +01:00
parent 7b003901a8
commit df11669618
8 changed files with 267 additions and 174 deletions

View File

@ -2,30 +2,45 @@
class GuideCategory extends ObjectModel
{
public $id;
public $id_guide_category;
public $name;
public $active = 1;
public $description;
public $id_parent;
public $id_category_family;
public $position;
public $level_depth;
public $link_rewrite;
public $meta_title;
public $meta_keywords;
public $meta_description;
public $id;
public $id_guide_category;
public $name;
public $active = 1;
public $description;
public $id_parent;
public $id_category_family;
public $position;
public $level_depth;
public $link_rewrite;
public $meta_title;
public $meta_keywords;
public $meta_description;
protected $table = 'guide_category';
protected $identifier = 'id_guide_category';
protected $table = 'guide_category';
protected $identifier = 'id_guide_category';
protected $tables = array ('guide_category', 'guide_category_lang');
protected $tables = array (
'guide_category',
'guide_category_lang',
);
protected $fieldsRequired = array('id_parent', 'active');
protected $fieldsSize = array('id_parent' => 10, 'active' => 1);
protected $fieldsValidate = array('active' => 'isBool', 'id_parent' => 'isUnsignedInt');
protected $fieldsRequiredLang = array('name', 'link_rewrite');
protected $fieldsSizeLang = array(
protected $fieldsRequired = array(
'id_parent',
'active'
);
protected $fieldsSize = array(
'id_parent' => 10,
'active' => 1
);
protected $fieldsValidate = array(
'active' => 'isBool',
'id_parent' => 'isUnsignedInt'
);
protected $fieldsRequiredLang = array(
'name',
'link_rewrite'
);
protected $fieldsSizeLang = array(
'name' => 64,
'link_rewrite' => 64,
'meta_title' => 128,
@ -46,6 +61,7 @@ class GuideCategory extends ObjectModel
public function getFields()
{
parent::validateFields();
if (isset($this->id)) {
$fields['id_guide_category'] = (int)($this->id);
}
@ -142,16 +158,18 @@ class GuideCategory extends ObjectModel
));
}
}
/////
// Check then return multilingual fields for database interaction
//
// @return array Multilingual fields
///
public function getTranslationsFieldsChild()
{
parent::validateFieldsLang();
return parent::getTranslationsFields(array('name', 'description', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description'));
return parent::getTranslationsFields(array(
'name',
'description',
'link_rewrite',
'meta_title',
'meta_keywords',
'meta_description'
));
}
public function add($autodate = true, $nullValues = false)
@ -267,7 +285,6 @@ class GuideCategory extends ObjectModel
return Db::getInstance()->getValue($sql);
}
private function cleanupPositions($id_parent)
{
$sql = 'SELECT `id_guide_category`
@ -286,7 +303,25 @@ class GuideCategory extends ObjectModel
}
return $position;
}
public function getLinkRewrite()
{
if ($this->id) {
return $this->id.'-'.$this->link_rewrite[2];
}
return '';
}
public function getLinkRewriteUrl(){}
public function getParent(){}
public function getMainStruct()
{
}
}

View File

@ -1,5 +1,4 @@
<?php
class GuidePost extends ObjectModel
{
public $id;
@ -13,27 +12,49 @@ class GuidePost extends ObjectModel
public $content;
public $link_rewrite;
protected $fieldsValidate = array('id_guide_category' => 'isUnsignedInt');
protected $fieldsRequiredLang = array('meta_title', 'link_rewrite');
protected $fieldsSizeLang = array('meta_description' => 255, 'meta_keywords' => 255, 'meta_title' => 128, 'link_rewrite' => 128, 'content' => 3999999999999);
protected $fieldsValidateLang = array('meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName', 'meta_title' => 'isGenericName', 'link_rewrite' => 'isLinkRewrite', 'content' => 'isString');
protected $fieldsValidate = array(
'id_guide_category' => 'isUnsignedInt'
);
protected $fieldsRequiredLang = array(
'meta_title',
'link_rewrite',
);
protected $fieldsSizeLang = array(
'meta_description' => 255,
'meta_keywords' => 255,
'meta_title' => 128,
'link_rewrite' => 128,
'content' => 3999999999999,
);
protected $fieldsValidateLang = array(
'meta_description' => 'isGenericName',
'meta_keywords' => 'isGenericName',
'meta_title' => 'isGenericName',
'link_rewrite' => 'isLinkRewrite',
'content' => 'isString',
);
protected $table = 'guide_post';
protected $identifier = 'id_guide_post';
protected $webserviceParameters = array(
protected $webserviceParameters = array(
'objectNodeName' => 'content',
'objectsNodeName' => 'content_management_system',
);
public function getFields()
{
public function getFields()
{
parent::validateFields();
$fields['id_guide_post'] = (int)($this->id);
$fields['id_guide_category'] = (int)($this->id_guide_category);
$fields['position'] = (int)($this->position);
$fields['active'] = (int)($this->active);
return $fields;
return $fields;
}
public function getTranslationsFieldsChild()
@ -67,9 +88,9 @@ class GuidePost extends ObjectModel
public function updatePosition($way, $position)
{
if (!$res = Db::getInstance()->ExecuteS('
SELECT cp.`id_guide_post`, cp.`position`, cp.`id_guide_category`
SELECT cp.`id_guide_post`, cp.`position`, cp.`id_guide_category`
FROM `'._DB_PREFIX_.'guide_post` cp
WHERE cp.`id_guide_category` = '.(int)$this->id_guide_category.'
WHERE cp.`id_guide_category` = '.(int)$this->id_guide_category.'
ORDER BY cp.`position` ASC'
))
return false;
@ -86,8 +107,8 @@ class GuidePost extends ObjectModel
return (Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'guide_post`
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
WHERE `position`
'.($way
WHERE `position`
'.($way
? '> '.(int)($movedPost['position']).' AND `position` <= '.(int)($position)
: '< '.(int)($movedPost['position']).' AND `position` >= '.(int)($position)).'
AND `id_guide_category`='.(int)($movedPost['id_guide_category']))
@ -145,5 +166,18 @@ class GuidePost extends ObjectModel
}
return $position;
}
public function getLinkRewrite()
{
if ($this->id) {
return $this->id.'-'.$this->link_rewrite[2];
}
return '';
}
public function getLinkRewriteTree(){}
}

View File

@ -10,52 +10,19 @@ class CategoryController extends FrontController
parent::process();
$id_lang = self::$cookie->id_lang;
$id_category = Tools::getValue('cid', 0);
$id_subcategory = Tools::getValue('sid', 0);
$categories = array();
// Get parent categories
if ($id_category == 0) {
$sql = "SELECT gc.id_guide_category, gcl.name, gcl.link_rewrite, gcl.meta_title,
gcl.meta_description, gcl.meta_keywords
FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=0 AND gcl.id_lang=".$id_lang;
$catResult = Db::getInstance()->ExecuteS($sql);
if (count($catResult) > 0) {
foreach ($catResult as $c) {
// Name
// Link link_rewrite
// Image getImageFilePath
$categories[] = $c;
}
}
}
// Get main category, subcategory, content
else {
// Main category
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=".$id_category." AND gcl.id_lang=".$id_lang;
$categories = Db::getInstance()->ExecuteS($sql);
// Select the subcategory
if ($id_subcategory == 0) {
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=".$id_category." AND gc.id_guide_category=".$id_category.
" AND gcl.id_lang=".$id_lang;
$subcategories = Db::getInstance()->ExecuteS($sql);
}
// Auto Select the subcategory
else {
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=".$id_category." AND gcl.id_lang=".$id_lang.
" ORDER BY position DESC LIMIT 1";
$subcategories = Db::getInstance()->ExecuteS($sql);
// Get main categories
$sql = "SELECT gc.id_guide_category, gcl.name, gcl.link_rewrite, gcl.meta_title,
gcl.meta_description, gcl.meta_keywords
FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=0 AND gcl.id_lang=".$id_lang;
$catResult = Db::getInstance()->ExecuteS($sql);
if (count($catResult) > 0) {
foreach ($catResult as $c) {
$categories[] = $c;
}
}

View File

@ -1,77 +0,0 @@
<?php
class ContentController extends FrontController
{
public function process()
{
parent::process();
$id_lang = self::$cookie->id_lang;
$id_category = Tools::getValue('cid', 0);
$id_subcategory = Tools::getValue('sid', 0);
$id_post = Tools::getValue('id', 0);
// Main category
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_guide_category=".$id_category." AND gcl.id_lang=".$id_lang;
$categories = Db::getInstance()->getRow($sql);
// Auto Select the subcategory
if ($id_subcategory == 0) {
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=".$id_category." AND gcl.id_lang=".$id_lang.
" ORDER BY gc.position ASC";
$subcategories = Db::getInstance()->getRow($sql);
}
// Select the subcategory
else {
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_guide_category=".$id_subcategory." AND gcl.id_lang=".$id_lang;
$subcategories = Db::getInstance()->getRow($sql);
}
// Auto select post
if ($id_post == 0) {
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$subcategories['id_guide_category'].
" AND gpl.id_lang=".$id_lang." ORDER BY position ASC";
$content = Db::getInstance()->getRow($sql);
}
// Select post
else {
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$subcategories['id_guide_category']." AND gp.id_guide_post=".$id_post.
" AND gpl.id_lang=".$id_lang;
$content = Db::getInstance()->getRow($sql);
}
self::$smarty->assign(array(
'path' => 'Guide > TODO',
'id_category' => $id_category,
'categoryTitle' => $categories['name'],
'subcategoryTitle' => $subcategories['name'],
'subcategoryContent' => $subcategories['description'],
'postTitle' => $content['meta_title'],
'postContent' => $content['content'],
));
}
public function displayContent()
{
parent::displayContent();
if (is_file(_PS_THEME_DIR_ . 'modules/purchaseguide/views/front/content.tpl')) {
$tplFile = _PS_THEME_DIR_ . 'modules/purchaseguide/views/front/content.tpl';
}
else {
$tplFile = _PS_MODULE_DIR_ . 'purchaseguide/views/templates/front/content.tpl';
}
self::$smarty->display($tplFile);
}
}

View File

@ -0,0 +1,124 @@
<?php
class PostController extends FrontController
{
public function process()
{
parent::process();
$id_lang = self::$cookie->id_lang;
$id_category = Tools::getValue('cid', 0);
$id_post = Tools::getValue('pid', 0);
$content = null;
// Start form post
if ($id_post != 0) {
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_post=".$id_post." AND gpl.id_lang=".$id_lang;
$content = Db::getInstance()->getRow($sql);
$id_category = $content['id_guide_category'];
}
// Categories
if ($id_category == 0) {
// Error
}
else {
// Category
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_guide_category=".$id_category." AND gcl.id_lang=".$id_lang;
$category = Db::getInstance()->getRow($sql);
// Get Parent category
$isSubCategory = false;
if ($category['id_parent'] != 0) {
$isSubCategory = true;
}
if ($isSubCategory) {
// Get Parent category
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_guide_category=".$category['id_parent']." AND gcl.id_lang=".$id_lang;
$parentCategory = Db::getInstance()->getRow($sql);
}
else {
$parentCategory = $category;
// Auto Select category
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE gc.active=1 AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=".$id_category." AND gcl.id_lang=".$id_lang.
" ORDER BY position DESC";
$category = Db::getInstance()->getRow($sql);
}
}
// Post
if ($content === null) {
if ($id_post != 0) {
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$category['id_guide_category']." AND gp.id_guide_post=".$id_post.
" AND gpl.id_lang=".$id_lang;
$content = Db::getInstance()->getRow($sql);
}
// Auto Select Post
else {
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$category['id_guide_category'].
" AND gpl.id_lang=".$id_lang." ORDER BY position ASC";
$content = Db::getInstance()->getRow($sql);
}
}
// Liste des Posts
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE gp.active=1 AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$category['id_guide_category'].
" AND gpl.id_lang=".$id_lang." ORDER BY position ASC";
$postList = Db::getInstance()->ExecuteS($sql);
$parentCategoryModel = new GuideCategory($parentCategory['id_guide_category']);
$parentCategoryLink = $parentCategoryModel->getLinkRewrite();
$categoryModel = new GuideCategory($category['id_guide_category']);
$categoryLink = $categoryModel->getLinkRewrite();
self::$smarty->assign(array(
'path' => 'Guide > TODO',
'id_category' => $id_category,
'categoryTitle' => $parentCategory['name'],
'categoryLink' => $parentCategoryLink,
'categoryRewrite' => $parentCategory['link_rewrite'],
'subcategoryTitle' => $category['name'],
'subcategoryContent' => $category['description'],
'subcategoryImg' => $categoryModel->getImageFileUrl(),
'subcategoryLink' => $categoryLink,
'subcategoryRewrite' => $category['link_rewrite'],
'postList' => $postList,
'postTitle' => $content['meta_title'],
'postContent' => $content['content'],
'postLink' => '',
));
}
public function displayContent()
{
parent::displayContent();
if (is_file(_PS_THEME_DIR_ . 'modules/purchaseguide/views/front/content.tpl')) {
$tplFile = _PS_THEME_DIR_ . 'modules/purchaseguide/views/front/content.tpl';
}
else {
$tplFile = _PS_MODULE_DIR_ . 'purchaseguide/views/templates/front/content.tpl';
}
self::$smarty->display($tplFile);
}
}

View File

@ -1,6 +1,6 @@
<?php
require_once dirname(__FILE__).'/../../config/config.inc.php';
require_once dirname(__FILE__).'/controllers/front/ContentController.php';
require_once dirname(__FILE__).'/controllers/front/PostController.php';
$controller = new ContentController();
$controller = new PostController();
$controller->run();

View File

@ -6,9 +6,9 @@
<div class="row">
{foreach from=$categories item=c}
<div>
<a href="{$c.link_rewrite}">
<a href="guide/{$c.id_guide_category}-{$c.link_rewrite}">
<img alt="{$c.name}" src="./img/purchaseguide/{$c.id_guide_category}.jpg">
<span>{$c.name}</span>
<span>{$c.meta_title}</span>
</a>
</div>
{/foreach}

View File

@ -3,22 +3,32 @@
<h1>Guide d'achat - {$categoryTitle}</h1>
<div class="rte{if $content_only} content_only{/if}">
<h2>{$subcategoryTitle}</h2>
<div>
<p>{$subcategoryContent}</p>
<div style="width:50%; float:left;">
<h2>{$subcategoryTitle}</h2>
<div>
<p>{$subcategoryContent}</p>
</div>
</div>
<div>
<img alt="" src="{$subcategoryImg}"/>
</div>
</div>
<div>
<div class="clear">
<div style="width:50%; float:left; border:1px solid #cccccc;">
<ul>
{foreach from=$postList item=p}
<li><a href="{$p.id_guide_post}-{$p.link_rewrite}">{$p.meta_title}</a></li>
<li><a href="{$base_dir_ssl}guide/{$categoryRewrite}/{$subcategoryRewrite}/{$p.id_guide_post}-{$p.link_rewrite}">{$p.meta_title}</a></li>
{/foreach}
</ul>
</div>
<div>
<div style="width:50%; float:right; border:1px solid #cccccc;">
<h3>{$postTitle}</h3>
<p>{$postContent}</p>
</div>
</div>
</div>