/** * Dynamically create the search query, and set the proper filter and order * * @param string $source a valid source identifier (@see $possible_sources) * @param int $object_id the source object ID * @return ModelCriteria the propel Query object */ protected function createSearchQuery($source, $object_id) { $search = DiaporamaImageQuery::create(); !is_null($object_id) and $search->filterByDiaporamaId($object_id); $orders = $this->getOrder(); // Results ordering foreach ($orders as $order) { switch ($order) { case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha-reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual-reverse": $search->orderByPosition(Criteria::DESC); break; case "manual": $search->orderByPosition(Criteria::ASC); break; case "random": $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); break 2; break; } } return $search; }
/** * Returns the number of related DiaporamaImage objects. * * @param Criteria $criteria * @param boolean $distinct * @param ConnectionInterface $con * @return int Count of related DiaporamaImage objects. * @throws PropelException */ public function countDiaporamaImages(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) { $partial = $this->collDiaporamaImagesPartial && !$this->isNew(); if (null === $this->collDiaporamaImages || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collDiaporamaImages) { return 0; } if ($partial && !$criteria) { return count($this->getDiaporamaImages()); } $query = ChildDiaporamaImageQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByDiaporama($this)->count($con); } return count($this->collDiaporamaImages); }
/** * Load an existing object from the database */ protected function getExistingObject() { return DiaporamaImageQuery::create()->findPk($this->getRequest()->query->get("diaporama_image_id")); }
protected function getDiaporamaImage(DiaporamaImageEvent $event) { $model = DiaporamaImageQuery::create()->findPk($event->getId()); if (null === $model) { throw new \RuntimeException(sprintf("The 'diaporama_image' id '%d' doesn't exist", $event->getId())); } return $model; }
public function deleteImageAction($imageId) { // Check current user authorization if (null !== ($response = $this->checkAuth($this->resourceCode, $this->getModuleCode(), AccessManager::DELETE))) { return $response; } try { $diaporama_image = DiaporamaImageQuery::create()->findPk($imageId); $event = new DiaporamaImageEvent($imageId); $event->setId($imageId); $this->dispatch($this->deleteEventIdentifier, $event); $this->performAdditionalDeleteAction($event); return $this->generateRedirect($diaporama_image->getRedirectionUrl()); } catch (\Exception $e) { return $this->renderAfterDeleteError($e); } }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see DiaporamaImage::setDeleted() * @see DiaporamaImage::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(DiaporamaImageTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildDiaporamaImageQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Performs an INSERT on the database, given a DiaporamaImage or Criteria object. * * @param mixed $criteria Criteria or DiaporamaImage 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(DiaporamaImageTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from DiaporamaImage object } if ($criteria->containsKey(DiaporamaImageTableMap::ID) && $criteria->keyContainsValue(DiaporamaImageTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . DiaporamaImageTableMap::ID . ')'); } // Set the correct dbName $query = DiaporamaImageQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * Get the associated ChildDiaporamaImage object * * @param ConnectionInterface $con Optional Connection object. * @return ChildDiaporamaImage The associated ChildDiaporamaImage object. * @throws PropelException */ public function getDiaporamaImage(ConnectionInterface $con = null) { if ($this->aDiaporamaImage === null && $this->id !== null) { $this->aDiaporamaImage = ChildDiaporamaImageQuery::create()->findPk($this->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->aDiaporamaImage->addDiaporamaImageI18ns($this); */ } return $this->aDiaporamaImage; }