/** * @param CrossForeignKeys $crossFKs * @param ForeignKey $excludeFK * @return string */ protected function getCrossRefFKRemoveObjectNames(CrossForeignKeys $crossFKs, ForeignKey $excludeFK) { $names = []; $fks = $crossFKs->getCrossForeignKeys(); foreach ($crossFKs->getMiddleTable()->getForeignKeys() as $fk) { if ($fk !== $excludeFK && ($fk === $crossFKs->getIncomingForeignKey() || in_array($fk, $fks))) { if ($fk === $crossFKs->getIncomingForeignKey()) { $names[] = '$this'; } else { $names[] = '$' . lcfirst($this->getFKPhpNameAffix($fk, false)); } } } foreach ($crossFKs->getUnclassifiedPrimaryKeys() as $pk) { $names[] = '$' . lcfirst($pk->getPhpName()); } return implode(', ', $names); }
protected function addFilterByCrossFK(&$script, CrossForeignKeys $crossFKs) { $relationName = $this->getRefFKPhpNameAffix($crossFKs->getIncomingForeignKey(), $plural = false); foreach ($crossFKs->getCrossForeignKeys() as $crossFK) { $queryClass = $this->getQueryClassName(); $crossRefTable = $crossFK->getTable(); $foreignTable = $crossFK->getForeignTable(); $fkPhpName = $foreignTable->getPhpName(); $crossTableName = $crossRefTable->getName(); $relName = $this->getFKPhpNameAffix($crossFK, $plural = false); $objectName = '$' . $foreignTable->getCamelCaseName(); $script .= "\n /**\n * Filter the query by a related {$fkPhpName} object\n * using the {$crossTableName} table as cross reference\n *\n * @param {$fkPhpName} {$objectName} the related object to use as filter\n * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL\n *\n * @return {$queryClass} The current query, for fluid interface\n */\n public function filterBy{$relName}({$objectName}, \$comparison = Criteria::EQUAL)\n {\n return \$this\n ->use{$relationName}Query()\n ->filterBy{$relName}({$objectName}, \$comparison)\n ->endUse();\n }\n"; } }
/** * @param CrossForeignKeys $crossFKs * @param ForeignKey $excludeFK * @return string */ protected function getCrossRefFKGetterName(CrossForeignKeys $crossFKs, ForeignKey $excludeFK) { $names = []; $fks = $crossFKs->getCrossForeignKeys(); foreach ($crossFKs->getMiddleTable()->getForeignKeys() as $fk) { if ($fk !== $excludeFK && ($fk === $crossFKs->getIncomingForeignKey() || in_array($fk, $fks))) { $names[] = $this->getFKPhpNameAffix($fk, false); } } foreach ($crossFKs->getUnclassifiedPrimaryKeys() as $pk) { $names[] = $pk->getPhpName(); } $name = implode($names); return $this->getPluralizer()->getPluralForm($name); }