<?php
namespace Entity; class CustomerSegment extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected $addAndUpdateDateTimeFormat = 'timestamp'; protected function setTableName(): void { global $DBTCustomersSegments; $this->tableName = $DBTCustomersSegments; } protected function getAttribute($var) { switch ($var) { 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 'name': { $this->fields[$var]=$value; break; } default: { throw new \Exception("The field '$var' is not valid for the `".__CLASS__."` entity."); } } } protected function save_postProcess(Array $saveData) { if ($this->operation == 'delete') { $this->save_postProcess_deleteAssocCustomers($saveData); } } private function save_postProcess_deleteAssocCustomers(Array $saveData) { \App\Loader_Lang::getInstance()->loadAppFile("_customLoad/entities/CustomerSegment.lang.php"); $_LANG = \App\Loader_Lang::getInstance()->getAll(); try { $custObj = new \App\EntityList\Customers(); $custObj->setFilter('cust.idSegment', "=", $this->id); $custObj->setForUpdate(true); $customers = $custObj->getExecution(); foreach ($customers as $customer) { $cust = \Entity\Customer::update($customer['id']); $cust->idSegment = 0; $cust->save(); } } catch (\App\Entity\Exception $e) { $msgs = new \App\MessagesCollector(); $msgs->appendMessages($e->getMessagesCollector(), $_LANG['globalEntityMessages']['::CustomerSegment']['delete_failCustomersAssoc']); $this->messages->removeSuccess(); $this->messages->addMessageCollector($msgs); $this->messages->throwMessages(); } } }