/** * Checks to determine if inheritance creates a circular chain. This is * done by recursively going through inheritance trees and seeing if the * source template is already found. If so, this would create a circular * inheritance loop and destroy our world as we know it. * *@param int $targetTemplateId what template Id are we looking at *@param int $originalSourceTemplateId what template Id are we looking for */ static function isCircular($targetTemplateId, $originalSourceTemplateId) { if ($targetTemplateId == $originalSourceTemplateId) { return true; } else { // Get all the potential inheritance in which the target template id // is the source $c = new Criteria(); $c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $targetTemplateId); $inheritances = NagiosHostTemplateInheritancePeer::doSelect($c); foreach ($inheritances as $inheritance) { if (NagiosHostTemplateInheritance::isCircular($inheritance->getTargetTemplate(), $originalSourceTemplateId)) { return true; } } } return false; }
/** * Gets an array of NagiosHostTemplateInheritance objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this NagiosHost has previously been saved, it will retrieve * related NagiosHostTemplateInheritances from storage. If this NagiosHost is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array NagiosHostTemplateInheritance[] * @throws PropelException */ public function getNagiosHostTemplateInheritances($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(NagiosHostPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosHostTemplateInheritances === null) { if ($this->isNew()) { $this->collNagiosHostTemplateInheritances = array(); } else { $criteria->add(NagiosHostTemplateInheritancePeer::SOURCE_HOST, $this->id); NagiosHostTemplateInheritancePeer::addSelectColumns($criteria); $this->collNagiosHostTemplateInheritances = NagiosHostTemplateInheritancePeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(NagiosHostTemplateInheritancePeer::SOURCE_HOST, $this->id); NagiosHostTemplateInheritancePeer::addSelectColumns($criteria); if (!isset($this->lastNagiosHostTemplateInheritanceCriteria) || !$this->lastNagiosHostTemplateInheritanceCriteria->equals($criteria)) { $this->collNagiosHostTemplateInheritances = NagiosHostTemplateInheritancePeer::doSelect($criteria, $con); } } } $this->lastNagiosHostTemplateInheritanceCriteria = $criteria; return $this->collNagiosHostTemplateInheritances; }
$tempTemplate->save(); $success = "Template moved down in inheritance chain."; $found = true; break; } } } if (empty($error)) { $error = "Could not find that template specified."; } } else { if ($_GET['request'] == "moveup" && $_GET['section'] == "inheritance") { $c = new Criteria(); $c->add(NagiosHostTemplateInheritancePeer::SOURCE_HOST, $host->getId()); $c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER); $inheritanceList = NagiosHostTemplateInheritancePeer::doSelect($c); $found = false; for ($counter = 0; $counter < count($inheritanceList); $counter++) { if ($inheritanceList[$counter]->getNagiosHostTemplateRelatedByTargetTemplate()->getId() == $_GET['template_id']) { // Omg, we found it! if ($counter == 0) { // We're at the end of the array, we couldn't possibly move down more! $error = "Cannot move that template up any further."; break; } else { $tempTemplate = $inheritanceList[$counter - 1]; $inheritanceList[$counter]->setOrder($inheritanceList[$counter]->getOrder() - 1); $tempTemplate->setOrder($tempTemplate->getOrder() + 1); $inheritanceList[$counter]->save(); $tempTemplate->save(); $success = "Template moved up in inheritance chain.";
function integrityCheck() { // Get our services $services = $this->getNagiosServices(); foreach ($services as $service) { $service->integrityCheck(); } $c = new Criteria(); $c->add(NagiosHostTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId()); $c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER); $inheritanceTemplates = NagiosHostTemplateInheritancePeer::doSelect($c); foreach ($inheritanceTemplates as $inheritance) { $template = $inheritance->getNagiosHostTemplateRelatedByTargetTemplate(); $template->integrityCheck(); } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosHostTemplateInheritancePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosHostTemplateInheritancePeer::DATABASE_NAME); $criteria->add(NagiosHostTemplateInheritancePeer::ID, $pks, Criteria::IN); $objs = NagiosHostTemplateInheritancePeer::doSelect($criteria, $con); } return $objs; }
function getNagiosHostTemplateInheritances() { $c = new Criteria(); $c->add(NagiosHostTemplateInheritancePeer::SOURCE_HOST, $this->getId()); $c->addAscendingOrderByColumn(NagiosHostTemplateInheritancePeer::ORDER); $list = array(); $inheritanceTemplates = NagiosHostTemplateInheritancePeer::doSelect($c); foreach ($inheritanceTemplates as $inheritanceItem) { $list[] = $inheritanceItem->getNagiosHostTemplateRelatedByTargetTemplate(); } return $list; }