public function testStaticTemplate() { try { Template::getTemplate(__FILE__); } catch (\Exception $E) { $this->assertInstanceOf('MOC\\V\\Component\\Template\\Exception\\TemplateTypeException', $E); } try { Template::getTemplate('Missing.twig'); } catch (\Exception $E) { } try { Template::getTemplate('Missing.tpl'); } catch (\Exception $E) { } }
/** * @param $Location * * @return \MOC\V\Component\Template\Component\IBridgeInterface */ public function getTemplate($Location) { return Template::getTemplate($Location); }
public function testMPdfDocument() { $Bridge = new MPdf(); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->loadFile(new FileParameter(__DIR__ . '/Content/BridgeTest-Twig.pdf'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setPaperSizeParameter(new PaperSizeParameter('A4'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setPaperOrientationParameter(new PaperOrientationParameter('PORTRAIT'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setContent(Template::getTwigTemplate(__DIR__ . '/Content/BridgeTest.twig'))); // // $this->assertStringStartsWith( '%PDF-', $Bridge->getContent() ); // // $this->assertInstanceOf( 'MOC\V\Component\Document\Component\IBridgeInterface', // $Bridge->saveFile() // ); // $this->assertInstanceOf( 'MOC\V\Component\Document\Component\IBridgeInterface', // $Bridge->saveFile( new FileParameter( __DIR__.'/Content/BridgeTest-Twig-As.pdf' ) ) // ); // $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->loadFile(new FileParameter(__DIR__ . '/Content/BridgeTest-Tpl.pdf'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setPaperSizeParameter(new PaperSizeParameter('A4'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setPaperOrientationParameter(new PaperOrientationParameter('PORTRAIT'))); $this->assertInstanceOf('MOC\\V\\Component\\Document\\Component\\IBridgeInterface', $Bridge->setContent(Template::getSmartyTemplate(__DIR__ . '/Content/BridgeTest.tpl'))); // // $this->assertStringStartsWith( '%PDF-', $Bridge->getContent() ); // // $this->assertInstanceOf( 'MOC\V\Component\Document\Component\IBridgeInterface', // $Bridge->saveFile() // ); // $this->assertInstanceOf( 'MOC\V\Component\Document\Component\IBridgeInterface', // $Bridge->saveFile( new FileParameter( __DIR__.'/Content/BridgeTest-Tpl-As.pdf' ) ) // ); }
/** * @param null $Id * @param bool|false $Option * * @return bool|string */ public function ShowThumbnail($Id = null, $Option = false) { if ($Id === null) { return false; } $Picture = Test::useService()->getTestPictureById($Id); $Name = $Picture->getName(); $Auth = new Authenticator(new Get()); $Query = http_build_query($Auth->getAuthenticator()->createSignature(array('Id' => $Id), '/Api/Test/ShowImage')); $Button = null; if ($Option) { $Button = new Standard('', '/Platform/System/Test/Upload/Delete/Check', new Remove(), array('Id' => $Id), 'Löschen'); } return Template::getTwigTemplateString('<div class="thumbnail"> <img class="img-responsive" src="/Api/Test/ShowImage?' . $Query . '"> <div class="caption text-center"> {{ Name }} </div> <div class="text-right" > {{ Button }} </div> </div>')->setVariable('Button', $Button)->setVariable('Name', $Name)->getContent(); }
/** * @param string $String * * @return IBridgeInterface */ public static function getTwigTemplateString($String) { $Template = new Template(new Vendor(new TwigTemplate())); $Template->getBridgeInterface()->loadString($String, true); return $Template->getBridgeInterface(); }
/** * @param string $Name * @param null|string $Label * @param array $Data array( value => title ) * @param IIconInterface $Icon */ public function __construct($Name, $Label = '', $Data = array(), IIconInterface $Icon = null) { if (empty($Data)) { $Data[0] = '-[ Nicht verfügbar ]-'; } $this->Name = $Name; $this->Template = $this->getTemplate(__DIR__ . '/SelectBox.twig'); $this->Template->setVariable('ElementName', $Name); $this->Template->setVariable('ElementLabel', $Label); // Data is Entity-List ? if (count($Data) == 1 && !is_numeric(key($Data))) { $Attribute = key($Data); $Convert = array(); // Attribute is Twig-Template ? if (preg_match_all('/\\{\\%\\s*(.*)\\s*\\%\\}|\\{\\{(?!%)\\s*((?:[^\\s])*)\\s*(?<!%)\\}\\}/i', $Attribute, $Placeholder)) { /** @var Element $Entity */ foreach ((array) $Data[$Attribute] as $Entity) { if (is_object($Entity)) { if ($Entity->getId() === null) { $Entity->setId(0); } $Template = Template::getTwigTemplateString($Attribute); foreach ((array) $Placeholder[2] as $Variable) { $Chain = explode('.', $Variable); if (count($Chain) > 1) { $Template->setVariable($Chain[0], $Entity->{'get' . $Chain[0]}()); } else { if (method_exists($Entity, 'get' . $Variable)) { $Template->setVariable($Variable, $Entity->{'get' . $Variable}()); } else { if (property_exists($Entity, $Variable)) { $Template->setVariable($Variable, $Entity->{$Variable}); } else { $Template->setVariable($Variable, null); } } } } $Convert[$Entity->getId()] = $Template->getContent(); } } } else { /** @var Element $Entity */ foreach ((array) $Data[$Attribute] as $Entity) { if (is_object($Entity)) { if ($Entity->getId() === null) { $Entity->setId(0); } if (method_exists($Entity, 'get' . $Attribute)) { $Convert[$Entity->getId()] = $Entity->{'get' . $Attribute}(); } else { $Convert[$Entity->getId()] = $Entity->{$Attribute}; } } } } if (array_key_exists(0, $Convert)) { $Convert[0] = '-[ Nicht ausgewählt ]-'; } asort($Convert); $this->Template->setVariable('ElementData', $Convert); } else { if (array_key_exists(0, $Data)) { $Data[0] = '-[ Nicht ausgewählt ]-'; } asort($Data); $this->Template->setVariable('ElementData', $Data); } if (null !== $Icon) { $this->Template->setVariable('ElementIcon', $Icon); } }