protected function load($args) { $params = $args["params"]; $this->data["pack"] = PackQuery::create()->findPK($params["id"]); if (!$this->data["pack"]) { $this->sendFlashMessage("Pack with ID " . $params["id"] . " does not exist.", "error"); $this->redirect("/404"); } return true; }
/** * Get the associated ChildPack object * * @param ConnectionInterface $con Optional Connection object. * @return ChildPack The associated ChildPack object. * @throws PropelException */ public function getPack(ConnectionInterface $con = null) { if ($this->aPack === null && $this->pack_id !== null) { $this->aPack = ChildPackQuery::create()->findPk($this->pack_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aPack->addComments($this); */ } return $this->aPack; }
/** * Returns the number of related Pack objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related Pack objects. * @throws PropelException */ public function countPacks(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collPacksPartial && !$this->isNew(); if (null === $this->collPacks || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collPacks) { return 0; } if ($partial && !$criteria) { return count($this->getPacks()); } $query = ChildPackQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByOwner($this)->count($con); } return count($this->collPacks); }
protected function search() { $this->data['title'] = 'Starling'; $this->data['keywords'] .= 'search, results'; $this->data['description'] .= 'Results of searching.'; if (isset($_GET["q"]) && $_GET["q"] != "") { $q = urldecode($_GET["q"]); $page = 1; $perPage = 10; $this->data["q"] = $q; $this->data["search"] = "pack"; if (isset($_GET["search"])) { $this->data["search"] = $_GET["search"]; } if (isset($_GET["page"]) && $_GET["page"] >= 1) { $page = $_GET["page"]; } $qParts = preg_split("/\\s+/", $q); for ($i = 0; $i < count($qParts); $i++) { $qParts[$i] = $qParts[$i] . "%"; } $qMatch = $q . "*"; $likeQuery = ""; if ($this->data["search"] == "user") { for ($i = 0; $i < count($qParts); $i++) { if ($i > 0) { $likeQuery .= " OR "; } $likeQuery .= 'user.username LIKE ?'; } for ($i = 0; $i < count($qParts); $i++) { $likeQuery .= ' OR user.name LIKE ?'; } for ($i = 0; $i < count($qParts); $i++) { $likeQuery .= ' OR user.surname LIKE ?'; } $qParts = array_merge($qParts, $qParts, $qParts); $this->data["items"] = UserQuery::create()->condition("cond1", "MATCH(user.username, user.name, user.surname) AGAINST(? IN BOOLEAN MODE)", $qMatch)->condition("cond2", "user.deleted_at IS NULL")->condition("cond3", $likeQuery, $qParts)->combine(array("cond1", "cond3"), "or", "cond13")->where(array("cond13", "cond2"), "and")->paginate($page, $perPage); $this->viewFile($this->template); return; } if ($this->data["search"] == "pack") { for ($i = 0; $i < count($qParts); $i++) { if ($i > 0) { $likeQuery .= " OR "; } $likeQuery .= 'pack.name LIKE ?'; } if (count($qParts) == 1) { $qParts = $qParts[0]; } $this->data["items"] = PackQuery::create()->condition("cond1", "MATCH(pack.name, pack.description) AGAINST(? IN BOOLEAN MODE)", $qMatch)->condition("cond2", "pack.private=false")->condition("cond3", $likeQuery, $qParts)->combine(array("cond1", "cond3"), "or", "cond13")->where(array("cond13", "cond2"), "and")->paginate($page, $perPage); $this->viewFile($this->template); return; } else { $this->redirect("/"); } } else { $this->redirect("/"); } }
/** * Performs an INSERT on the database, given a Pack or Criteria object. * * @param mixed $criteria Criteria or Pack object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(PackTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Pack object } if ($criteria->containsKey(PackTableMap::COL_ID) && $criteria->keyContainsValue(PackTableMap::COL_ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . PackTableMap::COL_ID . ')'); } // Set the correct dbName $query = PackQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use($con, $query) { return $query->doInsert($con); }); }
public function getForeignPacks() { $packs = ChildPackQuery::create()->select(array("pack.name", "user.username", "pack.id", "pack_permission.value"))->useOwnerQuery()->select("user.username")->endUse()->usePackPermissionQuery()->filterByUser($this)->endUse()->find(); return $packs; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @throws LogicException if no primary key is defined * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = ChildPackQuery::create(); $criteria->add(PackTableMap::COL_ID, $this->id); return $criteria; }