19 declare(strict_types=1);
41 $this->db = $DIC->database();
42 $this->
lng = $DIC->language();
75 return $this->properties->isValid();
86 public function __call($a_method, $a_value)
88 $type = substr($a_method, 0, 3);
91 $parsed = strtolower(preg_replace(
"/([A-Z])/",
" $1", substr($a_method, 3)));
92 $parsed = str_replace(
" ",
"_", trim($parsed));
93 if (!$this->properties->hasElement($parsed)) {
94 throw new Exception(
"ilADTObject unknown property " . $parsed);
96 return $this->properties->getElement($parsed);
99 throw new Exception(
"ilADTObject unknown type: " . $type);
113 abstract protected function parsePrimary(array $a_args): void;
119 abstract protected function hasPrimary(): bool;
140 throw new Exception(
"ilADTBasedObject no primary");
144 $adt_db = $factory->getDBBridgeForInstance($this->properties);
152 return $factory->getActiveRecordInstance($adt_db);
184 $this->db_errors[$e->
getColumn()][] = $e->getCode();
208 $this->db_errors[$e->
getColumn()][] = $e->getCode();
220 public function delete():
bool 248 foreach ($a_codes as $code) {
251 $res[] =
"Unknown ADT error code " . $code;
267 foreach ($this->
getProperties()->getValidationErrorsByElements() as $error_code => $element_id) {
268 $tmp[] = $element_id .
" [validation]: " . $this->
getProperties()->translateErrorCode($error_code);
271 foreach ($this->
getDBErrors() as $element_id => $codes) {
276 return get_class($this) . $delimiter . implode($delimiter, $tmp);
initActiveRecordInstance()
Init active record helper for current table, primary and properties.
hasPrimary()
Check if currently has primary.
initDBBridge(ilADTDBBridge $a_adt_db)
Init (properties) DB bridge.
translateDBErrorCodes(array $a_codes)
Translate DB error codes.
initProperties()
Init properties (aka set ADT definition)
__construct()
Constructor Tries to read record from DB, in accordance to current ILIAS behaviour.
parsePrimary(array $a_args)
Parse incoming primary key.
getDBErrors()
Get DB errors.
ADT DB bridge base class.
update()
Update record (only if valid)
__call($a_method, $a_value)
Get property magic method ("get<PropertyName>()") Setters are type-specific and cannot be magic...
getProperties()
Get all properties.
getAllTranslatedErrors(string $delimiter="\)
Get translated error codes (DB, Validation)
ADT Active Record helper class This class expects a valid primary for all actions! ...
ADT based-object base class Currently "mixed" with ActiveRecord-pattern, could be splitted...
createPrimaryKeyb()
Create new primary key, e.g.
create()
Create record (only if valid)