//move all module classes in module sub-folder

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15154 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
vAugagneur
2012-05-10 09:32:04 +00:00
parent 2c8eb3fa4e
commit e472fd98d6
7 changed files with 0 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also 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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class CarrierModuleCore extends Module
{
abstract public function getOrderShippingCost($params, $shipping_cost);
abstract public function getOrderShippingCostExternal($params);
}
+93
View File
@@ -0,0 +1,93 @@
<?php
/**
* ImportModule class, ImportModule.php
* Import module management
* @category classes
*
* @author PrestaShop <support@prestashop.com>
* @copyright PrestaShop
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
* @version 1.4
*
*/
abstract class ImportModuleCore extends Module
{
protected $_link = null;
public $server;
public $user;
public $passwd;
public $database;
/** @var string Prefix database */
public $prefix;
public function __destruct()
{
if ($this->_link)
@mysql_close($this->_link);
}
protected function initDatabaseConnection()
{
if ($this->_link != null)
return $this->_link;
if ($this->_link = mysql_connect($this->server, $this->user, $this->passwd, true))
{
if (!mysql_select_db($this->database, $this->_link))
die(Tools::displayError('The database selection cannot be made.'));
if (!mysql_query('SET NAMES \'utf8\'', $this->_link))
die(Tools::displayError('Fatal error: no UTF-8 support. Please check your server configuration.'));
}
else
die(Tools::displayError('Link to database cannot be established.'));
return $this->_link;
}
public function ExecuteS($query)
{
$this->initDatabaseConnection();
$result = mysql_query($query, $this->_link);
$resultArray = array();
if ($result !== true)
while ($row = mysql_fetch_assoc($result))
$resultArray[] = $row;
return $resultArray;
}
public function Execute($query)
{
$this->initDatabaseConnection();
return mysql_query($query, $this->_link);
}
public function getValue($query)
{
$this->initDatabaseConnection();
$result = $this->executeS($query);
if (!count($result))
return 0;
else
return array_shift($result[0]);
}
public static function getImportModulesOnDisk()
{
$modules = Module::getModulesOnDisk(true);
foreach ($modules as $key => $module)
if (!isset($module->parent_class) || $module->parent_class != 'ImportModule')
unset($modules[$key]);
return $modules;
}
abstract public function getDefaultIdLang();
}
?>
File diff suppressed because it is too large Load Diff
+330
View File
@@ -0,0 +1,330 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also 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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 7329 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class ModuleGraphCore extends Module
{
protected $_employee;
/** @var integer array graph data */
protected $_values = array();
/** @var string array graph legends (X axis) */
protected $_legend = array();
/**@var string graph titles */
protected $_titles = array('main' => null, 'x' => null, 'y' => null);
/** @var ModuleGraphEngine graph engine */
protected $_render;
abstract protected function getData($layers);
public function setEmployee($id_employee)
{
$this->_employee = new Employee($id_employee);
}
public function setLang($id_lang)
{
$this->_id_lang = $id_lang;
}
protected function setDateGraph($layers, $legend = false)
{
// Get dates in a manageable format
$from_array = getdate(strtotime($this->_employee->stats_date_from));
$to_array = getdate(strtotime($this->_employee->stats_date_to));
// If the granularity is inferior to 1 day
if ($this->_employee->stats_date_from == $this->_employee->stats_date_to)
{
if ($legend)
for ($i = 0; $i < 24; $i++)
{
if ($layers == 1)
$this->_values[$i] = 0;
else
for ($j = 0; $j < $layers; $j++)
$this->_values[$j][$i] = 0;
$this->_legend[$i] = ($i % 2) ? '' : sprintf('%02dh', $i);
}
if (is_callable(array($this, 'setDayValues')))
$this->setDayValues($layers);
}
// If the granularity is inferior to 1 month TODO : change to manage 28 to 31 days
elseif (strtotime($this->_employee->stats_date_to) - strtotime($this->_employee->stats_date_from) <= 2678400)
{
if ($legend)
{
$days = array();
if ($from_array['mon'] == $to_array['mon'])
for ($i = $from_array['mday']; $i <= $to_array['mday']; ++$i)
$days[] = $i;
else
{
$imax = date('t', mktime(0, 0, 0, $from_array['mon'], 1, $from_array['year']));
for ($i = $from_array['mday']; $i <= $imax; ++$i)
$days[] = $i;
for ($i = 1; $i <= $to_array['mday']; ++$i)
$days[] = $i;
}
foreach ($days as $i)
{
if ($layers == 1)
$this->_values[$i] = 0;
else
for ($j = 0; $j < $layers; $j++)
$this->_values[$j][$i] = 0;
$this->_legend[$i] = ($i % 2) ? '' : sprintf('%02d', $i);
}
}
if (is_callable(array($this, 'setMonthValues')))
$this->setMonthValues($layers);
}
// If the granularity is less than 1 year
elseif (strtotime('-1 year', strtotime($this->_employee->stats_date_to)) < strtotime($this->_employee->stats_date_from))
{
if ($legend)
{
$months = array();
if ($from_array['year'] == $to_array['year'])
for ($i = $from_array['mon']; $i <= $to_array['mon']; ++$i)
$months[] = $i;
else
{
for ($i = $from_array['mon']; $i <= 12; ++$i)
$months[] = $i;
for ($i = 1; $i <= $to_array['mon']; ++$i)
$months[] = $i;
}
foreach ($months as $i)
{
if ($layers == 1)
$this->_values[$i] = 0;
else
for ($j = 0; $j < $layers; $j++)
$this->_values[$j][$i] = 0;
$this->_legend[$i] = sprintf('%02d', $i);
}
}
if (is_callable(array($this, 'setYearValues')))
$this->setYearValues($layers);
}
// If the granularity is greater than 1 year
else
{
if ($legend)
{
$years = array();
for ($i = $from_array['year']; $i <= $to_array['year']; ++$i)
$years[] = $i;
foreach ($years as $i)
{
if ($layers == 1)
$this->_values[$i] = 0;
else
for ($j = 0; $j < $layers; $j++)
$this->_values[$j][$i] = 0;
$this->_legend[$i] = sprintf('%04d', $i);
}
}
if (is_callable(array($this, 'setAllTimeValues')))
$this->setAllTimeValues($layers);
}
}
protected function csvExport($datas)
{
$context = Context::getContext();
$this->setEmployee($context->employee->id);
$this->setLang($context->language->id);
$layers = isset($datas['layers']) ? $datas['layers'] : 1;
if (isset($datas['option']))
$this->setOption($datas['option'], $layers);
$this->getData($layers);
// @todo use native CSV PHP functions ?
// Generate first line (column titles)
if (is_array($this->_titles['main']))
for ($i = 0, $total_main = count($this->_titles['main']); $i <= $total_main; $i++)
{
if ($i > 0)
$this->_csv .= ';';
if (isset($this->_titles['main'][$i]))
$this->_csv .= $this->_titles['main'][$i];
}
else // If there is only one column title, there is in fast two column (the first without title)
$this->_csv .= ';'.$this->_titles['main'];
$this->_csv .= "\n";
if (count($this->_legend))
{
$total = 0;
if ($datas['type'] == 'pie')
foreach ($this->_legend as $key => $legend)
for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i)
$total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$key]);
foreach ($this->_legend as $key => $legend)
{
$this->_csv .= $legend.';';
for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i)
{
if (!isset($this->_values[$i]) || !is_array($this->_values[$i]))
if (isset($this->_values[$key]))
{
// We don't want strings to be divided. Example: product name
if (is_numeric($this->_values[$key]))
$this->_csv .= $this->_values[$key] / (($datas['type'] == 'pie') ? $total : 1);
else
$this->_csv .= $this->_values[$key];
}
else
$this->_csv .= '0';
else
{
// We don't want strings to be divided. Example: product name
if (is_numeric($this->_values[$i][$key]))
$this->_csv .= $this->_values[$i][$key] / (($datas['type'] == 'pie') ? $total : 1);
else
$this->_csv .= $this->_values[$i][$key];
}
$this->_csv .= ';';
}
$this->_csv .= "\n";
}
}
$this->_displayCsv();
}
protected function _displayCsv()
{
ob_end_clean();
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$this->displayName.' - '.time().'.csv"');
echo $this->_csv;
exit;
}
public function create($render, $type, $width, $height, $layers)
{
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!Tools::file_exists_cache($file = dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
die(Tools::displayError());
require_once($file);
$this->_render = new $render($type);
$this->getData($layers);
$this->_render->createValues($this->_values);
$this->_render->setSize($width, $height);
$this->_render->setLegend($this->_legend);
$this->_render->setTitles($this->_titles);
}
public function draw()
{
$this->_render->draw();
}
/**
* @todo Set this method as abstracted ? Quid of module compatibility.
*/
public function setOption($option, $layers = 1)
{
}
public function engine($params)
{
$context = Context::getContext();
if (!($render = Configuration::get('PS_STATS_RENDER')))
return Tools::displayError('No graph engine selected');
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!file_exists(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
return Tools::displayError('Graph engine selected is unavailable.');
$id_employee = (int)$context->employee->id;
$id_lang = (int)$context->language->id;
if (!isset($params['layers']))
$params['layers'] = 1;
if (!isset($params['type']))
$params['type'] = 'column';
if (!isset($params['width']))
$params['width'] = 550;
if (!isset($params['height']))
$params['height'] = 270;
$url_params = $params;
$url_params['render'] = $render;
$url_params['module'] = Tools::getValue('module');
$url_params['id_employee'] = $id_employee;
$url_params['id_lang'] = $id_lang;
$drawer = 'drawer.php?'.http_build_query(array_map('Tools::safeOutput', $url_params), '', '&');
require_once(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php');
return call_user_func(array($render, 'hookGraphEngine'), $params, $drawer);
}
protected static function getEmployee($employee = null, Context $context = null)
{
if (!$context)
$context = Context::getContext();
if (!$employee)
$employee = $context->employee;
if (empty($employee->stats_date_from) || empty($employee->stats_date_to)
|| $employee->stats_date_from == '0000-00-00' || $employee->stats_date_to == '0000-00-00')
{
if (empty($employee->stats_date_from) || $employee->stats_date_from == '0000-00-00')
$employee->stats_date_from = date('Y').'-01-01';
if (empty($employee->stats_date_to) || $employee->stats_date_to == '0000-00-00')
$employee->stats_date_to = date('Y').'-12-31';
$employee->update();
}
return $employee;
}
public function getDate()
{
return ModuleGraph::getDateBetween($this->_employee);
}
public static function getDateBetween($employee = null)
{
$employee = ModuleGraph::getEmployee($employee);
return ' \''.$employee->stats_date_from.' 00:00:00\' AND \''.$employee->stats_date_to.' 23:59:59\' ';
}
public function getLang()
{
return $this->_id_lang;
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also 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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class ModuleGraphEngineCore extends Module
{
protected $_type;
public function __construct($type)
{
$this->_type = $type;
}
public function install()
{
if (!parent::install())
return false;
return Configuration::updateValue('PS_STATS_RENDER', $this->name);
}
public static function getGraphEngines()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT m.`name`
FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \'displayAdminStatsGraphEngine\'
');
$array_engines = array();
foreach ($result as $module)
{
$instance = Module::getInstanceByName($module['name']);
if (!$instance)
continue;
$array_engines[$module['name']] = array($instance->displayName, $instance->description);
}
return $array_engines;
}
abstract public function createValues($values);
abstract public function setSize($width, $height);
abstract public function setLegend($legend);
abstract public function setTitles($titles);
abstract public function draw();
}
+185
View File
@@ -0,0 +1,185 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also 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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 7048 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class ModuleGridCore extends Module
{
protected $_employee;
/** @var string array graph data */
protected $_values = array();
/** @var integer total number of values **/
protected $_totalCount = 0;
/**@var string graph titles */
protected $_title;
/**@var integer start */
protected $_start;
/**@var integer limit */
protected $_limit;
/**@var string column name on which to sort */
protected $_sort = null;
/**@var string sort direction DESC/ASC */
protected $_direction = null;
/** @var ModuleGridEngine grid engine */
protected $_render;
abstract protected function getData();
public function setEmployee($id_employee)
{
$this->_employee = new Employee($id_employee);
}
public function setLang($id_lang)
{
$this->_id_lang = $id_lang;
}
public function create($render, $type, $width, $height, $start, $limit, $sort, $dir)
{
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!Tools::file_exists_cache($file = dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
die(Tools::displayError());
require_once($file);
$this->_render = new $render($type);
$this->_start = $start;
$this->_limit = $limit;
$this->_sort = $sort;
$this->_direction = $dir;
$this->getData();
$this->_render->setTitle($this->_title);
$this->_render->setSize($width, $height);
$this->_render->setValues($this->_values);
$this->_render->setTotalCount($this->_totalCount);
$this->_render->setLimit($this->_start, $this->_limit);
}
public function render()
{
$this->_render->render();
}
public function engine($params)
{
if (!($render = Configuration::get('PS_STATS_GRID_RENDER')))
return Tools::displayError('No grid engine selected');
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!file_exists(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
return Tools::displayError('Grid engine selected is unavailable.');
$grider = 'grider.php?render='.$render.'&module='.Tools::safeOutput(Tools::getValue('module'));
$context = Context::getContext();
$grider .= '&id_employee='.(int)$context->employee->id;
$grider .= '&id_lang='.(int)$context->language->id;
if (!isset($params['width']) || !Validate::IsUnsignedInt($params['width']))
$params['width'] = 600;
if (!isset($params['height']) || !Validate::IsUnsignedInt($params['height']))
$params['height'] = 920;
if (!isset($params['start']) || !Validate::IsUnsignedInt($params['start']))
$params['start'] = 0;
if (!isset($params['limit']) || !Validate::IsUnsignedInt($params['limit']))
$params['limit'] = 40;
$grider .= '&width='.$params['width'];
$grider .= '&height='.$params['height'];
if (isset($params['start']) && Validate::IsUnsignedInt($params['start']))
$grider .= '&start='.$params['start'];
if (isset($params['limit']) && Validate::IsUnsignedInt($params['limit']))
$grider .= '&limit='.$params['limit'];
if (isset($params['type']) && Validate::IsName($params['type']))
$grider .= '&type='.$params['type'];
if (isset($params['option']) && Validate::IsGenericName($params['option']))
$grider .= '&option='.$params['option'];
if (isset($params['sort']) && Validate::IsName($params['sort']))
$grider .= '&sort='.$params['sort'];
if (isset($params['dir']) && Validate::isSortDirection($params['dir']))
$grider .= '&dir='.$params['dir'];
require_once(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php');
return call_user_func(array($render, 'hookGridEngine'), $params, $grider);
}
protected function csvExport($datas)
{
$this->_sort = $datas['defaultSortColumn'];
$this->setLang(Context::getContext()->language->id);
$this->getData();
$layers = isset($datas['layers']) ? $datas['layers'] : 1;
if (isset($datas['option']))
$this->setOption($datas['option'], $layers);
if (count($datas['columns']))
{
foreach ($datas['columns'] as $column)
$this->_csv .= $column['header'].';';
$this->_csv = rtrim($this->_csv, ';')."\n";
foreach ($this->_values as $value)
{
foreach ($datas['columns'] as $column)
$this->_csv .= $value[$column['dataIndex']].';';
$this->_csv = rtrim($this->_csv, ';')."\n";
}
}
$this->_displayCsv();
}
protected function _displayCsv()
{
ob_end_clean();
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$this->displayName.' - '.time().'.csv"');
echo $this->_csv;
exit;
}
public function getDate()
{
return ModuleGraph::getDateBetween($this->_employee);
}
public function getLang()
{
return $this->_id_lang;
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also 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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class ModuleGridEngineCore extends Module
{
protected $_type;
public function __construct($type)
{
$this->_type = $type;
}
public function install()
{
if (!parent::install())
return false;
return Configuration::updateValue('PS_STATS_GRID_RENDER', $this->name);
}
public static function getGridEngines()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT m.`name`
FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \'displayAdminStatsGridEngine\'
');
$array_engines = array();
foreach ($result as $module)
{
$instance = Module::getInstanceByName($module['name']);
if (!$instance)
continue;
$array_engines[$module['name']] = array($instance->displayName, $instance->description);
}
return $array_engines;
}
abstract public function setValues($values);
abstract public function setTitle($title);
abstract public function setSize($width, $height);
abstract public function setTotalCount($totalCount);
abstract public function setLimit($start, $limit);
abstract public function render();
}