<?php
namespace Entity; class BspPeriod extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected function setTableName(): void { global $DBTBspPeriod; $this->tableName = $DBTBspPeriod; } protected function getAttribute($var) { switch ($var) { case 'office': { return \Entity\Office::select($this->fields['idOffice'], $this->selectForUpdate); } 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 'group': case 'periodStart': case 'periodEnd': case 'filename': case 'fileType': case 'idOffice': case 'iataCode': case 'description': { $this->fields[$var]=$value; break; } default: { throw new \Exception("The field '$var' is not valid for the `".__CLASS__."` entity."); } } } protected function save_executeDelete(Array $saveData) { $this->save_executeSql_delete($this->tableName, $this->tablePrimaryKey, $this->id); $this->messages->addSuccessCode('delete_ok'); $db=\DB::getInstance(); global $DBTBspRecords, $DBTBspRecordsData, $DBTBspSettlementRecords; $query = "UPDATE `{$DBTBspSettlementRecords}` SET `bspRecordId`=NULL WHERE `bspRecordId` IN (SELECT `id` FROM `{$DBTBspRecords}` WHERE `idPeriod`=?)"; $db->Execute($query, [$this->id]); if ($db->ErrorNo()) { throw new \DBException("Error in method ".__METHOD__." - called class: ".get_called_class()."."); } $query = "DELETE FROM `{$DBTBspRecordsData}` WHERE `id` IN (SELECT `id` FROM `{$DBTBspRecords}` WHERE `idPeriod`=?)"; $db->Execute($query, [$this->id]); if ($db->ErrorNo()) { throw new \DBException("Error in method ".__METHOD__." - called class: ".get_called_class()."."); } $query = "DELETE FROM `{$DBTBspRecords}` WHERE `idPeriod`=?"; $db->Execute($query, [$this->id]); if ($db->ErrorNo()) { throw new \DBException("Error in method ".__METHOD__." - called class: ".get_called_class()."."); } } } 