ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilADTBasedObject Class Reference

ADT based-object base class Currently "mixed" with ActiveRecord-pattern, could be splitted. More...

+ Inheritance diagram for ilADTBasedObject:
+ Collaboration diagram for ilADTBasedObject:

Public Member Functions

 __construct ()
 Constructor Tries to read record from DB, in accordance to current ILIAS behaviour. More...
 
 getProperties ()
 Get all properties. More...
 
 isValid ()
 Validate. More...
 
 __call ($a_method, $a_value)
 Get property magic method ("get<PropertyName>()") Setters are type-specific and cannot be magic. More...
 
 read ()
 Read record. More...
 
 create ()
 Create record (only if valid) More...
 
 update ()
 Update record (only if valid) More...
 
 delete ()
 Delete record. More...
 
 getDBErrors ()
 Get DB errors. More...
 
 translateDBErrorCodes (array $a_codes)
 Translate DB error codes. More...
 
 getAllTranslatedErrors (string $delimiter="\)
 Get translated error codes (DB, Validation) More...
 

Protected Member Functions

 initProperties ()
 Init properties (aka set ADT definition) More...
 
 parsePrimary (array $a_args)
 Parse incoming primary key. More...
 
 hasPrimary ()
 Check if currently has primary. More...
 
 createPrimaryKeyb ()
 Create new primary key, e.g. More...
 
 initDBBridge (ilADTDBBridge $a_adt_db)
 Init (properties) DB bridge. More...
 
 initActiveRecordInstance ()
 Init active record helper for current table, primary and properties. More...
 

Protected Attributes

ilADT $properties
 
array $db_errors = []
 
ilDBInterface $db
 
ilLanguage $lng
 

Detailed Description

ADT based-object base class Currently "mixed" with ActiveRecord-pattern, could be splitted.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 26 of file class.ilADTBasedObject.php.

Constructor & Destructor Documentation

◆ __construct()

ilADTBasedObject::__construct ( )

Constructor Tries to read record from DB, in accordance to current ILIAS behaviour.

Definition at line 38 of file class.ilADTBasedObject.php.

References $DIC, initProperties(), ILIAS\Repository\lng(), parsePrimary(), and read().

39  {
40  global $DIC;
41  $this->db = $DIC->database();
42  $this->lng = $DIC->language();
43  $this->properties = $this->initProperties();
44 
45  // :TODO: to keep constructor "open" we COULD use func_get_args()
46  $this->parsePrimary(func_get_args());
47  $this->read();
48  }
initProperties()
Init properties (aka set ADT definition)
parsePrimary(array $a_args)
Parse incoming primary key.
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

ilADTBasedObject::__call (   $a_method,
  $a_value 
)

Get property magic method ("get<PropertyName>()") Setters are type-specific and cannot be magic.

Parameters
string$a_method
mixed$a_value
Returns
ilADT
Exceptions
Exception

Definition at line 86 of file class.ilADTBasedObject.php.

References createPrimaryKeyb(), hasPrimary(), initDBBridge(), and parsePrimary().

87  {
88  $type = substr($a_method, 0, 3);
89  switch ($type) {
90  case "get":
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);
95  }
96  return $this->properties->getElement($parsed);
97 
98  default:
99  throw new Exception("ilADTObject unknown type: " . $type);
100  }
101  }
+ Here is the call graph for this function:

◆ create()

ilADTBasedObject::create ( )

Create record (only if valid)

Returns
bool

Definition at line 172 of file class.ilADTBasedObject.php.

References Vendor\Package\$e, createPrimaryKeyb(), ilADTDBException\getColumn(), hasPrimary(), initActiveRecordInstance(), isValid(), and update().

Referenced by update().

172  : bool
173  {
174  if ($this->hasPrimary()) {
175  return $this->update();
176  }
177 
178  if ($this->isValid()) {
179  if ($this->createPrimaryKeyb()) {
180  try {
181  $rec = $this->initActiveRecordInstance();
182  $rec->create();
183  } catch (ilADTDBException $e) {
184  $this->db_errors[$e->getColumn()][] = $e->getCode();
185  return false;
186  }
187  return true;
188  }
189  }
190  return false;
191  }
initActiveRecordInstance()
Init active record helper for current table, primary and properties.
hasPrimary()
Check if currently has primary.
update()
Update record (only if valid)
createPrimaryKeyb()
Create new primary key, e.g.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createPrimaryKeyb()

