CHTMLTable::getTable()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.9197
cc 4
eloc 12
nc 6
nop 0
crap 4
1
<?php
2
namespace Jovis\HTMLTable;
3
4
/** tar resultatet från en databasfråga och placerar ut i en HTML tabell, 
5
* inklusive länkar och hantering av paginering och sortering 
6
*
7
*/
8
9
class CHTMLTable{ 
10
  
11
  private $data;
12
  private $headline;
13
  
14
  //tar emot en headline som enkel array och data som tvådimensionell array
15 1
  public function __construct($headline, $data){
16 1
    $this->data = $data;
17 1
    $this->headline = $headline;
18 1
  }
19
 
20
 /**
21
  * skapar en tabell (sträng) med rubriker från den endimensionella 
22
  * arrayen $headline och innehåll från
23
  * den tvådimensionella arrayen $data array
24
  *
25
  * @return string $html, sträng innehållande en tabell
26
  */
27
   
28 1
  public function getTable(){
29
       
30
    $table = "<div class='dbtable'>
31
      <table class>
32 1
        <tr class='rows'>";
33
        
34 1
   foreach($this->headline as $h) {
35 1
      $table.= "<th>" . $h ."</th>";
36 1
     }
37
   
38 1
   $table .= "</tr>";
39 1
   foreach($this->data as $d){
40 1
     $table .= "<tr>";  
41 1
     foreach ($d as $v) {
42 1
       $table .= "<td>$v</td>";
43 1
     }
44 1
     $table .= "</tr>";
45 1
   }
46 1
   $table .="</table></div>";
47
    
48 1
   return $table;
49
  }
50
}
51