<?php
 namespace Entity; class ContactPerson extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected $addAndUpdateDateTimeFormat = 'timestamp'; protected function setTableName(): void { global $DBTContactPersons; $this->tableName = $DBTContactPersons; } protected function getAttribute($var) { switch ($var) { case 'name': { if (!isset($this->fields[$var])){ $this->fields[$var] = \App\Smarty\Functions\NameFormat::renderStr((string)$this->fields['firstName'], (string)$this->fields['lastName']); } return $this->fields[$var]; } case 'typeName': { global $_LANG; return $_LANG['generalData']['companyType'][$this->fields['type']]; } case 'titleCode': { if (!isset($this->fields['titleCode'])) $this->fields['titleCode'] = $this->fields['title']; return $this->fields['titleCode']; } case 'titleName': { global $_LANG; return $_LANG['generalData']['personTitles'][$this->fields['title']]; } case 'roleName': { if ($this->fields['role']) { global $_LANG; return $_LANG['generalData']['contactPersonsRoles'][$this->fields['role']]; } else { return ''; } } case 'company': { if ($this->fields['type'] == 'supplier') { return \Entity\Supplier::select($this->fields['idCompany'], $this->selectForUpdate); } else { return \Entity\Corporate::select($this->fields['idCompany'], $this->selectForUpdate); } } case 'corporateOffice': { return \Entity\CorporateOffice::select($this->fields['idOffice'], $this->selectForUpdate); } case 'processedRemarks': { if (!is_array($this->fields['processedRemarks'])){ $rm = new \App\Entity\Utils\Remarks_ContactPerson($this->id); $this->fields[$var] = $rm->getAll(); } return $this->fields['processedRemarks']; } case 'addUser': { return User::select($this->fields['idAddUser'], $this->selectForUpdate); } case 'updateUser': { return 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 'title': case 'firstName': case 'lastName': case 'birthday': case 'idOffice': case 'department': case 'job': case 'role': case 'email': case 'telephone': case 'telephoneMobile': case 'fax': case 'comments': case '_exportToGds': { $this->fields[$var] = $value; break; } case 'type': case 'idCompany': { if ($this->operation == 'update') { throw new \Exception('Cannot __set `type` and `idCompany` for contact persons update operation.'); } else { $this->fields[$var] = $value; } break; } case 'remarks': { $this->fields['remarks'] = $value; $this->fields['processedRemarks'] = \App\Config\Remarks::process($value, 'contactPerson'); break; } default: { throw new \Exception("The field '$var' is not valid for the `".__CLASS__."` entity."); } } } protected function save_filterSaveData(Array $saveData) { unset($saveData['_exportToGds']); if (array_key_exists('remarks', $saveData)) { $saveData['processedRemarks'] = $this->getSerializedProcessedRemarks(); } return $saveData; } protected function save_postProcess(Array $saveData) { if (($this->operation == 'insert' or $this->operation == 'update') and array_key_exists('remarks', $this->fields)) { try { $remarks = new \App\Entity\Utils\Remarks_ContactPerson($this->id); $remarks->save($this->fields['remarks']); } catch (\App\Entity\UtilsException $ex) { $this->messages->removeSuccess(); $this->messages->addErrorCode('remarksSaveFail'); } } } protected function save_finishOperation() { parent::save_finishOperation(); if (in_array($this->operation, ['insert', 'update', 'delete', ])) { if ($this->fields['_exportToGds']) { $persEnt = self::selectForUpdate($this->id); if ($persEnt->type == 'corporate' && $persEnt->company->idGdsProfileTemplate) { $queueManager = \App\GdsProfile\QueueManager::getInstance(); $queueManager->insertRow('corporate', $persEnt->idCompany); } } } } }