/** * Constructor * * @param string $name Module unique name * @param Context $context */ public function __construct($name = null, Context $context = null) { // Load context and smarty $this->context = $context ? $context : Context::getContext(); if (is_object($this->context->smarty)) { $this->smarty = $this->context->smarty->createData($this->context->smarty); } // If the module has no name we gave him its id as name if ($this->name == null) { $this->name = $this->id; } // If the module has the name we load the corresponding data from the cache if ($this->name != null) { // If cache is not generated, we generate it if (self::$modules_cache == null && !is_array(self::$modules_cache)) { $id_shop = Validate::isLoadedObject($this->context->shop) ? $this->context->shop->id : 1; self::$modules_cache = array(); // Join clause is done to check if the module is activated in current shop context $result = Db::getInstance()->executeS(' SELECT m.`id_module`, m.`name`, ( SELECT id_module FROM `' . _DB_PREFIX_ . 'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` = ' . (int) $id_shop . ' LIMIT 1 ) as mshop FROM `' . _DB_PREFIX_ . 'module` m'); foreach ($result as $row) { self::$modules_cache[$row['name']] = $row; self::$modules_cache[$row['name']]['active'] = $row['mshop'] > 0 ? 1 : 0; } } // We load configuration from the cache if (isset(self::$modules_cache[$this->name])) { if (isset(self::$modules_cache[$this->name]['id_module'])) { $this->id = self::$modules_cache[$this->name]['id_module']; } foreach (self::$modules_cache[$this->name] as $key => $value) { if (key_exists($key, $this)) { $this->{$key} = $value; } } $this->_path = __PS_BASE_URI__ . 'modules/' . $this->name . '/'; } $this->local_path = _PS_MODULE_DIR_ . $this->name . '/'; } }
/** * Constructor * * @param string $name Module unique name * @param Context $context */ public function __construct($name = null, Context $context = null) { if (isset($this->ps_versions_compliancy) && !isset($this->ps_versions_compliancy['min'])) { $this->ps_versions_compliancy['min'] = '1.4.0.0'; } if (isset($this->ps_versions_compliancy) && !isset($this->ps_versions_compliancy['max'])) { $this->ps_versions_compliancy['max'] = _PS_VERSION_; } if (strlen($this->ps_versions_compliancy['min']) == 3) { $this->ps_versions_compliancy['min'] .= '.0.0'; } if (strlen($this->ps_versions_compliancy['max']) == 3) { $this->ps_versions_compliancy['max'] .= '.999.999'; } // Load context and smarty $this->context = $context ? $context : Context::getContext(); if (is_object($this->context->smarty)) { $this->smarty = $this->context->smarty->createData($this->context->smarty); } // If the module has no name we gave him its id as name if ($this->name === null) { $this->name = $this->id; } // If the module has the name we load the corresponding data from the cache if ($this->name != null) { // If cache is not generated, we generate it if (self::$modules_cache == null && !is_array(self::$modules_cache)) { $id_shop = Validate::isLoadedObject($this->context->shop) ? $this->context->shop->id : Configuration::get('PS_SHOP_DEFAULT'); self::$modules_cache = array(); // Join clause is done to check if the module is activated in current shop context $result = Db::getInstance()->executeS(' SELECT m.`id_module`, m.`name`, ms.`id_module`as `mshop` FROM `' . _DB_PREFIX_ . 'module` m LEFT JOIN `' . _DB_PREFIX_ . 'module_shop` ms ON m.`id_module` = ms.`id_module` AND ms.`id_shop` = ' . (int) $id_shop); foreach ($result as $row) { self::$modules_cache[$row['name']] = $row; self::$modules_cache[$row['name']]['active'] = $row['mshop'] > 0 ? 1 : 0; } } // We load configuration from the cache if (isset(self::$modules_cache[$this->name])) { if (isset(self::$modules_cache[$this->name]['id_module'])) { $this->id = self::$modules_cache[$this->name]['id_module']; } foreach (self::$modules_cache[$this->name] as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } $this->_path = __PS_BASE_URI__ . 'modules/' . $this->name . '/'; } if (!$this->context->controller instanceof Controller) { self::$modules_cache = null; } $this->local_path = _PS_MODULE_DIR_ . $this->name . '/'; } }