* */ class ems_framework_entityrelationship extends ems_framework_datamodelbase { /** * The datasource reference for entity relationships * * @var ems_datasource_interface_entityrelationship * @access protected */ protected $ds; /** * The primary table def ID of the relationship. * * @var int * @access protected */ protected $tableDefID; /** * The primary reference ID of the relationship. This is the ID of the entity defined by the table def ID. * * @var int * @access protected */ protected $refID; /** * The primary object defined in the relationship. This can also be generated by the table def and ref ID through the factory createObj method. * * @var table def object * @access protected */ protected $obj; /** * The related table def ID of the relationship. * * @var int * @access protected */ protected $relatedTableDefID; /** * The related reference ID of the relationship. This is the ID of the entity defined by the table def ID. * * @var int * @access protected */ protected $relatedRefID; /** * The related object defined in the relationship. This can also be generated by the table def and ref ID through the factory createObj method. * * @var table def object * @access protected */ protected $relatedObj; /** * The order the related items are in for the primary relationship * * @var int * @access protected */ protected $order; /** * The category ID between the primary and related references * * @var int * @access protected */ protected $categoryID; /** * The category name between the primary and related references * * @var text * @access protected */ protected $category; /** * The note that is between the primary and relatated references * * @var text * @access protected */ protected $note; /** * A boolean that defines if the relationship between the primary and related references is the primary relationship. * * @var boolean * @access protected */ protected $isPrimary; /** * The order of the items assigned to the related entity, from the perspective of the related entity. * * @var int * @access protected */ protected $rOrder; /** * The category ID between the related entity and the primary entity from the perspective of the related entity. * * @var int * @access protected */ protected $rCategoryID; /** * The category name between the related entity and the primary entity from the perspective of the related entity. * * @var text * @access protected */ protected $rCategory; /** * The note between the related entity and the primary entity from the perspective of the related entity. * * @var text * @access protected */ protected $rNote; /** * A boolean that defines if the relationship between the related entity and the primary entity, from the perspective of the related entity, is the primary relationship * * @var boolean * @access protected */ protected $rIsPrimary; /** * Constructor object for the class * * @param ems_framework_registry $param * @access public * @return void */ public function __construct(ems_framework_registry $param) { parent::__construct($param); $this->setDefaultValues(); } /** * Initializes the properties of the class to their defaults. * * @access private * @return void */ private function setDefaultValues() { $this->ds = $this->param->factory->ds->createEntityRelationship(); $this->tableDefID = null; $this->refID = null; $this->obj = null; $this->relatedTableDefID = null; $this->relatedRefID = null; $this->relatedObj = null; $this->order = 0; $this->categoryID = null; $this->category = null; $this->note = null; $this->isPrimary = false; $this->rOrder = 0; $this->rCategoryID = null; $this->rCategory = null; $this->rNote = null; $this->rIsPrimary = false; } /** * Allows the setting of a different datasource for this class * * @param ems_datasource_interface_account $ds * @access public * @return void */ public function setDataSource(ems_datasource_interface_entityrelationship $ds) { $this->ds = $ds; } /** * Loads the data for a specific relationship based on the two table def IDs and the two ref IDs needed for a relationship * * @param integer $tableDefID, interger $id, integer $relatedTableDefID, integer $relatedID * @access public * @return boolean Whether or not the data loading was successful. */ public function getData($tableDefID,$id,$relatedTableDefID,$relatedID) { $this->checkDS("getData"); $data = $this->ds->getEntityRelationship($tableDefID,$id,$relatedTableDefID,$relatedID); if (is_array($data)) { $this->setTableDefID($data['a_er_table_def_id']); $this->setRefID($data['a_er_ref_id']); $this->setRelatedTableDefID($data['a_er_related_table_def_id']); $this->setRelatedRefID($data['a_er_related_ref_id']); $this->setOrder($data['a_er_order']); $this->setCategoryID($data['a_er_category_id']); $this->setNote($data['a_er_note']); $this->setIsPrimary($data['a_er_is_primary']); $this->setRelatedOrder($data['a_er_related_order']); $this->setRelatedCategoryID($data['a_er_related_category_id']); $this->setRelatedNote($data['a_er_related_note']); $this->setRelatedIsPrimary($data['a_er_related_is_primary']); $this->getDataRun = true; } return $this->getDataRun; } /** * Performs a getData operation but by passing a specially formatted string that is parsed for the ID's needed. The string's syntax is: "$tableDefID-$refID-$relatedTableDefID-$relatedRefID" * * @param string $id * @access public * @return boolean */ public function getDataByCreatedID($id) { if (!$id) $ids = array(null, null, null, null); else $ids = explode('-', $id, 4); return $this->getData($ids[0], $ids[1], $ids[2], $ids[3]); } /** * Returns a single numeric string that represents the concatinated ID of the relationship * * @param none * @access public * @return string */ public function getID() { return $this->getTableDefID() . $this->getRefID() . $this->getRelatedTableDefID() . $this->getRelatedRefID(); } /** * Returns the ID strings in a format that is used by getDataByCreatedID() * * @param none * @access public * @return string */ public function getCreatedID() { return "{$this->getTableDefID()}-{$this->getRefID()}-{$this->getRelatedTableDefID()}-{$this->getRelatedRefID()}"; } /** * Returns the primary table def ID * * @param none * @access public * @return int */ public function getTableDefID() { return $this->tableDefID; } /** * Returns the primary ref ID * * @param none * @access public * @return int */ public function getRefID() { return $this->refID; } /** * Returns the primary object and it is not set, uses the factory's createObj method to generate an appropriate object and query for it's data * * @param none * @access public * @return object */ public function getObj() { if (!$this->obj && $this->tableDefID && $this->refID) { $this->obj = $this->param->factory->createObj($this->tableDefID); $this->obj->getData($this->refID); } return $this->obj; } /** * Returns the related table def ID * * @param none * @access public * @return int */ public function getRelatedTableDefID() { return $this->relatedTableDefID; } /** * Returns the related ref ID * * @param none * @access public * @return int */ public function getRelatedRefID() { return $this->relatedRefID; } /** * Returns the related object and it is not set, uses the factory's createObj method to generate an appropriate object and query for it's data * * @param none * @access public * @return object */ public function getRelatedObj() { if (!$this->relatedObj && $this->relatedTableDefID && $this->relatedRefID) { $this->relatedObj = $this->param->factory->createObj($this->relatedTableDefID); $this->relatedObj->getData($this->relatedRefID); } return $this->relatedObj; } /** * Returns the order value in the perspective of the primary entity * * @param none * @access public * @return int */ public function getOrder() { if ($this->order === null && $this->rOrder !== null) return $this->getRelatedOrder(); return $this->order; } /** * Returns the category ID of the relationship in the perspective of the primary entity * * @param none * @access public * @return int */ public function getCategoryID() { if ($this->categoryID === null && $this->rCategoryID !== null) return $this->getRelatedCategoryID(); return $this->categoryID; } /** * Returns the category name of the relationship in the perspective of the primary entity * * @param none * @access public * @return string */ public function getCategory() { if (!$this->category && $this->getCategoryID()) $this->setCategory($this->getCategoryValue($this->getCategoryID())); return $this->category; } /** * Returns the note of the relationship in the perspective of the primary entity * * @param none * @access public * @return string */ public function getNote() { if ($this->note === null && $this->rNote !== null) return $this->getRelatedNote(); return $this->note; } /** * Returns the isPrimary boolean of the relationship in the perspective of the primary entity * * @param none * @access public * @return boolean */ public function getIsPrimary() { if ($this->isPrimary === null && $this->rIsPrimary !== null) return $this->getRelatedIsPrimary(); return $this->isPrimary; } /** * Returns the order value in the perspective of the related entity * * @param none * @access public * @return int */ public function getRelatedOrder() { return $this->rOrder; } /** * Returns the category ID of the relationship from the perspective of the related entity * * @param none * @access public * @return int */ public function getRelatedCategoryID() { return $this->rCategoryID; } /** * Returns the category name of the relationship from the perspective of the related entity * * @param none * @access public * @return string */ public function getRelatedCategory() { if (!$this->rCategory) $this->setRelatedCategory($this->getCategoryValue($this->getRelatedCategoryID())); return $this->rCategory; } /** * Returns the note of the relationship from the perspective of the related entity * * @param none * @access public * @return string */ public function getRelatedNote() { return $this->rNote; } /** * Returns the isPrimary boolean of the relationship in the perspective of the related entity * * @param none * @access public * @return boolean */ public function getRelatedIsPrimary() { return $this->rIsPrimary; } /** * Sets the table def value of the primary entity * * @param int $value * @access public * @return void */ public function setTableDefID($value) { $this->tableDefID = null; if (is_numeric($value)) $this->tableDefID = $value; } /* * Sets the ref ID of the primary entity * * @param int $value * @access public * @return void */ public function setRefID($value) { $this->refID = null; if (($value)) $this->refID = $value; } /* * Sets the primary entity object * * @param object $value * @access public * @return void */ public function setObj($value) { $this->obj = null; if ($value) $this->obj = $value; } /* * Sets the table def of the related entity * * @param int $value * @access public * @return void */ public function setRelatedTableDefID($value) { $this->relatedTableDefID = null; if (is_numeric($value)) $this->relatedTableDefID = $value; } /* * Sets the ref ID of the related entity * * @param int $value * @access public * @return void */ public function setRelatedRefID($value) { $this->relatedRefID = null; if (($value)) $this->relatedRefID = $value; } /* * Sets the related entity object * * @param object $value * @access public * @return void */ public function setRelatedObj($value) { $this->relatedObj = null; if ($value) $this->relatedObj = $value; } /* * Sets the order of the related entity in the perspective of the primary entity * * @param int $value * @access public * @return void */ public function setOrder($value) { $this->order = 0; if (is_numeric($value)) $this->order = $value; } /* * Sets the category ID of the relationship from the perspective of the primary entity * * @param int $value * @access public * @return void */ public function setCategoryID($value) { $this->categoryID = null; if (is_numeric($value)) $this->categoryID = $value; } /* * Sets the category name of the relationship from the perspective of the primary entity * * @param string $value * @access public * @return void */ public function setCategory($value) { $this->category = null; if ($value) $this->category = $value; } /* * Sets the note of the relationship from the perspective of the primary entity * * @param string $value * @access public * @return void */ public function setNote($value) { $this->note = null; if ($value !== null) $this->note = $value; } /* * Sets the boolean for the relationship to be primary in the perspective of the primary entity * * @param string $value * @access public * @return void */ public function setIsPrimary($value) { if ($value) { $this->isPrimary = true; } else { $this->isPrimary = false; } } /* * Sets the order of the primary entity in the perspective of the related entity * * @param int $value * @access public * @return void */ public function setRelatedOrder($value) { $this->rOrder = 0; if (is_numeric($value)) $this->rOrder = $value; } /* * Sets the category ID of the relationship from the perspective of the related entity * * @param int $value * @access public * @return void */ public function setRelatedCategoryID($value) { $this->rCategoryID = null; if (is_numeric($value)) $this->rCategoryID = $value; } /* * Sets the category name of the relationship from the perspective of the related entity * * @param string $value * @access public * @return void */ public function setRelatedCategory($value) { $this->rCategory = null; if ($value) $this->rCategory = $value; } /* * Sets the note of the relationship from the perspective of the related entity * * @param string $value * @access public * @return void */ public function setRelatedNote($value) { $this->rNote = null; if ($value !== null) $this->rNote = $value; } /* * Sets the boolean for the relationship to be primary in the perspective of the related entity * * @param string $value * @access public * @return void */ public function setRelatedIsPrimary($value) { if ($value) { $this->rIsPrimary = true; } else { $this->rIsPrimary = false; } } /* * This method will swap all the category, note, order, and isPrimary fields around if the data is queried from a related entity perspective but is used in a primary entity organization * * @param none * @access public * @return void */ public function swapProperties() { $tempPrimary = $this->getIsPrimary(); $tempOrder = $this->getOrder(); $tempCategoryID = $this->getCategoryID(); $tempNote = $this->getNote(); $this->setIsPrimary($this->getRelatedIsPrimary()); $this->setOrder($this->getRelatedOrder()); $this->setCategoryID($this->getRelatedCategoryID()); $this->setNote($this->getRelatedNote()); $this->setRelatedIsPrimary($tempPrimary); $this->setRelatedOrder($tempOrder); $this->setRelatedCategoryID($tempCategoryID); $this->setRelatedNote($tempNote); } /* * Persists the current state of the object to the mechanism employed by the current datasource. Returns true if it succeeds otherwise false. * * @param none * @access public * @return boolean */ public function save() { $this->checkDS("save"); if ($this->ds->saveEntityRelationship($this)) { return true; } else { return false; } } /* * Removes the persistence entry for the current configuration of the object from the current datasource. Returns true if it succeeds otherwise false. * * @param none * @access public * @return boolean */ public function delete() { $this->checkDS("delete"); if ($this->ds->deleteEntityRelationship($this)) { return true; } else { return false; } } } ?>