Created
November 6, 2012 20:01
-
-
Save mcfdn/4027123 to your computer and use it in GitHub Desktop.
Table View Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author James McFadden <[email protected]> | |
*/ | |
class App_View_Helper_RenderTable extends Zend_View_Helper_Abstract | |
{ | |
/** | |
* Generate and return the table HTML | |
* | |
* @param array $headerDataMap | |
* @param array $data | |
* @return string | |
*/ | |
public function renderTable(array $headerDataMap, array $models) | |
{ | |
$headers = array_keys($headerDataMap); | |
$html = ''; | |
$html .= ' <table> | |
<thead> | |
<tr> | |
'; | |
foreach($headers as $header) { | |
$html .= '<th>' . $header . '</th>'; | |
} | |
$html .= ' </tr> | |
</thead> | |
<tbody> | |
'; | |
foreach($models as $model) { | |
$html .= '<tr>'; | |
foreach($headers as $x => $header) { | |
$classProperty = $headerDataMap[$headers[$x]]; | |
if(is_array($classProperty)) { | |
$tdValue = $classProperty['Static']; | |
if(isset($classProperty['Placeholders'])) { | |
foreach($classProperty['Placeholders'] as $placeholderName => $propertyWanted) { | |
$placeholderValue = $model->{$classProperty}; | |
$tdValue = str_replace('%' . $placeholderName . '%', $placeholderValue, $tdValue); | |
} | |
} | |
} else { | |
$tdValue = $model->{$classProperty}; | |
} | |
$html .= '<td>' . $tdValue . '</td>'; | |
} | |
$html .= '</tr>'; | |
} | |
$html .= ' </tbody> | |
</table>'; | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment