/** * Construct an instance of an entity with no deep linking * * Observation, maximum consumption o(n*2*n) * @param unknown $query_result */ protected function buildInstance($query_result) { /** * Finds all occurrences of this entity in query result */ $this->filterQueryResult($query_result); foreach ($this->occurences as $occurrenceNumber => $occurrenceHash) { /** * suppose that the instance wasn't yet created * @var unknown_type */ $instanceExists = false; /** * Search for an instance with key equal to query_result value */ if (isset($query_result[$occurrenceHash . $this->fields[0]->name])) { $instanceKeyValue = $query_result[$occurrenceHash . $this->fields[0]->name]; if (isset($this->instances) && isset($this->indexedInstances[$instanceKeyValue])) { $instanceExists = true; } } /** * if instance doesn't exists and the key field in query result is different from null * then build an instance */ if (!$instanceExists && isset($query_result[$occurrenceHash . $this->fields[0]->name])) { $entityInstance = new Instance($this); foreach ($this->fields as $fieldKey => $field) { if (isset($query_result[$occurrenceHash . $field->name])) { $entityInstance->setFieldValue($field->name, $query_result[$occurrenceHash . $field->name]); } } $presentation = $this->getPresentation(); $presentation = explode(", ", $presentation['fields']); $text = ""; foreach ($presentation as $a => $v) { $text .= " " . $entityInstance->getFieldValue($v); } $entityInstance->presentation = $text; $this->instances[] = $entityInstance; $this->indexedInstances[$entityInstance->getKeyFieldValue()] = $entityInstance; } $this->loaded = true; } }