PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / availability / timeline / renderer / table.php
vikappointments / site / helpers / libraries / availability / timeline / renderer Last commit date
default.php 5 days ago dropdown.php 5 days ago index.html 5 days ago multiple.php 5 days ago ratesgrid.php 5 days ago seats.php 5 days ago table.php 5 days ago
table.php
106 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.availability.timeline.renderer');
15
16 /**
17 * Employees list times-table renderer.
18 *
19 * @since 1.7
20 */
21 class VAPAvailabilityTimelineRendererTable extends VAPAvailabilityTimelineRenderer
22 {
23 /**
24 * Prepares the data to display.
25 *
26 * @param array $data An array of display data.
27 *
28 * @return array The resulting display data.
29 */
30 public function getDisplayData(array $data = array())
31 {
32 // register times-table
33 $data['table'] = $this->timeline;
34
35 // create previous date
36 $prev = JFactory::getDate(key($this->timeline) . ' 00:00:00');
37 $prev->modify('-' . count($this->timeline) . ' day');
38 $data['prev_day'] = $prev->format('Y-m-d');
39
40 if ($prev < JFactory::getDate('today 00:00:00'))
41 {
42 // day in the past, disable button
43 $data['prev_day'] = null;
44 }
45
46 // create next date
47 $next = JFactory::getDate(key($this->timeline) . ' 00:00:00');
48 $next->modify('+' . count($this->timeline) . ' day');
49 $data['next_day'] = $next->format('Y-m-d');
50
51 /**
52 * This value is used to calculate the maximum
53 * number of times available for a certain day.
54 *
55 * @var integer
56 */
57 $max_rows = 0;
58
59 // iterate all the supported times
60 foreach ($this->timeline as $timeline)
61 {
62 if (!$timeline)
63 {
64 // invalid timeline, go ahead
65 continue;
66 }
67
68 // register service ID
69 $data['id_ser'] = $timeline->getSearch()->get('id_service');
70
71 // convert timeline into a single level array
72 $arr = $timeline->toArray($flatten = true);
73
74 // take only the available time-slots
75 $arr = array_filter($arr, function($status)
76 {
77 return $status == 1;
78 });
79
80 // get maximum number of rows
81 $max_rows = max(array(count($arr), $max_rows));
82 }
83
84 // register maximum rows as display data
85 $data['max_rows'] = $max_rows;
86
87 return $data;
88 }
89
90 /**
91 * Renders the layout of the specified timeline.
92 *
93 * @param array $data An array of display data.
94 *
95 * @return string The timeline HTML.
96 */
97 protected function render(array $data = array())
98 {
99 $layout = new JLayoutFile('timeline.table');
100
101 // the layout is available only for the front-end
102
103 return $layout->render($data);
104 }
105 }
106