<?php
 namespace Entity; class Station extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected $addAndUpdateDateTimeFormat = 'timestamp'; protected $tablePrimaryKey='code'; protected $primaryKeyType='string'; protected function setTableName(): void { global $DBTStations; $this->tableName=$DBTStations; } protected function getAttribute($var) { switch ($var) { case 'country': { return \Entity\Country::select($this->fields['countryCode'], $this->selectForUpdate); } case 'city': { return \Entity\City::select($this->fields['cityId'], $this->selectForUpdate); } case 'nameStandard': { if (!$this->fields['nameStandard']) { $this->fields['nameStandard'] = $this->fields['name']; } return $this->fields['nameStandard']; } 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 'code': { if ($this->operation == 'insert') { $this->fields[$var] = $value; } else { throw new \Exception('You can use __set magic method with `code` parameter only with insert operation in `'.__CLASS__.'` class.'); } break; } case 'type': { if ($this->operation == 'insert') { $this->fields[$var] = $value; } else { throw new \Exception('You can use __set magic method with `type` parameter only with insert operation in `'.__CLASS__.'` class.'); } break; } case 'name': case 'nameLocal': case 'codeLocal': case 'cityId': case 'timezone': { $this->fields[$var] = $value; break; } case 'countryCode': { $this->fields[$var] = $value; if (!$this->fields['cityId']) { $this->fields['cityId'] = 0; } break; } default: { throw new \Exception("The field '$var' is not valid for the `".__METHOD__."` class/method."); } } } protected function save_executeDelete(Array $saveData) { $this->save_executeSql_delete($this->tableName, $this->tablePrimaryKey, $this->id); $this->messages->addSuccessCode('delete_ok'); } } 