preview.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | VAPLoader::import('libraries.worktime.import.layout'); |
| 15 | |
| 16 | /** |
| 17 | * Groups the times by date, in order to have a better preview. |
| 18 | * |
| 19 | * @since 1.7.1 |
| 20 | */ |
| 21 | class VAPWorktimeImportLayoutPreview implements VAPWorktimeImportLayout |
| 22 | { |
| 23 | /** |
| 24 | * Refactor the times array into a specific layout. |
| 25 | * |
| 26 | * @param array $times An array of working times. |
| 27 | * |
| 28 | * @return mixed The resulting layout. |
| 29 | */ |
| 30 | public function build($times) |
| 31 | { |
| 32 | $lookup = []; |
| 33 | |
| 34 | $config = VAPFactory::getConfig(); |
| 35 | |
| 36 | foreach ($times as $time) |
| 37 | { |
| 38 | $time = (object) $time; |
| 39 | |
| 40 | $date = $time->tsdate; |
| 41 | |
| 42 | if (!isset($lookup[$date])) |
| 43 | { |
| 44 | $dt = JFactory::getDate($date); |
| 45 | |
| 46 | $dateElem = new stdClass; |
| 47 | $dateElem->date = $dt->format($config->get('dateformat')); |
| 48 | $dateElem->ymd = $dt->format('Ymd'); |
| 49 | $dateElem->times = []; |
| 50 | |
| 51 | $lookup[$date] = $dateElem; |
| 52 | } |
| 53 | |
| 54 | if (isset($time->fromts)) |
| 55 | { |
| 56 | $time->fromTime = JHtml::fetch('vikappointments.min2time', $time->fromts); |
| 57 | $time->toTime = JHtml::fetch('vikappointments.min2time', $time->endts); |
| 58 | |
| 59 | $lookup[$date]->times[] = $time; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return $lookup; |
| 64 | } |
| 65 | } |
| 66 |