Merge branch 'ticket-10393-guide-achat' into develop

This commit is contained in:
Michael RICOIS 2017-11-23 16:50:34 +01:00
commit b31246f357
4 changed files with 41 additions and 35 deletions

View File

@ -309,9 +309,6 @@ class GuideCategory extends ObjectModel
return Db::getInstance()->getValue($sql);
}
public function findByCategoryFamily($id, $id_lang)
{
$sql = "SELECT gc.*, gcl.name FROM `"._DB_PREFIX_."guide_category` gc, `"._DB_PREFIX_."guide_category_lang` gcl
@ -348,10 +345,10 @@ class GuideCategory extends ObjectModel
return $result;
}
public function getAutoCategoryLang($id_category, $id_lang, $active = true)
public function getAutoCategoryLang($id_category, $id_lang, $all = false)
{
$sql = "SELECT * FROM ps_guide_category gc, ps_guide_category_lang gcl
WHERE ".($active===true?' gc.active=1 ':' 1 ')." AND gc.id_guide_category=gcl.id_guide_category
WHERE ".($all===false?' gc.active=1 ':' 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 ASC";
$result = Db::getInstance()->getRow($sql);
@ -362,14 +359,15 @@ class GuideCategory extends ObjectModel
/**
* Gest All main categories
* @param int $id_lang
* @param boolean $all
* @return array
*/
public static function getRoot($id_lang, $active = true)
public static function getRoot($id_lang, $all = false)
{
$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 ".($active===true?' gc.active=1 ':' 1 ')." AND gc.id_guide_category=gcl.id_guide_category
WHERE ".($all===false?' gc.active=1 ':' 1 ')." AND gc.id_guide_category=gcl.id_guide_category
AND gc.id_parent=0 AND gcl.id_lang=".$id_lang;
$result = Db::getInstance()->ExecuteS($sql);
@ -382,25 +380,25 @@ class GuideCategory extends ObjectModel
* @param int $active
* @return array
*/
public function getTree($id_lang, $active = true)
public function getTree($id_lang, $all = false)
{
return $this->recurseData(0, $id_lang, $active);
return $this->recurseData(0, $id_lang, $all);
}
/**
* Recurse data
* @param int $id_category
* @param int $id_lang
* @param int $active
* @param boolean $all
* @return array
*/
protected function recurseData($id_category, $id_lang, $active = true)
protected function recurseData($id_category, $id_lang, $all = false)
{
$data = array();
$sql = "SELECT gc.*, gcl.name, gcl.link_rewrite
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.
($active===true?' AND gc.active=1 ':'')." AND gc.id_parent=".$id_category.
($all===false?' AND gc.active=1':'')." AND gc.id_parent=".$id_category.
" ORDER BY position ASC";
$result = Db::getInstance()->ExecuteS($sql);
if (count($result) > 0) {

View File

@ -183,15 +183,15 @@ class GuidePost extends ObjectModel
* Get Post with one language
* @param int $id_category
* @param int $id_lang
* @param boolean $active
* @param boolean $all
* @return array
*/
public function getPostLang($id_post, $id_lang, $id_category = null, $active = true)
public function getPostLang($id_post, $id_lang, $id_category = null, $all = false)
{
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE ".($active===true?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
WHERE ".($all===false?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
".($id_category===null?"":" AND gp.id_guide_category=".$id_category).
"AND gp.id_guide_post=".$id_post." AND gpl.id_lang=".$id_lang;
" AND gp.id_guide_post=".$id_post." AND gpl.id_lang=".$id_lang;
$result = Db::getInstance()->getRow($sql);
return $result;
@ -201,13 +201,13 @@ class GuidePost extends ObjectModel
* Auto select post
* @param int $id_category
* @param int $id_lang
* @param boolean $active
* @param boolean $all
* @return array
*/
public function getAutoPostLang($id_category, $id_lang, $active = true)
public function getAutoPostLang($id_category, $id_lang, $all = false)
{
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE ".($active===true?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
WHERE ".($all===false?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$id_category.
" AND gpl.id_lang=".$id_lang." ORDER BY position ASC";
$result = Db::getInstance()->getRow($sql);
@ -222,10 +222,10 @@ class GuidePost extends ObjectModel
* @param boolean $active
* @return array
*/
public function findByCategory($id_category, $id_lang, $active = true)
public function findByCategory($id_category, $id_lang, $all = false)
{
$sql = "SELECT * FROM ps_guide_post gp, ps_guide_post_lang gpl
WHERE ".($active===true?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
WHERE ".($all===false?' gp.active=1 ':' 1 ')." AND gp.id_guide_post=gpl.id_guide_post
AND gp.id_guide_category=".$id_category.
" AND gpl.id_lang=".$id_lang." ORDER BY position ASC";
$result = Db::getInstance()->ExecuteS($sql);

View File

@ -16,18 +16,18 @@ class PostController extends FrontController
$id_post = Tools::getValue('pid', 0);
$content = null;
// @todo, si on vient de l'admin, voir les post ???
$isEmployee = self::$cookie->isLoggedBack();
global $cookie;
$isEmployee = $cookie->isLoggedBack();
// Start form post
$postModel = new GuidePost();
if ($id_post != 0) {
$content = $postModel->getPostLang($id_post, $id_lang, !$isEmployee);
$content = $postModel->getPostLang($id_post, $id_lang, null, $isEmployee);
$id_category = $content['id_guide_category'];
}
// Categories
if ($id_category == 0 && $isEmployee === false) {
if ($id_category == 0) {
Tools::display404Error('404.php');
}
else {
@ -48,23 +48,23 @@ class PostController extends FrontController
else {
$parentCategory = $category;
// Auto Select category
$category = $categoryModel->getAutoCategoryLang($id_category, $id_lang, !$isEmployee);
$category = $categoryModel->getAutoCategoryLang($id_category, $id_lang, $isEmployee);
}
}
// Post
if ($content === null) {
if ($id_post != 0) {
$content = $postModel->getPostLang($id_post, $id_lang, $category['id_guide_category'], !$isEmployee);
$content = $postModel->getPostLang($id_post, $id_lang, $category['id_guide_category'], $isEmployee);
}
// Auto Select Post
else {
$content = $postModel->getAutoPostLang($category['id_guide_category'], $id_lang, !$isEmployee);
$content = $postModel->getAutoPostLang($category['id_guide_category'], $id_lang, $isEmployee);
}
}
// Liste des Posts
$postList = $postModel->findByCategory($category['id_guide_category'], $id_lang, !$isEmployee);
$postList = $postModel->findByCategory($category['id_guide_category'], $id_lang, $isEmployee);
$parentCategoryModel = new GuideCategory($parentCategory['id_guide_category']);
$parentCategoryLink = $parentCategoryModel->getLinkRewrite($id_lang);

View File

@ -268,17 +268,25 @@ class PurchaseGuide extends Module
{
global $cookie, $smarty, $site_version, $page_name;
if (!in_array($page_name, array('rubrique', 'post'))) {
if (!in_array($page_name, array('module-purchaseguide-rubrique', 'rubrique',
'module-purchaseguide-post', 'post'))) {
return false;
}
$isEmployee = $cookie->isLoggedBack();
$id_category = Tools::getValue('cid', 0);
$id_post = Tools::getValue('pid', 0);
$content = null;
// Récup de l'arbre en fonction des catégories
// Get from post
if ($id_post != 0) {
$postModel = new GuidePost($id_post);
$id_category = $postModel->id_guide_category;
}
// Get selected categories
$model = new GuideCategory($id_category);
if ($model->id_parent == 0) {
if ($model->id_parent === 0) {
$id_main_category = $id_category;
$id_child_category = 0;
} else {
@ -286,7 +294,7 @@ class PurchaseGuide extends Module
$id_main_category = $mainCategory['id_guide_category'];
$id_child_category = $id_category;
}
$tree = $model->getTree($cookie->id_lang);
$tree = $model->getTree($cookie->id_lang, $isEmployee);
$smarty->assign(array(
'id_guide_category_select_main' => $id_main_category,