diff --git a/modules/purchaseguide/classes/GuideCategory.php b/modules/purchaseguide/classes/GuideCategory.php index 768b226a..b6509aa6 100644 --- a/modules/purchaseguide/classes/GuideCategory.php +++ b/modules/purchaseguide/classes/GuideCategory.php @@ -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() + { + + } + } - - diff --git a/modules/purchaseguide/classes/GuidePost.php b/modules/purchaseguide/classes/GuidePost.php index 34d3f0b3..d2b62a71 100644 --- a/modules/purchaseguide/classes/GuidePost.php +++ b/modules/purchaseguide/classes/GuidePost.php @@ -1,5 +1,4 @@ '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(){} + + } diff --git a/modules/purchaseguide/controllers/front/CategoryController.php b/modules/purchaseguide/controllers/front/CategoryController.php index 7230c4be..085cb58c 100644 --- a/modules/purchaseguide/controllers/front/CategoryController.php +++ b/modules/purchaseguide/controllers/front/CategoryController.php @@ -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; } } diff --git a/modules/purchaseguide/controllers/front/ContentController.php b/modules/purchaseguide/controllers/front/ContentController.php deleted file mode 100644 index 1f0e3795..00000000 --- a/modules/purchaseguide/controllers/front/ContentController.php +++ /dev/null @@ -1,77 +0,0 @@ -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); - } -} \ No newline at end of file diff --git a/modules/purchaseguide/controllers/front/PostController.php b/modules/purchaseguide/controllers/front/PostController.php new file mode 100644 index 00000000..8fd027f8 --- /dev/null +++ b/modules/purchaseguide/controllers/front/PostController.php @@ -0,0 +1,124 @@ +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); + } +} \ No newline at end of file diff --git a/modules/purchaseguide/post.php b/modules/purchaseguide/post.php index c188e443..36915b18 100644 --- a/modules/purchaseguide/post.php +++ b/modules/purchaseguide/post.php @@ -1,6 +1,6 @@ run(); \ No newline at end of file diff --git a/modules/purchaseguide/views/templates/front/category.tpl b/modules/purchaseguide/views/templates/front/category.tpl index 355d6bc8..890eb84b 100644 --- a/modules/purchaseguide/views/templates/front/category.tpl +++ b/modules/purchaseguide/views/templates/front/category.tpl @@ -6,9 +6,9 @@
{$subcategoryContent}
+{$subcategoryContent}
+{$postContent}