forked from bekos/ColumnListView
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEColumnListView.php
82 lines (65 loc) · 2.14 KB
/
EColumnListView.php
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
<?php
/**
* EColumnListView class file.
*
* @author Tasos Bekos <[email protected]>
* @copyright Copyright © 2012 Tasos Bekos
*/
/**
* EColumnListView represents a list view in multiple columns.
*
* @author Tasos Bekos <[email protected]>
*/
Yii::import('zii.widgets.CListView');
class EColumnListView extends CListView {
/**
*
* @var mixed integer the number of columns
*/
public $columns = 2;
/**
* Renders the item view.
* This is the main entry of the whole view rendering.
*
* This is override function that supports multiple columns
*/
public function renderItems() {
$numColumns = (int) $this->columns; // Number of columns
if ($numColumns < 2) {
parent::renderItems();
return;
}
echo CHtml::openTag($this->itemsTagName, array('class' => $this->itemsCssClass)) . "\n";
$data = $this->dataProvider->getData();
if (($n = count($data)) > 0) {
// Compute column width
$width = 100 / $numColumns;
// Initialize table
echo CHtml::openTag('table') . CHtml::openTag('tr');
$owner = $this->getOwner();
$render = $owner instanceof CController ? 'renderPartial' : 'render';
//$j = 0;
foreach ($data as $i => $item) {
// Open cell
echo CHtml::openTag('td', array('style' => 'width:' . $width . '%; vertical-align:top;'));
$data = $this->viewData;
$data['index'] = $i;
$data['data'] = $item;
$data['widget'] = $this;
$owner->$render($this->itemView, $data);
// Close cell
echo CHtml::closeTag('td');
// Change row
if (($i + 1) % $numColumns == 0) {
echo CHtml::closeTag('tr') . CHtml::openTag('tr');
}
}
// Close table
echo CHtml::closeTag('tr') . CHtml::closeTag('table');
} else {
$this->renderEmptyText();
}
echo CHtml::closeTag($this->itemsTagName);
}
}
?>