Overview

Namespaces

  • mechanicious
    • Columnizer
    • Extensions
      • Bs3Table
    • Support
    • Tableman
    • TablemanExtension
    • Test
      • Tableman
  • PHP

Classes

  • Bs3Table
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php namespace mechanicious\Extensions\Bs3Table;
 2: 
 3: use mechanicious\TablemanExtension\TablemanExtension;
 4: use mechanicious\TablemanExtension\Config;
 5: use mechanicious\Tableman\Tableman;
 6: use Jacopo\Bootstrap3Table\BootstrapTable;
 7: 
 8: /**
 9:  * Is responsible for creating a HTML Boostrap 3 Table
10:  */
11: class Bs3Table extends TablemanExtension
12: {
13: 
14:   /**
15:    * Creates the table
16:    *     
17:    * @param  Tableman $ref
18:    * @param  Config   $conf
19:    * @config config, headers, extra_classes
20:    * @usage  https://github.com/mechanicious/tableman/wiki/Bs3Table-Extension-Usage
21:    * @return string
22:    */
23:   public function make(Tableman &$ref, Config $conf)
24:   {
25:     $items = $ref->getColumns();
26:     $columnNames = $ref->getColumnHeaders();
27:     $rows = $ref->getRows();
28: 
29:     $table = new BootstrapTable();
30:     $table->setConfig($conf->get('config'));
31:     $table->setHeader($conf->get('header'));
32:     $table->setTableExtraClasses($conf->get('extra_classes'));
33:     $limit = $conf->get('limit');
34: 
35:     array_walk($rows, function($row, $rowIndex) use(&$table, &$columnNames, $limit) {
36:       if( ! is_null($limit) && $rowIndex > $limit) return;
37:       // Flatten I mean from boundary: array('columnName' => 'rowData'), to: array('rowData').
38:       foreach($columnNames as $columnName) // This guy dictates the order of cells
39:       {
40:         $flattenRows = array(); 
41:         foreach($row as $columnHeader => $cell)
42:         {
43:           $mockedRow = array();
44:           if(isset($row[$columnName])) // If this is false then data got somehow mixed up
45:             $mockedRow[] = array($row[$columnName]);
46:         }
47:         $flattenRows[] = $row;
48:       }
49:       $table->addRows(array_flatten($flattenRows));
50:     });
51:     // __toString do the work!
52:     return (string) $table;
53:   }
54: }
API documentation generated by ApiGen 2.8.0