view.html.php
215 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 methods of payment view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewpayments 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 | $dbo = JFactory::getDbo(); |
| 31 | |
| 32 | $filters = array(); |
| 33 | $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName() . '.keys', 'keys', '', 'string'); |
| 34 | $filters['status'] = $app->getUserStateFromRequest($this->getPoolName() . '.status', 'status', '', 'string'); |
| 35 | $filters['type'] = $app->getUserStateFromRequest($this->getPoolName() . '.type', 'type', 0, 'uint'); |
| 36 | $filters['file'] = $app->getUserStateFromRequest($this->getPoolName() . '.file', 'file', '', 'string'); |
| 37 | |
| 38 | $filters['id_employee'] = $input->get('id_employee', 0, 'uint'); |
| 39 | |
| 40 | if ($filters['id_employee']) |
| 41 | { |
| 42 | $q = $dbo->getQuery(true) |
| 43 | ->select($dbo->qn('nickname')) |
| 44 | ->from($dbo->qn('#__vikappointments_employee')) |
| 45 | ->where($dbo->qn('id') . ' = ' . (int) $filters['id_employee']); |
| 46 | |
| 47 | $dbo->setQuery($q, 0, 1); |
| 48 | $employee = $dbo->loadResult(); |
| 49 | |
| 50 | if (!$employee) |
| 51 | { |
| 52 | throw new Exception(sprintf('Employee [%d] not found', $filters['id_employee']), 404); |
| 53 | } |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | $employee = ''; |
| 58 | } |
| 59 | |
| 60 | // set the toolbar |
| 61 | $this->addToolBar($employee); |
| 62 | |
| 63 | $this->filters = $filters; |
| 64 | |
| 65 | $this->ordering = $app->getUserStateFromRequest($this->getPoolName() . '.ordering', 'filter_order', 'p.ordering', 'string'); |
| 66 | $this->orderDir = $app->getUserStateFromRequest($this->getPoolName() . '.orderdir', 'filter_order_Dir', 'ASC', 'string'); |
| 67 | |
| 68 | // db object |
| 69 | $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint'); |
| 70 | $lim0 = $this->getListLimitStart($filters); |
| 71 | $navbut = ""; |
| 72 | |
| 73 | $rows = array(); |
| 74 | |
| 75 | $q = $dbo->getQuery(true); |
| 76 | |
| 77 | $q->select('SQL_CALC_FOUND_ROWS p.*') |
| 78 | ->from($dbo->qn('#__vikappointments_gpayments', 'p')) |
| 79 | ->where($dbo->qn('p.id_employee') . ' = ' . $filters['id_employee']) |
| 80 | ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir); |
| 81 | |
| 82 | if (strlen($filters['keys'])) |
| 83 | { |
| 84 | $q->andWhere(array( |
| 85 | $dbo->qn('p.name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"), |
| 86 | $dbo->qn('p.file') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"), |
| 87 | ), 'OR'); |
| 88 | } |
| 89 | |
| 90 | if (strlen($filters['status'])) |
| 91 | { |
| 92 | $q->where($dbo->qn('p.published') . ' = ' . (int) $filters['status']); |
| 93 | } |
| 94 | |
| 95 | if ($filters['type'] == 1) |
| 96 | { |
| 97 | $q->where($dbo->qn('p.appointments') . ' = 1'); |
| 98 | } |
| 99 | else if ($filters['type'] == 2) |
| 100 | { |
| 101 | $q->where($dbo->qn('p.subscr') . ' = 1'); |
| 102 | } |
| 103 | |
| 104 | if ($filters['file']) |
| 105 | { |
| 106 | $q->where($dbo->qn('p.file') . ' = ' . $dbo->q($filters['file'])); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Add support for manipulating query through the plugins. |
| 111 | * |
| 112 | * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery() |
| 113 | * |
| 114 | * @since 1.7 |
| 115 | */ |
| 116 | $this->onBeforeListQuery($q); |
| 117 | |
| 118 | $dbo->setQuery($q, $lim0, $lim); |
| 119 | $dbo->execute(); |
| 120 | |
| 121 | // assert limit used for list query |
| 122 | $this->assertListQuery($lim0, $lim); |
| 123 | |
| 124 | if ($dbo->getNumRows()) |
| 125 | { |
| 126 | $rows = $dbo->loadAssocList(); |
| 127 | $dbo->setQuery('SELECT FOUND_ROWS();'); |
| 128 | jimport('joomla.html.pagination'); |
| 129 | $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim); |
| 130 | $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]); |
| 131 | } |
| 132 | |
| 133 | if (VikAppointments::isMultilanguage()) |
| 134 | { |
| 135 | $translator = VAPFactory::getTranslator(); |
| 136 | |
| 137 | // find available translations |
| 138 | $lang = $translator->getAvailableLang( |
| 139 | 'payment', |
| 140 | array_map(function($row) { |
| 141 | return $row['id']; |
| 142 | }, $rows) |
| 143 | ); |
| 144 | |
| 145 | // assign languages found to the related elements |
| 146 | foreach ($rows as $k => $row) |
| 147 | { |
| 148 | $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array(); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | $this->rows = $rows; |
| 153 | $this->navbut = $navbut; |
| 154 | |
| 155 | // display the template (default.php) |
| 156 | parent::display($tpl); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Setting the toolbar. |
| 161 | * |
| 162 | * @param string $employee The employee name, if not looking for global payments. |
| 163 | * |
| 164 | * @return void |
| 165 | */ |
| 166 | protected function addToolBar($employee = '') |
| 167 | { |
| 168 | // add menu title and some buttons to the page |
| 169 | if ($employee) |
| 170 | { |
| 171 | // employee payments |
| 172 | JToolBarHelper::title(JText::sprintf('VAPMAINTITLEVIEWEMPPAYMENTS', $employee), 'vikappointments'); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | // global payments |
| 177 | JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWPAYMENTS'), 'vikappointments'); |
| 178 | } |
| 179 | |
| 180 | $user = JFactory::getUser(); |
| 181 | |
| 182 | if ($employee) |
| 183 | { |
| 184 | JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_vikappointments&view=employees'); |
| 185 | } |
| 186 | |
| 187 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 188 | { |
| 189 | JToolBarHelper::addNew('payment.add'); |
| 190 | } |
| 191 | |
| 192 | if ($user->authorise('core.edit', 'com_vikappointments')) |
| 193 | { |
| 194 | JToolBarHelper::editList('payment.edit'); |
| 195 | } |
| 196 | |
| 197 | if ($user->authorise('core.delete', 'com_vikappointments')) |
| 198 | { |
| 199 | JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'payment.delete'); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Checks for advanced filters set in the request. |
| 205 | * |
| 206 | * @return boolean True if active, otherwise false. |
| 207 | */ |
| 208 | protected function hasFilters() |
| 209 | { |
| 210 | return (strlen($this->filters['status']) |
| 211 | || $this->filters['type'] |
| 212 | || $this->filters['file']); |
| 213 | } |
| 214 | } |
| 215 |