apiban.php
4 years ago
apilog.php
2 years ago
apiplugin.php
4 years ago
apiuser.php
2 years ago
apiuseroptions.php
2 years ago
backup.php
4 months ago
caldays.php
1 month ago
calendar.php
1 month ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
4 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
4 months ago
conversion.php
4 years ago
country.php
2 years ago
coupon.php
2 years ago
couponemployee.php
4 years ago
coupongroup.php
2 years ago
couponservice.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
4 months ago
customf.php
2 years ago
customfservice.php
4 years ago
customizer.php
4 years ago
empgroup.php
2 years ago
employee.php
2 years ago
empsettings.php
4 years ago
file.php
4 years ago
findreservation.php
1 month ago
group.php
2 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langempgroup.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
2 years ago
langoptiongroup.php
4 years ago
langoptionvar.php
4 years ago
langpackage.php
4 years ago
langpackgroup.php
4 years ago
langpayment.php
4 years ago
langservice.php
4 years ago
langstatuscode.php
4 years ago
langsubscr.php
4 years ago
langtax.php
2 years ago
langtaxrule.php
4 years ago
location.php
2 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
2 years ago
multiorder.php
1 month ago
option.php
1 year ago
optiongroup.php
2 years ago
optionvar.php
1 year ago
orderstatus.php
2 years ago
package.php
2 years ago
packageservice.php
4 years ago
packgroup.php
2 years ago
packorder.php
2 years ago
packorderitem.php
1 month ago
payment.php
2 years ago
rate.php
2 years ago
reportsemp.php
4 months ago
reportsser.php
4 months ago
reservation.php
1 month ago
resoptassoc.php
2 years ago
restriction.php
2 years ago
review.php
3 years ago
serempassoc.php
1 year ago
seroptassoc.php
4 years ago
serrateassoc.php
4 years ago
serrestrassoc.php
4 years ago
service.php
2 years ago
state.php
2 years ago
statswidget.php
2 years ago
statuscode.php
2 years ago
subscription.php
1 month ago
subscrorder.php
1 month ago
tag.php
4 years ago
tax.php
2 years ago
taxrule.php
2 years ago
updateprogram.php
4 years ago
usernote.php
2 years ago
waitinglist.php
1 month ago
webhook.php
1 year ago
worktime.php
1 month ago
customf.php
222 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 | VAPLoader::import('libraries.mvc.model'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments custom field model. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsModelCustomf extends JModelVAP |
| 22 | { |
| 23 | /** |
| 24 | * Returns a list of services assigned to the specified field. |
| 25 | * |
| 26 | * @param integer $id The field id. |
| 27 | * |
| 28 | * @return array |
| 29 | */ |
| 30 | public function getServices($id) |
| 31 | { |
| 32 | if ($id) |
| 33 | { |
| 34 | $dbo = JFactory::getDbo(); |
| 35 | |
| 36 | // load any field-service relation |
| 37 | $q = $dbo->getQuery(true) |
| 38 | ->select($dbo->qn('id_service')) |
| 39 | ->from($dbo->qn('#__vikappointments_cf_service_assoc')) |
| 40 | ->where($dbo->qn('id_field') . ' = ' . (int) $id); |
| 41 | |
| 42 | $dbo->setQuery($q); |
| 43 | return $dbo->loadColumn(); |
| 44 | } |
| 45 | |
| 46 | return array(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Basic save implementation. |
| 51 | * |
| 52 | * @param mixed $data Either an array or an object of data to save. |
| 53 | * |
| 54 | * @return mixed The ID of the record on success, false otherwise. |
| 55 | */ |
| 56 | public function save($data) |
| 57 | { |
| 58 | $table = $this->getTable(); |
| 59 | |
| 60 | // manually register here the specified data into the user state |
| 61 | $table->setUserStateData($data); |
| 62 | |
| 63 | // bind data into table |
| 64 | if (!$table->bind($data)) |
| 65 | { |
| 66 | // something went wrong, while binding |
| 67 | $error = $table->getError($get_last = null, $string = true); |
| 68 | |
| 69 | if ($error) |
| 70 | { |
| 71 | // error found, register it within the model |
| 72 | $this->setError($error); |
| 73 | } |
| 74 | |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | // get employee model |
| 79 | $employeeModel = JModelVAP::getInstance('employee'); |
| 80 | |
| 81 | // in case of form name, make sure the employee database table |
| 82 | // doesn't own yet a column with the same name |
| 83 | if ($table->formname && $employeeModel->hasColumn($table->formname)) |
| 84 | { |
| 85 | // column already occupied, register error |
| 86 | $this->setError(JText::translate('VAPCUSTOMFFORMNAMEERR')); |
| 87 | |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // attempt to save data |
| 92 | if (!$table->save(array())) |
| 93 | { |
| 94 | // something went wrong, try to obtain an error |
| 95 | $error = $table->getError($get_last = null, $string = true); |
| 96 | |
| 97 | if ($error) |
| 98 | { |
| 99 | // error found, register it within the model |
| 100 | $this->setError($error); |
| 101 | } |
| 102 | |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | // register save data within the internal state |
| 107 | $this->set('data', $table->getProperties()); |
| 108 | |
| 109 | $id = $table->id; |
| 110 | |
| 111 | if ($table->formname) |
| 112 | { |
| 113 | // finalize by creating the column on the employees database table |
| 114 | if (!$employeeModel->createColumn($table->formname, $table->type)) |
| 115 | { |
| 116 | // something went wrong, try to obtain an error from model |
| 117 | $error = $employeeModel->getError($get_last = null, $string = true); |
| 118 | |
| 119 | if ($error) |
| 120 | { |
| 121 | // error found, register it within the model |
| 122 | $this->setError($error); |
| 123 | } |
| 124 | |
| 125 | // DO NOT break the flow becase the custom field has been |
| 126 | // saved successfully. The caller of this method should now |
| 127 | // look for an error even if the model returned a successful |
| 128 | // response. |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if (isset($data['services'])) |
| 133 | { |
| 134 | // get custom field-service model |
| 135 | $model = JModelVAP::getInstance('customfservice'); |
| 136 | // define relations |
| 137 | $model->setRelation($id, $data['services']); |
| 138 | } |
| 139 | |
| 140 | return $id; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Extend delete implementation to delete any related records |
| 145 | * stored within a separated table. |
| 146 | * |
| 147 | * @param mixed $ids Either the record ID or a list of records. |
| 148 | * |
| 149 | * @return boolean True on success, false otherwise. |
| 150 | */ |
| 151 | public function delete($ids) |
| 152 | { |
| 153 | // only int values are accepted |
| 154 | $ids = array_map('intval', (array) $ids); |
| 155 | |
| 156 | $dbo = JFactory::getDbo(); |
| 157 | |
| 158 | // load the form name of all the custom fields that |
| 159 | // we are going to delete (only for employees group) |
| 160 | $q = $dbo->getQuery(true) |
| 161 | ->select($dbo->qn('formname')) |
| 162 | ->from($dbo->qn('#__vikappointments_custfields')) |
| 163 | ->where($dbo->qn('group') . ' = 1') |
| 164 | ->where($dbo->qn('id') . ' IN (' . implode(',', $ids) . ')' ); |
| 165 | |
| 166 | $dbo->setQuery($q); |
| 167 | |
| 168 | if ($fields = $dbo->loadColumn()) |
| 169 | { |
| 170 | // get employee model |
| 171 | $model = JModelVAP::getInstance('employee'); |
| 172 | |
| 173 | // drop fields one by one |
| 174 | foreach ($fields as $field) |
| 175 | { |
| 176 | $model->dropColumn($field); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // invoke parent first |
| 181 | if (!parent::delete($ids)) |
| 182 | { |
| 183 | // nothing to delete |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | // load any assigned translation |
| 188 | $q = $dbo->getQuery(true) |
| 189 | ->select($dbo->qn('id')) |
| 190 | ->from($dbo->qn('#__vikappointments_lang_customf')) |
| 191 | ->where($dbo->qn('id_customf') . ' IN (' . implode(',', $ids) . ')' ); |
| 192 | |
| 193 | $dbo->setQuery($q); |
| 194 | |
| 195 | if ($lang_ids = $dbo->loadColumn()) |
| 196 | { |
| 197 | // get translation model |
| 198 | $model = JModelVAP::getInstance('langcustomf'); |
| 199 | // delete assigned translations |
| 200 | $model->delete($lang_ids); |
| 201 | } |
| 202 | |
| 203 | // load any custom field-service relation |
| 204 | $q = $dbo->getQuery(true) |
| 205 | ->select($dbo->qn('id')) |
| 206 | ->from($dbo->qn('#__vikappointments_cf_service_assoc')) |
| 207 | ->where($dbo->qn('id_field') . ' IN (' . implode(',', $ids) . ')' ); |
| 208 | |
| 209 | $dbo->setQuery($q); |
| 210 | |
| 211 | if ($assoc_ids = $dbo->loadColumn()) |
| 212 | { |
| 213 | // get custom field-service model |
| 214 | $model = JModelVAP::getInstance('customfservice'); |
| 215 | // delete relations |
| 216 | $model->delete($assoc_ids); |
| 217 | } |
| 218 | |
| 219 | return true; |
| 220 | } |
| 221 | } |
| 222 |