ilADTBasedObject::createPrimaryKeyb ( )
abstractprotected

Create new primary key, e.g.

sequence

Returns
bool

Referenced by __call(), and create().

+ Here is the caller graph for this function:

◆ delete()

ilADTBasedObject::delete ( )

Delete record.

Returns
bool

Definition at line 220 of file class.ilADTBasedObject.php.

References hasPrimary(), and initActiveRecordInstance().

220  : bool
221  {
222  if ($this->hasPrimary()) {
223  $rec = $this->initActiveRecordInstance();
224  $rec->delete();
225  return true;
226  }
227  return false;
228  }
initActiveRecordInstance()
Init active record helper for current table, primary and properties.
hasPrimary()
Check if currently has primary.
+ Here is the call graph for this function:

◆ getAllTranslatedErrors()

ilADTBasedObject::getAllTranslatedErrors ( string  $delimiter = "\n")

Get translated error codes (DB, Validation)

Parameters
string$delimiter
Returns
string

Definition at line 263 of file class.ilADTBasedObject.php.

References getDBErrors(), getProperties(), and translateDBErrorCodes().

263  : string
264  {
265  $tmp = array();
266 
267  foreach ($this->getProperties()->getValidationErrorsByElements() as $error_code => $element_id) {
268  $tmp[] = $element_id . " [validation]: " . $this->getProperties()->translateErrorCode($error_code);
269  }
270 
271  foreach ($this->getDBErrors() as $element_id => $codes) {
272  $tmp[] = $element_id . " [db]: " . implode($delimiter, $this->translateDBErrorCodes($codes));
273  }
274 
275  if (count($tmp)) {
276  return get_class($this) . $delimiter . implode($delimiter, $tmp);
277  }
278  return '';
279  }
translateDBErrorCodes(array $a_codes)
Translate DB error codes.
getDBErrors()
Get DB errors.
getProperties()
Get all properties.
+ Here is the call graph for this function:

◆ getDBErrors()

ilADTBasedObject::getDBErrors ( )

Get DB errors.

Returns
array

Definition at line 234 of file class.ilADTBasedObject.php.

References $db_errors.

Referenced by getAllTranslatedErrors().

234  : array
235  {
236  return $this->db_errors;
237  }
+ Here is the caller graph for this function:

◆ getProperties()

ilADTBasedObject::getProperties ( )

Get all properties.

Definition at line 64 of file class.ilADTBasedObject.php.

References $properties.

Referenced by getAllTranslatedErrors().

64  : ilADT
65  {
66  return $this->properties;
67  }
ADT base class.
Definition: class.ilADT.php:25
+ Here is the caller graph for this function:

◆ hasPrimary()

ilADTBasedObject::hasPrimary ( )
abstractprotected

Check if currently has primary.

Returns
bool

Referenced by __call(), create(), delete(), initActiveRecordInstance(), read(), and update().

+ Here is the caller graph for this function:

◆ initActiveRecordInstance()

ilADTBasedObject::initActiveRecordInstance ( )
protected

Init active record helper for current table, primary and properties.

Returns
ilADTActiveRecord

PhpParamsInspection

Definition at line 137 of file class.ilADTBasedObject.php.

References ilADTFactory\getInstance(), hasPrimary(), and initDBBridge().

Referenced by create(), delete(), read(), and update().

138  {
139  if (!$this->hasPrimary()) {
140  throw new Exception("ilADTBasedObject no primary");
141  }
142 
143  $factory = ilADTFactory::getInstance();
144  $adt_db = $factory->getDBBridgeForInstance($this->properties);
145  $this->initDBBridge($adt_db);
146 
147  // use custom error handling
148  //FIXME
149  //$this->db->exception = "ilADTDBException";
150 
152  return $factory->getActiveRecordInstance($adt_db);
153  }
hasPrimary()
Check if currently has primary.
initDBBridge(ilADTDBBridge $a_adt_db)
Init (properties) DB bridge.
ADT Active Record helper class This class expects a valid primary for all actions! ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initDBBridge()

