view.html.php
187 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 status codes view. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | class VikAppointmentsViewstatuscodes 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 | $model = JModelVAP::getInstance('statuscode'); |
| 33 | |
| 34 | // set the toolbar |
| 35 | $this->addToolBar(); |
| 36 | |
| 37 | $filters = array(); |
| 38 | $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName() . '.keys', 'keys', '', 'string'); |
| 39 | $filters['group'] = $app->getUserStateFromRequest($this->getPoolName() . '.group', 'group', '', 'string'); |
| 40 | |
| 41 | $this->filters = $filters; |
| 42 | |
| 43 | $this->ordering = $app->getUserStateFromRequest($this->getPoolName() . '.ordering', 'filter_order', 's.ordering', 'string'); |
| 44 | $this->orderDir = $app->getUserStateFromRequest($this->getPoolName() . '.orderdir', 'filter_order_Dir', 'ASC', 'string'); |
| 45 | |
| 46 | // db object |
| 47 | $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint'); |
| 48 | $lim0 = $this->getListLimitStart($filters); |
| 49 | $navbut = ""; |
| 50 | |
| 51 | $rows = array(); |
| 52 | |
| 53 | $q = $dbo->getQuery(true); |
| 54 | |
| 55 | $q->select('SQL_CALC_FOUND_ROWS s.*') |
| 56 | ->from($dbo->qn('#__vikappointments_status_code', 's')) |
| 57 | ->where(1) |
| 58 | ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir); |
| 59 | |
| 60 | if (strlen($filters['keys'])) |
| 61 | { |
| 62 | $q->andWhere(array( |
| 63 | $dbo->qn('s.name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"), |
| 64 | $dbo->qn('s.description') . ' LIKE ' . $dbo->q("%{$filters['keys']}%"), |
| 65 | ), 'OR'); |
| 66 | } |
| 67 | |
| 68 | if ($filters['group']) |
| 69 | { |
| 70 | $q->where($dbo->qn('s.' . $filters['group']) . ' = 1'); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Add support for manipulating query through the plugins. |
| 75 | * |
| 76 | * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery() |
| 77 | * |
| 78 | * @since 1.7 |
| 79 | */ |
| 80 | $this->onBeforeListQuery($q); |
| 81 | |
| 82 | $dbo->setQuery($q, $lim0, $lim); |
| 83 | $dbo->execute(); |
| 84 | |
| 85 | // assert limit used for list query |
| 86 | $this->assertListQuery($lim0, $lim); |
| 87 | |
| 88 | if ($dbo->getNumRows()) |
| 89 | { |
| 90 | $rows = $dbo->loadAssocList(); |
| 91 | $dbo->setQuery('SELECT FOUND_ROWS();'); |
| 92 | jimport('joomla.html.pagination'); |
| 93 | $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim); |
| 94 | $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]); |
| 95 | } |
| 96 | |
| 97 | if (VikAppointments::isMultilanguage()) |
| 98 | { |
| 99 | $translator = VAPFactory::getTranslator(); |
| 100 | |
| 101 | // find available translations |
| 102 | $lang = $translator->getAvailableLang( |
| 103 | 'statuscode', |
| 104 | array_map(function($row) { |
| 105 | return $row['id']; |
| 106 | }, $rows) |
| 107 | ); |
| 108 | |
| 109 | // assign languages found to the related elements |
| 110 | foreach ($rows as $k => $row) |
| 111 | { |
| 112 | $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Run some tests to make sure the status codes are properly configured. |
| 118 | * |
| 119 | * @since 1.7.1 |
| 120 | */ |
| 121 | if ($model->runTests() === false) |
| 122 | { |
| 123 | // display all the error messages |
| 124 | foreach ($model->getErrors() as $error) |
| 125 | { |
| 126 | $app->enqueueMessage($error, 'error'); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | $this->rows = $rows; |
| 131 | $this->navbut = $navbut; |
| 132 | |
| 133 | // Display the template (default.php) |
| 134 | parent::display($tpl); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Setting the toolbar. |
| 139 | * |
| 140 | * @return void |
| 141 | */ |
| 142 | protected function addToolBar() |
| 143 | { |
| 144 | // add menu title and some buttons to the page |
| 145 | JToolBarHelper::title(JText::translate('VAPMAINTITLEVIEWSTATUSCODES'), 'vikappointments'); |
| 146 | |
| 147 | $user = JFactory::getUser(); |
| 148 | |
| 149 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 150 | { |
| 151 | JToolBarHelper::addNew('statuscode.add', JText::translate('VAPNEW')); |
| 152 | JToolBarHelper::divider(); |
| 153 | } |
| 154 | |
| 155 | if ($user->authorise('core.edit', 'com_vikappointments')) |
| 156 | { |
| 157 | JToolBarHelper::editList('statuscode.edit', JText::translate('VAPEDIT')); |
| 158 | JToolBarHelper::spacer(); |
| 159 | } |
| 160 | |
| 161 | if ($user->authorise('core.delete', 'com_vikappointments')) |
| 162 | { |
| 163 | JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'statuscode.delete', JText::translate('VAPDELETE')); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Added the possibility to restore the status codes at the factory settings. |
| 168 | * |
| 169 | * @since 1.7.1 |
| 170 | */ |
| 171 | if ($user->authorise('core.admin', 'com_vikappointments')) |
| 172 | { |
| 173 | JToolBarHelper::custom('statuscode.restore', 'loop', 'loop', JText::translate('VAPRESTORE'), false); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Checks for advanced filters set in the request. |
| 179 | * |
| 180 | * @return boolean True if active, otherwise false. |
| 181 | */ |
| 182 | protected function hasFilters() |
| 183 | { |
| 184 | return ($this->filters['group']); |
| 185 | } |
| 186 | } |
| 187 |