view.html.php
176 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 cities view. |
| 16 | * |
| 17 | * @since 1.5 |
| 18 | */ |
| 19 | class VikAppointmentsViewcities 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 | $id_state = $input->get('id_state', 0, 'uint'); |
| 33 | |
| 34 | $q = $dbo->getQuery(true) |
| 35 | ->select($dbo->qn(array('id_country', 'state_name'))) |
| 36 | ->from($dbo->qn('#__vikappointments_states')) |
| 37 | ->where($dbo->qn('id') . ' = ' . $id_state); |
| 38 | |
| 39 | $dbo->setQuery($q, 0, 1); |
| 40 | $row = $dbo->loadObject(); |
| 41 | |
| 42 | if (!$row) |
| 43 | { |
| 44 | // state not found, back to countries list |
| 45 | $app->redirect('index.php?option=com_vikappointments&view=countries'); |
| 46 | exit; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * The filters are also handled by the export gateway. |
| 51 | * |
| 52 | * @see libraries.import.classes.states |
| 53 | */ |
| 54 | $filters = array(); |
| 55 | $filters['keys'] = $app->getUserStateFromRequest($this->getPoolName($id_state) . '.keys', 'keys', '', 'string'); |
| 56 | $filters['status'] = $app->getUserStateFromRequest($this->getPoolName($id_state) . '.status', 'status', '', 'string'); |
| 57 | $filters['id_state'] = $id_state; |
| 58 | $filters['id_country'] = $row->id_country; |
| 59 | |
| 60 | $this->filters = $filters; |
| 61 | |
| 62 | $this->ordering = $app->getUserStateFromRequest('vapcities.ordering', 'filter_order', 'c.city_name', 'string'); |
| 63 | $this->orderDir = $app->getUserStateFromRequest('vapcities.orderdir', 'filter_order_Dir', 'ASC', 'string'); |
| 64 | |
| 65 | // db object |
| 66 | $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'uint'); |
| 67 | $lim0 = $this->getListLimitStart($filters, $id_state); |
| 68 | $navbut = ""; |
| 69 | |
| 70 | // set the toolbar |
| 71 | $this->addToolBar($row->state_name); |
| 72 | |
| 73 | $rows = array(); |
| 74 | |
| 75 | $q = $dbo->getQuery(true); |
| 76 | |
| 77 | $q->select('SQL_CALC_FOUND_ROWS c.*') |
| 78 | ->from($dbo->qn('#__vikappointments_cities', 'c')) |
| 79 | ->where($dbo->qn('c.id_state') . ' = ' . $id_state) |
| 80 | ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir); |
| 81 | |
| 82 | if (strlen($filters['keys'])) |
| 83 | { |
| 84 | $q->where($dbo->qn('c.city_name') . ' LIKE ' . $dbo->q("%{$filters['keys']}%")); |
| 85 | } |
| 86 | |
| 87 | if (strlen($filters['status'])) |
| 88 | { |
| 89 | $q->where($dbo->qn('c.published') . ' = ' . (int) $filters['status']); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Add support for manipulating query through the plugins. |
| 94 | * |
| 95 | * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery() |
| 96 | * |
| 97 | * @since 1.7 |
| 98 | */ |
| 99 | $this->onBeforeListQuery($q); |
| 100 | |
| 101 | $dbo->setQuery($q, $lim0, $lim); |
| 102 | $dbo->execute(); |
| 103 | |
| 104 | // assert limit used for list query |
| 105 | $this->assertListQuery($lim0, $lim, $id_state); |
| 106 | |
| 107 | if ($dbo->getNumRows()) |
| 108 | { |
| 109 | $rows = $dbo->loadAssocList(); |
| 110 | $dbo->setQuery('SELECT FOUND_ROWS();'); |
| 111 | jimport('joomla.html.pagination'); |
| 112 | $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim); |
| 113 | $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]); |
| 114 | } |
| 115 | |
| 116 | $this->rows = $rows; |
| 117 | $this->navbut = $navbut; |
| 118 | |
| 119 | // display the template (default.php) |
| 120 | parent::display($tpl); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Setting the toolbar. |
| 125 | * |
| 126 | * @return void |
| 127 | */ |
| 128 | protected function addToolBar($state_name) |
| 129 | { |
| 130 | // add menu title and some buttons to the page |
| 131 | JToolBarHelper::title(JText::sprintf('VAPMAINTITLEVIEWCITIES', $state_name), 'vikappointments'); |
| 132 | |
| 133 | $user = JFactory::getUser(); |
| 134 | |
| 135 | JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_vikappointments&view=states&id_country=' . $this->filters['id_country']); |
| 136 | |
| 137 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 138 | { |
| 139 | JToolBarHelper::addNew('city.add'); |
| 140 | } |
| 141 | |
| 142 | if ($user->authorise('core.edit', 'com_vikappointments')) |
| 143 | { |
| 144 | JToolBarHelper::editList('city.edit'); |
| 145 | } |
| 146 | |
| 147 | if ($user->authorise('core.edit.state', 'com_vikappointments')) |
| 148 | { |
| 149 | JToolBarHelper::publishList('city.publish'); |
| 150 | JToolBarHelper::unpublishList('city.unpublish'); |
| 151 | } |
| 152 | |
| 153 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 154 | { |
| 155 | JToolBarHelper::custom('import', 'upload', 'upload', JText::translate('VAPIMPORT'), false); |
| 156 | } |
| 157 | |
| 158 | JToolBarHelper::custom('export', 'download', 'download', JText::translate('VAPEXPORT'), false); |
| 159 | |
| 160 | if ($user->authorise('core.delete', 'com_vikappointments')) |
| 161 | { |
| 162 | JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'city.delete'); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Checks for advanced filters set in the request. |
| 168 | * |
| 169 | * @return boolean True if active, otherwise false. |
| 170 | */ |
| 171 | protected function hasFilters() |
| 172 | { |
| 173 | return strlen($this->filters['status']); |
| 174 | } |
| 175 | } |
| 176 |