public function executeJson(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $rd->getParameter('template'), '.xml'); } $template = new CronkGridTemplateXmlParser($file->getRealPath()); $template->parseTemplate(); $user = $this->getContext()->getUser()->getNsmUser(); $data = $template->getTemplateData(); if ($user->hasTarget('IcingaCommandRestrictions')) { $template->removeRestrictedCommands(); } return json_encode(array('template' => $template->getTemplateData(), 'fields' => $template->getFields(), 'keys' => $template->getFieldKeys(), 'params' => $rd->getParameters(), 'connections' => IcingaDoctrineDatabase::$icingaConnections)); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } }
/** * retrieves content via model and returns it * @param AgaviRequestDataHolder $rd required by Agavi but not used here * @return string $content generated content * @author Christian Doebler <*****@*****.**> */ public function executeSimple(AgaviRequestDataHolder $rd) { if ($rd->getParameter('interface', false) == true) { return $this->executeHtml($rd); } try { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); $file = null; foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { $file = AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } if ($file === null) { $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.to'), $fileName, '.xml'); } $model = $this->getContext()->getModel('System.StaticContent', 'Cronks', array('rparam' => $rd->getParameter('p', array()))); $model->setTemplateFile($file->getRealPath()); $content = $model->renderTemplate($rd->getParameter('render', 'MAIN'), $rd->getParameters()); return sprintf('<div class="%s">%s</div>', 'static-content-container', $content); } catch (AppKitFileUtilException $e) { $msg = 'Could not find template for ' . $rd->getParameter('template'); AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); return $msg; } } catch (Exception $e) { return $e->getMessage(); } }
/** * @group Bug */ public function testBug() { $ctx = IcingaWebTestTool::getContext(); $file = AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), self::TEMPLATE, '.xml'); $template = new CronkGridTemplateXmlParser($file->getRealPath(), $ctx); $template->parseTemplate(); $worker = CronkGridTemplateWorkerFactory::createWorker($template, $ctx, self::CONNECTION); $this->assertGreaterThanOrEqual(0, $worker->countResults()); }
private function getTemplateFile(AgaviRequestDataHolder $rd) { try { $modules = AgaviConfig::get("org.icinga.modules", array()); $fileName = $rd->getParameter('template'); foreach ($modules as $name => $path) { if (file_exists($path . "/config/templates/" . $fileName . '.xml')) { return AppKitFileUtil::getAlternateFilename($path . "/config/templates/", $fileName, '.xml'); } } return AppKitFileUtil::getAlternateFilename(AgaviConfig::get('modules.cronks.xml.path.grid'), $fileName, '.xml'); } catch (AppKitFileUtilException $e) { AppKitAgaviUtil::log('Could not find template for ' . $rd->getParameter('template'), AgaviLogger::ERROR); throw $e; } }