Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/dbitem.php
Show First 20 Lines • Show All 395 Lines • ▼ Show 20 Line(s) | |||||
* @access public | * @access public | ||||
* @param mixed $id item id of keys->values hash to load item by | * @param mixed $id item id of keys->values hash to load item by | ||||
* @param string $id_field_name Optional parameter to load item by given Id field | * @param string $id_field_name Optional parameter to load item by given Id field | ||||
* @param bool $cachable cache this query result based on it's prefix serial | * @param bool $cachable cache this query result based on it's prefix serial | ||||
* @return bool True if item has been loaded, false otherwise | * @return bool True if item has been loaded, false otherwise | ||||
*/ | */ | ||||
public function Load($id, $id_field_name = null, $cachable = false) | public function Load($id, $id_field_name = null, $cachable = false) | ||||
{ | { | ||||
$this->Clear(); | |||||
if ( isset($id_field_name) ) { | if ( isset($id_field_name) ) { | ||||
$this->IDField = $id_field_name; // set new IDField | $this->IDField = $id_field_name; // set new IDField | ||||
} | } | ||||
$keys_sql = ''; | $keys_sql = ''; | ||||
if (is_array($id)) { | if (is_array($id)) { | ||||
$keys_sql = $this->GetKeyClause('load', $id); | $keys_sql = $this->GetKeyClause('load', $id); | ||||
} | } | ||||
else { | else { | ||||
$this->setID($id); | $this->setID($id); | ||||
$keys_sql = $this->GetKeyClause('load'); | $keys_sql = $this->GetKeyClause('load'); | ||||
} | } | ||||
if ( isset($id_field_name) ) { | if ( isset($id_field_name) ) { | ||||
// restore original IDField from unit config | // restore original IDField from unit config | ||||
$this->IDField = $this->Application->getUnitOption($this->Prefix, 'IDField'); | $this->IDField = $this->Application->getUnitOption($this->Prefix, 'IDField'); | ||||
} | } | ||||
if (($id === false) || !$keys_sql) { | if (($id === false) || !$keys_sql) { | ||||
return $this->Clear(); | return false; | ||||
} | } | ||||
if (!$this->raiseEvent('OnBeforeItemLoad', $id)) { | if (!$this->raiseEvent('OnBeforeItemLoad', $id)) { | ||||
return false; | return false; | ||||
} | } | ||||
$q = $this->GetSelectSQL() . ' WHERE ' . $keys_sql; | $q = $this->GetSelectSQL() . ' WHERE ' . $keys_sql; | ||||
Show All 16 Lines | |||||
} | } | ||||
if ($field_values) { | if ($field_values) { | ||||
$this->FieldValues = array_merge($this->FieldValues, $field_values); | $this->FieldValues = array_merge($this->FieldValues, $field_values); | ||||
$this->OriginalFieldValues = $this->FieldValues; | $this->OriginalFieldValues = $this->FieldValues; | ||||
$this->Loaded = true; | $this->Loaded = true; | ||||
} | } | ||||
else { | else { | ||||
return $this->Clear(); | return false; | ||||
} | } | ||||
if (is_array($id) || isset($id_field_name)) { | if (is_array($id) || isset($id_field_name)) { | ||||
$this->setID($this->FieldValues[$this->IDField]); | $this->setID($this->FieldValues[$this->IDField]); | ||||
} | } | ||||
$this->UpdateFormattersSubFields(); // used for updating separate virtual date/time fields from DB timestamp (for example) | $this->UpdateFormattersSubFields(); // used for updating separate virtual date/time fields from DB timestamp (for example) | ||||
▲ Show 20 Lines • Show All 1127 Lines • Show Last 20 Lines |