BrowseColumns.inc.php
6.35 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/** BrowserColumns
*
* Presentation and render logic for the different columns. Each has two
* major methods:
*
* function renderHeader($sReturnURL)
* function renderData($aDataRow)
*
* renderHeader returns the _content_ of the header row.
* renderData returns the _content_ of the body row.
*/
require_once(KT_LIB_DIR . "/database/dbutil.inc");
class BrowseColumn {
var $label = null;
var $sort_on = false;
var $sort_direction = "asc";
var $name = "-";
function BrowseColumn($sLabel, $sName) {
$this->label = $sLabel;
$this->name = $sName;
}
// FIXME is it _really_ worth using a template here?
function renderHeader($sReturnURL) {
$text = "Abstract: " . $this->label;
$href = $sReturnURL . "&sort_on=" . $this->name . "&sort_order=";
$href .= $this->sort_direction == "asc"? "desc" : "asc" ;
return '<a href="' . $href . '">'.$text.'</a>';
}
function renderData($aDataRow) {
if ($aDataRow["type"] == "folder") {
return $this->name . ": ". print_r($aDataRow["folder"]->getName(), true);
} else {
return $this->name . ": ". print_r($aDataRow["document"]->getName(), true);
}
}
function setSortedOn($bIsSortedOn) { $this->sort_on = $bIsSortedOn; }
function getSortedOn() { return $this->sort_on; }
function setSortDirection($sSortDirection) { $this->sort_direction = $sSortDirection; }
function getSortDirection() { return $this->sort_direction; }
function addToFolderQuery() { return array(null, null, null); }
function addToDocumentQuery() { return array(null, null, null); }
}
class TitleColumn extends BrowseColumn {
// unlike others, this DOESN'T give its name.
function renderHeader($sReturnURL) {
$text = "Title";
$href = $sReturnURL . "&sort_on=" . $this->name . "&sort_order=";
$href .= $this->sort_direction == "asc"? "desc" : "asc" ;
return '<a href="' . $href . '">'.$text.'</a>';
}
// use inline, since its just too heavy to even _think_ about using smarty.
function renderData($aDataRow) {
$outStr = '';
if ($aDataRow["type"] == "folder") {
$outStr .= '<span class="contenttype folder">';
$outStr .= '<a href="?fFolderId='.$aDataRow["folder"]->getId().'">';
$outStr .= $aDataRow["folder"]->getName();
$outStr .= '</a>';
$outStr .= '</span>';
} else {
$outStr .= '<span class="contenttype '.$this->_mimeHelper($aDataRow["document"]->getMimeTypeId()).'">';
$outStr .= '<a href="documentmanagement/view.php?fDocumentId='.$aDataRow["document"]->getId().'" title="'.$aDataRow["document"]->getFilename().'">';
$outStr .= $aDataRow["document"]->getName();
$outStr .= '</a>';
$outStr .= ' (' . $this->prettySize($aDataRow["document"]->getSize()) . ')';
$outStr .= '</span>';
}
return $outStr;
}
function prettySize($size) {
$finalSize = $size;
$label = 'b';
if ($finalSize > 1000) { $label='Kb'; $finalSize = floor($finalSize/1000); }
if ($finalSize > 1000) { $label='Mb'; $finalSize = floor($finalSize/1000); }
return $finalSize . $label;
}
function _mimeHelper($iMimeTypeId) {
// FIXME lazy cache this.
$sQuery = 'SELECT icon_path FROM mime_types WHERE id = ?';
$res = DBUtil::getOneResult(array($sQuery, array($iMimeTypeId)));
if ($res[0] !== null) {
return $res[0];
} else {
return 'unspecified_type';
}
}
}
class DateColumn extends BrowseColumn {
var $field_function;
// $sDocumentFieldFunction is _called_ on the document.
function DateColumn($sLabel, $sName, $sDocumentFieldFunction) {
$this->field_function = $sDocumentFieldFunction;
parent::BrowseColumn($sLabel, $sName);
}
function renderHeader($sReturnURL) {
$text = $this->label;
$href = $sReturnURL . "&sort_on=" . $this->name . "&sort_order=";
$href .= $this->sort_direction == "asc"? "desc" : "asc" ;
return '<a href="' . $href . '">'.$text.'</a>';
}
// use inline, since its just too heavy to even _think_ about using smarty.
function renderData($aDataRow) {
$outStr = '';
if ($aDataRow["type"] == "folder") {
$outStr = ' '; // no-op on folders.
} else {
$fn = $this->field_function;
$dColumnDate = strtotime($aDataRow["document"]->$fn());
// now reformat this into something "pretty"
$outStr = date("d M, Y H\\hi", $dColumnDate);
}
return $outStr;
}
function _mimeHelper($iMimeTypeId) {
// FIXME lazy cache this.
$sQuery = 'SELECT icon_path FROM mime_types WHERE id = ?';
$res = DBUtil::getOneResult(array($sQuery, array($iMimeTypeId)));
if ($res[0] !== null) {
return $res[0];
} else {
return 'unspecified_type';
}
}
}
// use the _name_ parameter + _f_ + id to create a non-clashing checkbox.
class SelectionColumn extends BrowseColumn {
function renderHeader($sReturnURL) {
// FIXME clean up access to oPage.
global $main;
$main->requireJSResource("/resources/js/toggleselect.js");
return '<input type="checkbox" title="toggle all" onactivate="toggleSelectFor('.$this->name.')">';
}
// use inline, since its just too heavy to even _think_ about using smarty.
function renderData($aDataRow) {
$localname = $this->name . '_';
if ($aDataRow["type"] === "folder") { $localname .= "f_". $aDataRow["folderid"]; }
else { $localname .= "d_" . $aDataRow["docid"]; }
return '<input type="checkbox" name="'.$localname.'" onactivate="activateRow(this)">';
}
function _mimeHelper($iMimeTypeId) {
// FIXME lazy cache this.
$sQuery = 'SELECT icon_path FROM mime_types WHERE id = ?';
$res = DBUtil::getOneResult(array($sQuery, array($iMimeTypeId)));
if ($res[0] !== null) {
return $res[0];
} else {
return 'unspecified_type';
}
}
}
?>