Merge branch 'dispatch_modules' into development

This commit is contained in:
vAugagneur
2013-02-04 18:20:24 +01:00
22 changed files with 767 additions and 83 deletions
+47 -1
View File
@@ -42,6 +42,8 @@ class TabCore extends ObjectModel
/** @var integer active */
public $active = true;
const TAB_MODULE_LIST_URL = 'api.prestashop.com/xml/tab_modules_list.xml';
/**
* @see ObjectModel::$definition
@@ -503,4 +505,48 @@ class TabCore extends ObjectModel
{
return Db::getInstance()->getValue('SELECT class_name FROM '._DB_PREFIX_.'tab WHERE id_tab = '.(int)$id_tab);
}
}
public static function getTabModulesList($id_tab)
{
$modules_list = array('default_list' => array(), 'slider_list' => array());
$xml_tab_modules_list = false;
$db_tab_module_list = Db::getInstance()->executeS('
SELECT module
FROM '._DB_PREFIX_.'tab_module_preference
WHERE `id_tab` = '.(int)$id_tab.'
AND `id_employee` = '.(int)Context::getContext()->employee->id
);
if (file_exists(_PS_ROOT_DIR_.Module::CACHE_FILE_TAB_MODULES_LIST))
$xml_tab_modules_list = @simplexml_load_file(_PS_ROOT_DIR_.Module::CACHE_FILE_TAB_MODULES_LIST);
$class_name = null;
$display_type = 'default_list';
if ($xml_tab_modules_list)
foreach($xml_tab_modules_list->tab as $tab)
{
foreach($tab->attributes() as $key => $value)
if ($key == 'class_name')
$class_name = (string)$value;
if (Tab::getIdFromClassName((string)$class_name) == $id_tab)
{
foreach($tab->attributes() as $key => $value)
if ($key == 'display_type')
$display_type = (string)$value;
foreach ($tab->children() as $module)
foreach ($module->attributes() as $k => $v)
if ($k == 'name')
$modules_list[$display_type][] = (string)$v;
}
}
//merge tab modules preferences from db with xml
foreach($db_tab_module_list as $m)
if (!in_array($m, $modules_list))
$modules_list['slider_list'][] = $m['module'];
return $modules_list;
}
}
+189 -4
View File
@@ -96,7 +96,13 @@ class AdminControllerCore extends Controller
/** @var array list to be generated */
protected $fields_list;
/** @var array modules list filters */
protected $filter_modules_list = null;
/** @var array modules list filters */
protected $modules_list = array();
/** @var array edit form to be generated */
protected $fields_form;
@@ -227,6 +233,7 @@ class AdminControllerCore extends Controller
protected $action;
protected $display;
protected $_includeContainer = true;
protected $tab_modules_list = array('default_list' => array(), 'slider_list' => array());
public $tpl_folder;
@@ -1016,7 +1023,7 @@ class AdminControllerCore extends Controller
'desc' => $this->l('Add new')
);
}
$this->addToolBarModulesListButton();
}
/**
@@ -1368,6 +1375,7 @@ class AdminControllerCore extends Controller
$this->getLanguages();
// toolbar (save, cancel, new, ..)
$this->initToolbar();
$this->initTabModuleList();
if ($this->display == 'edit' || $this->display == 'add')
{
if (!$this->loadObject(true))
@@ -1384,7 +1392,7 @@ class AdminControllerCore extends Controller
}
elseif (!$this->ajax)
{
$this->content .= $this->renderModulesList();
$this->content .= $this->renderList();
$this->content .= $this->renderOptions();
@@ -1398,6 +1406,39 @@ class AdminControllerCore extends Controller
'url_post' => self::$currentIndex.'&token='.$this->token,
));
}
/**
* init tab modules list and add button in toolbar
*/
protected function initTabModuleList()
{
if (!$this->isFresh(Module::CACHE_FILE_TAB_MODULES_LIST, 604800))
$this->refresh(Module::CACHE_FILE_TAB_MODULES_LIST, 'http://'.Tab::TAB_MODULE_LIST_URL);
$this->tab_modules_list = Tab::getTabModulesList($this->id);
if (is_array($this->tab_modules_list['default_list']) && count($this->tab_modules_list['default_list']))
$this->filter_modules_list = $tab_modules_list['default_list'];
else if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
{
$this->addToolBarModulesListButton();
$this->context->smarty->assign(array(
'tab_modules_list' => implode(',', $this->tab_modules_list['slider_list']),
'admin_module_ajax_url' => $this->context->link->getAdminLink('AdminModules'),
'back_tab_modules_list' => $this->context->link->getAdminLink(Tools::getValue('controller')),
'tab_modules_open' => (int)Tools::getValue('tab_modules_open')
));
}
}
protected function addToolBarModulesListButton()
{
if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
$this->toolbar_btn['modules-list'] = array(
'href' => '#',
'desc' => $this->l('Modules List')
);
}
/**
* initialize the invalid doom page of death
@@ -1424,7 +1465,17 @@ class AdminControllerCore extends Controller
'iso_is_fr' => strtoupper($this->context->language->iso_code) == 'FR',
));
}
public function renderModulesList()
{
if ($this->getModulesList($this->filter_modules_list))
{
$helper = new Helper();
return $helper->renderModulesList($this->modules_list);
}
}
/**
* Function used to render the list to display for this controller
*/
@@ -2090,6 +2141,31 @@ class AdminControllerCore extends Controller
else
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
}
public function getModulesList($filter_modules_list)
{
if (!is_array($filter_modules_list) && !is_null($filter_modules_list))
$filter_modules_list = array($filter_modules_list);
if (!count($filter_modules_list))
return false; //if there is no modules to display just return false;
$all_modules = Module::getModulesOnDisk(true);
$this->modules_list = array();
foreach($all_modules as $module)
{
if (in_array($module->name, $filter_modules_list))
{
$this->fillModuleData($module, 'select');
$this->modules_list[] = $module;
}
}
if (count($this->modules_list))
return true;
return false; //no module found on disk just return false;
}
public function getLanguages()
{
@@ -2787,4 +2863,113 @@ class AdminControllerCore extends Controller
// No content, return false
return false;
}
public function fillModuleData(&$module, $output_type = 'link', $back = null)
{
$obj = null;
if ($module->onclick_option)
$obj = new $module->name();
// Fill module data
$module->logo = '../../img/questionmark.png';
if (file_exists('../modules/'.$module->name.'/logo.gif'))
$module->logo = 'logo.gif';
if (file_exists('../modules/'.$module->name.'/logo.png'))
$module->logo = 'logo.png';
$module->optionsHtml = $this->displayModuleOptions($module, $output_type);
$module->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['update_url'] = self::$currentIndex.'&update='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['uninstall_onclick'] = ((!$module->onclick_option) ?
((empty($module->confirmUninstall)) ? '' : 'return confirm(\''.addslashes($module->confirmUninstall).'\');') :
$obj->onclickOption('uninstall', $module->options['uninstall_url']));
if ((Tools::getValue('module_name') == $module->name || in_array($module->name, explode('|', Tools::getValue('modules_list')))) && (int)Tools::getValue('conf') > 0)
$module->message = $this->_conf[(int)Tools::getValue('conf')];
if ((Tools::getValue('module_name') == $module->name || in_array($module->name, explode('|', Tools::getValue('modules_list')))) && (int)Tools::getValue('conf') > 0)
unset($obj);
}
/**
* Display modules list
*
* @param $module
* @param $output_type (link or select)
* @param $back
*
* @return string
*/
protected $translationsTab = array();
public function displayModuleOptions($module, $output_type = 'link', $back = null)
{
if (!isset($this->translationsTab['Disable this module']))
{
$this->translationsTab['Disable this module'] = $this->l('Disable this module');
$this->translationsTab['Enable this module for all shops'] = $this->l('Enable this module for all shops');
$this->translationsTab['Disable'] = $this->l('Disable');
$this->translationsTab['Enable'] = $this->l('Enable');
$this->translationsTab['Reset'] = $this->l('Reset');
$this->translationsTab['Configure'] = $this->l('Configure');
$this->translationsTab['Delete'] = $this->l('Delete');
$this->translationsTab['Install'] = $this->l('Install');
$this->translationsTab['Uninstall'] = $this->l('Uninstall');
$this->translationsTab['This action will permanently remove the module from the server. Are you sure you want to do this?'] = $this->l('This action will permanently remove the module from the server. Are you sure you want to do this?');
}
$modules_options = array(
'configure-module' => array(
'href' => self::$currentIndex.'&configure='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.urlencode($module->name),
'onclick' => $module->onclick_option && isset($module->onclick_option_content['configure']) ? $module->onclick_option_content['configure'] : '',
'title' => '',
'text' => $this->translationsTab['Configure'],
'cond' => $module->id && isset($module->is_configurable) && $module->is_configurable,
),
'desactive-module' => array(
'href' => self::$currentIndex.'&token='.$this->token.'&module_name='.urlencode($module->name).'&'.($module->active ? 'enable=0' : 'enable=1').'&tab_module='.$module->tab,
'onclick' => $module->active && $module->onclick_option && isset($module->onclick_option_content['desactive']) ? $module->onclick_option_content['desactive'] : '' ,
'title' => Shop::isFeatureActive() ? htmlspecialchars($module->active ? $this->translationsTab['Disable this module'] : $this->translationsTab['Enable this module for all shops']) : '',
'text' => $module->active ? $this->translationsTab['Disable'] : $this->translationsTab['Enable'],
'cond' => $module->id,
),
'reset-module' => array(
'href' => self::$currentIndex.'&token='.$this->token.'&module_name='.urlencode($module->name).'&reset&tab_module='.$module->tab,
'onclick' => $module->onclick_option && isset($module->onclick_option_content['reset']) ? $module->onclick_option_content['reset'] : '',
'title' => '',
'text' => $this->translationsTab['Reset'],
'cond' => $module->id && $module->active,
),
'delete-module' => array(
'href' => self::$currentIndex.'&delete='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.urlencode($module->name),
'onclick' => $module->onclick_option && isset($module->onclick_option_content['delete']) ? $module->onclick_option_content['delete'] : 'return confirm(\''.$this->translationsTab['This action will permanently remove the module from the server. Are you sure you want to do this?'].'\');',
'title' => '',
'text' => $this->translationsTab['Delete'],
'cond' => true,
),
);
$return = '';
foreach($modules_options as $option_name => $option)
{
if ($option['cond'])
{
if ($output_type == 'link')
$return .= '<span class="'.$option_name.'">
<a class="action_module" href="'.$option['href'].(!is_null($back) ? '&back='.urlencode($back) : '').'" onclick="'.$option['onclick'].'" title="'.$option['title'].'">'.$option['text'].'</a>
</span>';
else if ($output_type == 'select')
$return .= '<option id="'.$option_name.'" data-href="'.$option['href'].(!is_null($back) ? '&back='.urlencode($back) : '').'" data-onclick="'.$option['onclick'].'">'.$option['text'].'</option>';
}
}
if ($output_type == 'select')
{
if (!$module->id)
$return = '<option data-onclick="" data-href="'.self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name).(!is_null($back) ? '&back='.urlencode($back) : '').'" >'.$this->translationsTab['Install'].'</option>'.$return;
else
$return = '<option data-onclick="" data-href="'.self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name).(!is_null($back) ? '&back='.urlencode($back) : '').'" >'.$this->translationsTab['Uninstall'].'</option>'.$return;
$return = '<select id="select_'.$module->name.'">'.$return.'</select>';
}
return $return;
}
}
+10
View File
@@ -350,6 +350,16 @@ class HelperCore
return $tpl->fetch();
}
public function renderModulesList($modules_list)
{
$this->tpl_vars = array('modules_list' => $modules_list);
$tpl = $this->createTemplate('helpers/modules_list/list.tpl');
$tpl->assign($this->tpl_vars);
return $tpl->fetch();
}
public static function renderShopList()
{
+2
View File
@@ -122,6 +122,8 @@ abstract class ModuleCore
const CACHE_FILE_MODULES_LIST = '/config/xml/modules_list.xml';
const CACHE_FILE_TAB_MODULES_LIST = '/config/xml/tab_modules_list.xml';
const CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST = '/config/xml/default_country_modules_list.xml';
const CACHE_FILE_CUSTOMER_MODULES_LIST = '/config/xml/customer_modules_list.xml';