From fc4a61a47dfac73acb88f446533fe8c85333eae4 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Fri, 13 Mar 2009 14:41:04 +0000
Subject: [PATCH] Update to the CollectionTable view helper

---
 library/App/View/Helper/CollectionTable.php | 37 +++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/library/App/View/Helper/CollectionTable.php b/library/App/View/Helper/CollectionTable.php
index 64145794..72d61b2d 100644
--- a/library/App/View/Helper/CollectionTable.php
+++ b/library/App/View/Helper/CollectionTable.php
@@ -1,8 +1,23 @@
 <?php
 class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
 {
-    public function collectionTable(Unl_Model_Collection $collection, array $columns, array $searchUrlParameters = array(), array $rowUrlSpec = array())
+    public function collectionTable(Unl_Model_Collection $collection, 
+                                    array $columns,
+                                    array $searchUrlParameters = null,
+                                    array $rowUrlSpec = null,
+                                    array $formatOptions = null)
     {
+        
+        if (!is_array($searchUrlParameters)) {
+            $searchUrlParameters = array();
+        }
+        if (!is_array($rowUrlSpec)) {
+            $rowUrlSpec = array();
+        }
+        if (!is_array($formatOptions)) {
+            $formatOptions = array();
+        }
+        
         $output = '';
         
         $output .= "<table>\n";
@@ -27,7 +42,7 @@ class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
                 if ($url) {
                     $output .= '<a href="' . $url . '">';
                 }
-                $output .= $row->{'get' . $field}();
+                $output .= $this->_applyFormatting($row->{'get' . $field}(), $formatOptions[$field]);
                 if ($url) {
                     $output .= '</a>';
                 }
@@ -52,4 +67,22 @@ class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
         }
         return call_user_func_array('sprintf', $params);
     }
+    
+    protected function _applyFormatting($data, $options)
+    {
+        if (!is_array($options)) {
+        
+            if (is_array($data)) {
+                $data = implode(', ', $data);
+            }
+            
+            return $data;
+        }
+        
+        if ($options['type'] == 'Zend_Date' && $data instanceof Zend_Date) {
+            $data = $data->toString($options['format']);
+        }
+        
+        return $data;
+    }
 }
\ No newline at end of file
-- 
GitLab