[evolvis-commits] r17548: - Added Table API↵ - Made some minor changes↵ - Tracker index is currently not usable! Dont merge this!

messer at evolvis.org messer at evolvis.org
Mon Sep 12 15:47:34 CEST 2011


Author: messer
Date: 2011-09-12 15:47:34 +0200 (Mon, 12 Sep 2011)
New Revision: 17548

Added:
   branches/evolvis-me/common/include/Cell.class.php
   branches/evolvis-me/common/include/FusionForgeTableRenderer.class.php
   branches/evolvis-me/common/include/IDataProvider.interface.php
   branches/evolvis-me/common/include/ITableRenderer.interface.php
   branches/evolvis-me/common/include/Row.class.php
   branches/evolvis-me/common/include/Table.class.php
   branches/evolvis-me/common/tracker/TrackerDataProvider.class.php
Modified:
   branches/evolvis-me/common/advanced_search/ASToken.class.php
   branches/evolvis-me/www/tracker/browse.php
   branches/evolvis-me/www/tracker/index.php
Log:
- Added Table API
- Made some minor changes
- Tracker index is currently not usable! Dont merge this!

Modified: branches/evolvis-me/common/advanced_search/ASToken.class.php
===================================================================
--- branches/evolvis-me/common/advanced_search/ASToken.class.php	2011-09-12 12:18:06 UTC (rev 17547)
+++ branches/evolvis-me/common/advanced_search/ASToken.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -1,5 +1,5 @@
 <?php
-/**
+/**17489
  * Copyright (c) 2011
  *      Mike Esser <m.esser at tarent.de>
  */

Added: branches/evolvis-me/common/include/Cell.class.php
===================================================================
--- branches/evolvis-me/common/include/Cell.class.php	                        (rev 0)
+++ branches/evolvis-me/common/include/Cell.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,19 @@
+<?php
+/**
+ * This class stores data for one single Cell. It is used by the Row class.
+ * 
+ * Copyright (C) 2011 Mike Esser (tarent GmbH)
+ */
+
+class Cell {
+    protected $data;
+    
+    public function GetData() {
+        return $this->data;
+    }
+    
+    public function SetData($data) {
+        $this->data = $data;
+    }
+}
+?>

Added: branches/evolvis-me/common/include/FusionForgeTableRenderer.class.php
===================================================================
--- branches/evolvis-me/common/include/FusionForgeTableRenderer.class.php	                        (rev 0)
+++ branches/evolvis-me/common/include/FusionForgeTableRenderer.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+require_once 'ITableRenderer.interface.php';
+require_once 'Table.class.php';
+
+class FusionForgeTableRenderer implements ITableRenderer {
+    private static $singleton = null;
+    
+    public static function Instance() {
+        if(self::$singleton === null) {
+            self::$singleton = new FusionForgeTableRenderer();
+        }
+        
+        return self::$singleton;
+    }
+    
+    function __clone() {
+        //Dont allow to clone this object (its only existing once!);
+    }
+    
+    public function Render($table) {
+        $dataProvider = $table->GetDataProvider();
+        $tableClass   = $table->GetTableClass();
+        $tableHeader  = $table->GetTableHeader();
+        
+        $renderResult = "<table class=\"$tableClass\"><tr>";
+        
+        foreach($tableHeader as $curHeader) {
+            $renderResult .= "\n<th>$curHeader</th>";
+        }
+        
+        $renderResult .= "</tr>";
+        
+        //Render the table
+        for($i = 0; $i < $dataProvider->GetNumRows(); $i++) {
+            $curRow = $dataProvider->GetRow($i);
+            
+            $renderResult .= "<tr>\n";
+            
+            for($j = 0; $j < $curRow->GetNumCells(); $j++) {
+                $curCell = $curRow->GetCell($j);
+                echo "rendering Row $i Cell $j<br />";
+                $renderResult .= '<td>'.$curCell->GetData()."</td>\n";
+            }
+            
+            $renderResult .= "</tr>\n";
+        }
+        
+        $renderResult .= '</table>';
+        
+        return $renderResult;
+    }
+}
+?>

