/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see MenuItemVersion::setDeleted() * @see MenuItemVersion::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(MenuItemVersionTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildMenuItemVersionQuery::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 MenuItemVersion or Criteria object. * * @param mixed $criteria Criteria or MenuItemVersion 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(MenuItemVersionTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from MenuItemVersion object } // Set the correct dbName $query = MenuItemVersionQuery::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; }
/** * Sets the properties of the current object to the value they had at a specific version * * @param ChildMenuVersion $version The version object to use * @param ConnectionInterface $con the connection to use * @param array $loadedObjects objects that been loaded in a chain of populateFromVersion calls on referrer or fk objects. * * @return ChildMenu The current object (for fluent API support) */ public function populateFromVersion($version, $con = null, &$loadedObjects = array()) { $loadedObjects['ChildMenu'][$version->getId()][$version->getVersion()] = $this; $this->setId($version->getId()); $this->setVisible($version->getVisible()); $this->setPosition($version->getPosition()); $this->setCreatedAt($version->getCreatedAt()); $this->setUpdatedAt($version->getUpdatedAt()); $this->setVersion($version->getVersion()); $this->setVersionCreatedAt($version->getVersionCreatedAt()); $this->setVersionCreatedBy($version->getVersionCreatedBy()); if ($fkValues = $version->getMenuItemIds()) { $this->clearMenuItems(); $fkVersions = $version->getMenuItemVersions(); $query = ChildMenuItemVersionQuery::create(); foreach ($fkValues as $key => $value) { $c1 = $query->getNewCriterion(MenuItemVersionTableMap::ID, $value); $c2 = $query->getNewCriterion(MenuItemVersionTableMap::VERSION, $fkVersions[$key]); $c1->addAnd($c2); $query->addOr($c1); } foreach ($query->find($con) as $relatedVersion) { if (isset($loadedObjects['ChildMenuItem']) && isset($loadedObjects['ChildMenuItem'][$relatedVersion->getId()]) && isset($loadedObjects['ChildMenuItem'][$relatedVersion->getId()][$relatedVersion->getVersion()])) { $related = $loadedObjects['ChildMenuItem'][$relatedVersion->getId()][$relatedVersion->getVersion()]; } else { $related = new ChildMenuItem(); $related->populateFromVersion($relatedVersion, $con, $loadedObjects); $related->setNew(false); } $this->addMenuItem($related); $this->collMenuItemsPartial = false; } } return $this; }
/** * retrieve the last $number versions. * * @param Integer $number the number of record to return. * @return PropelCollection|array \Menu\Model\MenuItemVersion[] List of \Menu\Model\MenuItemVersion objects */ public function getLastVersions($number = 10, $criteria = null, $con = null) { $criteria = ChildMenuItemVersionQuery::create(null, $criteria); $criteria->addDescendingOrderByColumn(MenuItemVersionTableMap::VERSION); $criteria->limit($number); return $this->getMenuItemVersions($criteria, $con); }