Beispiel #1
0
 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";
     }
 }
Beispiel #2
0
 /**
  * Extracts some useful information from a CrossForeignKeys object.
  *
  * @param CrossForeignKeys $crossFKs
  * @param array|ForeignKey $crossFKToIgnore
  * @param array            $signature
  * @param array            $shortSignature
  * @param array            $normalizedShortSignature
  * @param array            $phpDoc
  */
 protected function extractCrossInformation(CrossForeignKeys $crossFKs, $crossFKToIgnore = null, &$signature, &$shortSignature, &$normalizedShortSignature, &$phpDoc)
 {
     foreach ($crossFKs->getCrossForeignKeys() as $fk) {
         if (is_array($crossFKToIgnore) && in_array($fk, $crossFKToIgnore)) {
             continue;
         } else {
             if ($fk === $crossFKToIgnore) {
                 continue;
             }
         }
         $phpType = $typeHint = $this->getClassNameFromTable($fk->getForeignTable());
         $name = '$' . lcfirst($this->getFKPhpNameAffix($fk));
         $normalizedShortSignature[] = $name;
         $signature[] = ($typeHint ? "{$typeHint} " : '') . $name;
         $shortSignature[] = $name;
         $phpDoc[] = "\n     * @param {$phpType} {$name}";
     }
     foreach ($crossFKs->getUnclassifiedPrimaryKeys() as $primaryKey) {
         //we need to add all those $primaryKey s as additional parameter as they are needed
         //to create the entry in the middle-table.
         $defaultValue = $primaryKey->getDefaultValueString();
         $phpType = $primaryKey->getPhpType();
         $typeHint = $primaryKey->isPhpArrayType() ? 'array' : '';
         $name = '$' . lcfirst($primaryKey->getPhpName());
         $normalizedShortSignature[] = $name;
         $signature[] = ($typeHint ? "{$typeHint} " : '') . $name . ('null' !== $defaultValue ? " = {$defaultValue}" : '');
         $shortSignature[] = $name;
         $phpDoc[] = "\n     * @param {$phpType} {$name}";
     }
 }
Beispiel #3
0
 /**
  * @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);
 }
Beispiel #4
0
 /**
  * Returns the list of cross foreign keys.
  *
  * @return CrossForeignKeys[]
  */
 public function getCrossFks()
 {
     $crossFks = [];
     foreach ($this->referrers as $refFK) {
         if ($refFK->getTable()->isCrossRef()) {
             $crossFK = new CrossForeignKeys($refFK, $this);
             foreach ($refFK->getOtherFks() as $fk) {
                 if ($fk->isAtLeastOneLocalPrimaryKeyIsRequired() && $crossFK->isAtLeastOneLocalPrimaryKeyNotCovered($fk)) {
                     $crossFK->addCrossForeignKey($fk);
                 }
             }
             if ($crossFK->hasCrossForeignKeys()) {
                 $crossFks[] = $crossFK;
             }
         }
     }
     return $crossFks;
 }