/**
  * 
  * @param PollerTemplate $pollerTemplate
  * @return type
  * @throws Exception
  */
 public static function buildPollerTemplateForm(PollerTemplate $pollerTemplate, $pollerId)
 {
     $setUp = $pollerTemplate->getBrokerPart()->getSetup();
     if (count($setUp) < 1) {
         throw new Exception('No setup found in the template');
     }
     $currentSetUp = $setUp[0];
     $brokerMode = $currentSetUp->getMode('normal');
     $formHandler = new Form('broker_full_form');
     $formComponents = array();
     $defaultValues = array();
     $formComponents['General']['general'] = static::addGeneralParams($formHandler, $defaultValues, $pollerId);
     $formComponents['General']['path'] = static::addPathParams($formHandler, $defaultValues, $pollerId);
     foreach ($brokerMode as $mode) {
         if (!isset($mode['general'])) {
             throw new Exception('No name detected');
         }
         $sectionName = $mode['general']['name'];
         unset($mode['general']);
         $formComponents[$sectionName] = array();
         foreach ($mode as $blockInitialName => $blockContent) {
             switch ($blockInitialName) {
                 default:
                     continue;
                     break;
                 case 'logger':
                     $elements = static::parseLoggerParams($formHandler, $blockInitialName, $blockContent, $defaultValues, $sectionName);
                     if (count($elements) > 0) {
                         $formComponents[$sectionName][$blockInitialName] = $elements;
                     }
                     break;
                 case 'input':
                 case 'output':
                     $elements = static::parseOutputInputParams($formHandler, $blockInitialName, $blockContent, $defaultValues, $sectionName);
                     if (count($elements) > 0) {
                         $formComponents[$sectionName][$blockInitialName] = $elements;
                     }
                     break;
                 case 'module_directory':
                 case 'event_queue_max_size':
                 case 'write_thread_id':
                 case 'write_timestamp':
                 case 'flush_logs':
                     $elements = static::parseCustomParams($formHandler, $blockInitialName, array($blockInitialName => $blockContent), $defaultValues);
                     if (count($elements) > 0) {
                         $formComponents[$sectionName][$blockInitialName] = $elements;
                     }
                     break;
             }
         }
         if (count($formComponents[$sectionName]) == 0) {
             unset($formComponents[$sectionName]);
         }
     }
     $formHandler->addHidden('poller_id', $pollerId);
     $formHandler->addHidden('poller_tmpl', $pollerTemplate->getName());
     $formHandler->addSubmit('save_form', _("Save"));
     static::getSavedDefaultValues($pollerId, $defaultValues);
     $formHandler->setDefaults($defaultValues);
     $finalForm = static::genForm($formHandler, $formComponents);
     return $finalForm;
 }
Example #2
0
 public function testGetTemplateName()
 {
     $myTestTemplate = new Template('myTestTemplate');
     $this->assertEquals('myTestTemplate', $myTestTemplate->getName());
 }