employees.php
3 days ago
index.html
3 days ago
locations.php
3 days ago
locwdays.php
3 days ago
options.php
3 days ago
packages.php
3 days ago
payments.php
3 days ago
services.php
3 days ago
subscriptions.php
3 days ago
syspack.php
3 days ago
syssubscr.php
3 days ago
system.php
3 days ago
taxes.php
3 days ago
locations.php
203 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 | * Implement the wizard step used to configure the |
| 16 | * locations and the Google API Key. |
| 17 | * |
| 18 | * @since 1.7.1 |
| 19 | */ |
| 20 | class VAPWizardStepLocations extends VAPWizardStep |
| 21 | { |
| 22 | /** |
| 23 | * Returns the step title. |
| 24 | * Used as a very-short description. |
| 25 | * |
| 26 | * @return string The step title. |
| 27 | */ |
| 28 | public function getTitle() |
| 29 | { |
| 30 | return JText::translate('VAPMENULOCATIONS'); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Returns the step description. |
| 35 | * |
| 36 | * @return string The step description. |
| 37 | */ |
| 38 | public function getDescription() |
| 39 | { |
| 40 | return JText::translate('VAP_WIZARD_STEP_LOCATIONS_DESC'); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns an optional step icon. |
| 45 | * |
| 46 | * @return string The step icon. |
| 47 | */ |
| 48 | public function getIcon() |
| 49 | { |
| 50 | return '<i class="fas fa-map-marker-alt"></i>'; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Return the group to which the step belongs. |
| 55 | * |
| 56 | * @return string The group name. |
| 57 | */ |
| 58 | public function getGroup() |
| 59 | { |
| 60 | // belongs to APPOINTMENTS group |
| 61 | return JText::translate('VAPMENUTITLEHEADER2'); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the completion progress in percentage. |
| 66 | * |
| 67 | * @return integer The percentage progress (always rounded). |
| 68 | */ |
| 69 | public function getProgress() |
| 70 | { |
| 71 | $progress = 0; |
| 72 | |
| 73 | if ($this->getGoogleAK() !== '') |
| 74 | { |
| 75 | // API Key specified or ignored, increase progress |
| 76 | $progress += 50; |
| 77 | } |
| 78 | |
| 79 | if ($this->getLocations()) |
| 80 | { |
| 81 | // created locations, increase progress |
| 82 | $progress += 50; |
| 83 | } |
| 84 | |
| 85 | return $progress; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Checks whether the step has been completed. |
| 90 | * |
| 91 | * @return boolean True if completed, false otherwise. |
| 92 | */ |
| 93 | public function isCompleted() |
| 94 | { |
| 95 | // look for 100% completion progress |
| 96 | return $this->getProgress() == 100; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the button used to process the step. |
| 101 | * |
| 102 | * @return string The HTML of the button. |
| 103 | */ |
| 104 | public function getExecuteButton() |
| 105 | { |
| 106 | if ($this->getGoogleAK() !== '') |
| 107 | { |
| 108 | // point to the controller for creating a new location |
| 109 | return '<a href="index.php?option=com_vikappointments&task=location.add" class="btn btn-success">' . JText::translate('VAPNEW') . '</a>'; |
| 110 | } |
| 111 | |
| 112 | // use the default save button otherwise |
| 113 | $btn = parent::getExecuteButton(); |
| 114 | |
| 115 | // also append a button to skip avoid adding a Google API Key |
| 116 | $btn .= '<button type="button" class="btn" data-role="process.skip" style="float: right; margin-right: 4px;">' . JText::translate('VAPWIZARDBTNNOTNOW') . '</button>'; |
| 117 | |
| 118 | return $btn; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Implements the step execution. |
| 123 | * |
| 124 | * @param JRegistry $data The request data. |
| 125 | * |
| 126 | * @return boolean |
| 127 | */ |
| 128 | protected function doExecute($data) |
| 129 | { |
| 130 | // fetch the specified Google API Key |
| 131 | $apikey = $data->get('googleapikey'); |
| 132 | |
| 133 | if ($apikey) |
| 134 | { |
| 135 | // update configuration value |
| 136 | VAPFactory::getConfig()->set('googleapikey', $apikey); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | // missing API Key, register "skipped" flag |
| 141 | JFactory::getSession()->set('locations_gak_skipped', 1, 'vikappointments.wizard'); |
| 142 | } |
| 143 | |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Checks whether the specified step can be skipped. |
| 149 | * By default, all the steps are mandatory. |
| 150 | * |
| 151 | * @return boolean True if skippable, false otherwise. |
| 152 | */ |
| 153 | public function canIgnore() |
| 154 | { |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns a list of created locations. |
| 160 | * |
| 161 | * @return array A list of locations. |
| 162 | */ |
| 163 | public function getLocations() |
| 164 | { |
| 165 | static $locations = null; |
| 166 | |
| 167 | // get locations only once |
| 168 | if (is_null($locations)) |
| 169 | { |
| 170 | $dbo = JFactory::getDbo(); |
| 171 | |
| 172 | $q = $dbo->getQuery(true) |
| 173 | ->select($dbo->qn(array('id', 'name'))) |
| 174 | ->from($dbo->qn('#__vikappointments_employee_location')) |
| 175 | ->order($dbo->qn('id') . ' ASC'); |
| 176 | |
| 177 | $dbo->setQuery($q); |
| 178 | $locations = $dbo->loadObjectList(); |
| 179 | } |
| 180 | |
| 181 | return $locations; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Returns the configured Google API Key. |
| 186 | * |
| 187 | * @return mixed The google API Key or false if ignored. |
| 188 | */ |
| 189 | public function getGoogleAK() |
| 190 | { |
| 191 | // check whether the user decided to skip the configuration of the Google API Key |
| 192 | $ak_ignored = JFactory::getSession()->get('locations_gak_skipped', 0, 'vikappointments.wizard'); |
| 193 | |
| 194 | if ($ak_ignored) |
| 195 | { |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | // fetch Google API Key from configuration |
| 200 | return VAPFactory::getConfig()->get('googleapikey'); |
| 201 | } |
| 202 | } |
| 203 |