Added: branches/evolvis-me/common/include/IDataProvider.interface.php
===================================================================
--- branches/evolvis-me/common/include/IDataProvider.interface.php	                        (rev 0)
+++ branches/evolvis-me/common/include/IDataProvider.interface.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,44 @@
+<?php
+/**
+ * This interface represents a simple data provider. It is responsible
+ * for getting data from any source. If you need data from the Database
+ * that is connected to an object model, implement this interface to retrieve
+ * the data.
+ * 
+ * Copyright (C) 2011 Mike Esser (tarent GmbH)
+ */
+
+require_once 'Row.class.php';
+
+interface IDataProvider {
+    /**
+     * Returns one single Row Object. Returns null if object is not existing.
+     * 
+     * @param int The Row that should be returned starting at 0.
+     */
+    function GetRow($rowIndex);
+    /**
+     * Returns the total number of rows.
+     */
+    function GetNumRows();
+    /**
+     * Fetchs the Data with the current filter. This function should not
+     * display or return any results.
+     * 
+     * @param int Maximum count of rows that should be fetched
+     * @param int Offset on rows.
+     */
+    function Fetch($limit, $offset);
+    /**
+     * Sets a new Filter. Make sure that you use a correct filter for the
+     * given Dataprovider.
+     * 
+     * @param string the filter.
+     */
+    function SetFilter($filter);
+    /**
+     * Returns the current Filter. 
+     */
+    function GetFilter();
+}
+?>

Added: branches/evolvis-me/common/include/ITableRenderer.interface.php
===================================================================
--- branches/evolvis-me/common/include/ITableRenderer.interface.php	                        (rev 0)
+++ branches/evolvis-me/common/include/ITableRenderer.interface.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,18 @@
+<?php
+/**
+ * This interface is used to render a table. Implement it if needed.
+ * 
+ * Copyright (C) 2011 Mike Esser (tarent GmbH)
+ */
+
+/**
+ *
+ * @author messer
+ */
+interface ITableRenderer {
+    static public function Instance();
+    function __clone();
+    function Render($table);
+}
+
+?>

Added: branches/evolvis-me/common/include/Row.class.php
===================================================================
--- branches/evolvis-me/common/include/Row.class.php	                        (rev 0)
+++ branches/evolvis-me/common/include/Row.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,52 @@
+<?php
+/**
+ * This class represents a Data Row. It is used by the IDataProvider Interface
+ * implementations.
+ * 
+ * Copyright (C) 2011 Mike Esser (tarent GmbH)
+ */
+
+require_once 'Cell.class.php';
+
+class Row {
+    
+    protected $cells = array();
+    
+    /**
+     * Returns a single Cell object if it exsits. Otherwise it returns null. 
+     *
+     * @param int $cellIndex the position of the Cell (starts with 0) 
+     */
+    public function GetCell($cellIndex) {
+        if(array_key_exists($cellIndex, $this->cells)){
+            return $this->cells[$cellIndex];
+        }
+        
+        return null;
+    }
+    
+    /**
+     *
+     * @param int $cellIndex the position of the Cell (starts with 0)
+     * @param Cell $newCell the Cell object to replace
+     */
+    public function SetCell($cellIndex, $newCell) {
+        $this->cells[$cellIndex] = $newCell;
+    }
+    
+    /**
+     *
+     * @param Cell $cell the Cell to append 
+     */
+    public function Append($cell) {
+        $this->cells[] = $cell;
+    }
+    
+    /**
+     * Returns the number of cells.
+     */
+    public function GetNumCells() {
+        return count($this->cells);
+    }
+}
+?>

Added: branches/evolvis-me/common/include/Table.class.php
===================================================================
--- branches/evolvis-me/common/include/Table.class.php	                        (rev 0)
+++ branches/evolvis-me/common/include/Table.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,61 @@
+<?php
+/**
+ * This class represents a Table. It gives access to all relevant data.
+ * The Appereance of the Table is defined by the used ITableRendeder.
+ * 
+ * Copyright (C) 2011 Mike Esser (tarent GmbH)
+ */
+
+require_once 'IDataProvider.interface.php';
+require_once 'ITableRenderer.interface.php';
+
+class Table {
+    protected $tableRenderer;
+    protected $dataProvider;
+    protected $tableHeader = array();
+    protected $tableClass;
+    
+    public function Render() {
+        $result = "Error while rendering table. Maybe there is no Data Provider
+                   set?";
+        
+        if(isset($this->dataProvider) && isset($this->tableRenderer)) {
+            $result = $this->tableRenderer->Render($this);
+        }
+        
+        return $result;
+    }
+    
+    public function SetDataProvider($dataProvider) {
+        $this->dataProvider = $dataProvider;
+    }
+    
+    public function GetDataProvider() {
+        return $this->dataProvider;
+    }
+    
+    public function SetTableRenderer(&$tableRenderer) {
+        $this->tableRenderer = $tableRenderer;
+    }
+    
+    public function GetTableRenderer() {
+        return $this->tableRenderer;
+    }
+    
+    public function SetTableHeader($tableHeader) {
+        $this->tableHeader = $tableHeader;
+    } 
+    
+    public function GetTableHeader($columnIndex) {
+        return $this->tableHeader[$columnIndex];
+    }
+    
+    public function SetTableClass($tableClass) {
+        return $this->tableClass = $tableClass;
+    }
+    
+    public function GetTableClass() {
+        return $this->tableClass;
+    }
+}
+?>

