} } else { if ($_POST['request'] == 'exclusion_add') { // first hceck to see if the exclusion exists. $c = new Criteria(); $c->add(NagiosTimeperiodExcludePeer::TIMEPERIOD_ID, $timeperiod->getId()); $c->add(NagiosTimeperiodExcludePeer::EXCLUDED_TIMEPERIOD, $_POST['timeperiod_manage']['exclusion_add']['timeperiod_id']); $tempExclusion = NagiosTimeperiodExcludePeer::doSelectOne($c); if ($tempExclusion) { $error = "That exclusion already exists."; } else { $targetTimeperiod = NagiosTimeperiodPeer::retrieveByPK($_POST['timeperiod_manage']['exclusion_add']['timeperiod_id']); if (!$targetTimeperiod) { $error = "That timeperiod is not in the system."; } else { $tempExclusion = new NagiosTimeperiodExclude(); $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($targetTimeperiod); $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timeperiod); $tempExclusion->save(); $success = "Exclusion added."; } } } } } } // Create subnav $subnav = array('general' => 'General', 'entries' => 'Time Entries', 'exclusions' => 'Exclusions'); print_header("Time Period Editor"); print_window_header("Modify A Time Period - " . $timeperiod->getName(), "100%"); print_subnav($subnav, $_GET['section'], "section", $_SERVER['PHP_SELF'] . "?timeperiod_id=" . $timeperiod->getId());
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $timePeriod = new NagiosTimeperiod(); $segment = $this->getSegment(); // First check if we have a use $useTemplate = $segment->get("use"); if ($useTemplate) { // Okay, we need to check to see if we have an existing dependency $val = $useTemplate[0]['value']; $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $val); $c->setIgnoreCase(true); $dependant = NagiosTimeperiodPeer::doSelectOne($c); if ($dependant) { // We need to add all the entries from that time period to ours. $entries = $dependant->getNagiosTimeperiodEntrys(); foreach ($entries as $entry) { $tempEntry = new NagiosTimeperiodEntry(); $tempEntry->setEntry($entry->getEntry()); $tempEntry->setValue($entry->getValue()); $timePeriod->addNagiosTimeperiodEntry($tempEntry); } $exclusions = $dependant->getNagiosTimeperiodExcludesRelatedByTimeperiodId(); foreach ($exclusions as $exclusion) { $tempExclusion = new NagiosTimeperiodExclude(); $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod); $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($exclusion->getNagiosTimeperiodRelatedByExcludedTimePeriod); } $dependent->clearAllReferences(true); } } $values = $segment->getValues(); $fileName = $segment->getFilename(); foreach ($values as $key => $entries) { foreach ($entries as $entry) { if ($key == "exclude") { continue; } $value = $entry['value']; $lineNum = $entry['line']; if ($key == "use") { continue; } if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') { // Okay, let's check that the method DOES exist if (!method_exists($timePeriod, $this->fieldMethods[$key])) { $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName); if (!$config->getVar('continue_error')) { return false; } } else { call_user_method($this->fieldMethods[$key], $timePeriod, $value); } } else { // It's an entry. Let's rebuild the string and grab the entry and value // This is pretty hackish $pos = $this->preg_pos("/[0-9]{1,2}:[0-9]{1,2}/", $entry['text']); // Look for the first 00:00 $tempLabel = trim(substr($entry['text'], 0, $pos - 1)); $commentPos = strpos($entry['text'], ";"); if ($commentPos === false) { $commentLength = 0; } else { $commentLength = strlen(substr($entry['text'], $commentPos)); } $valLength = strlen($entry['text']) - ($commentLength + $pos); $tempValue = trim(substr($entry['text'], $pos, $valLength)); $tempEntry = new NagiosTimeperiodEntry(); $tempEntry->setEntry($tempLabel); $tempEntry->setValue($tempValue); $timePeriod->addNagiosTimeperiodEntry($tempEntry); $tempEntry->clearAllReferences(true); } } } // Check to see if there is an exclusion $excludes = $segment->get("exclude"); if ($excludes) { $val = $excludes[0]['value']; // Multiple timeperiods are seperated by a comma $timeperiods = explode(",", $val); if (count($timeperiods)) { foreach ($timeperiods as $timeperiod) { $timeperiod = trim($timeperiod); $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $val); $c->setIgnoreCase(true); $target = NagiosTimeperiodPeer::doSelectOne($c); if (!$target) { $job->addLogEntry("Dependent exclude timeperiod " . $timeperiod . " not found. ", ImportLogEntry::TYPE_NOTICE); return false; } else { $exclusion = new NagiosTimeperiodExclude(); $exclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod); $exclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($target); $exclusion->clearAllReferences(true); $target->clearAllReferences(true); } } } } $timePeriod->save(); $timePeriod->clearAllReferences(true); $job->addNotice("NagiosTimePeriodImporter finished importing timeperiod: " . $timePeriod->getName()); return true; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param NagiosTimeperiodExclude $value A NagiosTimeperiodExclude object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(NagiosTimeperiodExclude $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }