Example #1
0
 /**
  * @todo refactor this thing
  */
 public function tabs($callback, $variant = 'top')
 {
     $tabs = Module::driver('tabs');
     $tabs->apply($callback);
     $list = array();
     foreach ($tabs->titles as $i => $title) {
         $i++;
         $attributes = $i == $tabs->active ? array('class' => 'active') : array();
         $list[] = HTML::element('li', HTML::link('#tab' . $i, $title, array('data-toggle' => 'tab')), $attributes);
     }
     $output = HTML::ul($list, array('class' => 'nav nav-tabs'));
     $contents = '';
     foreach ($tabs->contents as $i => $content) {
         $i++;
         $contents .= HTML::div(Module::render($content), array('id' => 'tab' . $i, 'class' => 'tab-pane' . ($i == $tabs->active ? ' active' : '')));
     }
     $output .= HTML::div($contents, array('class' => 'tab-content'));
     if ($variant !== 'top') {
         return HTML::div($output, array('class' => 'tabbable tab-' . $variant));
     }
     return $output;
 }
Example #2
0
 /**
  * Display the table
  * 
  * // Add the description to the "roles" column 
  * <code>
  * $table->display(array(
  * 		'roles' => function($account)
  * 		{
  * 			$html = '';
  * 			if(isset($account->roles))
  * 			{
  * 				foreach($account->roles as $role)
  * 				{
  * 					$html .= '<b>'.$role->name.'</b><br>'.$role->description;
  * 				}
  *			}
  * 			return $html;
  * 		}
  * ));
  * </code>
  * 
  * @param array $options custom display functions per column
  * @return string
  */
 public function display($options)
 {
     $columns = $this->columns;
     $sortable = $this->sortable;
     $rows = $this->rows;
     if ($rows instanceof Paginator) {
         $rows = $rows->results;
     }
     // Render and return the no_results view when no rows are found
     if (count($rows) === 0) {
         return Module::render($this->no_results);
     }
     // Create the table calls that will be sent off to the default Renderer later
     $display = function ($table) use($options, $columns, $sortable, $rows) {
         $table->thead(function ($table) use($columns, $sortable) {
             foreach ($columns as $column => $title) {
                 if (is_array($title)) {
                     $title = array_key_exists('title', $title) ? $title['title'] : '';
                 }
                 $table->th(in_array($column, $sortable) ? HTML::sort_link('', $column, $title) : $title);
             }
         });
         $table->tbody(function ($table) use($rows, $columns, $options) {
             foreach ($rows as $row) {
                 $table->tr(function ($table) use($row, $columns, $options) {
                     foreach ($columns as $column => $title) {
                         $attributes = array();
                         if (is_array($title)) {
                             extract($title);
                         }
                         $table->td(!empty($column) ? array_key_exists($column, $options) ? call_user_func($options[$column], $row) : $row->{$column} : '', $attributes);
                     }
                 });
             }
         });
     };
     // Render the table with the default Renderer and return the html
     return Module::render($display);
 }