Added: branches/evolvis-me/common/tracker/TrackerDataProvider.class.php
===================================================================
--- branches/evolvis-me/common/tracker/TrackerDataProvider.class.php	                        (rev 0)
+++ branches/evolvis-me/common/tracker/TrackerDataProvider.class.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+require_once gfcommon .'include/IDataProvider.interface.php';
+require_once $gfcommon.'tracker/ArtifactFactory.class.php';
+require_once $gfcommon.'tracker/ArtifactQuery.class.php';
+
+class TrackerDataProvider implements IDataProvider {
+     
+    protected $rows = array();
+    protected $filter;
+    
+    /**
+     * Returns one single Row Object. Returns null if object is not existing.
+     * 
+     * @param int The Row that should be returned starting at 0.
+     */
+    function GetRow($rowIndex) {
+        return $this->rows;
+    }
+    /**
+     * Returns the total number of rows.
+     */
+    function GetNumRows() {
+        return count($this->rows);
+    }
+    /**
+     * Fetchs the Data with the current filter. This function should not
+     * display or return any results.
+     * 
+     * @param int Maximum count of rows that should be fetched
+     * @param int Offset on rows.
+     */
+    function Fetch($limit, $offset) {
+        /**
+         * NOTE: This is currently only a workaround. The way the Data is fetched
+         *       should be rewritten in time.
+         *       
+         *       It has to be rewritten when the new Search comes in place!
+         *       Otherwise the new features won't work (AND, OR, Not, etc)
+         */
+        
+    }
+    /**
+     * Sets a new Filter. Make sure that you use a correct filter for the
+     * given Dataprovider.
+     * 
+     * @param string the filter.
+     */
+    function SetFilter($filter) {
+        $this->filter = $filter;
+    }
+    /**
+     * Returns the current Filter. 
+     */
+    function GetFilter() {
+        return $this->filter;
+    }
+}
+
+?>

