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
1322 lines (1176 loc) · 35.2 KB
/
View.class.php
File metadata and controls
1322 lines (1176 loc) · 35.2 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* 掲示板データ取得コンポーネントクラス
*
* @package NetCommons Components
* @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 Bbs_Components_View
{
/**
* @var DBオブジェクトを保持
*
* @access private
*/
var $_db = null;
/**
* @var Requestオブジェクトを保持
*
* @access private
*/
var $_request = null;
/**
* @var Sessionオブジェクトを保持
*
* @access private
*/
var $_session = null;
/**
* コンストラクター
*
* @access public
*/
function Bbs_Components_View()
{
$container =& DIContainerFactory::getContainer();
$this->_db =& $container->getComponent("DbObject");
$this->_request =& $container->getComponent("Request");
$this->_session =& $container->getComponent("Session");
}
/**
* 掲示板が配置されているブロックデータを取得する
*
* @return string ブロックデータ
* @access public
*/
function &getBlock()
{
$params = array($this->_request->getParameter("bbs_id"));
$sql = "SELECT B.room_id, BL.block_id ".
"FROM {bbs} B ".
"INNER JOIN {bbs_block} BL ".
"ON B.bbs_id = BL.bbs_id ".
"WHERE B.bbs_id = ? ".
"ORDER BY BL.block_id";
$blocks = $this->_db->execute($sql, $params, 1);
if ($blocks === false) {
$this->_db->addError();
return $blocks;
}
return $blocks[0];
}
/**
* 掲示板が存在するか判断する
*
* @return boolean true:存在する、false:存在しない
* @access public
*/
function bbsExists()
{
$params = array(
$this->_request->getParameter("bbs_id"),
$this->_request->getParameter("room_id")
);
$sql = "SELECT bbs_id ".
"FROM {bbs} ".
"WHERE bbs_id = ? ".
"AND room_id = ?";
$bbsIDs = $this->_db->execute($sql, $params);
if ($bbsIDs === false) {
$this->_db->addError();
return $bbsIDs;
}
if (count($bbsIDs) > 0) {
return true;
}
return false;
}
/**
* ルームIDの掲示板件数を取得する
*
* @return string 掲示板件数
* @access public
*/
function getBbsCount()
{
$params["room_id"] = $this->_request->getParameter("room_id");
$count = $this->_db->countExecute("bbs", $params);
return $count;
}
/**
* 在配置されている掲示板IDを取得する
*
* @return string 配置されている掲示板ID
* @access public
*/
function &getCurrentBbsID()
{
$params = array($this->_request->getParameter("block_id"));
$sql = "SELECT bbs_id ".
"FROM {bbs_block} ".
"WHERE block_id = ?";
$bbsIDs = $this->_db->execute($sql, $params);
if ($bbsIDs === false) {
$this->_db->addError();
return $bbsIDs;
}
return $bbsIDs[0]["bbs_id"];
}
/**
* 掲示板一覧データを取得する
*
* @return array 掲示板一覧データ配列
* @access public
*/
function &getBbses()
{
$limit = $this->_request->getParameter("limit");
$offset = $this->_request->getParameter("offset");
$sortColumn = $this->_request->getParameter("sort_col");
if (empty($sortColumn)) {
$sortColumn = "bbs_id";
}
$sortDirection = $this->_request->getParameter("sort_dir");
if (empty($sortDirection)) {
$sortDirection = "DESC";
}
$orderParams[$sortColumn] = $sortDirection;
$params = array($this->_request->getParameter("room_id"));
$sql = "SELECT bbs_id, bbs_name, activity, insert_time, insert_user_id, insert_user_name ".
"FROM {bbs} ".
"WHERE room_id = ? ".
$this->_db->getOrderSQL($orderParams);
$bbses = $this->_db->execute($sql, $params, $limit, $offset);
if ($bbses === false) {
$this->_db->addError();
}
return $bbses;
}
/**
* 掲示板用デフォルトデータを取得する
*
* @return array 掲示板用デフォルトデータ配列
* @access public
*/
function &getDefaultBbs()
{
$container =& DIContainerFactory::getContainer();
$configView =& $container->getComponent("configView");
$moduleID = $this->_request->getParameter("module_id");
$config = $configView->getConfig($moduleID, false);
if ($config === false) {
return $config;
}
$bbs = array(
"activity" => constant($config["activity"]["conf_value"]),
"topic_authority" => constant($config["topic_authority"]["conf_value"]),
"child_flag" => constant($config["child_flag"]["conf_value"]),
"vote_flag" => constant($config["vote_flag"]["conf_value"]),
"new_period" => $config["new_period"]["conf_value"],
"mail_send" => constant($config["mail_send"]["conf_value"]),
"mail_authority" => constant($config["mail_authority"]["conf_value"]),
"display" => constant($config["display"]["conf_value"]),
"expand" => constant($config["expand"]["conf_value"]),
"visible_row" => $config["visible_row"]["conf_value"]
);
return $bbs;
}
/**
* 掲示板データを取得する
*
* @return array 掲示板データ配列
* @access public
*/
function &getBbs()
{
$sql = "SELECT bbs_id, bbs_name, ";
$container =& DIContainerFactory::getContainer();
$actionChain =& $container->getComponent("ActionChain");
$actionName = $actionChain->getCurActionName();
if ($actionName == "bbs_view_edit_entry" ||
$actionName == "bbs_action_edit_entry") {
$sql .= "activity, topic_authority, child_flag, vote_flag, new_period, ".
"mail_send, mail_authority, mail_subject, mail_body ";
} else {
$prefixID = $this->_request->getParameter("prefix_id_name");
if (strpos($prefixID, BBS_PREFIX_REFERENCE) === 0) {
$sql .= _OFF . " AS activity";
} else {
$sql .= "activity";
}
$sql .= ", child_flag, vote_flag, new_period, mail_send, ".
BBS_DISPLAY_TOPIC_VALUE. " AS display ";
}
$params = array($this->_request->getParameter("bbs_id"));
$sql .= "FROM {bbs} ".
"WHERE bbs_id = ?";
$bbses = $this->_db->execute($sql, $params);
if ($bbses === false) {
$this->_db->addError();
return $bbses;
}
$default = $this->getDefaultBbs();
$bbses[0]["expand"] = $default["expand"];
$bbses[0]["visible_row"] = $default["visible_row"];
$bbses[0]["display"] = $default["display"];
return $bbses[0];
}
/**
* 現在配置されている掲示板データを取得する
*
* @return array 配置されている掲示板データ配列
* @access public
*/
function &getCurrentBbs()
{
$params = array($this->_request->getParameter("block_id"));
$sql = "SELECT BL.block_id, BL.bbs_id, BL.display, BL.expand, BL.visible_row, ".
"B.bbs_name, B.activity, B.topic_authority, B.child_flag, B.vote_flag, B.new_period, B.mail_send ".
"FROM {bbs_block} BL ".
"INNER JOIN {bbs} B ".
"ON BL.bbs_id = B.bbs_id ".
"WHERE BL.block_id = ?";
$bbses = $this->_db->execute($sql, $params);
if ($bbses === false) {
$this->_db->addError();
}
if (empty($bbses)) {
return $bbses;
}
$bbses[0]["topic_authority"] = $this->_hasTopicAuthority($bbses[0]);
$bbses[0]["new_period_time"] = $this->_getNewPeriodTime($bbses[0]["new_period"]);
return $bbses[0];
}
/**
* 根記事投稿権限を取得する
*
* @param array $bbs 掲示板状態、表示方法、根記事投稿権限の配列
* @return boolean true:権限有り、false:権限無し
* @access public
*/
function _hasTopicAuthority($bbs)
{
if ($bbs["activity"] != _ON) {
return false;
}
if ($bbs["display"] == BBS_DISPLAY_OLD_VALUE) {
return false;
}
$authID = $this->_session->getParameter("_auth_id");
if ($authID >= $bbs["topic_authority"]) {
return true;
}
return false;
}
/**
* new記号表示期間から対象年月日を取得する
*
* @param string $new_period new記号表示期間
* @return string new記号表示対象年月日(YmdHis)
* @access public
*/
function &_getNewPeriodTime($new_period)
{
if (empty($new_period)) {
$new_period = -1;
}
$time = timezone_date();
$time = mktime(0, 0, 0,
intval(substr($time, 4, 2)),
intval(substr($time, 6, 2)) - $new_period,
intval(substr($time, 0, 4))
);
$time = date("YmdHis", $time);
return $time;
}
/**
* 権限判断用のSQL文FROM句を取得する
*
* @return string 権限判断用のSQL文FROM句
* @access public
*/
function &_getAuthorityFromSQL()
{
$authID = $this->_session->getParameter("_auth_id");
$sql = "";
if ($authID >= _AUTH_CHIEF) {
return $sql;
}
$sql .= "LEFT JOIN {pages_users_link} PU ".
"ON P.insert_user_id = PU.user_id ".
"AND P.room_id = PU.room_id ".
"LEFT JOIN {authorities} A ".
"ON PU.role_authority_id = A.role_authority_id ";
return $sql;
}
/**
* 権限判断用のSQL文WHERE句を取得する
* パラメータ用配列に必要な値を追加する
*
* @param array $params パラメータ用配列
* @return string 権限判断用のSQL文WHERE句
* @access public
*/
function &_getAuthorityWhereSQL(&$params)
{
$authID = $this->_session->getParameter("_auth_id");
$sql = "";
if ($authID >= _AUTH_CHIEF) {
return $sql;
}
$sql .= "AND (P.status = ? OR A.hierarchy < ? OR P.insert_user_id = ?";
$defaultEntry = $this->_session->getParameter("_default_entry_flag");
$hierarchy = $this->_session->getParameter("_hierarchy");
if ($defaultEntry == _ON && $hierarchy > $this->_session->getParameter("_default_entry_hierarchy")) {
$sql .= " OR A.hierarchy IS NULL) ";
} else {
$sql .= ") ";
}
$params[] = BBS_STATUS_RELEASED_VALUE;
$params[] = $hierarchy;
$params[] = $this->_session->getParameter("_user_id");
return $sql;
}
/**
* 根記事の件数を取得する
*
* @return string 根記事の件数
* @access public
*/
function &getTopicCount()
{
$params = array($this->_request->getParameter("bbs_id"));
$sql = "SELECT COUNT(T.topic_id) ".
"FROM {bbs_topic} T ".
"INNER JOIN {bbs_post} P ".
"ON T.topic_id = P.post_id ".
$this->_getAuthorityFromSQL().
"WHERE P.bbs_id = ? ".
$this->_getAuthorityWhereSQL($params);
$counts = $this->_db->execute($sql, $params, null, null, false);
if ($counts === false) {
$this->_db->addError();
return $counts;
}
return $counts[0][0];
}
/**
* 最新根記事IDを取得する
*
* @return string 最新根記事ID
* @access public
*/
function &getNewestTopicID()
{
$params = array(
$this->_request->getParameter("bbs_id"),
BBS_STATUS_RELEASED_VALUE
);
$sql = "SELECT T.topic_id ".
"FROM {bbs_topic} T ".
"INNER JOIN {bbs_post} P ".
"ON T.topic_id = P.post_id ".
"WHERE P.bbs_id = ? ".
"AND P.status = ? ".
"ORDER BY P.insert_time DESC";
$topicIDs = $this->_db->execute($sql, $params, 1, null, false);
if ($topicIDs === false) {
$this->_db->addError();
return $topicIDs;
}
return $topicIDs[0][0];
}
/**
* 根記事データ取得用のSQL文を取得する
*
* @param string $body 本文使用フラグ
* @return string 根記事データ取得用のSQL文
* @access public
*/
function &_getTopicSQL($body = false)
{
$bodySelect = "";
$bodyFrom = "";
if ($body) {
$bodySelect = ", BD.body ";
$bodyFrom = "INNER JOIN {bbs_post_body} BD ".
"ON T.topic_id = BD.post_id ";
}
$userID = $this->_session->getParameter("_user_id");
$readSelect = "";
$readFrom = "";
if (!empty($userID)) {
$readSelect = ",U.read_flag ";
$readFrom = "LEFT JOIN {bbs_user_post} U ".
"ON U.user_id = '". $userID. "' ".
"AND U.post_id = T.topic_id ";
} else {
$readSelect = ",". _ON. " AS read_flag ";
}
$sql = "SELECT T.topic_id, T.newest_time, T.child_num, ".
"P.post_id, P.bbs_id, P.bbs_id, P.parent_id, P.subject, P.icon_name, ".
"P.contained_sign, P.vote_num, P.status, P.insert_time, P.insert_user_id, P.insert_user_name ".
$bodySelect.
$readSelect.
"FROM {bbs_topic} T ".
"INNER JOIN {bbs_post} P ".
"ON T.topic_id = P.post_id ".
$bodyFrom.
$readFrom.
$this->_getAuthorityFromSQL();
return $sql;
}
/**
* スレッド記事配列を生成する
* 親ID、記事IDをKeyとした2次元配列(スレッド記事配列)及び、枝配列を生成する
* 親記事毎に再起処理を行う
* 枝配列についてT字型は兄弟の弟がある場合、L字型はない場合、I字型は親兄弟の弟がある場合、B字型はいない場合
*
* @param array $recordSet 親記事ID、記事IDでソートされているADORecordSet
* @param array $params[0] $parentID:対象の親記事ID
* @param array $params[1] $branches:枝データ配列(記事IDをkeyとした根記事まで辿った枝データ)
* @return array スレッド記事配列
* @access private
*/
function &_makeThreadArray(&$recordSet, &$params)
{
// 初期処理
$parentID = $params[0];
$branches = $params[1];
$parentArray = array();
$pattern = array("/Y/", "/L/");
$replacement = array("I", "B");
// 元になる記事データ配列のループ
while ($post = $recordSet->fields) {
if (!isset($parentID)) {
$parentID = $post["parent_id"];
}
if ($post["parent_id"] == $parentID) {
// === 包含表示データの分割 ===
$post["contained_sign"] = explode("|", $post["contained_sign"]);
// === スレッド記事配列を生成 ===
$parentArray[$parentID][$post["post_id"]] = $post;
// === 枝配列を生成 ===
// 次の記事を取得
$recordSet->MoveNext();
if ($post["parent_id"] == "0") {
// 枝配列無し
$branches[$post["post_id"]] = array();
$parentArray[$parentID][$post["post_id"]]["branches"] = array();
continue;
} else {
// 根記事までの枝配列(先祖)に対してT字型をI字型、L字型をB字型に変換
$tmpBranches = preg_replace($pattern, $replacement, $branches[$post["parent_id"]]);
}
$nextPost = $recordSet->fields;
if ($nextPost && $nextPost["parent_id"] == $parentID) {
// 兄弟の弟がある場合T字型を付加
$branches[$post["post_id"]] = array_merge($tmpBranches, array("Y"));
} else {
// 兄弟の弟がない場合L字型を付加
$branches[$post["post_id"]] = array_merge($tmpBranches, array("L"));
}
$parentArray[$parentID][$post["post_id"]]["branches"] = $branches[$post["post_id"]];
} else {
// === 親記事IDが変わった場合は、変わった親記事IDを元に再帰処理 ===
$tmpParentArray =& call_user_func(array($this, "_makeThreadArray"), $recordSet, array($post["parent_id"], $branches));
if (!empty($tmpParentArray)) {
$parentArray += $tmpParentArray;
}
return $parentArray;
}
}
return $parentArray;
}
/**
* 根記事配列を取得する
*
* @param string $limi 件数
* @param string $offset 取得開始行
* @return array 根記事配列
* @access public
*/
function &getTopic($limit = null, $offset = null)
{
$params = array($this->_request->getParameter("bbs_id"));
$sql = $this->_getTopicSQL().
"WHERE P.bbs_id = ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC";
$parentID = null;
$branches = array();
$result = $this->_db->execute($sql, $params, $limit, $offset, true, array($this, "_makeThreadArray"), array($parentID, $branches));
if ($result === false) {
$this->_db->addError();
}
return $result;
}
/**
* 記事データ取得用のSQL文を取得する
*
* @param string $body 本文使用フラグ
* @return string 記事データ取得用のSQL文
* @access public
*/
function &_getPostSQL($body = false)
{
$bodySelect = "";
$bodyFrom = "";
if ($body) {
$bodySelect = ", BD.body ";
$bodyFrom = "INNER JOIN {bbs_post_body} BD ".
"ON P.post_id = BD.post_id ";
}
$userID = $this->_session->getParameter("_user_id");
$readSelect = "";
$readFrom = "";
if (!empty($userID)) {
$readSelect = ",U.read_flag ";
$readFrom = "LEFT JOIN {bbs_user_post} U ".
"ON U.user_id = '". $userID. "' ".
"AND U.post_id = P.post_id ";
} else {
$readSelect = ",". _ON. " ";
}
$sql = "SELECT P.post_id, P.bbs_id, P.bbs_id, P.topic_id, P.parent_id, P.subject, P.icon_name, ".
"P.contained_sign, P.vote_num, P.status, P.insert_time, P.insert_user_id, P.insert_user_name ".
$bodySelect. $readSelect. ", T.newest_time, T.child_num ".
"FROM {bbs_post} P ".
$bodyFrom.
$readFrom.
"LEFT JOIN {bbs_topic} T ".
"ON P.post_id = T.topic_id ";
return $sql;
}
/**
* スレッド表示用記事配列を取得する
*
* @param string $topicID 根記事ID
* @return array スレッド表示用記事配列
* @access public
*/
function &getThread($topicID)
{
$params = array($topicID);
$sql = $this->_getPostSQL().
$this->_getAuthorityFromSQL().
"WHERE P.topic_id = ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY P.parent_id, P.post_id";
$parentID = null;
$branches = array();
$topics = $this->_db->execute($sql, $params, null, null, true, array($this, "_makeThreadArray"), array($parentID, $branches));
if ($topics === false) {
$this->_db->addError();
}
return $topics;
}
/**
* 過去根記事配列を取得する
*
* @param string $limit 件数
* @param string $offset 取得開始行
* @return array 過去根記事配列
* @access public
*/
function &getOldTopic($limit = null, $offset = null)
{
$params = array(
$this->_request->getParameter("bbs_id"),
$this->getNewestTopicID()
);
$sql = $this->_getTopicSQL().
"WHERE P.bbs_id = ? ".
"AND T.topic_id != ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC";
$parentID = null;
$branches = array();
$topics = $this->_db->execute($sql, $params, $limit, $offset, true, array($this, "_makeThreadArray"), array($parentID, $branches));
if ($topics === false) {
$this->_db->addError();
}
return $topics;
}
/**
* 根記事IDをIN句の値として取得する
*
* @param string $limit 件数
* @param string $offset 取得開始行
* @return string 根記事IDのIN句の値
* @access private
*/
function &_getTopicIDString($limit = null, $offset = null)
{
$params = array($this->_request->getParameter("bbs_id"));
$sql = "SELECT T.topic_id ".
"FROM {bbs_topic} T ".
"INNER JOIN {bbs_post} P ".
"ON T.topic_id = P.post_id ".
$this->_getAuthorityFromSQL().
"WHERE P.bbs_id = ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC";
$topicIDString = $this->_db->execute($sql, $params, $limit, $offset, false, array($this, "_makeImplodeString"));
if (empty($topicIDString)) {
$this->_db->addError();
return false;
}
return $topicIDString;
}
/**
* ADORecordSetの1カラム目を指定文字区切りの文字列にする
*
* @param array $recordSet ADORecordSet
* @param array $glue 区切り文字
* @return array 指定文字区切りの文字列
* @access private
*/
function &_makeImplodeString(&$recordSet, $glue = ",")
{
$string = "";
while ($row = $recordSet->fetchRow()) {
$string .= $row[0]. $glue;
}
if (!empty($glue)) {
$string = substr($string, 0, strlen($glue) * -1);
}
return $string;
}
/**
* 全件記事配列を取得する
*
* @param string $limi 件数
* @param string $offset 取得開始行
* @return array 全件記事配列
* @access public
*/
function &getAll($limit = null, $offset = null)
{
$topicIDString = $this->_getTopicIDString($limit, $offset);
if (empty($topicIDString)) {
return false;
}
$params = array();
$sql = $this->_getPostSQL().
$this->_getAuthorityFromSQL().
"WHERE P.topic_id IN (". $topicIDString. ") ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC, P.parent_id, P.post_id";
$parentID = null;
$branches = array();
$topics = $this->_db->execute($sql, $params, null, null, true, array($this, "_makeThreadArray"), array($parentID, $branches));
if ($topics === false) {
$this->_db->addError();
}
return $topics;
}
/**
* フラット表示用全件記事配列を生成する
* 最新返信日時順の根記事ID毎に、返信日付の降順でソートされた子記事配列を並べ替える
*
* @param array $recordSet 根記事ID、投稿日時降順でソートされているADORecordSet
* @return array フラット表示用全件記事配列
* @access private
*/
function &_makeFlatArray(&$recordSet)
{
$mobile_flag = $this->_session->getParameter("_mobile_flag");
if ($mobile_flag == _ON) {
$container =& DIContainerFactory::getContainer();
$commonMain =& $container->getComponent("commonMain");
$convertHtml =& $commonMain->registerClass(WEBAPP_DIR.'/components/convert/Html.class.php', "Convert_Html", "convertHtml");
}
// === 根記事ID毎にまとめる ===
$topics = array();
while ($row = $recordSet->fetchRow()) {
if ($mobile_flag == _ON) {
$row["body"] = $convertHtml->convertHtmlToText($row["body"]);
}
$topicID = $row["topic_id"];
// === 包含表示データの分割 ===
$row["contained_sign"] = explode("|", $row["contained_sign"]);
$topics[$topicID][] = $row;
}
// === まとめた根記事ID毎のデータをマージ ===
$result = array();
foreach (array_keys($topics) as $topicID) {
$result = array_merge($result, $topics[$topicID]);
}
return $result;
}
/**
* フラット表示用根記事配列を取得する
*
* @param string $limi 件数
* @param string $offset 取得開始行
* @return array フラット表示用根記事配列
* @access public
*/
function &getFlatTopic($limit = null, $offset = null)
{
$params = array($this->_request->getParameter("bbs_id"));
$sql = $this->_getTopicSQL(true).
"WHERE P.bbs_id = ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC";
$posts = $this->_db->execute($sql, $params, $limit, $offset, true, array($this, "_makeFlatArray"));
if ($posts === false) {
$this->_db->addError();
}
return $posts;
}
/**
* フラット表示用記事配列を取得する
*
* @param string $topicID 根記事ID
* @return array フラット表示用記事配列
* @access public
*/
function &getFlat($topicID)
{
$params = array($topicID);
$sql = $this->_getPostSQL(true).
$this->_getAuthorityFromSQL().
"WHERE P.topic_id = ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY T.topic_id DESC, insert_time DESC";
$posts = $this->_db->execute($sql, $params, null, null, true, array($this, "_makeFlatArray"));
if ($posts === false) {
$this->_db->addError();
}
return $posts;
}
/**
* 過去根記事配列を取得する
*
* @param string $limit 件数
* @param string $offset 取得開始行
* @return array 過去根記事配列
* @access public
*/
function &getFlatOldTopic($limit = null, $offset = null)
{
$params = array(
$this->_request->getParameter("bbs_id"),
$this->getNewestTopicID()
);
$sql = $this->_getTopicSQL(true).
"WHERE P.bbs_id = ? ".
"AND T.topic_id != ? ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC";
$posts = $this->_db->execute($sql, $params, $limit, $offset, true, array($this, "_makeFlatArray"));
if ($posts === false) {
$this->_db->addError();
}
return $posts;
}
/**
* フラット表示用全件記事配列を取得する
*
* @param string $limi 件数
* @param string $offset 取得開始行
* @return array フラット表示用全件記事配列
* @access public
*/
function &getFlatAll($limit = null, $offset = null)
{
$topicIDString = $this->_getTopicIDString($limit, $offset);
if (empty($topicIDString)) {
return false;
}
$params = array();
$sql = $this->_getPostSQL(true).
$this->_getAuthorityFromSQL().
"WHERE P.topic_id IN (". $topicIDString. ") ".
$this->_getAuthorityWhereSQL($params).
"ORDER BY newest_time DESC, P.topic_id DESC, insert_time DESC";
$posts = $this->_db->execute($sql, $params, null, null, true, array($this, "_makeFlatArray"));
if ($posts === false) {
$this->_db->addError();
}
return $posts;
}
/**
* 記事が存在するか判断する
*
* @param string $postID 記事ID
* @return boolean true:存在する、false:存在しない
* @access public
*/
function postExists($postID)
{
$params = array(
$this->_request->getParameter("bbs_id"),
$postID
);
$sql = "SELECT post_id ".
"FROM {bbs_post} ".
"WHERE bbs_id = ? ".
"AND post_id = ?";
$postIDs = $this->_db->execute($sql, $params);
if ($postIDs === false) {
$this->_db->addError();
return $postIDs;
}
if (count($postIDs) > 0) {
return true;
}
return false;
}
/**
* 根記事IDを取得する
*
* @param string $postID 記事ID
* @return string 根記事ID
* @access public
*/
function &getTopicID($postID)
{
$params = array($postID);
$sql = "SELECT topic_id ".
"FROM {bbs_post} ".
"WHERE post_id = ?";
$topicIDs = $this->_db->execute($sql, $params, null, null, false);
if ($topicIDs === false) {
$this->_db->addError();
return $topicIDs;
}
return $topicIDs[0][0];
}
/**
* 参照可能な子記事が存在するか判断する
*
* @param string $postID 記事ID
* @return boolean true:存在する、false:存在しない
* @access public
*/
function viewableChildExists($postID)
{
$params = array($postID);
$sql = "SELECT post_id ".
"FROM {bbs_post} P ".
$this->_getAuthorityFromSQL().
"WHERE parent_id = ? ".
$this->_getAuthorityWhereSQL($params);
$postIDs = $this->_db->execute($sql, $params, 1);
if ($postIDs === false) {
$this->_db->addError();
return $postIDs;
}
if (count($postIDs) > 0) {
return true;
}
return false;
}
/**
* 記事内容を取得する
*
* @param string $postID 記事ID
* @return array 記事内容配列
* @access public
*/
function &getPost($postID)
{
$params = array($postID);
$sql = $this->_getPostSQL(true).
$this->_getAuthorityFromSQL().
"WHERE P.post_id = ? ".
$this->_getAuthorityWhereSQL($params);
$posts = $this->_db->execute($sql, $params);
if (empty($posts)) {
$this->_db->addError();
return $posts;
}
$post = $posts[0];
$bbs = $this->getBbs($post["bbs_id"]);
if (empty($bbs)) {
$this->_db->addError();
return $bbs;
}
$post["contained_sign"] = explode("|", $post["contained_sign"]);