PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/designers/designers.php

https://gitlab.com/sutrix.hoa.tran/Research-Prestashop
PHP | 322 lines | 159 code | 26 blank | 137 comment | 7 complexity | a98f40853fb5b5eb1abfc36a906b6998 MD5 | raw file
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hoa.tran
  5. * Date: 08/08/2016
  6. * Time: 15:15
  7. */
  8. require_once(dirname(__FILE__) . '/classes/Designer.php');
  9. class Designers extends Module
  10. {
  11. public function __construct()
  12. {
  13. $this->uninstall();
  14. $this->name = 'designers';
  15. $this->tab = 'front_office_features';
  16. $this->version = '0.1';
  17. $this->author = 'Hoa Tran';
  18. $this->displayName = "Designers";
  19. $this->description = 'With this module, you can add designers for your product';
  20. parent::__construct();
  21. }
  22. public function install()
  23. {
  24. parent::install();
  25. $tab = new Tab();
  26. $this->tabClassName = 'AdminDesigners';
  27. $this->tabParentName = 'AdminCatalog';
  28. $tab->class_name = $this->tabClassName;
  29. if (Shop::isFeatureActive())
  30. Shop::setContext(Shop::CONTEXT_ALL);
  31. // $this->registerHook('displayProductTabContent');
  32. if (!$this->installTab($this->tabParentName, $this->tabClassName,
  33. 'Designers')
  34. )
  35. return false;
  36. if (!$this->registerHook('displayAdminProductsExtra') ||
  37. !$this->registerHook('displayBackOfficeHeader') ||
  38. !$this->registerHook('displayLeftColumn') ||
  39. !$this->registerHook('ModuleRoutes')
  40. ) {
  41. return false;
  42. }
  43. $this->img_folder = _PS_IMG_DIR_.'des';
  44. if(!is_dir($this->img_folder) && !file_exists($this->img_folder))
  45. {
  46. mkdir($this->img_folder);
  47. chown($this->img_folder,fileowner(_PS_IMG_DIR_));
  48. chgrp($this->img_folder,filegroup(_PS_IMG_DIR_));
  49. chmod($this->img_folder,fileperms(_PS_IMG_DIR_));
  50. }
  51. // create table
  52. // create ss_designer
  53. Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `ps_ss_designer` (
  54. `id_ss_designer` INT(7) NOT NULL AUTO_INCREMENT,
  55. `image` VARCHAR(50) NULL DEFAULT \'0\',
  56. `address` VARCHAR(100) NULL DEFAULT \'0\',
  57. `email` VARCHAR(100) NULL DEFAULT \'0\',
  58. `telephone` VARCHAR(50) NULL DEFAULT \'0\',
  59. `active` TINYINT(1) NOT NULL DEFAULT \'0\',
  60. `id_feature_value` INT(11) NULL DEFAULT NULL,
  61. `shipping_fee` INT(11) NULL DEFAULT NULL,
  62. PRIMARY KEY (`id_ss_designer`)
  63. )
  64. COLLATE=\'utf8_general_ci\'
  65. ENGINE=InnoDB
  66. AUTO_INCREMENT=1;');
  67. // create ss_designer_lang
  68. Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `ps_ss_designer_lang` (
  69. `id_ss_designer` INT(11) NOT NULL,
  70. `id_lang` INT(11) NOT NULL,
  71. `name` VARCHAR(100) NULL DEFAULT NULL,
  72. `url_name` VARCHAR(50) NULL DEFAULT NULL,
  73. `description` VARCHAR(255) NULL DEFAULT NULL,
  74. `meta_keywords` VARCHAR(255) NULL DEFAULT NULL,
  75. `meta_description` VARCHAR(255) NULL DEFAULT NULL,
  76. PRIMARY KEY (`id_ss_designer`, `id_lang`)
  77. )
  78. COLLATE=\'utf8_general_ci\'
  79. ENGINE=InnoDB;');
  80. // create table designer_shop
  81. Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `ps_ss_designer_shop` (
  82. `id_ss_designer` INT(7) NOT NULL,
  83. `id_shop` INT(11) NOT NULL,
  84. PRIMARY KEY (`id_ss_designer`, `id_shop`))
  85. COLLATE=\'utf8_general_ci\'
  86. ENGINE=InnoDB;');
  87. //Create table designer_supplier
  88. Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `ps_ss_designer_supplier` (
  89. `id_ss_designer_supplier` INT(11) NOT NULL AUTO_INCREMENT,
  90. `id_ss_designer` INT(11) NULL DEFAULT NULL,
  91. `id_ss_product` INT(11) NULL DEFAULT NULL,
  92. PRIMARY KEY (`id_ss_designer_supplier`),
  93. UNIQUE INDEX `id_ss_designer` (`id_ss_designer`),
  94. UNIQUE INDEX `id_ss_product` (`id_ss_product`))
  95. COLLATE=\'utf8_general_ci\'
  96. ENGINE=InnoDB
  97. ;');
  98. return true;
  99. }
  100. public function installTab($parent, $class_name, $name)
  101. {
  102. $tab = new Tab();
  103. $tab->id_parent = (int)Tab::getIdFromClassName($parent);
  104. $tab->name = array();
  105. foreach (Language::getLanguages(true) as $lang)
  106. $tab->name[$lang['id_lang']] = $name;
  107. $tab->class_name = $class_name;
  108. $tab->module = $this->name;
  109. $tab->active = 1;
  110. return $tab->add();
  111. }
  112. public function uninstallTab($class_name)
  113. {
  114. $id_tab = (int)Tab::getIdFromClassName($class_name);
  115. $tab = new Tab((int)$id_tab);
  116. return $tab->delete();
  117. }
  118. public function processConfiguration()
  119. {
  120. }
  121. public function assignConfiguration()
  122. {
  123. }
  124. public function getContent()
  125. {
  126. $this->processConfiguration();
  127. $this->assignConfiguration();
  128. return $this->display(__FILE__, 'getContent.tpl');
  129. }
  130. public function uninstall()
  131. {
  132. if (!parent::uninstall() ||
  133. !Configuration::deleteByName('designers')
  134. )
  135. return false;
  136. if (!$this->uninstallTab('AdminDesigners'))
  137. return false;
  138. return true;
  139. }
  140. ////
  141. // public function hookDisplayAdminProductsExtra($params)
  142. // {
  143. //// echo 'hello world';
  144. // return $this->display(__FILE__, 'displayAdminProductsExtra.tpl');
  145. //
  146. // }
  147. public function getHookController($hook_name)
  148. {
  149. // Include the controller file
  150. require_once(dirname(__FILE__) . '/controllers/hook/' . $hook_name . '.php');
  151. // Build the controller name dynamically
  152. $controller_name = $this->name . $hook_name . 'Controller';
  153. // Instantiate controller
  154. $controller = new $controller_name();
  155. // Return the controller
  156. return $controller;
  157. }
  158. public function hookDisplayAdminProductsExtra($params)
  159. {
  160. $controller = $this->getHookController('AdminProductsExtra');
  161. return $controller->run();
  162. }
  163. public function hookModuleRoutes()
  164. {
  165. return array(
  166. 'module-designers-designer' => array(
  167. 'controller' => 'designer',
  168. // 'rule' => 'product-designer{/:module_action}{/:id_ss_designer}/page{/:page}',
  169. // 'rule' => 'designer{/:id_ss_designer}/page{/:page}',
  170. 'rule' => 'designer{/:url_name}',
  171. 'keywords' => array(
  172. 'url_name' => array(
  173. 'regexp' => '[\w]+',
  174. 'param' => 'url_name'),
  175. // 'page' => array(
  176. // 'regexp' => '[\d]+',
  177. // 'param' => 'page')
  178. // 'module_action' => array(
  179. // 'regexp' => '[\w]+',
  180. // 'param' => 'module_action'),
  181. ),
  182. 'params' => array(
  183. 'fc' => 'module',
  184. 'module' => 'designers',
  185. 'controller' => 'designer'
  186. )
  187. )
  188. );
  189. // return array(
  190. // 'module-designers-designer' => array(
  191. // 'controller' => 'designer',
  192. // 'rule' => 'designer{/:url_name}',
  193. // 'keywords' => array(
  194. // 'url_name' => array(
  195. // 'regexp' => '[\w]+',
  196. // 'param' => 'url_name'),
  197. // ),
  198. // 'params' => array(
  199. // 'fc' => 'module',
  200. // 'module' => 'designers',
  201. // 'controller' => 'designer'
  202. // )
  203. // )
  204. // );
  205. }
  206. }
  207. /*
  208. if(!defined('_PS_VERSION_')) exit;
  209. require_once(dirname(__FILE__).'/classes/Designer.php');
  210. class Designers extends Module
  211. {
  212. public function __construct()
  213. {
  214. $this->name = 'designers';
  215. $this->tab = 'administration';
  216. $this->version = '1.0.0';
  217. $this->author = 'Thao Nguyen';
  218. $this->need_instance = 0;
  219. $this->ps_version_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
  220. $this->bootstrap = true;
  221. parent::__construct();
  222. $this->displayName = $this->l('Designers');
  223. $this->desciption = $this->l('Manage Designers');
  224. $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
  225. $this->img_folder = _PS_IMG_DIR_.'desg/';
  226. if(!defined('_PS_DESIGNER_IMG_DIR_'))
  227. define('_PS_DESIGNER_IMG_DIR_', $this->img_folder);
  228. }
  229. public function install()
  230. {
  231. if (Shop::isFeatureActive())
  232. Shop::setContext(Shop::CONTEXT_ALL);
  233. if (!parent::install() ||
  234. !$this->registerHook('leftColumn') ||
  235. !$this->registerHook('header') ||
  236. !$this->registerHook('displayProductTabContent') ||
  237. !$this->registerHook('displayBackOfficeHeader') ||
  238. !$this->registerHook('displayAdminProductsExtra') ||
  239. !$this->registerHook('displayHome') ||
  240. !$this->registerHook('displayHomeTab') ||
  241. !$this->registerHook('displayHomeTabContent') ||
  242. !$this->registerHook('ModuleRoutes') ||
  243. !$this->installTab('AdminCatalog','AdminDesigners','Designer')
  244. )
  245. return false;
  246. return true;
  247. }
  248. public function uninstall()
  249. {
  250. if (!parent::uninstall() ||
  251. !$this->uninstallTab('AdminDesigners')
  252. )
  253. return false;
  254. $this->uninstallTab('AdminSsDesigner');
  255. return true;
  256. }
  257. public function installTab($parent, $class_name, $name)
  258. {
  259. $tab = new Tab();
  260. $tab->id_parent = (int)Tab::getIdFromClassName($parent);
  261. $tab->name = array();
  262. foreach (Language::getLanguages(true) as $lang)
  263. $tab->name[$lang['id_lang']] = $name;
  264. $tab->class_name = $class_name;
  265. $tab->module = $this->name;
  266. $tab->active = 1;
  267. return $tab->add();
  268. }
  269. public function uninstallTab($class_name)
  270. {
  271. $id_tab = (int)Tab::getIdFromClassName($class_name);
  272. $tab = new Tab($id_tab);
  273. return $tab->delete();
  274. }
  275. }
  276. */