/** * Build SQL WHERE section for an object * * @param $path string Base property path pointing to the object * @param $object object The value is an object, which will be used for search * @return string */ private function buildObject($path, $object) { $class = new Link_Class(get_class($object)); $id = $this->sql_link->getObjectIdentifier($object, $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null); if ($id) { // object is linked to stored data : search with object identifier return $this->buildValue($path, $id, $path == 'id' ? '' : 'id_'); } // object is a search object : each property is a search entry, and must join table $this->joins->add($path); $array = []; $class = new Reflection_Class(get_class($object)); foreach ($class->accessProperties() as $property_name => $property) { if (isset($object->{$property_name})) { $sub_path = $property_name; $array[$sub_path] = $object->{$property_name}; } } $sql = $this->buildArray($path, $array, 'AND'); if (!$sql) { $sql = 'FALSE'; } return $sql; }
/** * Used to get an object's identifier * * A null value will be returned for an object that is not linked to data link. * If $object is already an identifier, the identifier is returned. * * @param $object object an object to get data link identifier from * @param $property_name string a property name to get data link identifier from instead of object * @return mixed you can test if an object identifier is set with empty($of_this_result) */ public function getObjectIdentifier($object, $property_name = null) { return isset($property_name) ? parent::getObjectIdentifier($object, $property_name) : ($this->getLinkObjectIdentifier($object) ?: parent::getObjectIdentifier($object)); }
/** * @param $result mixed[] * @param $first boolean * @return array */ private function resultToRow($result, $first) { $row = []; for ($i = 0; $i < $this->column_count; $i++) { $j = $this->i_to_j[$i]; if (!isset($this->classes[$j])) { $row[$this->columns[$j]] = $result[$i]; } else { if (!isset($row[$this->columns[$j]])) { // TODO LOW try to get the object from object map to avoid multiple instances $row[$this->columns[$j]] = Builder::create($this->classes[$j]); if ($first && !isset($this->reflection_classes[$this->classes[$j]])) { $class = new Reflection_Class($this->classes[$j]); $class->accessProperties(); $this->reflection_classes[$this->classes[$j]] = $class; } } $property_name = $this->column_names[$i]; if ($property_name === 'id') { $this->link->setObjectIdentifier($row[$this->columns[$j]], $result[$i]); } else { $row[$this->columns[$j]]->{$property_name} = $result[$i]; } } } return $row; }