ilADTBasedObject::initDBBridge ( ilADTDBBridge  $a_adt_db)
abstractprotected

Init (properties) DB bridge.

Parameters
ilADTDBBridge$a_adt_db

Referenced by __call(), and initActiveRecordInstance().

+ Here is the caller graph for this function:

◆ initProperties()

ilADTBasedObject::initProperties ( )
abstractprotected

Init properties (aka set ADT definition)

Returns
ilADT

Referenced by __construct().

+ Here is the caller graph for this function:

◆ isValid()

ilADTBasedObject::isValid ( )

Validate.

Returns
bool

Definition at line 73 of file class.ilADTBasedObject.php.

Referenced by create(), and update().

73  : bool
74  {
75  return $this->properties->isValid();
76  }
+ Here is the caller graph for this function:

◆ parsePrimary()

ilADTBasedObject::parsePrimary ( array  $a_args)
abstractprotected

Parse incoming primary key.

Parameters
array$a_args
See also
__construct()

Referenced by __call(), and __construct().

+ Here is the caller graph for this function:

◆ read()

ilADTBasedObject::read ( )

Read record.

Returns
bool

Definition at line 159 of file class.ilADTBasedObject.php.

References hasPrimary(), and initActiveRecordInstance().

Referenced by __construct().

159  : bool
160  {
161  if ($this->hasPrimary()) {
162  $rec = $this->initActiveRecordInstance();
163  return $rec->read();
164  }
165  return false;
166  }
initActiveRecordInstance()
Init active record helper for current table, primary and properties.
hasPrimary()
Check if currently has primary.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translateDBErrorCodes()

ilADTBasedObject::translateDBErrorCodes ( array  $a_codes)

Translate DB error codes.

Parameters
array$a_codes
Returns
array

Definition at line 244 of file class.ilADTBasedObject.php.

References $res.

Referenced by getAllTranslatedErrors().

244  : array
245  {
246  $res = array();
247 
248  foreach ($a_codes as $code) {
249  switch ($code) {
250  default:
251  $res[] = "Unknown ADT error code " . $code;
252  break;
253  }
254  }
255  return $res;
256  }
$res
Definition: ltiservices.php:66
+ Here is the caller graph for this function:

◆ update()

ilADTBasedObject::update ( )

Update record (only if valid)

Returns
bool

Definition at line 197 of file class.ilADTBasedObject.php.

References Vendor\Package\$e, create(), ilADTDBException\getColumn(), hasPrimary(), initActiveRecordInstance(), and isValid().

Referenced by create().

197  : bool
198  {
199  if (!$this->hasPrimary()) {
200  return $this->create();
201  }
202 
203  if ($this->isValid()) {
204  try {
205  $rec = $this->initActiveRecordInstance();
206  $rec->update();
207  } catch (ilADTDBException $e) {
208  $this->db_errors[$e->getColumn()][] = $e->getCode();
209  return false;
210  }
211  return true;
212  }
213  return false;
214  }
initActiveRecordInstance()
Init active record helper for current table, primary and properties.
hasPrimary()
Check if currently has primary.
create()
Create record (only if valid)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilADTBasedObject::$db
protected

Definition at line 31 of file class.ilADTBasedObject.php.

◆ $db_errors

array ilADTBasedObject::$db_errors = []
protected

Definition at line 29 of file class.ilADTBasedObject.php.

Referenced by getDBErrors().

◆ $lng

ilLanguage ilADTBasedObject::$lng
protected

Definition at line 32 of file class.ilADTBasedObject.php.

◆ $properties

ilADT ilADTBasedObject::$properties
protected

Definition at line 28 of file class.ilADTBasedObject.php.

Referenced by getProperties().


The documentation for this class was generated from the following file: