srikanthash 0 Posted August 8, 2015 Posted August 8, 2015 he following module(s) could not be installed properly: ptsstaticfooter : <?php // Security if (!defined('_PS_VERSION_')) exit; // Checking compatibility with older PrestaShop and fixing it if (!defined('_MYSQL_ENGINE_')) define('_MYSQL_ENGINE_', 'MyISAM'); // Loading Models require_once(_PS_MODULE_DIR_ . 'ptsstaticfooter/models/Staticfooter.php'); class ptsstaticfooter extends Module { public $hookAssign = array(); public $_staticModel = ""; public function __construct() { $this->name = 'ptsstaticfooter'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'fieldthemes'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6'); $this->hookAssign = array('footer'); $this->_staticModel = new Staticfooter(); parent::__construct(); $this->displayName = $this->l('Pts Static Footer'); $this->description = $this->l('Manager Static blocks'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); $this->admin_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/admin/'; } public function install() { // Install SQL include(dirname(__FILE__) . '/sql/install.php'); foreach ($sql as $s) if (!Db::getInstance()->execute($s)) return false; // Install Tabs if(!(int)Tab::getIdFromClassName('AdminPtsMenu')) { $parent_tab = new Tab(); // Need a foreach for the language $parent_tab->name[$this->context->language->id] = $this->l('Field Themes'); $parent_tab->class_name = 'AdminPtsMenu'; $parent_tab->id_parent = 0; // Home tab $parent_tab->module = $this->name; $parent_tab->add(); } $tab = new Tab(); // Need a foreach for the language foreach (Language::getLanguages() as $language) $tab->name[$language['id_lang']] = $this->l('Manage Static Footer'); $tab->class_name = 'AdminPtsstaticfooter'; $tab->id_parent = (int)Tab::getIdFromClassName('AdminPtsMenu'); $tab->module = $this->name; $tab->add(); // Set some defaults return parent::install() && $this->registerHook('footer') && $this->_installHookCustomer()&& $this->registerHook('blockFooter1')&& $this->registerHook('blockFooter2')&& $this->registerHook('blockFooter3')&& $this->registerHook('displayBackOfficeHeader'); } public function uninstall() { Configuration::deleteByName('PTSSTATICFOOTER'); // Uninstall Tabs //$tab = new Tab((int) Tab::getIdFromClassName('AdminPtsstaticblocksMain')); //$tab->delete(); $sql = array(); include (dirname(__file__) . '/sql/uninstall_sql.php'); foreach ($sql as $s) { if (!Db::getInstance()->Execute($s)) { return FALSE; } } $tab = new Tab((int) Tab::getIdFromClassName('AdminPtsstaticfooter')); $tab->delete(); // Uninstall Module if (!parent::uninstall()) return false; return true; } public function hookFooter($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'footer'); if(count($staticBlocks)<1) return null; $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookDisplayBackOfficeHeader($params) { if (method_exists($this->context->controller, 'addJquery')) { $this->context->controller->addJquery(); $this->context->controller->addJS(($this->_path).'js/staticblock.js'); } } /* define some hook customer */ public function hookBlockFooter1($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter1'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookBlockFooter2($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter2'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookBlockFooter3($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter3'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function getModulById($id_module) { return Db::getInstance()->getRow(' SELECT m.* FROM `' . _DB_PREFIX_ . 'module` m JOIN `' . _DB_PREFIX_ . 'module_shop` ms ON (m.`id_module` = ms.`id_module` AND ms.`id_shop` = ' . (int) ($this->context->shop->id) . ') WHERE m.`id_module` = ' . $id_module); } public function getHooksByModuleId($id_module) { $module = self::getModulById($id_module); $moduleInstance = Module::getInstanceByName($module['name']); $hooks = array(); if ($this->hookAssign) foreach ($this->hookAssign as $hook) { if (_PS_VERSION_ < "1.5") { if (is_callable(array($moduleInstance, 'hook' . $hook))) { $hooks[] = $hook; } } else { $retro_hook_name = Hook::getRetroHookName($hook); if (is_callable(array($moduleInstance, 'hook' . $hook)) || is_callable(array($moduleInstance, 'hook' . $retro_hook_name))) { $hooks[] = $retro_hook_name; } } } $results = self::getHookByArrName($hooks); return $results; } public static function getHookByArrName($arrName) { $result = Db::getInstance()->ExecuteS(' SELECT `id_hook`, `name` FROM `' . _DB_PREFIX_ . 'hook` WHERE `name` IN (\'' . implode("','", $arrName) . '\')'); return $result; } //$hooks = $this->getHooksByModuleId(10); public function getListModuleInstalled() { $mod = new ptsstaticfooter(); $modules = $mod->getModulesInstalled(0); $arrayModule = array(); foreach($modules as $key => $module) { if($module['active']==1) { $arrayModule[0] = array('id_module'=>0, 'name'=>'Chose Module'); $arrayModule[$key] = $module; } } if ($arrayModule) return $arrayModule; return array(); } private function _installHookCustomer(){ $hookspts = array( 'blockFooter1', 'blockFooter2', 'blockFooter3', ); foreach( $hookspts as $hook ){ if( Hook::getIdByName($hook) ){ } else { $new_hook = new Hook(); $new_hook->name = pSQL($hook); $new_hook->title = pSQL($hook); $new_hook->add(); $id_hook = $new_hook->id; } } return true; } } ptsstaticfooter.php Share this post Link to post Share on other sites
srikanthash 0 Posted August 8, 2015 Posted August 8, 2015 Hi, I am doing a module . But when I am doing click on install of that module every time its showing <?php // Security if (!defined('_PS_VERSION_')) exit; // Checking compatibility with older PrestaShop and fixing it if (!defined('_MYSQL_ENGINE_')) define('_MYSQL_ENGINE_', 'MyISAM'); // Loading Models require_once(_PS_MODULE_DIR_ . 'ptsstaticfooter/models/Staticfooter.php'); class ptsstaticfooter extends Module { public $hookAssign = array(); public $_staticModel = ""; public function __construct() { $this->name = 'ptsstaticfooter'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'fieldthemes'; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6'); $this->hookAssign = array('footer'); $this->_staticModel = new Staticfooter(); parent::__construct(); $this->displayName = $this->l('Pts Static Footer'); $this->description = $this->l('Manager Static blocks'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); $this->admin_tpl_path = _PS_MODULE_DIR_ . $this->name . '/views/templates/admin/'; } public function install() { // Install SQL include(dirname(__FILE__) . '/sql/install.php'); foreach ($sql as $s) if (!Db::getInstance()->execute($s)) return false; // Install Tabs if(!(int)Tab::getIdFromClassName('AdminPtsMenu')) { $parent_tab = new Tab(); // Need a foreach for the language $parent_tab->name[$this->context->language->id] = $this->l('Field Themes'); $parent_tab->class_name = 'AdminPtsMenu'; $parent_tab->id_parent = 0; // Home tab $parent_tab->module = $this->name; $parent_tab->add(); } $tab = new Tab(); // Need a foreach for the language foreach (Language::getLanguages() as $language) $tab->name[$language['id_lang']] = $this->l('Manage Static Footer'); $tab->class_name = 'AdminPtsstaticfooter'; $tab->id_parent = (int)Tab::getIdFromClassName('AdminPtsMenu'); $tab->module = $this->name; $tab->add(); // Set some defaults return parent::install() && $this->registerHook('footer') && $this->_installHookCustomer()&& $this->registerHook('blockFooter1')&& $this->registerHook('blockFooter2')&& $this->registerHook('blockFooter3')&& $this->registerHook('displayBackOfficeHeader'); } public function uninstall() { Configuration::deleteByName('PTSSTATICFOOTER'); // Uninstall Tabs //$tab = new Tab((int) Tab::getIdFromClassName('AdminPtsstaticblocksMain')); //$tab->delete(); $sql = array(); include (dirname(__file__) . '/sql/uninstall_sql.php'); foreach ($sql as $s) { if (!Db::getInstance()->Execute($s)) { return FALSE; } } $tab = new Tab((int) Tab::getIdFromClassName('AdminPtsstaticfooter')); $tab->delete(); // Uninstall Module if (!parent::uninstall()) return false; return true; } public function hookFooter($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'footer'); if(count($staticBlocks)<1) return null; $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookDisplayBackOfficeHeader($params) { if (method_exists($this->context->controller, 'addJquery')) { $this->context->controller->addJquery(); $this->context->controller->addJS(($this->_path).'js/staticblock.js'); } } /* define some hook customer */ public function hookBlockFooter1($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter1'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookBlockFooter2($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter2'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function hookBlockFooter3($param) { $id_shop = (int)Context::getContext()->shop->id; $staticBlocks = $this->_staticModel->getStaticfooterLists($id_shop,'blockFooter3'); if(count($staticBlocks)<1) return null; //if(is_array($staticBlocks)) $this->smarty->assign(array( 'staticblocks' => $staticBlocks, )); return $this->display(__FILE__, 'block_footer.tpl'); } public function getModulById($id_module) { return Db::getInstance()->getRow(' SELECT m.* FROM `' . _DB_PREFIX_ . 'module` m JOIN `' . _DB_PREFIX_ . 'module_shop` ms ON (m.`id_module` = ms.`id_module` AND ms.`id_shop` = ' . (int) ($this->context->shop->id) . ') WHERE m.`id_module` = ' . $id_module); } public function getHooksByModuleId($id_module) { $module = self::getModulById($id_module); $moduleInstance = Module::getInstanceByName($module['name']); $hooks = array(); if ($this->hookAssign) foreach ($this->hookAssign as $hook) { if (_PS_VERSION_ < "1.5") { if (is_callable(array($moduleInstance, 'hook' . $hook))) { $hooks[] = $hook; } } else { $retro_hook_name = Hook::getRetroHookName($hook); if (is_callable(array($moduleInstance, 'hook' . $hook)) || is_callable(array($moduleInstance, 'hook' . $retro_hook_name))) { $hooks[] = $retro_hook_name; } } } $results = self::getHookByArrName($hooks); return $results; } public static function getHookByArrName($arrName) { $result = Db::getInstance()->ExecuteS(' SELECT `id_hook`, `name` FROM `' . _DB_PREFIX_ . 'hook` WHERE `name` IN (\'' . implode("','", $arrName) . '\')'); return $result; } //$hooks = $this->getHooksByModuleId(10); public function getListModuleInstalled() { $mod = new ptsstaticfooter(); $modules = $mod->getModulesInstalled(0); $arrayModule = array(); foreach($modules as $key => $module) { if($module['active']==1) { $arrayModule[0] = array('id_module'=>0, 'name'=>'Chose Module'); $arrayModule[$key] = $module; } } if ($arrayModule) return $arrayModule; return array(); } private function _installHookCustomer(){ $hookspts = array( 'blockFooter1', 'blockFooter2', 'blockFooter3', ); foreach( $hookspts as $hook ){ if( Hook::getIdByName($hook) ){ } else { $new_hook = new Hook(); $new_hook->name = pSQL($hook); $new_hook->title = pSQL($hook); $new_hook->add(); $id_hook = $new_hook->id; } } return true; } } plz help me........................... ptsstaticfooter.zip Share this post Link to post Share on other sites
Recommended Posts