3
* $RCSfile: ShowAllComments.inc,v $
5
* Gallery - a web based photo album viewer and editor
6
* Copyright (C) 2000-2006 Bharat Mediratta
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or (at
11
* your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
24
* @version $Revision: 1.3 $ $Date: 2006/01/10 04:39:11 $
26
* @subpackage UserInterface
27
* @author Johannes Schmittat <Johannes@Schmittat.com>
31
* This view will show all comments stored in the Gallery
34
* @subpackage UserInterface
37
class ShowAllCommentsView extends GalleryView {
40
* @see GalleryView::loadTemplate
42
function loadTemplate(&$template, &$form) {
43
GalleryCoreApi::requireOnce('modules/comment/classes/GalleryCommentHelper.class');
45
list ($ret, $item) = $this->_getItem();
47
return array($ret->wrap(__FILE__, __LINE__), null);
49
$ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'comment.view');
51
return array($ret->wrap(__FILE__, __LINE__), null);
54
list ($ret, $showCount) =
55
GalleryCoreApi::getPluginParameter('module', 'comment', 'comments.show');
57
return array($ret->wrap(__FILE__, __LINE__), null);
59
$page = GalleryUtilities::getRequestVariables('page');
64
list ($ret, $comments, $count) = GalleryCommentHelper::fetchAllComments(
65
$item->getId(), $showCount, ($page - 1) * $showCount, ORDER_DESCENDING);
67
return array($ret->wrap(__FILE__, __LINE__), null);
70
$commenters = $itemIds = $can = $itemData = array();
71
for ($i = 0; $i < count($comments); $i++) {
72
/* Get the commenter ids */
73
$commenters[$comments[$i]->getCommenterId()] = 1;
74
$itemIds[$comments[$i]->getParentId()] = 1;
76
/* Extract the member data */
77
$comments[$i] = (array)$comments[$i];
80
if (!empty($commenters)) {
81
list ($ret, $commentersList) =
82
GalleryCoreApi::loadEntitiesById(array_keys($commenters));
84
return array($ret->wrap(__FILE__, __LINE__), null);
87
foreach ($commentersList as $commenter) {
88
$commenters[$commenter->getId()] = (array)$commenter;
92
if (!empty($itemIds)) {
93
$itemIds = array_keys($itemIds);
94
$ret = GalleryCoreApi::studyPermissions($itemIds);
96
return array($ret->wrap(__FILE__, __LINE__), null);
98
list ($ret, $itemList) = GalleryCoreApi::loadEntitiesById($itemIds);
100
return array($ret->wrap(__FILE__, __LINE__), null);
102
foreach ($itemList as $it) {
103
$items[$it->getId()] = (array)$it;
105
list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($itemIds);
107
return array($ret->wrap(__FILE__, __LINE__), null);
111
foreach ($comments as $comment) {
112
list ($ret, $permissions) = GalleryCoreApi::getPermissions($comment['parentId']);
114
return array($ret->wrap(__FILE__, __LINE__), null);
116
foreach (array('delete' => 'comment.delete',
117
'edit' => 'comment.edit') as $canFlag => $permission) {
118
$can[$comment['id']][$canFlag] = isset($permissions[$permission]);
121
if (!isset($itemData[$comment['parentId']])) {
122
$it = $items[$comment['parentId']];
123
if (isset($thumbnails[$comment['parentId']])) {
124
$it['thumb'] = (array)$thumbnails[$comment['parentId']];
126
$itemData[$comment['parentId']] = $it;
130
$navigator = array('page' => $page, 'pageCount' => ceil($count/$showCount));
132
$navigator['first'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
133
'itemId' => $item->getId(), 'page' => 1));
134
$navigator['back'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
135
'itemId' => $item->getId(), 'page' => $page - 1));
137
if ($page < $navigator['pageCount']) {
138
$navigator['next'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
139
'itemId' => $item->getId(), 'page' => $page + 1));
140
$navigator['last'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
141
'itemId' => $item->getId(), 'page' => $navigator['pageCount']));
144
$template->setVariable('ShowAllComments', array(
145
'comments' => $comments,
146
'commenters' => $commenters,
148
'item' => (array)$item,
149
'itemData' => $itemData,
150
'navigator' => $navigator));
151
$template->style('modules/comment/comment.css');
154
array('body' => 'modules/comment/templates/ShowAllComments.tpl'));
158
* @see GalleryView::getViewDescription()
160
function getViewDescription() {
161
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'comment');
163
return array($ret->wrap(__FILE__, __LINE__), null);
166
return array(null, $module->translate('show comments'));