/** * Magische Methode, die von PHP beim Deserialisieren des Objekts aufgerufen wird */ public function __wakeup() { // Verbindung zud DB wieder herstellen $this->db = Application::resolve($this->getDatabaseServiceName()); }
/** * Singleton-Funktion * @return Database aktuelle Instanz */ public static function getInstance() { if (self::$instance === null) { self::$instance = Application::resolve('default_database'); } return self::$instance; }
/** * Daten anzeigen * @return string HTML-String der Datenzeilen */ private function getDaten() { $tbody = Html::create('tbody'); $i = 0; $groupValue = null; $addedRow = false; $summe = 0; Logging::debug('Verwende DB-Service: ' . $this->entity->getDatabaseServiceName()); $db = Application::resolve($this->entity->getDatabaseServiceName()); while ($row = $db->fetch()) { $addedRow = true; // Daten in Entität laden, damit die formatierten Feldwerte zur Verfügung stehen $this->entity->loadFromRow($row); // Gruppieren if ($this->groupColumn > -1 && $groupValue != $this->columns[$this->groupColumn]->getData($row)) { $colcount = count($this->columns); if (!$this->renderGrouped) { $colcount--; } $i = 0; $groupValue = $this->columns[$this->groupColumn]->getData($row); $th = Html::create('th')->addAttribute('colspan', $colcount)->text($groupValue); $tr = Html::create('tr')->css('groupHeader')->text($th); $tbody->text($tr); } if ($this->sum > -1) { $summe += $this->columns[$this->sum]->getRawData($row); } $tr = Html::create('tr')->addAttribute('data-id', $this->entity->id); // Callable aufrufen um Klasse der Zeile zu ermitteln if (isset($this->rowClassCallable)) { $callable = $this->rowClassCallable; $tr->css($callable($this->entity)); } $j = 0; foreach ($this->columns as $column) { if ($this->renderGrouped || $j != $this->groupColumn) { $td = Html::create('td')->css($column->getCssClass())->text($column->getData($row)); if ($column->getNoWrap()) { $td->css('nowrap'); } $tr->text($td); } $j++; } // spalten $tbody->text($tr); $i++; } // zeilen // Summe rendern if ($this->sum > -1) { $tr = Html::create('tr'); $j = 0; foreach ($this->columns as $column) { if ($this->renderGrouped || $j != $this->groupColumn) { if ($j == $this->sum) { $td = Html::create('td')->css($column->getCssClass())->text('<strong>' . number_format($summe, 2, ',', '.') . '</strong>'); } else { $td = Html::create('td')->css($column->getCssClass())->text(' '); } if ($column->getNoWrap()) { $td->css('nowrap'); } $tr->create($td); } $j++; } // spalten $tbody->text($tr); } if ($addedRow) { return $tbody; } else { return null; } }