/** * Erzeugt ein PDF auf Basis der übergebenen Funktion. * @param $module * @param $action * @param $param * @param null $filename falls kein Dateiname angegeben wird, wird das PDF direkt im Browser ausgegeben * @throws \Exception */ public static function generate($module, $action, $param, $filename = null, $template = true, $margin = 0) { $druckinhalt = new WrapperControl(null, 'druck'); $druckinhalt->setModule($module)->setAction($action)->addParams($param); $pdf = new \mPDF('de-DE', 'A4'); $pdf->SetDisplayMode('fullpage'); // Zeigt eine ganze Seite an, wenn das PDF in Acrobat geöffnet wird if ($margin > 0) { $pdf->SetTopMargin($margin); } $pdf->SetFooter('Seite {PAGENO} / {nb}'); //file_get_contents('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css') . $stylesheet = file_get_contents('templates/print/css/default.css'); $pdf->WriteHTML($stylesheet, 1); if ($template && file_exists('site/Print.template.html')) { $vars = ['heading' => Application::getCurrentResponse()->getMetadata()->getHeading()]; $header = Parser::parse(null, null, $vars, file_get_contents('site/Print.template.html')); $pdf->WriteHTML($header, 2); } $pdf->WriteHTML($druckinhalt->toHtml(), 2); if ($filename === null) { $pdf->Output($module . $action . '.pdf', 'I'); } else { //$filename = Files::validateFilename($filename); $pdf->Output($filename, 'F'); } unset($pdf); }
/** * @covers \NewFrontiers\Framework\Output\Parser::parse * @covers \NewFrontiers\Framework\Output\Parser::getReplacement * @covers \NewFrontiers\Framework\Output\Parser::getWertFromEntity * @covers \NewFrontiers\Framework\Output\Parser::getWertFromVars */ public function testParse() { $instance = Parser::getInstance(); $instance->editMode = true; $entity = $this->createMock(BaseEntity::class); $control = new PanelControl(null, "ungewöhnliche ID"); $template = "This is {my} {thisControl.id} on {site.url}. " . "This is a {control_var} {controls}" . "<?php echo 'Merged'; echo 'string'; ?>"; //$ts = "{hallo}"; $result = Parser::parse($entity, $control, ["thisControl" => $entity], $template); //var_dump($result); $this->assertContains("This is", $result); $this->assertContains("This", $result); $this->assertContains("Mergedstring", $result); $result = Parser::parse($entity, $control, [], $template); //var_dump($result); /*$this->assertContains("Und", end($items)["msg"]); print_r(end($items)["msg"]);*/ }
/** * Generiert den HTML-Code des Controls auf Basis der aktuellen Skin * @return string */ public function renderBySkin() { $this->loadSkin(); $this->setVar('css', $this->getCssString()); $this->setVar('id', $this->getId()); $result = Parser::parse($this->entity, $this, $this->vars, $this->skin); return $result; }
/** * Gibt den Text einer Spalte aus. Ist ein Template vorhanden, so wird * dieses ggf. geparst und dann die Daten ausgegeben. Ohne Template * wird das entsprchende Feld zurückgegeben * * @param array $row * @return string */ public function getData($row) { if (isset($this->template)) { $variables = array($this->data); // array_merge($row, $this->data); return Parser::parse($this->entity, null, $variables, $this->template, $this->matches); } elseif (isset($this->text)) { return $this->text; } elseif (isset($this->entity) && (isset($this->field) && $this->entity->hasField($this->field))) { return $this->entity->felder[$this->field]->toString(); } else { return ""; } }
/** * @param $match * @param BaseEntity $entity * @param $useControl * @return BaseEntity|string */ private function getWertFromEntity($match, BaseEntity $entity, $useControl) { if (!$useControl) { return $entity->{$match}; } else { /** @var Control $control */ $control = $entity->felder[$match]->getEditControl(); $control->setReadOnly(!Parser::getInstance()->editMode); $js = ''; foreach ($control->getJavascript() as $akt) { $js .= $akt; } if ($js !== '') { $js = '<script>' . $js . '</script>'; } return $control->toHtml() . $js; } }
/** * Exportiert einen Datensatz. Der Datensatz wird in ein passendes * Array gewandelt (auf Basis des Mappings). Dieses wird dann über * die Array-Funktion exportiert. * * @param BaseEntity $entity */ protected function exportEntityRow(BaseEntity $entity) { $row = []; foreach ($this->mapping as $header => $field) { $value = ''; if ($field !== '') { if (Parser::hasVariable($field)) { // Falls eine Variable enthalten ist -> Parsen $value = Parser::getInstance()->parse($entity, null, [], $field); } else { // Jetzt könnte es ein Feld oder ein fester Wert sein if ($entity->hasField($field)) { $value = $entity->{$field}; } else { $value = $field; } } // Muss ein Callback aufgerufen werden if (isset($this->callbacks[$header])) { $callable = $this->callbacks[$header]; $value = $callable($value); } $value = trim($value); if (strlen($value) > $this->length[$header]) { $value = substr($value, 0, $this->length[$header]); } } $row[$header] = trim($value); } $this->exportArrayRow($row); }