ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilADTBasedObject Class Reference

ADT based-object base class. More...

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

Public Member Functions

 __construct ()
 Constructor.
 getProperties ()
 Get all properties.
 isValid ()
 Validate.
 __call ($a_method, $a_value)
 Get property magic method ("get<PropertyName>()")
 read ()
 Read record.
 create ()
 Create record (only if valid)
 update ()
 Update record (only if valid)
 delete ()
 Delete record.
 getDBErrors ()
 Get DB errors.
 translateDBErrorCodes (array $a_codes)
 Translate DB error codes.
 getAllTranslatedErrors ($delimiter="\n")
 Get translated error codes (DB, Validation)

Protected Member Functions

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

Protected Attributes

 $properties = array()
 $db_errors = array()

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
Version
$Id$

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

Constructor & Destructor Documentation

ilADTBasedObject::__construct ( )

Constructor.

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

Returns
self

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

References initProperties(), parsePrimary(), and read().

{
$this->properties = $this->initProperties();
// :TODO: to keep constructor "open" we COULD use func_get_args()
$this->parsePrimary(func_get_args());
$this->read();
}

+ Here is the call graph for this function:

Member Function Documentation

ilADTBasedObject::__call (   $a_method,
  $a_value 
)

Get property magic method ("get<PropertyName>()")

Setters are type-specific and cannot be magic

Exceptions
Exception
Parameters
string$a_method
mixed$a_value
Returns
ilADT

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

{
$type = substr($a_method, 0, 3);
switch($type)
{
case "get":
$parsed = strtolower(preg_replace("/([A-Z])/", " $1", substr($a_method, 3)));
$parsed = str_replace(" ", "_", trim($parsed));
if(!$this->properties->hasElement($parsed))
{
throw new Exception("ilADTObject unknown property ".$parsed);
}
return $this->properties->getElement($parsed);
default:
throw new Exception("ilADTObject unknown method ".$parsed);
}
}
ilADTBasedObject::create ( )

Create record (only if valid)

Returns
boolean

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

References createPrimaryKey(), ilADTDBException\getColumn(), hasPrimary(), initActiveRecordInstance(), isValid(), and update().

Referenced by update().

{
if($this->hasPrimary())
{
return $this->update();
}
if($this->isValid())
{
if($this->createPrimaryKey())
{
try
{
$rec = $this->initActiveRecordInstance();
$rec->create();
}
catch(ilADTDBException $e)
{
$this->db_errors[$e->getColumn()][] = $e->getCode();
return false;
}
return true;
}
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilADTBasedObject::createPrimaryKey ( )
abstractprotected

Create new primary key, e.g.

sequence

Returns
bool

Reimplemented in ilADTTest.

Referenced by create().

+ Here is the caller graph for this function:

ilADTBasedObject::delete ( )

Delete record.

Returns
boolean

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

References hasPrimary(), and initActiveRecordInstance().

{
if($this->hasPrimary())
{
$rec = $this->initActiveRecordInstance();
$rec->delete();
return true;
}
return false;
}

+ Here is the call graph for this function:

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

Get translated error codes (DB, Validation)

Parameters
type$delimiter
Returns
string

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

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

{
$tmp = array();
foreach($this->getProperties()->getValidationErrorsByElements() as $error_code => $element_id)
{
$tmp[] = $element_id." [validation]: ".$this->getProperties()->translateErrorCode($error_code);
}
foreach($this->getDBErrors() as $element_id => $codes)
{
$tmp[] = $element_id." [db]: ".implode($delimiter, $this->translateDBErrorCodes($codes));
}
if(sizeof($tmp))
{
return get_class($this).$delimiter.implode($delimiter, $tmp);
}
}

+ Here is the call graph for this function:

ilADTBasedObject::getDBErrors ( )

Get DB errors.

Returns
array

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

References $db_errors.

Referenced by getAllTranslatedErrors().

{
}

+ Here is the caller graph for this function:

ilADTBasedObject::getProperties ( )

Get all properties.

Returns
array ilADT

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

References $properties.

Referenced by getAllTranslatedErrors().

{
}

+ Here is the caller graph for this function:

ilADTBasedObject::hasPrimary ( )
abstractprotected

Check if currently has primary.

Returns
bool

Reimplemented in ilADTTest.

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

+ Here is the caller graph for this function:

ilADTBasedObject::initActiveRecordInstance ( )
protected

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

Returns
ilADTActiveRecord

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

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

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

{
global $ilDB;
if(!$this->hasPrimary())
{
throw new Exception("ilADTBasedObject no primary");
}
$this->adt_db = $factory->getDBBridgeForInstance($this->properties);
$this->initDBBridge($this->adt_db);
// use custom error handling
include_once "Services/ADT/classes/class.ilADTDBException.php";
$ilDB->exception = "ilADTDBException";
return $factory->getActiveRecordInstance($this->adt_db);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilADTBasedObject::initDBBridge ( ilADTGroupDBBridge  $a_adt_db)
abstractprotected

Init (properties) DB bridge.

Parameters
ilADTGroupDBBridge$a_adt_db

Reimplemented in ilADTTest.

Referenced by initActiveRecordInstance().

+ Here is the caller graph for this function:

ilADTBasedObject::initProperties ( )
abstractprotected

Init properties (aka set ADT definition)

Returns
ilADT

Reimplemented in ilADTTest.

Referenced by __construct().

+ Here is the caller graph for this function:

ilADTBasedObject::isValid ( )

Validate.

Returns
bool

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

Referenced by create(), and update().

{
return $this->properties->isValid();
}

+ Here is the caller graph for this function:

ilADTBasedObject::parsePrimary ( array  $a_args)
abstractprotected

Parse incoming primary key.

See Also
__construct()
Parameters
array$a_args

Reimplemented in ilADTTest.

Referenced by __construct().

+ Here is the caller graph for this function:

ilADTBasedObject::read ( )

Read record.

Returns
boolean

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

References hasPrimary(), and initActiveRecordInstance().

Referenced by __construct().

{
if($this->hasPrimary())
{
$rec = $this->initActiveRecordInstance();
return $rec->read();
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilADTBasedObject::translateDBErrorCodes ( array  $a_codes)

Translate DB error codes.

Parameters
array$a_codes
Returns
array

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

References $lng, $res, and MDB2_ERROR_CONSTRAINT.

Referenced by getAllTranslatedErrors().

{
global $lng;
$res = array();
foreach($a_codes as $code)
{
switch($code)
{
$res[] = $lng->txt("adt_error_db_constraint");
break;
default:
$res[] = "Unknown ADT error code ".$code;
break;
}
}
return $res;
}

+ Here is the caller graph for this function:

ilADTBasedObject::update ( )

Update record (only if valid)

Returns
boolean

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

References create(), ilADTDBException\getColumn(), hasPrimary(), initActiveRecordInstance(), and isValid().

Referenced by create().

{
if(!$this->hasPrimary())
{
return $this->create();
}
if($this->isValid())
{
try
{
$rec = $this->initActiveRecordInstance();
$rec->update();
}
catch(ilADTDBException $e)
{
$this->db_errors[$e->getColumn()][] = $e->getCode();
return false;
}
return true;
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilADTBasedObject::$db_errors = array()
protected

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

Referenced by getDBErrors().

ilADTBasedObject::$properties = array()
protected

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

Referenced by getProperties().


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