view.html.php
151 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 manage coupon view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanagecoupon 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 | $ids = $input->getUint('cid', array()); |
| 33 | $type = $ids ? 'edit' : 'new'; |
| 34 | |
| 35 | // set the toolbar |
| 36 | $this->addToolBar($type); |
| 37 | |
| 38 | $coupon = null; |
| 39 | |
| 40 | if ($type == 'edit') |
| 41 | { |
| 42 | $q = $dbo->getQuery(true) |
| 43 | ->select('*') |
| 44 | ->from($dbo->qn('#__vikappointments_coupon')) |
| 45 | ->where($dbo->qn('id') . ' = ' . $ids[0]); |
| 46 | |
| 47 | $dbo->setQuery($q, 0, 1); |
| 48 | $coupon = $dbo->loadObject(); |
| 49 | |
| 50 | if ($coupon) |
| 51 | { |
| 52 | // get coupon employees |
| 53 | $q = $dbo->getQuery(true) |
| 54 | ->select($dbo->qn('id_employee')) |
| 55 | ->from($dbo->qn('#__vikappointments_coupon_employee_assoc')) |
| 56 | ->where($dbo->qn('id_coupon') . ' = ' . $coupon->id); |
| 57 | |
| 58 | $dbo->setQuery($q); |
| 59 | $coupon->employees = $dbo->loadColumn(); |
| 60 | |
| 61 | // get coupon services |
| 62 | $q = $dbo->getQuery(true) |
| 63 | ->select($dbo->qn('id_service')) |
| 64 | ->from($dbo->qn('#__vikappointments_coupon_service_assoc')) |
| 65 | ->where($dbo->qn('id_coupon') . ' = ' . $coupon->id); |
| 66 | |
| 67 | $dbo->setQuery($q); |
| 68 | $coupon->services = $dbo->loadColumn(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (empty($coupon)) |
| 73 | { |
| 74 | $coupon = (object) $this->getBlankItem(); |
| 75 | } |
| 76 | |
| 77 | // use coupon data stored in user state |
| 78 | $this->injectUserStateData($coupon, 'vap.coupon.data'); |
| 79 | |
| 80 | $this->coupon = $coupon; |
| 81 | |
| 82 | // display the template |
| 83 | parent::display($tpl); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Setting the toolbar. |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | protected function addToolBar($type) |
| 92 | { |
| 93 | // add menu title and some buttons to the page |
| 94 | if ($type == 'edit') |
| 95 | { |
| 96 | JToolBarHelper::title(JText::translate('VAPMAINTITLEEDITCOUPON'), 'vikappointments'); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | JToolBarHelper::title(JText::translate('VAPMAINTITLENEWCOUPON'), 'vikappointments'); |
| 101 | } |
| 102 | |
| 103 | $user = JFactory::getUser(); |
| 104 | |
| 105 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 106 | || $user->authorise('core.create', 'com_vikappointments')) |
| 107 | { |
| 108 | JToolbarHelper::apply('coupon.save', JText::translate('VAPSAVE')); |
| 109 | JToolbarHelper::save('coupon.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 110 | } |
| 111 | |
| 112 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 113 | && $user->authorise('core.create', 'com_vikappointments')) |
| 114 | { |
| 115 | JToolbarHelper::save2new('coupon.savenew', JText::translate('VAPSAVEANDNEW')); |
| 116 | } |
| 117 | |
| 118 | JToolbarHelper::cancel('coupon.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns a blank item. |
| 123 | * |
| 124 | * @return array A blank item for new requests. |
| 125 | */ |
| 126 | protected function getBlankItem() |
| 127 | { |
| 128 | return array( |
| 129 | 'id' => 0, |
| 130 | 'code' => VikAppointments::generateSerialCode(12, 'coupon'), |
| 131 | 'type' => 1, |
| 132 | 'percentot' => 2, |
| 133 | 'value' => 0.0, |
| 134 | 'mincost' => 0.0, |
| 135 | 'pubmode' => 1, |
| 136 | 'dstart' => '', |
| 137 | 'dend' => '', |
| 138 | 'lastminute' => 0, |
| 139 | 'max_quantity' => 1, |
| 140 | 'used_quantity' => 0, |
| 141 | 'maxperuser' => 0, |
| 142 | 'remove_gift' => 0, |
| 143 | 'applicable' => '', |
| 144 | 'notes' => '', |
| 145 | 'id_group' => 0, |
| 146 | 'services' => array(), |
| 147 | 'employees' => array(), |
| 148 | ); |
| 149 | } |
| 150 | } |
| 151 |