view.html.php
192 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 | /** |
| 15 | * VikAppointments employees view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewemployeeslist extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $app = JFactory::getApplication(); |
| 29 | $input = $app->input; |
| 30 | |
| 31 | // get employee group from request |
| 32 | $this->empGroup = $input->getInt('employee_group', 0); |
| 33 | |
| 34 | /** |
| 35 | * Load employees through the view model. |
| 36 | * |
| 37 | * @since 1.7 |
| 38 | */ |
| 39 | $model = JModelVAP::getInstance('employeeslist'); |
| 40 | |
| 41 | $options = array(); |
| 42 | |
| 43 | // set initial pagination offset |
| 44 | $options['start'] = $input->getUint('limitstart', 0); |
| 45 | |
| 46 | // get selected ordering |
| 47 | $options['ordering'] = $app->getUserStateFromRequest('employees.ordering', 'ordering', null, 'uint'); |
| 48 | |
| 49 | // search query (filters in request) |
| 50 | $filters = $model->getActiveFilters(); |
| 51 | |
| 52 | /** |
| 53 | * Inject employee ID within the filters. |
| 54 | * |
| 55 | * @since 1.7.8 Ignore in case the group is empty, otherwise clicking the pagination buttons |
| 56 | * might inject unused filters within the query string and automatically switch |
| 57 | * the page layout (AJAX filters). |
| 58 | */ |
| 59 | if ($this->empGroup > 0) |
| 60 | { |
| 61 | $filters['employee_group'] = $this->empGroup; |
| 62 | } |
| 63 | |
| 64 | // load employees |
| 65 | $this->employees = $model->getItems($filters, $options); |
| 66 | |
| 67 | $filters_in_request = (bool) $filters; |
| 68 | |
| 69 | // unset employee group from filters |
| 70 | unset($filters['employee_group']); |
| 71 | |
| 72 | if ($this->employees) |
| 73 | { |
| 74 | // get pagination HTML |
| 75 | $this->navbut = $model->getPagination()->getPagesLinks(); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | $this->navbut = ''; |
| 80 | } |
| 81 | |
| 82 | // get employees groups |
| 83 | $this->groups = $model->getGroups(); |
| 84 | |
| 85 | // get AJAX search mode from configuration |
| 86 | $this->ajaxSearch = VAPFactory::getConfig()->getUint('empajaxsearch'); |
| 87 | |
| 88 | if ($this->ajaxSearch == 2) |
| 89 | { |
| 90 | // if AJAX seach should be used only with filters, make sure |
| 91 | // there is at least a filter set |
| 92 | $this->ajaxSearch = (int) $filters_in_request; |
| 93 | } |
| 94 | |
| 95 | // register selected employee for auto-scroll |
| 96 | $this->selEmployee = $input->getInt('id_emp', 0); |
| 97 | |
| 98 | $this->hasFilters = $filters_in_request; |
| 99 | $this->filters = $filters; |
| 100 | $this->options = $options; |
| 101 | |
| 102 | $this->employeesCount = $model->getTotal(); |
| 103 | |
| 104 | // fetch current menu item ID |
| 105 | $this->itemid = $input->getUint('Itemid'); |
| 106 | |
| 107 | if ($this->ajaxSearch) |
| 108 | { |
| 109 | // include script needed to support AJAX search |
| 110 | $this->addJS(); |
| 111 | } |
| 112 | |
| 113 | // prepare page content |
| 114 | VikAppointments::prepareContent($this); |
| 115 | |
| 116 | // display the template |
| 117 | parent::display($tpl); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Helper method used to include the JS functions |
| 122 | * required for the AJAX search tool. |
| 123 | * |
| 124 | * @return void |
| 125 | * |
| 126 | * @since 1.6 |
| 127 | */ |
| 128 | private function addJS() |
| 129 | { |
| 130 | $vik = VAPApplication::getInstance(); |
| 131 | |
| 132 | // build AJAX end-point |
| 133 | $url = $vik->ajaxUrl('index.php?option=com_vikappointments&task=employeeslist.availtableajax' . ($this->itemid ? '&Itemid=' . $this->itemid : ''), false); |
| 134 | |
| 135 | // setup display data for layout |
| 136 | $data = array( |
| 137 | 'url' => $url, |
| 138 | ); |
| 139 | |
| 140 | /** |
| 141 | * The javascript functions needed by the time table are declared by the layout below: |
| 142 | * /components/com_vikappointments/layouts/javascript/timeline/table.php |
| 143 | * |
| 144 | * If you need to change something from this layout, just create |
| 145 | * an override of this layout by following the instructions below: |
| 146 | * - open the back-end of your Joomla |
| 147 | * - visit the Extensions > Templates > Templates page |
| 148 | * - edit the active template |
| 149 | * - access the "Create Overrides" tab |
| 150 | * - select Layouts > com_vikappointments > javascript |
| 151 | * - start editing the timeline/table.php file on your template to create your own layout |
| 152 | * |
| 153 | * @since 1.6 |
| 154 | */ |
| 155 | $js = JLayoutHelper::render('javascript.timeline.table', $data); |
| 156 | |
| 157 | $this->document->addScriptDeclaration($js); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Helper method used to convert the filters into a URI query string. |
| 162 | * |
| 163 | * @return string |
| 164 | * |
| 165 | * @since 1.7.6 |
| 166 | */ |
| 167 | protected function getUriFilters() |
| 168 | { |
| 169 | $query = ''; |
| 170 | |
| 171 | foreach ($this->filters as $k => $v) |
| 172 | { |
| 173 | if ($v !== null && $v !== '') |
| 174 | { |
| 175 | if (is_array($v)) |
| 176 | { |
| 177 | foreach ($v as $iv) |
| 178 | { |
| 179 | $query .= "&filters[$k][]=$iv"; |
| 180 | } |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | $query .= "&filters[$k]=$v"; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return ltrim($query, '&'); |
| 190 | } |
| 191 | } |
| 192 |