-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtreecategories.php
99 lines (86 loc) · 2.79 KB
/
treecategories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* ---------------------------------------------------------------------------------
*
* 1997-2013 Quadra Informatique
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author Quadra Informatique <[email protected]>
* @copyright 1997-2013 Quadra Informatique
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* ---------------------------------------------------------------------------------
*/
if (!defined('_PS_VERSION_'))
exit;
class Treecategories extends Module
{
function __construct()
{
$this->name = 'treecategories';
$this->tab = 'tree_categories';
$this->version = 1.1;
$this->author = 'Quadra Informatique';
$this->need_instance = 0;
$this->key='';
parent::__construct();
$this->displayName = $this->l('Tree-like categories');
$this->description = $this->l('Allows to manage categories like tree items.');
$this->confirmUninstall = $this->l('Are you sure you want to remove this feature ?');
}
function install()
{
if (!parent::install())
return false;
$id_lang = Language::getIdByIso('en');
$query = '
SELECT t.`id_tab`
FROM `'._DB_PREFIX_.'tab` t
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.')
WHERE tl.`name` = "Catalog"
';
$result = Db::getInstance()->executeS($query);
$this->installModuleTab('AdminTreeCategories', array(Language::getIdByIso('fr') => 'Catégories (vue en arbre)',
Language::getIdByIso('en') => 'Categories (tree view)'),
$result[0]['id_tab']);
return true;
}
function uninstall()
{
if (!parent::uninstall())
return false;
$this->uninstallModuleTab('AdminTreeCategories');
return true;
}
private function installModuleTab($tabClass, $tabName, $idTabParent)
{
$tab = new Tab();
$tab->name = $tabName;
$tab->class_name = $tabClass;
$tab->module = $this->name;
$tab->id_parent = (int)($idTabParent);
if (!$tab->save())
return false;
return true;
}
private function uninstallModuleTab($tabClass)
{
$idTab = Tab::getIdFromClassName($tabClass);
if ($idTab != 0)
{
$tab = new Tab($idTab);
$tab->delete();
return true;
}
return false;
}
}