openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

CSVTable.class.php (2083B)


      1 <?php
      2 namespace cms\macros\macro;
      3 // OpenRat Content Management System
      4 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
      5 //
      6 // This program is free software; you can redistribute it and/or
      7 // modify it under the terms of the GNU General Public License
      8 // as published by the Free Software Foundation; either version 2
      9 // of the License, or (at your option) any later version.
     10 //
     11 // This program is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15 //
     16 // You should have received a copy of the GNU General Public License
     17 // along with this program; if not, write to the Free Software
     18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     19 use cms\model\File;
     20 use util\Macro;
     21 
     22 
     23 /**
     24  * Aus einer CSV-Datei wird eine HTML-Tabelle erstellt.
     25  *
     26  * @author Jan Dankert
     27  */
     28 class CSVList extends Macro
     29 {
     30 	/**
     31 	 * Id der Datei, welche die Werte enthält. 
     32 	 * @var unknown_type
     33 	 */
     34 	var $fileid                = 0;
     35 	
     36 	/**
     37 	 * CSS-Klasse der Tabelle.
     38 	 * @var unknown_type
     39 	 */
     40 	var $css_class             = 'table';
     41 	
     42 	/**
     43 	 * Trennzeichen (Default: Komma).
     44 	 * @var unknown_type
     45 	 */
     46 	var $seperator             = ',';
     47 	
     48 	/**
     49 	 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich.
     50 	 * @type String
     51 	 */
     52 	var $description = 'Creates a HTML-table from a CSV-file';
     53 
     54 	
     55 	
     56 	function execute()
     57 	{
     58 		$this->output('<table class="'.$this->css_class.'">');
     59 		
     60 		// Datei lesen
     61 		$file = new File( $this->fileid );
     62 		$values = $file->loadValue();
     63 		
     64 		// In einzelne Zeilen zerlegen.
     65 		$lines = explode("\n",$values);
     66 		
     67 		foreach( $lines as $line )
     68 		{
     69 			$this->output('<tr>');
     70 			
     71 			// In einzelne Spalten zerlegen.
     72 			$columns = explode($seperator,$line);
     73 			foreach( $columns as $column )
     74 			{
     75 				$this->output('<td>' );
     76 				$this->output($column);
     77 				$this->output('</td>');
     78 			}
     79 			$this->output('</tr>');
     80 		}
     81 
     82 		$this->output('</table>');
     83 	}
     84 }
     85 
     86 
     87 ?>