view.html.php
170 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 groups view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewgroups 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 | // extract page type from session |
| 33 | $page_type = $app->getUserStateFromRequest($this->getPoolName() . 'pagetype', 'type', 1, 'uint'); |
| 34 | |
| 35 | // set the toolbar |
| 36 | $this->addToolBar($page_type); |
| 37 | |
| 38 | $filters = array(); |
| 39 | $filters['keysearch'] = $app->getUserStateFromRequest($this->getPoolName($page_type) . '.keysearch', 'keysearch', '', 'string'); |
| 40 | |
| 41 | $this->filters = $filters; |
| 42 | |
| 43 | $this->ordering = $app->getUserStateFromRequest($this->getPoolName($page_type) . '.ordering', 'filter_order', 'g.ordering', 'string'); |
| 44 | $this->orderDir = $app->getUserStateFromRequest($this->getPoolName($page_type) . '.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, $page_type); |
| 49 | $navbut = ""; |
| 50 | |
| 51 | $rows = array(); |
| 52 | |
| 53 | $q = $dbo->getQuery(true); |
| 54 | |
| 55 | $q->select('SQL_CALC_FOUND_ROWS g.*') |
| 56 | ->group($dbo->qn('g.id')) |
| 57 | ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir); |
| 58 | |
| 59 | if ($page_type == 1) |
| 60 | { |
| 61 | $q->select('COUNT(s.id) AS ' . $dbo->qn('count')) |
| 62 | ->from($dbo->qn('#__vikappointments_group', 'g')) |
| 63 | ->leftjoin($dbo->qn('#__vikappointments_service', 's') . ' ON ' . $dbo->qn('g.id') . ' = ' . $dbo->qn('s.id_group')); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | $q->select('COUNT(e.id) AS ' . $dbo->qn('count')) |
| 68 | ->from($dbo->qn('#__vikappointments_employee_group', 'g')) |
| 69 | ->leftjoin($dbo->qn('#__vikappointments_employee', 'e') . ' ON ' . $dbo->qn('g.id') . ' = ' . $dbo->qn('e.id_group')); |
| 70 | } |
| 71 | |
| 72 | $q->where(1); |
| 73 | |
| 74 | if (strlen($filters['keysearch'])) |
| 75 | { |
| 76 | $q->andWhere(array( |
| 77 | $dbo->qn('g.name') . ' LIKE ' . $dbo->q("%{$filters['keysearch']}%"), |
| 78 | $dbo->qn('g.description') . ' LIKE ' . $dbo->q("%{$filters['keysearch']}%"), |
| 79 | ), 'OR'); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Add support for manipulating query through the plugins. |
| 84 | * |
| 85 | * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery() |
| 86 | * |
| 87 | * @since 1.7 |
| 88 | */ |
| 89 | $this->onBeforeListQuery($q); |
| 90 | |
| 91 | $dbo->setQuery($q, $lim0, $lim); |
| 92 | $dbo->execute(); |
| 93 | |
| 94 | // assert limit used for list query |
| 95 | $this->assertListQuery($lim0, $lim, $page_type); |
| 96 | |
| 97 | if ($dbo->getNumRows()) |
| 98 | { |
| 99 | $rows = $dbo->loadAssocList(); |
| 100 | $dbo->setQuery('SELECT FOUND_ROWS();'); |
| 101 | jimport('joomla.html.pagination'); |
| 102 | $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim); |
| 103 | $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]); |
| 104 | } |
| 105 | |
| 106 | if (VikAppointments::isMultilanguage()) |
| 107 | { |
| 108 | $translator = VAPFactory::getTranslator(); |
| 109 | |
| 110 | // find available translations |
| 111 | $lang = $translator->getAvailableLang( |
| 112 | $page_type == 1 ? 'group' : 'empgroup', |
| 113 | array_map(function($row) { |
| 114 | return $row['id']; |
| 115 | }, $rows) |
| 116 | ); |
| 117 | |
| 118 | // assign languages found to the related elements |
| 119 | foreach ($rows as $k => $row) |
| 120 | { |
| 121 | $rows[$k]['languages'] = isset($lang[$row['id']]) ? $lang[$row['id']] : array(); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | $this->rows = $rows; |
| 126 | $this->pageType = $page_type; |
| 127 | $this->navbut = $navbut; |
| 128 | |
| 129 | // display the template (default.php) |
| 130 | parent::display($tpl); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Setting the toolbar. |
| 135 | * |
| 136 | * @return void |
| 137 | */ |
| 138 | protected function addToolBar($page) |
| 139 | { |
| 140 | // add menu title and some buttons to the page |
| 141 | JToolBarHelper::title(JText::translate($page == 1 ? 'VAPMAINTITLEVIEWGROUPS' : 'VAPMAINTITLEVIEWEMPGROUPS'), 'vikappointments'); |
| 142 | |
| 143 | $user = JFactory::getUser(); |
| 144 | |
| 145 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 146 | { |
| 147 | JToolBarHelper::addNew('group.add', JText::translate('VAPNEW')); |
| 148 | JToolBarHelper::divider(); |
| 149 | } |
| 150 | |
| 151 | if ($user->authorise('core.edit', 'com_vikappointments')) |
| 152 | { |
| 153 | JToolBarHelper::editList('group.edit', JText::translate('VAPEDIT')); |
| 154 | JToolBarHelper::spacer(); |
| 155 | } |
| 156 | |
| 157 | if ($user->authorise('core.delete', 'com_vikappointments')) |
| 158 | { |
| 159 | JToolBarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'group.delete', JText::translate('VAPDELETE')); |
| 160 | } |
| 161 | |
| 162 | if ($user->authorise('core.create', 'com_vikappointments')) |
| 163 | { |
| 164 | JToolBarHelper::custom('import', 'upload', 'upload', JText::translate('VAPIMPORT'), false); |
| 165 | } |
| 166 | |
| 167 | JToolBarHelper::custom('export', 'download', 'download', JText::translate('VAPEXPORT'), false); |
| 168 | } |
| 169 | } |
| 170 |