Employee could see all posts active and inactive
This commit is contained in:
parent
235f1add37
commit
195f3cc346
@ -128,7 +128,7 @@ class AdminGuidePosts extends AdminTab
|
||||
'id_guide_category' => array(
|
||||
'title' => $this->l('Catégorie du guide'),
|
||||
'type' => 'select',
|
||||
'options_raw' => GuideCategory::findCategoriesTree($cookie->id_lang),
|
||||
'options_raw' => GuideCategory::findCategoriesTree($cookie->id_lang, 2),
|
||||
'options_map' => ['id_guide_category', 'name', 'level'],
|
||||
'initial_value' => $obj->id_guide_category
|
||||
),
|
||||
|
@ -97,7 +97,7 @@ class GuideCategory extends ObjectModel
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function findCategoriesTree($id_lang, $exclude_id=0)
|
||||
public static function findCategoriesTree($id_lang, $levelMax = null, $exclude_id=0)
|
||||
{
|
||||
$sql = "SELECT DISTINCT a.`id_guide_category` as id_guide_category, `name`
|
||||
FROM `"._DB_PREFIX_."guide_category` a
|
||||
@ -106,11 +106,11 @@ class GuideCategory extends ObjectModel
|
||||
WHERE b.id_lang = '".intval($id_lang)."'
|
||||
AND a.`id_parent` = '%s'
|
||||
";
|
||||
if ($exclude_id!='0') {
|
||||
if ($exclude_id != '0') {
|
||||
$sql .= " AND a.`id_guide_category` <> '".intval($exclude_id)."'";
|
||||
}
|
||||
$rows = array();
|
||||
self::findRecursiveData($rows, $sql, array(
|
||||
self::findRecursiveData($rows, $sql, $levelMax, array(
|
||||
'id_parent' => 0,
|
||||
'identifier' => 'id_guide_category',
|
||||
'level' => -1
|
||||
@ -119,7 +119,7 @@ class GuideCategory extends ObjectModel
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function findFamiliesTree($id_lang, $exclude_id=0)
|
||||
public static function findFamiliesTree($id_lang, $levelMax = null, $exclude_id=0)
|
||||
{
|
||||
$sql = "SELECT DISTINCT a.`id_category_family` as id_category_family, `name`
|
||||
FROM `"._DB_PREFIX_."category_family` a
|
||||
@ -132,26 +132,28 @@ class GuideCategory extends ObjectModel
|
||||
$sql .= " AND a.`id_category_family` <> '".intval($exclude_id)."'";
|
||||
}
|
||||
$rows = array();
|
||||
self::findRecursiveData($rows, $sql, array(
|
||||
self::findRecursiveData($rows, $sql, $levelMax, array(
|
||||
'id_parent' => 0,
|
||||
'identifier' => 'id_category_family',
|
||||
'level' => -1
|
||||
'level' => 0
|
||||
));
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
private static function findRecursiveData(&$rows, $sql, array $params)
|
||||
private static function findRecursiveData(&$rows, $sql, $levelMax = null, array $params)
|
||||
{
|
||||
$level = $params['level'];
|
||||
$level++;
|
||||
if ($levelMax !== null && $level >= $levelMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
$resuts = Db::getInstance()->ExecuteS(sprintf($sql, intval($params['id_parent'])));
|
||||
foreach($resuts as &$row) {
|
||||
$results = Db::getInstance()->ExecuteS(sprintf($sql, intval($params['id_parent'])));
|
||||
foreach($results as &$row) {
|
||||
$row['level'] = $level;
|
||||
$rows[] = $row;
|
||||
self::findRecursiveData($rows, $sql, array(
|
||||
self::findRecursiveData($rows, $sql, $levelMax, array(
|
||||
'id_parent' => $row[$params['identifier']],
|
||||
'identifier' => $params['identifier'],
|
||||
'level' => $level
|
||||
@ -348,10 +350,10 @@ class GuideCategory extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getAutoCategoryLang($id_category, $id_lang)
|
||||
public function getAutoCategoryLang($id_category, $id_lang, $active = true)
|
||||
{
|
||||
$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
|
||||
WHERE ".($active===true?' 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);
|
||||
@ -364,12 +366,12 @@ class GuideCategory extends ObjectModel
|
||||
* @param int $id_lang
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoot($id_lang, $active = 1)
|
||||
public static function getRoot($id_lang, $active = true)
|
||||
{
|
||||
$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==1?' gc.active=1 ':' 1 ')." AND gc.id_guide_category=gcl.id_guide_category
|
||||
WHERE ".($active===true?' 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,7 +384,7 @@ class GuideCategory extends ObjectModel
|
||||
* @param int $active
|
||||
* @return array
|
||||
*/
|
||||
public function getTree($id_lang, $active = 1)
|
||||
public function getTree($id_lang, $active = true)
|
||||
{
|
||||
return $this->recurseData(0, $id_lang, $active);
|
||||
}
|
||||
@ -394,13 +396,13 @@ class GuideCategory extends ObjectModel
|
||||
* @param int $active
|
||||
* @return array
|
||||
*/
|
||||
protected function recurseData($id_category, $id_lang, $active = 1)
|
||||
protected function recurseData($id_category, $id_lang, $active = true)
|
||||
{
|
||||
$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==1?' AND gc.active=1 ':'')." AND gc.id_parent=".$id_category.
|
||||
($active===true?' AND gc.active=1 ':'')." AND gc.id_parent=".$id_category.
|
||||
" ORDER BY position ASC";
|
||||
$result = Db::getInstance()->ExecuteS($sql);
|
||||
if (count($result) > 0) {
|
||||
|
@ -180,15 +180,16 @@ class GuidePost extends ObjectModel
|
||||
public function getUrlRewriteFull(){}
|
||||
|
||||
/**
|
||||
* Get Post With one language
|
||||
* Get Post with one language
|
||||
* @param int $id_category
|
||||
* @param int $id_lang
|
||||
* @param boolean $active
|
||||
* @return array
|
||||
*/
|
||||
public function getPostLang($id_post, $id_lang, $id_category = null)
|
||||
public function getPostLang($id_post, $id_lang, $id_category = null, $active = true)
|
||||
{
|
||||
$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
|
||||
WHERE ".($active===true?' 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;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
@ -196,11 +197,17 @@ class GuidePost extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getAutoPostLang($id_category, $id_lang)
|
||||
/**
|
||||
* Auto select post
|
||||
* @param int $id_category
|
||||
* @param int $id_lang
|
||||
* @param boolean $active
|
||||
* @return array
|
||||
*/
|
||||
public function getAutoPostLang($id_category, $id_lang, $active = true)
|
||||
{
|
||||
$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
|
||||
WHERE ".($active===true?' 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);
|
||||
@ -208,10 +215,17 @@ class GuidePost extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function findByCategory($id_category, $id_lang)
|
||||
/**
|
||||
* Find posts filter by category
|
||||
* @param int $id_category
|
||||
* @param int $id_lang
|
||||
* @param boolean $active
|
||||
* @return array
|
||||
*/
|
||||
public function findByCategory($id_category, $id_lang, $active = true)
|
||||
{
|
||||
$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
|
||||
WHERE ".($active===true?' 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);
|
||||
|
@ -8,6 +8,7 @@ class CategoryController extends FrontController
|
||||
parent::preProcess();
|
||||
|
||||
$id_lang = self::$cookie->id_lang;
|
||||
$isEmployee = self::$cookie->isLoggedBack();
|
||||
$categories = array();
|
||||
|
||||
// Get main categories
|
||||
|
@ -17,16 +17,17 @@ class PostController extends FrontController
|
||||
$content = null;
|
||||
|
||||
// @todo, si on vient de l'admin, voir les post ???
|
||||
$isEmployee = self::$cookie->isLoggedBack();
|
||||
|
||||
// Start form post
|
||||
$postModel = new GuidePost();
|
||||
if ($id_post != 0) {
|
||||
$content = $postModel->getPostLang($id_post, $id_lang);
|
||||
$content = $postModel->getPostLang($id_post, $id_lang, !$isEmployee);
|
||||
$id_category = $content['id_guide_category'];
|
||||
}
|
||||
|
||||
// Categories
|
||||
if ($id_category == 0) {
|
||||
if ($id_category == 0 && $isEmployee === false) {
|
||||
Tools::display404Error('404.php');
|
||||
}
|
||||
else {
|
||||
@ -47,23 +48,23 @@ class PostController extends FrontController
|
||||
else {
|
||||
$parentCategory = $category;
|
||||
// Auto Select category
|
||||
$category = $categoryModel->getAutoCategoryLang($id_category, $id_lang);
|
||||
$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']);
|
||||
$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);
|
||||
$content = $postModel->getAutoPostLang($category['id_guide_category'], $id_lang, !$isEmployee);
|
||||
}
|
||||
}
|
||||
|
||||
// Liste des Posts
|
||||
$postList = $postModel->findByCategory($category['id_guide_category'], $id_lang);
|
||||
$postList = $postModel->findByCategory($category['id_guide_category'], $id_lang, !$isEmployee);
|
||||
|
||||
$parentCategoryModel = new GuideCategory($parentCategory['id_guide_category']);
|
||||
$parentCategoryLink = $parentCategoryModel->getLinkRewrite($id_lang);
|
||||
|
@ -272,6 +272,7 @@ class PurchaseGuide extends Module
|
||||
return false;
|
||||
}
|
||||
|
||||
$isEmployee = self::$cookie->isLoggedBack();
|
||||
$id_category = Tools::getValue('cid', 0);
|
||||
|
||||
// Récup de l'arbre en fonction des catégories
|
||||
|
Loading…
Reference in New Issue
Block a user