diff --git a/library/App/View/Helper/CollectionTable.php b/library/App/View/Helper/CollectionTable.php index 641457943da524ec4b368b1161d18d512139073a..72d61b2d5aeb29e962c08a4b3a735ea8d810ea21 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