* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ if (!defined('_PS_VERSION_')) { exit; } class GridHtml extends ModuleGridEngine { /** * @var array */ private $_values; /** * @var array */ private static $_columns; /** * @var string */ public $_title; /** * @var int */ public $_width; /** * @var int */ public $_height; /** * @var int */ public $_totalCount; /** * @var int */ public $_start; /** * @var int */ public $_limit; /** * GridHtml constructor. * * @param string|null $type */ public function __construct($type = null) { if ($type != null) { parent::__construct($type); } else { $this->name = 'gridhtml'; $this->tab = 'administration'; $this->version = '2.0.3'; $this->author = 'PrestaShop'; $this->need_instance = 0; Module::__construct(); $this->displayName = $this->trans('Simple HTML table display', [], 'Modules.Gridhtml.Admin'); $this->description = $this->trans('Just allow statistics to be displayed (and therefore analyzed) on your back office.', [], 'Modules.Gridhtml.Admin'); $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; } } public function install() { return parent::install() and $this->registerHook('GridEngine'); } /** * @param array $params * @param string $grider */ public static function hookGridEngine($params, $grider) { self::$_columns = $params['columns']; if (!isset($params['emptyMsg'])) { $params['emptyMsg'] = 'Empty'; } $customParams = ''; if (isset($params['customParams'])) { foreach ($params['customParams'] as $name => $value) { $customParams .= '&' . $name . '=' . urlencode($value); } } $html = ' '; foreach ($params['columns'] as $column) { $html .= ''; } $html .= '
' . $column['header'] . '
'; return $html; } public function setColumnsInfos(&$infos) { } /** * @param array $values */ public function setValues($values) { $this->_values = $values; } /** * @param string $title */ public function setTitle($title) { $this->_title = $title; } /** * @param int $width * @param int $height */ public function setSize($width, $height) { $this->_width = $width; $this->_height = $height; } /** * @param int $totalCount */ public function setTotalCount($totalCount) { $this->_totalCount = $totalCount; } /** * @param int $start * @param int $limit */ public function setLimit($start, $limit) { $this->_start = (int) $start; $this->_limit = (int) $limit; } public function render() { echo json_encode([ 'total' => $this->_totalCount, 'from' => min($this->_start + 1, $this->_totalCount), 'to' => min($this->_start + $this->_limit, $this->_totalCount), 'values' => $this->_values, ]); } }