<?php
 namespace Entity; class BankOffice extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected $addAndUpdateDateTimeFormat = 'timestamp'; protected function setTableName(): void { global $DBTBankOffices; $this->tableName = $DBTBankOffices; } protected function getAttribute($var) { switch ($var) { case 'bank': { return Bank::select($this->fields['idBank'], $this->selectForUpdate); } case 'nameStandard': { if (!isset($this->fields['nameStandard'])) { if ($this->fields['nameAlphabet'] == 'local'){ $this->fields['nameStandard']=$this->fields['name2']; } else { $this->fields['nameStandard']=$this->fields['name']; } } return $this->fields['nameStandard']; } case 'nameLocal': { if (!isset($this->fields['nameLocal'])) { if ($this->fields['nameAlphabet']=='local') $this->fields['nameLocal']=$this->fields['name']; else $this->fields['nameLocal']=$this->fields['name2']; } return $this->fields['nameLocal']; } case 'addressStandard': { if (!isset($this->fields['addressStandard'])) { if ($this->fields['addressAlphabet']=='local') $this->fields['addressStandard']=$this->fields['address2']; else $this->fields['addressStandard']=$this->fields['address']; } return $this->fields['addressStandard']; } case 'addressLocal': { if (!isset($this->fields['addressLocal'])) { if ($this->fields['addressAlphabet']=='local') $this->fields['addressLocal']=$this->fields['address']; else $this->fields['addressLocal']=$this->fields['address2']; } return $this->fields['addressLocal']; } case 'addUser': { return \Entity\User::select($this->fields['idAddUser'], $this->selectForUpdate); } case 'updateUser': { return \Entity\User::select($this->fields['idUpdateUser'], $this->selectForUpdate); } default: { return parent::getAttribute($var); } } } protected function setAttribute($var, $value) { if ($this->operation!='insert' and $this->operation!='update') { throw new \Exception('You can use __set magic method only with insert/update operation in `'.__CLASS__.'` class.'); } switch ($var) { case 'nameStandard': case 'nameLocal': case 'mfo': case 'swiftCode': case 'code': case 'addressStandard': case 'addressLocal': { $this->fields[$var]=$value; break; } case 'idBank': { if ($this->operation=='update') throw new \Exception('You cannot change the idBank of a bank office.'); $this->fields[$var]=$value; break; } default: { throw new \Exception("The field '$var' is not valid for the `".__CLASS__."` entity."); } } } protected function save_preCheck() { if ($this->operation == 'insert' or $this->operation == 'update') { if (array_key_exists('nameStandard', $this->fields) or array_key_exists('nameLocal', $this->fields) ) { $this->fields['name'] = max($this->fields['nameStandard'], $this->fields['nameLocal']); } if (array_key_exists('addressStandard', $this->fields) or array_key_exists('addressLocal', $this->fields)) { $this->fields['address'] = max($this->fields['addressStandard'], $this->fields['addressLocal']); } } } protected function save_filterSaveData(Array $saveData) { if (array_key_exists('nameStandard', $saveData) or array_key_exists('nameLocal', $saveData)) { if ($saveData['nameStandard']) { $saveData['name'] = $saveData['nameStandard']; $saveData['name2'] = (String)$saveData['nameLocal']; $saveData['nameAlphabet'] = 'standard'; } else { $saveData['name'] = (String)$saveData['nameLocal']; $saveData['name2'] = (String)$saveData['nameStandard']; $saveData['nameAlphabet'] = 'local'; } unset($saveData['nameStandard'], $saveData['nameLocal']); } if (array_key_exists('addressStandard', $saveData) or array_key_exists('addressLocal', $saveData)) { if ($saveData['addressStandard']) { $saveData['address'] = $saveData['addressStandard']; $saveData['address2'] = (String)$saveData['addressLocal']; $saveData['addressAlphabet'] = 'standard'; } else { $saveData['address'] = (String)$saveData['addressLocal']; $saveData['address2'] = (String)$saveData['addressStandard']; $saveData['addressAlphabet'] = 'local'; } unset($saveData['addressStandard'], $saveData['addressLocal']); } return $saveData; } }