* @copyright 2016-2017 GFI Informatique, 2016-2017 TNT * @license https://opensource.org/licenses/MIT MIT License */ require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_Debug.php'; /** * Class TNTOfficiel_ShippingMethodSmartyFunction. */ class TNTOfficiel_ShippingMethodSmartyFunction { /** * @var array */ protected $_days = array( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ); /** * Returns an array with schedules for each days. * * @param array $params Parameters of the function * @param $smarty Smarty engine * * @return array */ public function getSchedules(array $params, $smarty) { TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__)); // Deafult value if (is_null($params)) { $params = array(); } $schedules = array(); if ($hours = $params['hours']) { $index = 0; // Position corresponds to the number of the day $position = 0; // Current day $day = null; // Part of the day $part = null; foreach ($hours as $hour) { $hour = trim($hour); $day = $this->_days[$position]; if (($index % 2 === 0) && ($index % 4 === 0)) { $part = 'AM'; } elseif (($index % 2 === 0) && ($index % 4 === 2)) { $part = 'PM'; } // Prepare the current Day if (!isset($schedules[$day])) { $schedules[$day] = array(); } // Prepare the current period of the current dya if (!isset($schedules[$day][$part]) && $hour) { $schedules[$day][$part] = array(); } // If hours different from 0 if ($hour) { // Add hour $schedules[$day][$part][] = $hour; } ++$index; if ($index % 4 == 0) { ++$position; } } } if ($assign = $params['assign']) { $smarty->assign(array( $assign => $schedules, )); } } }