tabel-class-v3

Gesponsorde koppelingen

PHP script bestanden

  1. tabel-class-v3

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
    $settings
= array('id'=>'test',
                        'class'=>'test_class',
                        'bgcolor'=>'#fff',
                        'border'=>1,
                        'cellpadding'=>0,
                        'width'=>'100%');
                        
    $oTable = new Table($settings);
    $oTable->setRowClasses('odd','even','derde');
    //$oTable->autoAanvullen = false;
    
    $row = new Row(true);
        $row->addCell(new Cell('Header, Col 1'));
        $row->addCell(new Cell('Header, Col 2'));
    $oTable->addRow($row);
    
    $row = new Row;
        $row->addCell(new Cell('Rij 11 <b>test</b>, Col 1'));
        $row->addCell(new Cell('Rij 11 <b>test</b>, Col 2 en 3',2,false));
    $oTable->addRow($row);
    
    for($i=1;$i<11;$i++){
        $row = new Row;
            $row->addCell(new Cell('Rij '.$i.', Col 1'));
            $row->addCell(new Cell('Rij '.$i.', Col 2'));
            $row->addCell(new Cell('Rij '.$i.', Col 3'));
            $row->addCell(new Cell('Rij '.$i.', Col 4'));
        $oTable->addRow($row);
    }

    
    $row = new Row;
        $row->addCell(new Cell('Rij 11 <b>test</b>, Col 1 en 2',2));
        $row->addCell(new Cell('Rij 11 <b>test</b>, Col 3'));
        $row->addCell(new Cell('Rij 11 <b>test</b>, Col 4'));
    $oTable->addRow($row);
?>


Class:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
    class Table{
        private $settings = array();
        private $cCount = 0;
        private $rows = array();
        private $rowClasses = array();
        
        public $leegWaarde = '&nbsp;';    
        public $autoAanvullen = true;

        public function __construct($set){
            $this->settings = $set;
        }

        
        public function setRowClasses(){
            $args = func_get_args();
            $this->rowClasses = $args;
        }

        
        public function addRow(Row $row) {
            $this->rows[] = $row;
            $this->updateColsCount(count($row->cells));
        }

        
        private function updateColsCount($nr){
            if($nr > $this->cCount){
                $this->cCount = $nr;
            }
        }

        
        public function checkStyles(){
            $valid = array('id','class','bgcolor','border','cellpadding','width');
            $return = '';
            
            foreach($this->settings as $key => $value){
                if(in_array($key, $valid)){
                    $return .= ' '.$key.'="'.$value.'"';
                }
            }

            
            return $return;
        }

        
        public function display(){
            $return = '';
            $return .= '<table'.$this->checkStyles().'>';        
                for($i=0;$i<count($this->rows);$i++){
                    $class = (isset($this->rowClasses)) ? ' class="'.$this->rowClasses[$i%count($this->rowClasses)].'"': '';
                    
                    $return .= '<tr'.$class.'>';
                        $s = 0;
                        for($a = 0;$a < $this->cCount;$a++){
                            if(isset($this->rows[$i]->cells[$a])){
                                $ent = $this->rows[$i]->cells[$a]->htmlenteties;
                                $cont = ((isset($this->rows[$i]->cells[$a]->content)) ? (($ent) ? htmlentities($this->rows[$i]->cells[$a]->content): $this->rows[$i]->cells[$a]->content): $this->leegWaarde);
                                $return .= '<'.(($this->rows[$i]->rHead) ? "th": "td").' colspan="'.$this->rows[$i]->cells[$a]->colspan.'">'.$cont.'<'.(($this->rows[$i]->rHead) ? "/th": "/td").'>';
                                $s += $this->rows[$i]->cells[$a]->colspan;
                            }
elseif(!isset($this->rows[$i]->cells[$a]) && $s<$this->cCount AND $this->autoAanvullen){
                                $return .= '<'.(($this->rows[$i]->rHead) ? "th": "td").'>'.$this->leegWaarde.'<'.(($this->rows[$i]->rHead) ? "/th": "/td").'>';
                                $s++;
                            }
                        }

                    $return .= '<tr/>';
                }

                
            $return .= '</table>';
            return $return;
        }

        
        public function debugGetRows(){
            return print_r($this->rows);
        }
    }

    
    class Row{
        public $cells;    
        
        public function __construct($header = false) {
            $this->rHead = $header;
        }

        
        public function addCell(Cell $cell) {
            $this->cells[] = $cell;
        }

        
        public function debugGetCells(){
            return print_r($this->cells);
        }
    }

    
    class Cell{
        public $colspan;
        public $content;
        public $htmlenteties;
        
        public function __construct($content, $span = 1, $htmlenteties = false) {
            $this->content = $content;
            $this->colspan = $span;
            $this->htmlenteties = $htmlenteties;
        }
    }

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.