/** * Filter the query by a related \Models\Pack object * * @param \Models\Pack|ObjectCollection $pack The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildFileQuery The current query, for fluid interface */ public function filterByPack($pack, $comparison = null) { if ($pack instanceof \Models\Pack) { return $this->addUsingAlias(FileTableMap::COL_PACK_ID, $pack->getId(), $comparison); } elseif ($pack instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(FileTableMap::COL_PACK_ID, $pack->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByPack() only accepts arguments of type \\Models\\Pack or Collection'); } }
protected function create() { if (isset($_POST["name"])) { $pack = PackQuery::create()->filterByOwner($this->data["loggedUser"])->filterByName($_POST["name"])->findOne(); if ($pack) { $this->sendFlashMessage("Your pack has not been created. You already have pack with this name.", "error"); $this->redirect("/pack/new"); } $pack = new Pack(); $pack->setName($_POST["name"]); $pack->setOwner($this->data["loggedUser"]); $pack->setPrivate(isset($_POST["private"])); $pack->setDescription(isset($_POST["description"]) ? $_POST["description"] : null); if ($pack->save() <= 0) { $failures = $pack->getValidationFailures(); if (count($failures) > 0) { foreach ($failures as $failure) { $this->sendFlashMessage("Your pack has not been created. " . $failure->getMessage(), "error"); } $this->redirect($this->data["referersURI"]); } } $this->sendFlashMessage("You have successfuly created new pack.", "success"); $this->redirect("/pack/" . $pack->getId()); } else { setHTTPStatusCode("400"); } }
/** * Declares an association between this object and a ChildPack object. * * @param ChildPack $v * @return $this|\Models\Comment The current object (for fluent API support) * @throws PropelException */ public function setPack(ChildPack $v = null) { if ($v === null) { $this->setPackId(NULL); } else { $this->setPackId($v->getId()); } $this->aPack = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPack object, it will not be re-added. if ($v !== null) { $v->addComment($this); } return $this; }
/** * Exclude object from result * * @param ChildPack $pack Object to remove from the list of results * * @return $this|ChildPackQuery The current query, for fluid interface */ public function prune($pack = null) { if ($pack) { $this->addUsingAlias(PackTableMap::COL_ID, $pack->getId(), Criteria::NOT_EQUAL); } return $this; }