From 62827e6cf470449c117624058fb36ad94804bcc0 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 5 May 2020 14:25:42 +0200 Subject: Time tracking related plugins --- plugins/Timetrackingeditor/Html.php | 182 ++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 plugins/Timetrackingeditor/Html.php (limited to 'plugins/Timetrackingeditor/Html.php') diff --git a/plugins/Timetrackingeditor/Html.php b/plugins/Timetrackingeditor/Html.php new file mode 100644 index 00000000..eb3e1fa5 --- /dev/null +++ b/plugins/Timetrackingeditor/Html.php @@ -0,0 +1,182 @@ +write('php://output', $rows); + } + + /** + * Define column mapping between CSV and SQL columns + * + * @access public + * @param array $columns + * @return Csv + */ + public function setColumnMapping(array $columns) + { + $this->columns = $columns; + return $this; + } + + /** + * Write HTML file + * + * @access public + * @param string $filename + * @param array $rows + * @return Html + */ + public function write($filename, array $rows) + { + + $fp = fopen($filename, 'w'); + + if (is_resource($fp)) { + $types = array_shift($rows); + + $this->writeHeader($fp); + foreach ($rows as $row) { + $this->writeRow($fp, $types, $row); + } + $this->writeFooter($fp); + fclose($fp); + } + + return $this; + } + + /** + * write a HTML header + * + * @param $fp filepointer + */ + private function writeHeader($fp) + { + fwrite($fp,"\n"); + fwrite($fp,""); + + } + + /** + * write a single row + * + * @param fp filepointer + * @param $row row + */ + private function writeRow($fp, array $types, array $row) + { + fwrite($fp,""); + foreach ($row as $key => $value) { + fwrite($fp,""); + } + fwrite($fp,"\n"); + } + + /** + * write a HTML footer + */ + private function writeFooter($fp) + { + fwrite($fp,"
".$value."
"); + } + + /** + * Associate columns header with row values + * + * @access private + * @param array $row + * @return array + */ + private function associateColumns(array $row) + { + $line = array(); + $index = 0; + + foreach ($this->columns as $sql_name => $csv_name) { + if (isset($row[$index])) { + $line[$sql_name] = $row[$index]; + } else { + $line[$sql_name] = ''; + } + + $index++; + } + + return $line; + } + + /** + * Filter empty rows + * + * @access private + * @param array $row + * @return array + */ + private function filterRow(array $row) + { + return array_filter($row); + } +} -- cgit v1.2.3