/**
  * 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(NagiosServiceTemplateInheritancePeer::SOURCE_TEMPLATE, $targetTemplateId);
         $inheritances = NagiosServiceTemplateInheritancePeer::doSelect($c);
         foreach ($inheritances as $inheritance) {
             if (NagiosServiceTemplateInheritance::isCircular($inheritance->getTargetTemplate(), $originalSourceTemplateId)) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * 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(NagiosServiceTemplateInheritancePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosServiceTemplateInheritancePeer::DATABASE_NAME);
         $criteria->add(NagiosServiceTemplateInheritancePeer::ID, $pks, Criteria::IN);
         $objs = NagiosServiceTemplateInheritancePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * Gets an array of NagiosServiceTemplateInheritance 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 NagiosServiceTemplate has previously been saved, it will retrieve
  * related NagiosServiceTemplateInheritancesRelatedByTargetTemplate from storage. If this NagiosServiceTemplate 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 NagiosServiceTemplateInheritance[]
  * @throws     PropelException
  */
 public function getNagiosServiceTemplateInheritancesRelatedByTargetTemplate($criteria = null, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(NagiosServiceTemplatePeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collNagiosServiceTemplateInheritancesRelatedByTargetTemplate === null) {
         if ($this->isNew()) {
             $this->collNagiosServiceTemplateInheritancesRelatedByTargetTemplate = array();
         } else {
             $criteria->add(NagiosServiceTemplateInheritancePeer::TARGET_TEMPLATE, $this->id);
             NagiosServiceTemplateInheritancePeer::addSelectColumns($criteria);
             $this->collNagiosServiceTemplateInheritancesRelatedByTargetTemplate = NagiosServiceTemplateInheritancePeer::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(NagiosServiceTemplateInheritancePeer::TARGET_TEMPLATE, $this->id);
             NagiosServiceTemplateInheritancePeer::addSelectColumns($criteria);
             if (!isset($this->lastNagiosServiceTemplateInheritanceRelatedByTargetTemplateCriteria) || !$this->lastNagiosServiceTemplateInheritanceRelatedByTargetTemplateCriteria->equals($criteria)) {
                 $this->collNagiosServiceTemplateInheritancesRelatedByTargetTemplate = NagiosServiceTemplateInheritancePeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastNagiosServiceTemplateInheritanceRelatedByTargetTemplateCriteria = $criteria;
     return $this->collNagiosServiceTemplateInheritancesRelatedByTargetTemplate;
 }
示例#4
0
文件: service.php 项目: Evolix/lilac
                 $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(NagiosServiceTemplateInheritancePeer::SOURCE_SERVICE, $service->getId());
         $c->addAscendingOrderByColumn(NagiosServiceTemplateInheritancePeer::ORDER);
         $inheritanceList = NagiosServiceTemplateInheritancePeer::doSelect($c);
         $found = false;
         for ($counter = 0; $counter < count($inheritanceList); $counter++) {
             if ($inheritanceList[$counter]->getNagiosServiceTemplateRelatedByTargetTemplate()->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.";
示例#5
0
 function getNagiosServiceTemplateInheritances()
 {
     $c = new Criteria();
     $c->add(NagiosServiceTemplateInheritancePeer::SOURCE_TEMPLATE, $this->getId());
     $c->addAscendingOrderByColumn(NagiosServiceTemplateInheritancePeer::ORDER);
     $list = array();
     $inheritanceTemplates = NagiosServiceTemplateInheritancePeer::doSelect($c);
     foreach ($inheritanceTemplates as $inheritanceItem) {
         $list[] = $inheritanceItem->getNagiosServiceTemplateRelatedByTargetTemplate();
     }
     return $list;
 }