<?php
namespace Entity; class GdsProfileField extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected function setTableName(): void { global $DBTGdsProfileFields; $this->tableName=$DBTGdsProfileFields; } protected function getAttribute($var) { switch ($var) { case 'addUser': { return User::select($this->fields['idAddUser'], $this->selectForUpdate); } case 'possibleValues': { if (!is_array($this->fields[$var])) { $possibleValues = unserialize($this->fields['possibleValues']); $this->fields[$var] = ($possibleValues) ?: []; } return $this->fields[$var]; } case 'validator': { return unserialize($this->fields['validator']); } case 'idProfileTemplates': { if (!$this->fields[$var]) { global $DBTGdsProfileTemplatesFields; $db = \DB::getInstance(); $sql = "SELECT `idProfileTemplate` FROM `{$DBTGdsProfileTemplatesFields}` WHERE `idProfileField`=?"; $this->fields[$var] = $db->GetCol($sql, [$this->id]); if ($db->ErrorNo()) { throw new \DBException('SQL error while getting `idProfileTemplates`.'); } } return $this->fields[$var]; } default: { return parent::getAttribute($var); } } } protected function setAttribute($var, $value) { if ($this->operation!='insert' and $this->operation!='update') { throw new \Exception('You can call '.__METHOD__.' only for insert/update operations.'); } switch ($var) { case 'category': if ($this->operation != 'insert') { throw new \Exception("The field `{$var}` can only be set for insert operation"); } $this->fields[$var] = $value; break; case 'label': case 'description': case 'inputType': case 'validator': case 'mandatory': case 'remarkVar': case 'tagSabre': case 'tagAmadeus': case 'tagWorldspan': case 'tagGalileo': case 'tagApollo': case 'type': { $this->fields[$var]=$value; break; } case 'possibleValues': { if (!is_array($value)) { throw new \Exception('Possible values list can only be an array'); } $this->fields[$var] = $value; break; } case 'validator': { if (!is_array($value)) { throw new \Exception('Validator can only be an array'); } $this->fields[$var] = $value; break; } default: { throw new \Exception("The field '$var' is not valid for the `".__CLASS__."` entity."); } } } protected function save_filterSaveData(Array $saveData) { if (array_key_exists('possibleValues', $saveData)) { $saveData['possibleValues'] = ($saveData['possibleValues'] ? serialize($saveData['possibleValues']) : ''); } if (array_key_exists('validator', $saveData)) { $validator = array_filter($saveData['validator']); $saveData['validator'] = ($validator ? serialize($validator) : ''); } if (array_key_exists('inputType', $saveData) && !in_array($saveData['inputType'], ['radio', 'select'])) { $saveData['possibleValues'] = ''; } if (array_key_exists('mandatory', $saveData)) { $saveData['mandatory'] = ($saveData['mandatory'] ? 1 : 0); } return $saveData; } } 