Example #1
0
 /**
  * @param $renderApi
  * @param \Render\Unit $unit
  * @param Array $tabTitles
  */
 protected function renderTabBar($renderApi, $unit, $tabTitles)
 {
     $tabCount = 0;
     foreach ($tabTitles as $tabTitle) {
         $tabId = $unit->getId() . '_tab' . $tabCount;
         $input = new HtmlTagBuilder('input', array('type' => 'radio', 'name' => $unit->getId(), 'id' => $tabId));
         if ($tabCount === 0) {
             $input->set('checked', null);
         }
         echo $input->toString();
         $label = new HtmlTagBuilder('label', array('for' => $tabId, 'class' => 'tabLabel'), array($tabTitle));
         echo $label->toString();
         $tabCount++;
     }
 }
Example #2
0
 /**
  * Returns a map list of all provided module data
  *
  * @param Unit $rootUnit
  *
  * @return array
  */
 public function getAllModuleData(Unit $rootUnit)
 {
     $node = $this->getNodeByUnitId($rootUnit->getId());
     $moduleInfoVisitor = new ModuleDataVisitor($this->getRenderContext());
     $node->accept($moduleInfoVisitor);
     return $moduleInfoVisitor->getModuleData();
 }
Example #3
0
 private function getPostValue(Unit $unit)
 {
     foreach ($this->formSubmit->getPostValues() as $value) {
         if ($value->getKey() === $unit->getId()) {
             return $value->getValue();
         }
     }
 }
Example #4
0
 /**
  * @param Unit   $unit
  * @param string $key
  *
  * @return array|null
  */
 public function getUnitValue(Unit $unit, $key)
 {
     $key = (string) $key;
     $path = $this->cachePath . DIRECTORY_SEPARATOR . $unit->getId() . DIRECTORY_SEPARATOR . $this->getFileName($key);
     if (!is_readable($path)) {
         return null;
     }
     $content = file_get_contents($path);
     return json_decode($content, true);
 }
Example #5
0
 /**
  * @param RenderAPI  $renderApi
  * @param Unit       $unit
  * @param ModuleInfo $moduleInfo
  */
 public function renderContent($renderApi, $unit, $moduleInfo)
 {
     $formSend = false;
     $this->http = new \Request();
     $form = new \Form();
     $honeyPotComponent = new \HoneyPotComponent();
     $this->formSubmit = new \FormSubmit();
     $postRequest = $this->formSubmit->getPostValues();
     $elementProperties = $form->getElementProperties();
     $elementProperties->setId("form" . str_replace("-", "", $unit->getId()));
     $elementProperties->addAttribute('action', $_SERVER['REQUEST_URI'] . '#' . $unit->getId());
     $elementProperties->addAttribute('method', 'post');
     $elementProperties->addAttribute('enctype', 'multipart/form-data');
     $form->add($honeyPotComponent->getHoneyPot());
     $form->add($honeyPotComponent->getFormUnitIdentifier($unit->getId()));
     if ($this->formSubmit->isValid($renderApi, $unit) && count($postRequest) > 0 && $honeyPotComponent->isValidHoneyPot($postRequest) && $this->hasValidFormData($renderApi, $unit)) {
         $this->formSubmit->setFieldLabelsToFormValueSet($renderApi);
         try {
             $this->sentEmail($renderApi, $unit, $postRequest);
             $formSend = true;
         } catch (\Exception $e) {
             $errorText = new \Span();
             $errorText->setContent("Unable to send email:<br />" . $e->getMessage());
             $errorContainer = new \Container();
             $errorContainer->add($errorText);
             $errorContainer->getElementProperties()->addClass('vf__main_error');
             $form->add($errorContainer);
         }
     }
     if ($formSend) {
         $confirmationText = new \Span();
         $confirmationText->setContent(preg_replace('/\\n/', '<br>', $renderApi->getFormValue($unit, 'confirmationText')));
         $confirmationContainer = new \Container();
         $confirmationContainer->add($confirmationText);
         $confirmationContainer->getElementProperties()->addClass('confirmationText');
         $form->add($confirmationContainer);
         echo $form->renderElement();
     } else {
         echo $form->renderElementProgressive($renderApi, $unit);
     }
 }