Modified: branches/evolvis-me/www/tracker/browse.php
===================================================================
--- branches/evolvis-me/www/tracker/browse.php	2011-09-12 12:18:06 UTC (rev 17547)
+++ branches/evolvis-me/www/tracker/browse.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -421,19 +421,11 @@
 $pstart = 0;
 if ($selected_tracker == 0 || $search_all == 1) {
 	$countValue = 0;
-        //$total is not set. So why is this used here? Also pstart stands
-        //for paging start and not for the total amount of items...
 	$pstart = $total;
 	foreach ($artaf_arr as $art_arr) {
 		$countValue += count($art_arr);
 	}
 	$art_cnt = $countValue;
-        //What is the purpose of this ternary operator?
-        //If art_cnt (artifact count => number of artifacts?) is bigger
-        //then $total (which is 0 xD) + $paging a.k.a. $paging then choose
-        //$paging as max value otherwise choose the artifact count. But the max value
-        //is used beneath to indicate the there are displayed pagingstart-max values out of
-        //art_cnt. But max isn't indicating this.
 	$max = ($art_cnt > ($total + $paging)) ? ($total + $paging) : $art_cnt;
 } elseif ($art_cnt) {
 	if ($focus) {

Modified: branches/evolvis-me/www/tracker/index.php
===================================================================
--- branches/evolvis-me/www/tracker/index.php	2011-09-12 12:18:06 UTC (rev 17547)
+++ branches/evolvis-me/www/tracker/index.php	2011-09-12 13:47:34 UTC (rev 17548)
@@ -21,58 +21,126 @@
 require_once $gfwww.'tracker/include/ArtifactHtml.class.php';
 require_once $gfcommon.'tracker/ArtifactCanned.class.php';
 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
+require_once $gfcommon. 'include/Table.class.php';
+require_once $gfcommon. 'include/FusionForgeTableRenderer.class.php';
 
-if (!$sys_use_tracker) {
-	exit_disabled();
+class TestDataProvider implements IDataProvider {
+    protected $rows = array();
+    
+    public function GetRow($rowIndex) {
+        return $this->rows[$rowIndex];
+    }
+    
+    public function GetNumRows() {
+        return count($this->rows);
+    }
+    /**
+     * Fetchs the Data with the current filter. This function should not
+     * display or return any results.
+     * 
+     * @param int Maximum count of rows that should be fetched
+     * @param int Offset on rows.
+     */
+    function Fetch($limit, $offset){
+        $this->rows[] = new Row();
+        $this->rows[] = new Row();
+        $this->rows[] = new Row();
+        
+        $cell0 = new Cell();
+        $cell1 = new Cell();
+        $cell2 = new Cell();
+        $cell3 = new Cell();
+        
+        $cell0->SetData("Test item 01");
+        $this->rows[0]->Append($cell0);
+        $cell1->SetData("Test item 02");
+        $this->rows[0]->Append($cell1);
+        $cell2->SetData("Test item 03");
+        $this->rows[0]->Append($cell2);
+        $cell3->SetData("Test item 04");
+        $this->rows[0]->Append($cell3);  
+    }
+    /**
+     * Sets a new Filter. Make sure that you use a correct filter for the
+     * given Dataprovider.
+     * 
+     * @param string the filter.
+     */
+    function SetFilter($filter) {
+        
+    }
+    /**
+     * Returns the current Filter. 
+     */
+    function GetFilter() {
+        
+    }
 }
 
-$aid = getIntFromRequest('aid');
-$group_id = getIntFromRequest('group_id');
-$atid = getIntFromRequest('atid');
+$dataProvider   = new TestDataProvider();
+$tableRenderer  = FusionForgeTableRenderer::Instance();
+$table          = new Table();
 
-/*
- * BEGIN Important for Evolvis feature request [#608] Dropdown zur Trackerauswahl in Suchmaske
- * https://evolvis.org/tracker/t_follow.php/608
- */
-$selected_tracker = getIntFromRequest('selected_tracker');
-$search_tracker = getIntFromRequest('search_tracker');
-$search_all = getIntFromRequest('search_all');
+$dataProvider->Fetch(0, 0);
 
-$func_ = getStringFromRequest('func');
-if (($search_tracker == 1 || $func_ == 'massupdate') && $selected_tracker != 0) {
-	$atid = getIntFromRequest('selected_tracker');
-}
-/* END */
+$table->SetDataProvider($dataProvider);
+$table->SetTableRenderer($tableRenderer);
+$table->SetTableHeader(array('Header 01', 'Header 02', 'Header 03', 'Header 04'));
+$table->SetTableClass("nothing");
 
-//if the ATID and GID are not provided, but
-//the artifact_id is, then fetch the other vars
-if ($aid && (!$group_id || !$atid)) {
-	$a =& artifact_get_object($aid);
-	if (!$a || !is_object($a) || $a->isError()) {
-		exit_error('Error','Could Not Get Artifact Object');
-	} else {
-		$group_id=$a->ArtifactType->Group->getID();
-		$atid=$a->ArtifactType->getID();
-		$func='detail';
-	}
-}
+echo $table->Render();
 
-if ($group_id && $atid) {
-	include $gfwww.'tracker/tracker.php';
+//if (!$sys_use_tracker) {
+//	exit_disabled();
+//}
+//
+//$aid = getIntFromRequest('aid');
+//$group_id = getIntFromRequest('group_id');
+//$atid = getIntFromRequest('atid');
+//
+///*
+// * BEGIN Important for Evolvis feature request [#608] Dropdown zur Trackerauswahl in Suchmaske
+// * https://evolvis.org/tracker/t_follow.php/608
+// */
+//$selected_tracker = getIntFromRequest('selected_tracker');
+//$search_tracker = getIntFromRequest('search_tracker');
+//$search_all = getIntFromRequest('search_all');
+//
+//$func_ = getStringFromRequest('func');
+//if (($search_tracker == 1 || $func_ == 'massupdate') && $selected_tracker != 0) {
+//	$atid = getIntFromRequest('selected_tracker');
+//}
+///* END */
+//
+////if the ATID and GID are not provided, but
+////the artifact_id is, then fetch the other vars
+//if ($aid && (!$group_id || !$atid)) {
+//	$a =& artifact_get_object($aid);
+//	if (!$a || !is_object($a) || $a->isError()) {
+//		exit_error('Error','Could Not Get Artifact Object');
+//	} else {
+//		$group_id=$a->ArtifactType->Group->getID();
+//		$atid=$a->ArtifactType->getID();
+//		$func='detail';
+//	}
+//}
+//
+//if ($group_id && $atid) {
+//	include $gfwww.'tracker/tracker.php';
+//
+//} elseif ($group_id) {
+//
+//	include $gfwww.'tracker/ind.php';
+//
+//} else {
+//
+//	exit_no_group();
+//
+//}
+//
+//// Local Variables:
+//// mode: php
+//// c-file-style: "bsd"
+//// End:
 
-} elseif ($group_id) {
-
-	include $gfwww.'tracker/ind.php';
-
-} else {
-
-	exit_no_group();
-
-}
-
-// Local Variables:
-// mode: php
-// c-file-style: "bsd"
-// End:
-
 ?>



More information about the evolvis-commits mailing list