<?php
 namespace Entity; class AriaChatMessage extends \App\Entity\GeneralAbstract { protected $saveInsideTransaction = true; protected function setTableName(): void { global $DBTAriaChatMessages; $this->tableName = $DBTAriaChatMessages; } static public function update($id) { throw new \Exception('Not developed.'); } static public function delete($id) { throw new \Exception('Not developed.'); } protected function getAttribute($var) { switch ($var) { case 'chat': { return \Entity\AriaChat::select($this->fields['idChat'], $this->selectForUpdate); } case 'parentMessage': { return \Entity\AriaChat::select($this->fields['idParentMessage'], $this->selectForUpdate); } case 'reportContent': case 'requestLog': case 'responseLog':case 'tokens': { if (!is_array($this->fields[$var])) { $this->fields[$var] = $this->fields[$var] ? json_decode($this->fields[$var], true) : null ; } return $this->fields[$var]; } default: { return parent::getAttribute($var); } } } protected function setAttribute($var, $value) { if ($this->operation!='insert') { throw new \Exception("You cannot use __set magic method on `{$this->operation}` operation in `".__CLASS__."` class."); } switch ($var) { case 'idChat': case 'userPrompt':case 'callType':case 'textReply':case 'hidden':case 'idParentMessage': case 'requestLog':case 'responseLog': $this->fields[$var] = $value; break; case 'reportContent':case 'requestLog': case 'responseLog': if (!is_object($value)) { throw new \Exception("The `{$var}` key must be set as an object in ".__METHOD__); } $this->fields[$var] = $value; break; case 'tokens': if (!is_array($value)) { throw new \Exception("The `{$var}` key must be set as an array in ".__METHOD__); } $this->fields[$var] = $value; break; default: { throw new \Exception("The field '{$var}' is not valid for the `".__METHOD__."` entity call."); } } } protected function save_filterSaveData(Array $saveData) { if ($this->operation=='insert') { if (key_exists('reportContent', $saveData)) { $saveData['reportContent'] = json_encode($saveData['reportContent']); } if (key_exists('requestLog', $saveData)) { $saveData['requestLog'] = json_encode($saveData['requestLog']); } if (key_exists('responseLog', $saveData)) { $saveData['responseLog'] = json_encode($saveData['responseLog']); } if (key_exists('tokens', $saveData)) { $saveData['tokens'] = json_encode($saveData['tokens']); } } return $saveData; } protected function save_finalSaveData(Array $saveData) { if ($this->operation=='insert') { $saveData['addTime'] = DATETIME; return $saveData; } else { return parent::save_finalSaveData($saveData); } } protected function save_postProcess(Array $saveData) { $this->save_updateCache_addEntry('AriaChat', $this->fields['idChat']); parent::save_postProcess($saveData); } } 