forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.class.php
More file actions
309 lines (280 loc) · 9.1 KB
/
View.class.php
File metadata and controls
309 lines (280 loc) · 9.1 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/**
* ブロック表示用クラス
*
* @package NetCommons
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class Blocks_View {
/**
* @var DBオブジェクトを保持
*
* @access private
*/
var $_db = null;
var $_container = null;
/**
* コンストラクター
*
* @access public
*/
function Blocks_View() {
$this->_container =& DIContainerFactory::getContainer();
//DBオブジェクト取得
$this->_db =& $this->_container->getComponent("DbObject");
}
/**
* blockテーブルからblock_objectの配列を取得する
* @param int page_id or array page_id_array
* @param int module_id
* @param function func
* @param array func_param
* @return array
* @access public
*/
function &getBlockByPageId($params, $where_params = null, $func = null, $func_param = null)
{
$sql_where = "";
$count = 0;
if(is_array($params)) {$count = count($params);}
if (!empty($where_params)) {
foreach ($where_params as $key=>$item) {
if (isset($item)) {
$params[$key] = $item;
$sql_where .= " AND ".$key."=?";
} else {
$sql_where .= " AND ".$key;
}
}
}
if($count > 0) {
$sql = "SELECT {blocks}.* FROM {blocks} " .
" WHERE ({blocks}.page_id=?";
for($i = 1; $i < $count; $i++) {
$sql .= " OR {blocks}.page_id=?";
}
$sql .= ")";
$sql .= $sql_where;
$sql .= " ORDER BY {blocks}.page_id, {blocks}.thread_num,{blocks}.col_num,{blocks}.row_num ";
$result = $this->_db->execute($sql, $params, null, null, true, $func, $func_param);
} else {
$id = $params;
$params = array(
"page_id" => $id
);
$sql = "SELECT {blocks}.* FROM {blocks} " .
" WHERE {blocks}.page_id=? ";
$sql .= $sql_where;
$sql .= " ORDER BY {blocks}.page_id, {blocks}.thread_num,{blocks}.col_num,{blocks}.row_num ";
$result = $this->_db->execute($sql, $params, null, null, true, $func, $func_param);
}
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
//if(!isset($result[0])) {
// $result= false;
//}
return $result;
}
/*
function &getBlockByPageId($id)
{
//パラメータセット 引数の配列になければリクエストパラメータの値を使用
//if(is_array($param))
// $id = isset($param['page_id']) ? $param['page_id'] : $param['id'];
//else
// $id = $param;
$session =& $this->_container->getComponent("Session");
$params = array(
"user_id" => $session->getParameter("_user_id"),
"page_id" => $id
);
$result = $this->_db->execute("SELECT {blocks}.*,{location_link}.auth_id,{location_link}.show_flag,{location_link}.left_size,{location_link}.top_size FROM {blocks} " .
" LEFT JOIN {location_link} ON {blocks}.block_id = {location_link}.block_id AND {location_link}.user_id = ?" .
" WHERE {blocks}.page_id=? ORDER BY {blocks}.thread_num,{blocks}.col_num,{blocks}.row_num ",$params);
//$result = $this->_db->execute("SELECT {blocks}.*,{location_link}.auth_id,{location_link}.show_flag,{location_link}.left_size,{location_link}.top_size,{location_link}.thread_num FROM {blocks} " .
// " LEFT JOIN {location_link} ON {blocks}.block_id = {location_link}.block_id AND {location_link}.user_id = ?" .
// " WHERE {blocks}.page_id=? ORDER BY {blocks}.thread_num,{blocks}.col_num,{blocks}.row_num ",$params);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
if(isset($result[0])) {
return $result;
}else{
return false;
}
}
*/
/**
* block_idからblock_objectを取得する
* @param int block_id
* @return object block_object
* @access public
*/
function &getBlockById($id)
{
$params = array(
"block_id" => $id
);
$result = $this->_db->execute("SELECT {blocks}.* FROM {blocks} " .
" WHERE {blocks}.block_id=?",$params,1,0);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result[0];
}
/**
* module_idからblock_objectを取得する
* @param int module_id
* @return object block_object
* @access public
*/
function &getBlockByModuleId($module_id)
{
$params = array(
"module_id" => $module_id
);
$result = $this->_db->execute("SELECT {blocks}.* FROM {blocks} " .
" WHERE {blocks}.module_id=?",$params);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result;
}
/**
* parent_idからblock_object配列を取得する
* @param int parent_id
* @return object block_object
* @access public
*/
function &getBlockByParentId($parent_id, $page_id = null)
{
if($page_id == null) {
$params = array(
"parent_id" => $parent_id
);
$result = $this->_db->execute("SELECT * FROM {blocks} WHERE parent_id=?",$params);
} else {
$params = array(
"parent_id" => $parent_id,
"page_id" => $page_id
);
$result = $this->_db->execute("SELECT * FROM {blocks} WHERE parent_id=? AND page_id=?",$params);
}
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result;
}
/**
* root_idからblock_object配列を取得する
* @param int root_id
* @return object block_object
* @access public
*/
function &getBlockByRootId($root_id, $page_id = null)
{
if($page_id == null) {
$params = array(
"root_id" => $root_id
);
$result = $this->_db->execute("SELECT * FROM {blocks} WHERE root_id=? ORDER BY thread_num",$params);
} else {
$params = array(
"root_id" => $root_id,
"page_id" => $page_id
);
$result = $this->_db->execute("SELECT * FROM {blocks} WHERE root_id=? AND page_id=? ORDER BY thread_num",$params);
}
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result;
}
/**
* col_numの行数の取得
* @param array (key:page_id,parent_id,col_num)
* @return int 指定列の合計行数
* @access public
*/
function &getCountRownumByColnum($params=array())
{
////パラメータセット 引数の配列になければリクエストパラメータの値を使用
//$params = array(
// "page_id" => (isset($param_arr['page_id'])) ? $param_arr['page_id'] : $this->page_id,
// "parent_id" => (isset($param_arr['parent_id'])) ? $param_arr['parent_id'] : $this->parent_id,
// "col_num" => (isset($param_arr['col_num'])) ? $param_arr['col_num'] : $this->col_num
//);
$result = $this->_db->execute("SELECT COUNT(*) FROM {blocks} WHERE page_id=?" .
" AND parent_id=?" .
" AND col_num=?" .
" ",$params,null,null,false);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result[0][0];
}
/**
* parent_idから同じ深さのブロックをカウントする
* @param int parent_id
* @return int count_num
* @access public
*/
function getCountByParentid($parent_id)
{
$params = array(
"parent_id" => $parent_id
);
$result = $this->_db->execute("SELECT COUNT(*) FROM {blocks} WHERE parent_id=?" .
" ",$params,null,null,false);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result[0][0];
}
/*
function &getBlockById($id)
{
//パラメータセット 引数の配列になければリクエストパラメータの値を使用
//if(is_array($param))
// $id = isset($param['block_id']) ? $param['block_id'] : $param['id'];
//else
// $id = $param;
$session =& $this->_container->getComponent("Session");
$params = array(
"user_id" => $session->getParameter("_user_id"),
"block_id" => $id
);
$result = $this->_db->execute("SELECT {blocks}.*,{location_link}.auth_id,{location_link}.show_flag,{location_link}.left_size,{location_link}.top_size,{location_link}.thread_num FROM {blocks} " .
" LEFT JOIN {location_link} ON {blocks}.block_id = {location_link}.block_id AND {location_link}.user_id = ?" .
" WHERE {blocks}.block_id=?",$params);
if($result === false) {
//エラーが発生した場合、エラーリストに追加
$this->_db->addError();
return $result;
}
return $result[0];
}
*/
}
?>