/** * Loads object ids (UOID) to array * @param bool $force Whether to force loading or not * @return bool */ protected function _load($force = false) { // if loaded and no forcing if (!$force && $this->loaded) { // done return true; } // only need to initialize if array is not set if (is_array($this->array)) { $this->loaded = true; return true; } // initialize array with an empty array $this->array = array(); // get manager through object if (!($em = $this->o->epGetManager())) { $this->loaded = true; return true; } // get all relationship ids if ($array = $em->getRelationIds($this->o, $this->fm, $this->o->epGetClassMap())) { $this->array = $array; } return $this->loaded = true; }
/** * Make where part of a SQL select to get children values * @param epDbObject $db the db connection * @param epObject $o the child object for query * @param int $depth how many children down we are * @param string $parent the parent of this child * @return array('from', 'where') * @author Oak Nauhygon <*****@*****.**> * @author Trevan Richins <*****@*****.**> */ public static function sqlSelectChildren($db, $o, $depth, $parent) { // array to keep new tables in 'from' $from = array(); // array to keep new expression in 'where' $where = array(); // get the class map for the child object $cm = $o->epGetClassMap(); // get all vars in the object $vars = $o->epGetVars(); // if object has oid, select use oid if ($oid = $o->epGetObjectId()) { $where[] = $db->quoteId($cm->getOidColumn()) . ' = ' . $oid; return array('from' => $from, 'where' => $where); } // mark child object under search (to avoid loops) $o->epSetSearching(true); // total number of vars (primitive or non-primitive) collected $n = 0; // new depth $depth++; // number of non-primitive (relationship) fields collected $nprim_id = 0; // loop through vars while (list($var, $val) = each($vars)) { // get field map if (!($fm =& $cm->getField($var))) { // should not happen continue; } // exclude null values (including empty strings) if (is_null($val) || !$val && $fm->getType() == epFieldMap::DT_CHAR) { continue; } // is it a primitive var? if ($fm->isPrimitive()) { $where[] = $db->quoteId($parent) . '.' . $db->quoteId($fm->getColumnName()) . ' = ' . $db->quote($val, $fm); // done for this var $n++; continue; } // okay we are dealing with a non-primitive (relationship) var if ($val instanceof epArray) { foreach ($val as $obj) { // skip object that is under searching if (!$obj || $obj->epIsSearching()) { continue; } // get 'where' and 'from' from relationship $from_where = epObj2Sql::sqlSelectRelations($db, $fm, $cm, $obj->epGetClassMap()->getTable(), $depth . $nprim_id, $parent); $where = array_merge($where, $from_where['where']); $from = array_merge($from, $from_where['from']); // get 'where' and 'from' from relationship $from_where = epObj2Sql::sqlSelectChildren($db, $obj, $depth, '_' . $depth . $nprim_id); $where = array_merge($where, $from_where['where']); $from = array_merge($from, $from_where['from']); $nprim_id++; } } else { if ($val instanceof epObject && !$val->epIsSearching()) { // get 'where' and 'from' from relationship $from_where = epObj2Sql::sqlSelectRelations($db, $fm, $cm, $val->epGetClassMap()->getTable(), $depth . $nprim_id, $parent); $where = array_merge($where, $from_where['where']); $from = array_merge($from, $from_where['from']); // get 'where' and 'from' from relationship $from_where = epObj2Sql::sqlSelectChildren($db, $val, $depth, '_' . $depth . $nprim_id); $where = array_merge($where, $from_where['where']); $from = array_merge($from, $from_where['from']); $nprim_id++; } } $n++; } // reset search flag on child object $o->epSetSearching(false); return array('from' => $from, 'where' => $where); }