Example #6
0
 /**
  * @test
  * @group rendering
  * @group small
  * @group dev
  */
 public function test_createNewInstance()
 {
     // ARRANGE
     $expectedId = 'this is the unit id';
     $expectedModuleId = 'this is the unit module id';
     $expectedName = 'this is the unit name';
     $expectedFormValues = array('this is one unit form value');
     $expectedGhostContainer = true;
     $expectedTemplateUnitId = 'this is the unit template id';
     $expectedHtmlClass = 'this is the html class';
     // ACT
     $actualUnit = new Unit($expectedId, $expectedModuleId, $expectedName, $expectedFormValues, $expectedGhostContainer, $expectedTemplateUnitId, $expectedHtmlClass);
     // ASSERT
     $this->assertEquals($expectedId, $actualUnit->getId());
     $this->assertEquals($expectedModuleId, $actualUnit->getModuleId());
     $this->assertEquals($expectedName, $actualUnit->getName());
     $this->assertEquals($expectedFormValues, $actualUnit->getFormValues());
     $this->assertEquals($expectedGhostContainer, $actualUnit->isGhostContainer());
     $this->assertEquals($expectedTemplateUnitId, $actualUnit->getTemplateUnitId());
     $this->assertEquals($expectedHtmlClass, $actualUnit->getHtmlClass());
 }
 /**
  * @param \Render\APIs\APIv1\HeadAPI $api
  * @param \Render\Unit               $unit
  * @param \Render\ModuleInfo         $moduleInfo
  *
  * @return array
  */
 public function provideUnitData($api, $unit, $moduleInfo)
 {
     return array('method' => __METHOD__, 'module' => $moduleInfo->getId(), 'unit' => $unit->getId());
 }
Example #8
0
 /**
  * @return string the unitId of this node
  */
 public function getUnitId()
 {
     return $this->unit->getId();
 }
Example #9
0
 /**
  * Creates the html code for a single unit and writes it to output buffer.
  * This is an empty implementation and should be overridden if you want
  * to output any html code.
  *
  * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api
  * @param \Render\Unit $unit - an object which provides general unit specific
  *    data (e.g. unit id, form values, ... etc.)
  * @param \Render\ModuleInfo $moduleInfo - reference an object which provides
  *    the general module information (e.g. module id, asset url, manifest
  *    data, ... etc.)
  */
 public function render($renderApi, $unit, $moduleInfo)
 {
     if ($moduleInfo->isExtension()) {
         return;
     }
     $tag = new HtmlTagBuilder('div');
     $tag->set('id', $unit->getId());
     $tag->addClass($moduleInfo->getId());
     $tag->addClass('isModule');
     $tag->addClass($unit->getHtmlClass());
     // call hook
     $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo);
     echo $tag->getOpenString();
     $this->renderContent($renderApi, $unit, $moduleInfo);
     echo $tag->getCloseString();
 }
Example #10
0
 /**
  * Creates the html code for a single unit and writes it to output buffer.
  * This is an empty implementation and should be overridden if you want
  * to output any html code.
  *
  * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api
  * @param \Render\Unit $unit - an object which provides general unit specific
  *    data (e.g. unit id, form values, ... etc.)
  * @param \Render\ModuleInfo $moduleInfo - reference an object which provides
  *    the general module information (e.g. module id, asset url, manifest
  *    data, ... etc.)
  */
 public function render($renderApi, $unit, $moduleInfo)
 {
     if ($moduleInfo->isExtension()) {
         return;
     }
     $tag = new HtmlTagBuilder('div');
     $tag->set('id', $unit->getId());
     $tag->addClass($moduleInfo->getId());
     $tag->addClass('isModule');
     $tag->addClass($unit->getHtmlClass());
     // add style Set classes
     $children = $renderApi->getChildren($unit);
     $styleSetClasses = '';
     foreach ($children as $childUnit) {
         $styleSetClass = $renderApi->getFormValue($childUnit, 'cssStyleSets', false);
         if ($styleSetClass) {
             $styleSetClasses .= str_replace(",", " ", $styleSetClass) . " ";
         }
     }
     if ($styleSetClasses != '') {
         $tag->addClass($styleSetClasses);
     }
     // call hook
     $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo);
     echo $tag->getOpenString();
     $this->renderContent($renderApi, $unit, $moduleInfo);
     echo $tag->getCloseString();
 }
Example #11
0
 /**
  * @param \Render\APIs\APIv1\HeadAPI $api
  * @param \Render\Unit               $unit
  * @param string                     $key
  *
  * @return mixed
  */
 protected function getUnitContext($api, $unit, $key, $default = null)
 {
     $unitId = $unit->getId();
     if (!isset($this->unitContext[$unitId])) {
         return $default;
     }
     if (!isset($this->unitContext[$unitId][$key])) {
         return $default;
     }
     return $this->unitContext[$unitId][$key];
 }
Example #12
0
 /**
  * Triggers the rendering of the given unit with the current renderer
  *
  * @param Unit $unit the unit that should be rendered with the current renderer
  *
  * @return void
  */
 public function renderUnit(Unit $unit)
 {
     $node = $this->getNodeByUnitId($unit->getId());
     $node->accept($this->renderingVisitor);
 }
Example #13
0
 /**
  * Returns the module info object for the given unit, null if not found
  *
  * @param \Render\Unit $unit
  *
  * @return null|\Render\ModuleInfo
  */
 public function getModuleInfo(Unit $unit)
 {
     $node = $this->getAbstractRenderNodeById($unit->getId());
     if (is_null($node)) {
         return null;
     }
     return $node->getModuleInfo();
 }