/** * 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, $last = null, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(AbsenceEleveJustificationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $whereCriteria = new Criteria(AbsenceEleveJustificationPeer::DATABASE_NAME); $criterion = $whereCriteria->getNewCriterion(AbsenceEleveJustificationPeer::RANK_COL, $first, Criteria::GREATER_EQUAL); if (null !== $last) { $criterion->addAnd($whereCriteria->getNewCriterion(AbsenceEleveJustificationPeer::RANK_COL, $last, Criteria::LESS_EQUAL)); } $whereCriteria->add($criterion); $valuesCriteria = new Criteria(AbsenceEleveJustificationPeer::DATABASE_NAME); $valuesCriteria->add(AbsenceEleveJustificationPeer::RANK_COL, array('raw' => AbsenceEleveJustificationPeer::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL); BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con); AbsenceEleveJustificationPeer::clearInstancePool(); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(AbsenceEleveJustificationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = AbsenceEleveJustificationQuery::create() ->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // sortable behavior AbsenceEleveJustificationPeer::shiftRank(-1, $this->getSortableRank() + 1, null, $con); AbsenceEleveJustificationPeer::clearInstancePool(); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }