Пример #1
0
 /**
  * Get the associated Product object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Product The associated Product object.
  * @throws PropelException
  */
 public function getProduct(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aProduct === null && $this->product_id !== null && $doQuery) {
         $this->aProduct = ProductQuery::create()->findPk($this->product_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->aProduct->addProductAssignments($this);
            */
     }
     return $this->aProduct;
 }
Пример #2
0
 /**
  * Adds $delta to all Rank values that are >= $first and <= $last.
  * '$delta' can also be negative.
  *
  * @param      int $delta Value to be shifted by, can be negative
  * @param      int $first First node to be shifted
  * @param      int $last  Last node to be shifted
  * @param      PropelPDO $con Connection to use.
  */
 public static function shiftRank($delta, $first = null, $last = null, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $whereCriteria = ProductQuery::create();
     if (null !== $first) {
         $whereCriteria->add(ProductPeer::RANK_COL, $first, Criteria::GREATER_EQUAL);
     }
     if (null !== $last) {
         $whereCriteria->addAnd(ProductPeer::RANK_COL, $last, Criteria::LESS_EQUAL);
     }
     $valuesCriteria = new Criteria(ProductPeer::DATABASE_NAME);
     $valuesCriteria->add(ProductPeer::RANK_COL, array('raw' => ProductPeer::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
     BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
     ProductPeer::clearInstancePool();
 }
Пример #3
0
 /**
  * Returns the number of related Product objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Product objects.
  * @throws PropelException
  */
 public function countProducts(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collProductsPartial && !$this->isNew();
     if (null === $this->collProducts || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collProducts) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getProducts());
         }
         $query = ProductQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByPrincipal($this)->count($con);
     }
     return count($this->collProducts);
 }
Пример #4
0
 /**
  * Move the object to the bottom of the list
  *
  * @param     PropelPDO $con optional connection
  *
  * @return integer the old object's rank
  */
 public function moveToBottom(PropelPDO $con = null)
 {
     if ($this->isLast($con)) {
         return false;
     }
     if ($con === null) {
         $con = Propel::getConnection(ProductPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $bottom = ProductQuery::create()->getMaxRankArray($con);
         $res = $this->moveToRank($bottom, $con);
         $con->commit();
         return $res;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }