Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed old code

  • Loading branch information...
commit c5b18e5d54a4a9738041aa89b83df2c769c3b1bf 1 parent 8b3e44f
@mpscholten authored
Showing with 2 additions and 582 deletions.
  1. +2 −582 src/Propel/Generator/Builder/Om/ObjectBuilder.php
View
584 src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -316,13 +316,13 @@ protected function addClassBody(&$script)
'\Propel\Runtime\Parser\AbstractParser',
'\Propel\Runtime\Propel',
'\Propel\Runtime\Map\TableMap',
- '\Propel\Runtime\Util\PropelDateTime'
+ '\Propel\Runtime\Util\PropelDateTime',
+ '\Propel\Runtime\ActiveQuery\PropelQuery'
);
$script .= $this->twig->render('Object/_classBody.php.twig', ['builder' => $this]);
- $this->addRefFKMethods($script);
$this->addCrossFKMethods($script);
$this->addClearAllReferences($script);
@@ -782,75 +782,6 @@ public function set".$methodAffix."Key(\$key)
} // addFKByKeyMutator()
/**
- * Adds the method that fetches fkey-related (referencing) objects but also joins in data from another table.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
- {
- $table = $this->getTable();
- $tblFK = $refFK->getTable();
- $joinBehavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN';
-
- $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
- $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
-
- $fkObjectBuilder = $this->getNewObjectBuilder($tblFK);
- $className = $fkObjectBuilder->getObjectClassName();
-
- foreach ($tblFK->getForeignKeys() as $fk2) {
-
- $tblFK2 = $fk2->getForeignTable();
- $doJoinGet = !$tblFK2->isForReferenceOnly();
-
- // it doesn't make sense to join in rows from the current table, since we are fetching
- // objects related to *this* table (i.e. the joined rows will all be the same row as current object)
- if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) {
- $doJoinGet = false;
- }
-
- $relCol2 = $this->getFKPhpNameAffix($fk2, false);
-
- if ( $this->getRelatedBySuffix($refFK) != "" &&
- ($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) {
- $doJoinGet = false;
- }
-
- if ($doJoinGet) {
- $script .= "
-
- /**
- * If this collection has already been initialized with
- * an identical criteria, it returns the collection.
- * Otherwise if this ".$table->getPhpName()." is new, it will return
- * an empty collection; or if this ".$table->getPhpName()." has previously
- * been saved, it will retrieve related $relCol from storage.
- *
- * This method is protected by default in order to keep the public
- * api reasonable. You can provide public methods for those you
- * actually need in ".$table->getPhpName().".
- *
- * @param Criteria \$criteria optional Criteria object to narrow the query
- * @param ConnectionInterface \$con optional connection object
- * @param string \$joinBehavior optional join type to use (defaults to $joinBehavior)
- * @return Collection|{$className}[] List of $className objects
- */
- public function get".$relCol."Join".$relCol2."(\$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
- {";
- $script .= "
- \$query = $fkQueryClassName::create(null, \$criteria);
- \$query->joinWith('" . $this->getFKPhpNameAffix($fk2, false) . "', \$joinBehavior);
-
- return \$this->get". $relCol . "(\$query, \$con);
- }
-";
- } /* end if ($doJoinGet) */
-
- } /* end foreach ($tblFK->getForeignKeys() as $fk2) { */
-
- } // function
-
- /**
* Adds the attributes used to store objects that have referrer fkey relationships to this object.
* <code>protected collVarName;</code>
* <code>private lastVarNameCriteria = null;</code>
@@ -880,495 +811,6 @@ protected function addRefFKAttributes(&$script, ForeignKey $refFK)
}
}
- /**
- * Adds the methods for retrieving, initializing, adding objects that are related to this one by foreign keys.
- * @param string &$script The script will be modified in this method.
- */
- protected function addRefFKMethods(&$script)
- {
- if (!$referrers = $this->getTable()->getReferrers()) {
- return;
- }
- $this->addInitRelations($script, $referrers);
- foreach ($referrers as $refFK) {
- $this->declareClassFromBuilder($this->getNewStubObjectBuilder($refFK->getTable()), 'Child');
- $this->declareClassFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
- if ($refFK->isLocalPrimaryKey()) {
- $this->addPKRefFKGet($script, $refFK);
- $this->addPKRefFKSet($script, $refFK);
- } else {
- $this->addRefFKClear($script, $refFK);
- $this->addRefFKPartial($script, $refFK);
- $this->addRefFKInit($script, $refFK);
- $this->addRefFKGet($script, $refFK);
- $this->addRefFKSet($script, $refFK);
- $this->addRefFKCount($script, $refFK);
- $this->addRefFKAdd($script, $refFK);
- $this->addRefFKDoAdd($script, $refFK);
- $this->addRefFKRemove($script, $refFK);
- $this->addRefFKGetJoinMethods($script, $refFK);
- }
- }
- }
-
- protected function addInitRelations(&$script, $referrers)
- {
- $script .= "
-
- /**
- * Initializes a collection based on the name of a relation.
- * Avoids crafting an 'init[\$relationName]s' method name
- * that wouldn't work when StandardEnglishPluralizer is used.
- *
- * @param string \$relationName The name of the relation to initialize
- * @return void
- */
- public function initRelation(\$relationName)
- {";
- foreach ($referrers as $refFK) {
- if (!$refFK->isLocalPrimaryKey()) {
- $relationName = $this->getRefFKPhpNameAffix($refFK);
- $relCol = $this->getRefFKPhpNameAffix($refFK, true);
- $script .= "
- if ('$relationName' == \$relationName) {
- return \$this->init$relCol();
- }";
- }
- }
- $script .= "
- }
-";
- }
-
- /**
- * Adds the method that clears the referrer fkey collection.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKClear(&$script, ForeignKey $refFK)
- {
- $relCol = $this->getRefFKPhpNameAffix($refFK, true);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $script .= "
- /**
- * Clears out the $collName collection
- *
- * This does not modify the database; however, it will remove any associated objects, causing
- * them to be refetched by subsequent calls to accessor method.
- *
- * @return void
- * @see add$relCol()
- */
- public function clear$relCol()
- {
- \$this->$collName = null; // important to set this to NULL since that means it is uninitialized
- }
-";
- } // addRefererClear()
-
- /**
- * Adds the method that initializes the referrer fkey collection.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKInit(&$script, ForeignKey $refFK)
- {
- $relCol = $this->getRefFKPhpNameAffix($refFK, true);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $script .= "
- /**
- * Initializes the $collName collection.
- *
- * By default this just sets the $collName collection to an empty array (like clear$collName());
- * however, you may wish to override this method in your stub class to provide setting appropriate
- * to your application -- for example, setting the initial array to the values stored in database.
- *
- * @param boolean \$overrideExisting If set to true, the method call initializes
- * the collection even if it is not empty
- *
- * @return void
- */
- public function init$relCol(\$overrideExisting = true)
- {
- if (null !== \$this->$collName && !\$overrideExisting) {
- return;
- }
- \$this->$collName = new ObjectCollection();
- \$this->{$collName}->setModel('" . $this->getClassNameFromBuilder($this->getNewStubObjectBuilder($refFK->getTable()), true) . "');
- }
-";
- } // addRefererInit()
-
- /**
- * Adds the method that adds an object into the referrer fkey collection.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKAdd(&$script, ForeignKey $refFK)
- {
- $tblFK = $refFK->getTable();
-
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $joinedTableObjectBuilder->getObjectClassName();
-
- if ($tblFK->getChildrenColumn()) {
- $className = $joinedTableObjectBuilder->getFullyQualifiedClassName();
- }
-
- $collName = $this->getRefFKCollVarName($refFK);
-
- $script .= "
- /**
- * Method called to associate a $className object to this object
- * through the $className foreign key attribute.
- *
- * @param $className \$l $className
- * @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
- */
- public function add".$this->getRefFKPhpNameAffix($refFK, false)."($className \$l)
- {
- if (\$this->$collName === null) {
- \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "();
- \$this->{$collName}Partial = true;
- }
-
- if (!in_array(\$l, \$this->{$collName}->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
- \$this->doAdd" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(\$l);
- }
-
- return \$this;
- }
-";
- } // addRefererAdd
-
- /**
- * Adds the method that returns the size of the referrer fkey collection.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKCount(&$script, ForeignKey $refFK)
- {
- $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
- $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $this->getClassNameFromBuilder($joinedTableObjectBuilder);
-
- $script .= "
- /**
- * Returns the number of related $className objects.
- *
- * @param Criteria \$criteria
- * @param boolean \$distinct
- * @param ConnectionInterface \$con
- * @return int Count of related $className objects.
- * @throws PropelException
- */
- public function count{$relCol}(Criteria \$criteria = null, \$distinct = false, ConnectionInterface \$con = null)
- {
- \$partial = \$this->{$collName}Partial && !\$this->isNew();
- if (null === \$this->$collName || null !== \$criteria || \$partial) {
- if (\$this->isNew() && null === \$this->$collName) {
- return 0;
- }
-
- if (\$partial && !\$criteria) {
- return count(\$this->get$relCol());
- }
-
- \$query = $fkQueryClassName::create(null, \$criteria);
- if (\$distinct) {
- \$query->distinct();
- }
-
- return \$query
- ->filterBy" . $this->getFKPhpNameAffix($refFK) . "(\$this)
- ->count(\$con);
- }
-
- return count(\$this->$collName);
- }
-";
- }
-
- /**
- * Adds the method that returns the referrer fkey collection.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKGet(&$script, ForeignKey $refFK)
- {
- $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
- $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $joinedTableObjectBuilder->getObjectClassName();
-
- $script .= "
- /**
- * Gets an array of $className objects which contain a foreign key that references this object.
- *
- * If the \$criteria is not null, it is used to always fetch the results from the database.
- * Otherwise the results are fetched from the database the first time, then cached.
- * Next time the same method is called without \$criteria, the cached collection is returned.
- * If this ".$this->getObjectClassName()." is new, it will return
- * an empty collection or the current collection; the criteria is ignored on a new object.
- *
- * @param Criteria \$criteria optional Criteria object to narrow the query
- * @param ConnectionInterface \$con optional connection object
- * @return Collection|{$className}[] List of $className objects
- * @throws PropelException
- */
- public function get$relCol(\$criteria = null, ConnectionInterface \$con = null)
- {
- \$partial = \$this->{$collName}Partial && !\$this->isNew();
- if (null === \$this->$collName || null !== \$criteria || \$partial) {
- if (\$this->isNew() && null === \$this->$collName) {
- // return empty collection
- \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "();
- } else {
- \$$collName = $fkQueryClassName::create(null, \$criteria)
- ->filterBy" . $this->getFKPhpNameAffix($refFK) . "(\$this)
- ->find(\$con);
-
- if (null !== \$criteria) {
- if (false !== \$this->{$collName}Partial && count(\$$collName)) {
- \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(false);
-
- foreach (\$$collName as \$obj) {
- if (false == \$this->{$collName}->contains(\$obj)) {
- \$this->{$collName}->append(\$obj);
- }
- }
-
- \$this->{$collName}Partial = true;
- }
-
- \$$collName" . "->getInternalIterator()->rewind();
-
- return \$$collName;
- }
-
- if (\$partial && \$this->$collName) {
- foreach (\$this->$collName as \$obj) {
- if (\$obj->isNew()) {
- \${$collName}[] = \$obj;
- }
- }
- }
-
- \$this->$collName = \$$collName;
- \$this->{$collName}Partial = false;
- }
- }
-
- return \$this->$collName;
- }
-";
- } // addRefererGet()
-
- protected function addRefFKSet(&$script, ForeignKey $refFK)
- {
- $relatedName = $this->getRefFKPhpNameAffix($refFK, true);
- $relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
-
- $inputCollection = lcfirst($relatedName);
- $inputCollectionEntry = lcfirst($this->getRefFKPhpNameAffix($refFK, false));
-
- $collName = $this->getRefFKCollVarName($refFK);
- $relCol = $this->getFKPhpNameAffix($refFK, $plural = false);
-
- $script .= "
- /**
- * Sets a collection of $relatedObjectClassName objects related by a one-to-many relationship
- * to the current object.
- * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
- * and new objects from the given Propel collection.
- *
- * @param Collection \${$inputCollection} A Propel collection.
- * @param ConnectionInterface \$con Optional connection object
- * @return ".$this->getObjectClassname()." The current object (for fluent API support)
- */
- public function set{$relatedName}(Collection \${$inputCollection}, ConnectionInterface \$con = null)
- {
- \${$inputCollection}ToDelete = \$this->get{$relatedName}(new Criteria(), \$con)->diff(\${$inputCollection});
-
- ";
-
- if ($refFK->isAtLeastOneLocalPrimaryKey()) {
- $script .= "
- //since at least one column in the foreign key is at the same time a PK
- //we can not just set a PK to NULL in the lines below. We have to store
- //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
- \$this->{$inputCollection}ScheduledForDeletion = clone \${$inputCollection}ToDelete;
-";
- } else {
- $script .= "
- \$this->{$inputCollection}ScheduledForDeletion = \${$inputCollection}ToDelete;
-";
- }
-
- $script .= "
- foreach (\${$inputCollection}ToDelete as \${$inputCollectionEntry}Removed) {
- \${$inputCollectionEntry}Removed->set{$relCol}(null);
- }
-
- \$this->{$collName} = null;
- foreach (\${$inputCollection} as \${$inputCollectionEntry}) {
- \$this->add{$relatedObjectClassName}(\${$inputCollectionEntry});
- }
-
- \$this->{$collName} = \${$inputCollection};
- \$this->{$collName}Partial = false;
-
- return \$this;
- }
-";
- }
-
- /**
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKDoAdd(&$script, $refFK)
- {
- $relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, false);
- $lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $script .= "
- /**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to add.
- */
- protected function doAdd{$relatedObjectClassName}(\${$lowerRelatedObjectClassName})
- {
- \$this->{$collName}[]= \${$lowerRelatedObjectClassName};
- \${$lowerRelatedObjectClassName}->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this);
- }
-";
- }
-
- /**
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKRemove(&$script, $refFK)
- {
- $relatedName = $this->getRefFKPhpNameAffix($refFK, $plural = true);
- $relatedObjectClassName = $this->getRefFKPhpNameAffix($refFK, $plural = false);
- $inputCollection = lcfirst($relatedName . 'ScheduledForDeletion');
- $lowerRelatedObjectClassName = lcfirst($relatedObjectClassName);
-
- $collName = $this->getRefFKCollVarName($refFK);
- $relCol = $this->getFKPhpNameAffix($refFK, $plural = false);
- $localColumn = $refFK->getLocalColumn();
-
- $script .= "
- /**
- * @param {$relatedObjectClassName} \${$lowerRelatedObjectClassName} The $lowerRelatedObjectClassName object to remove.
- * @return ". $this->getObjectClassname() ." The current object (for fluent API support)
- */
- public function remove{$relatedObjectClassName}(\${$lowerRelatedObjectClassName})
- {
- if (\$this->get{$relatedName}()->contains(\${$lowerRelatedObjectClassName})) {
- \$this->{$collName}->remove(\$this->{$collName}->search(\${$lowerRelatedObjectClassName}));
- if (null === \$this->{$inputCollection}) {
- \$this->{$inputCollection} = clone \$this->{$collName};
- \$this->{$inputCollection}->clear();
- }";
-
- if (!$refFK->isComposite() && !$localColumn->isNotNull()) {
- $script .= "
- \$this->{$inputCollection}[]= \${$lowerRelatedObjectClassName};";
- } else {
- $script .= "
- \$this->{$inputCollection}[]= clone \${$lowerRelatedObjectClassName};";
- }
-
- $script .= "
- \${$lowerRelatedObjectClassName}->set{$relCol}(null);
- }
-
- return \$this;
- }
-";
- }
-
- /**
- * Adds the method that gets a one-to-one related referrer fkey.
- * This is for one-to-one relationship special case.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addPKRefFKGet(&$script, ForeignKey $refFK)
- {
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $joinedTableObjectBuilder->getObjectClassName();
-
- $queryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
-
- $varName = $this->getPKRefFKVarName($refFK);
-
- $script .= "
- /**
- * Gets a single $className object, which is related to this object by a one-to-one relationship.
- *
- * @param ConnectionInterface \$con optional connection object
- * @return $className
- * @throws PropelException
- */
- public function get".$this->getRefFKPhpNameAffix($refFK, false)."(ConnectionInterface \$con = null)
- {
-";
- $script .= "
- if (\$this->$varName === null && !\$this->isNew()) {
- \$this->$varName = $queryClassName::create()->findPk(\$this->getPrimaryKey(), \$con);
- }
-
- return \$this->$varName;
- }
-";
- }
-
- /**
- * Adds the method that sets a one-to-one related referrer fkey.
- * This is for one-to-one relationships special case.
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK The referencing foreign key.
- */
- protected function addPKRefFKSet(&$script, ForeignKey $refFK)
- {
- $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable());
- $className = $joinedTableObjectBuilder->getObjectClassName();
-
- $varName = $this->getPKRefFKVarName($refFK);
-
- $script .= "
- /**
- * Sets a single $className object as related to this object by a one-to-one relationship.
- *
- * @param $className \$v $className
- * @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
- * @throws PropelException
- */
- public function set".$this->getRefFKPhpNameAffix($refFK, false)."($className \$v = null)
- {
- \$this->$varName = \$v;
-
- // Make sure that that the passed-in $className isn't already associated with this object
- if (\$v !== null && \$v->get" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(null, false) === null) {
- \$v->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this);
- }
-
- return \$this;
- }
-";
- }
-
protected function addCrossFKAttributes(&$script, ForeignKey $crossFK)
{
$joinedTableObjectBuilder = $this->getNewObjectBuilder($crossFK->getForeignTable());
@@ -1529,28 +971,6 @@ public function clear{$relCol}()
} // addRefererClear()
/**
- * Adds the method that clears the referrer fkey collection.
- *
- * @param string &$script The script will be modified in this method.
- * @param ForeignKey $refFK
- */
- protected function addRefFKPartial(&$script, ForeignKey $refFK)
- {
- $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
- $collName = $this->getRefFKCollVarName($refFK);
-
- $script .= "
- /**
- * Reset is the $collName collection loaded partially.
- */
- public function resetPartial{$relCol}(\$v = true)
- {
- \$this->{$collName}Partial = \$v;
- }
-";
- } // addRefFKPartial()
-
- /**
* Adds the method that initializes the referrer fkey collection.
* @param string &$script The script will be modified in this method.
* @param ForeignKey $crossFK
Please sign in to comment.
Something went wrong with that request. Please try again.