public function executeJson(AgaviRequestDataHolder $rd) { $data = array(); $jsonResult = new AppKitExtJsonDocument(); $storage = $this->getContext()->getUser()->getNsmUser()->getStorage(); try { $file = $this->getTemplateFile($rd); $template = unserialize($storage->read("icinga.cronks.template." . $file)); if (!$template) { $template = new CronkGridTemplateXmlParser($file->getRealPath(), $this->getContext()); $template->parseTemplate(); $storage->write("icinga.cronks.template" . $file, serialize($template)); } $connection = $rd->getParameter("connection", "icinga"); $worker = CronkGridTemplateWorkerFactory::createWorker($template, $this->getContext(), $connection); if (is_numeric($rd->getParameter('page_start')) && is_numeric($rd->getParameter('page_limit'))) { $worker->setResultLimit($rd->getParameter('page_start'), $rd->getParameter('page_limit')); } else { $user = $this->context->getUser(); $worker->setResultLimit(0, $user->getPrefVal('org.icinga.grid.pagerMaxItems', AgaviConfig::get('modules.cronks.grid.pagerMaxItems', 25))); } if ($rd->getParameter('sort_field', null) !== null) { $worker->setOrderColumn($rd->getParameter('sort_field'), $rd->getParameter('sort_dir', 'ASC')); if ($rd->getParameter('additional_sort_field', null) !== null) { $worker->addOrderColumn($rd->getParameter('additional_sort_field'), $rd->getParameter('sort_dir', 'ASC')); } } // apply json and legacy filters /** @var $pm Cronks_System_ViewProcFilterParamsModel */ $pm = $this->getContext()->getModel('System.ViewProcFilterParams', 'Cronks'); if (is_array($rd->getParameter('f'))) { $pm->setParams($rd->getParameter('f')); } if ($rd->getParameter('filter_json', false)) { $pm->setParamsFromJson(json_decode($rd->getParameter('filter_json'), true)); } $pm->applyToWorker($worker); $worker->buildAll(); $data = $worker->fetchDataArray(); $worker->countResults(); $jsonResult->hasFieldBulk(array_fill_keys($template->getFieldKeys(), "")); $jsonResult->setSuccess(true); $jsonResult->setDefault(AppKitExtJsonDocument::PROPERTY_TOTAL, $worker->countResults()); $jsonResult->setData($data); } catch (AppKitFileUtilException $e) { $jsonResult->resetDoc(); $jsonResult->hasFieldBulk($template->getFieldKeys()); $jsonResult->setSuccess(true); $jsonResult->setDefault(AppKitExtJsonDocument::PROPERTY_TOTAL, 0); } return (string) $jsonResult; }