/** * Replace entity value placeholders on relation definitions * Currently replaces ':entity.[col]' with the field value from the passed entity object * @param \Spot\Entity\EntityInterface|\Spot\Entity\ResultsetInterface $entity * @param array $conditions * @param string $replace * @return array */ public function resolveEntityConditions($entity, array $conditions, $replace = ':entity.') { // Load foreign keys with data from current row // Replace ':entity.[col]' with the field value from the passed entity object if ($conditions) { $sourceTable = $this->entityManager->getTable($this->sourceEntity()); $relationTable = $this->entityManager->getTable($this->relationEntityName()); foreach ($conditions as $relationCol => $col) { if (is_string($relationCol) && false !== strpos($relationCol, ':relation.')) { unset($conditions[$relationCol]); $relationCol = str_replace(':relation.', $relationTable . '.', $relationCol); } if (is_string($col) && false !== strpos($col, $replace)) { $col = str_replace($replace, '', $col); if ($entity instanceof EntityInterface) { $conditions[$relationCol] = $entity->{$col}; } else { if ($entity instanceof ResultsetInterface) { $conditions[$relationCol] = array_unique($entity->toArray($col)); } } } } } return $conditions; }