Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
a6748eaf
Commit
a6748eaf
authored
Mar 23, 2010
by
Richard Mansfield
Browse files
Display view comments from new db tables
Signed-off-by:
Richard Mansfield
<
richardm@catalyst.net.nz
>
parent
69cdf5a3
Changes
7
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/comment/comments.json.php
0 → 100644
View file @
a6748eaf
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-comment
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define
(
'INTERNAL'
,
1
);
define
(
'PUBLIC'
,
1
);
define
(
'JSON'
,
1
);
require
(
dirname
(
dirname
(
dirname
(
__FILE__
)))
.
'/init.php'
);
require_once
(
get_config
(
'libroot'
)
.
'view.php'
);
require_once
(
get_config
(
'libroot'
)
.
'pieforms/pieform.php'
);
safe_require
(
'artefact'
,
'comment'
);
$extradata
=
json_decode
(
param_variable
(
'extradata'
));
if
(
!
can_view_view
(
$extradata
->
view
))
{
json_reply
(
'local'
,
get_string
(
'noaccesstoview'
,
'view'
));
}
if
(
!
empty
(
$extradata
->
artefact
)
&&
!
artefact_in_view
(
$extradata
->
artefact
,
$extradata
->
view
))
{
json_reply
(
'local'
,
get_string
(
'accessdenied'
,
'error'
));
}
$limit
=
param_integer
(
'limit'
,
10
);
$offset
=
param_integer
(
'offset'
,
0
);
if
(
!
empty
(
$extradata
->
artefact
))
{
$artefact
=
artefact_instance_from_id
(
$extradata
->
artefact
);
// $data = $artefact->get_comments($limit, $offset, $extradata->view);
}
$view
=
new
View
(
$extradata
->
view
);
$data
=
ArtefactTypeComment
::
get_comments
(
$limit
,
$offset
,
false
,
$view
,
$artefact
);
json_reply
(
false
,
array
(
'data'
=>
$data
));
?>
htdocs/artefact/comment/lang/en.utf8/artefact.comment.php
View file @
a6748eaf
...
...
@@ -28,5 +28,6 @@ defined('INTERNAL') || die();
$string
[
'pluginname'
]
=
'Comment'
;
$string
[
'Comment'
]
=
'Comment'
;
$string
[
'Comments'
]
=
'Comments'
;
?>
htdocs/artefact/comment/lib.php
View file @
a6748eaf
...
...
@@ -156,8 +156,21 @@ class ArtefactTypeComment extends ArtefactType {
return
array
(
'author'
,
'owner'
,
'admin'
);
}
public
static
function
get_comments
(
$limit
,
$offset
,
$lastpage
,
$userid
,
$canedit
,
$viewid
=
null
,
$artefactid
=
null
)
{
public
static
function
get_comments
(
$limit
,
$offset
,
$lastpage
,
&
$view
=
null
,
&
$artefact
=
null
)
{
global
$USER
;
$userid
=
$USER
->
get
(
'id'
);
$viewid
=
$view
->
get
(
'id'
);
if
(
!
empty
(
$artefact
))
{
$canedit
=
$USER
->
can_edit_artefact
(
$artefact
);
$isowner
=
$userid
&&
$userid
==
$artefact
->
get
(
'owner'
);
$artefactid
=
$artefact
->
get
(
'id'
);
}
else
{
$canedit
=
$USER
->
can_edit_view
(
$view
);
$isowner
=
$userid
&&
$userid
==
$view
->
get
(
'owner'
);
$artefactid
=
null
;
}
$result
=
(
object
)
array
(
'limit'
=>
$limit
,
...
...
@@ -166,14 +179,15 @@ class ArtefactTypeComment extends ArtefactType {
'view'
=>
$viewid
,
'artefact'
=>
$artefactid
,
'canedit'
=>
$canedit
,
'isowner'
=>
$isowner
,
'data'
=>
array
(),
);
if
(
!
empty
(
$
view
id
))
{
$where
=
'c.on
view = '
.
(
int
)
$view
id
;
if
(
!
empty
(
$
artefact
id
))
{
$where
=
'c.on
artefact = '
.
$artefact
id
;
}
else
{
$where
=
'c.on
artefact = '
.
(
int
)
$artefact
id
;
$where
=
'c.on
view = '
.
$view
id
;
}
if
(
!
$canedit
)
{
$where
.
=
' AND (c.private = 0 OR a.author = '
.
(
int
)
$userid
.
')'
;
...
...
@@ -184,65 +198,80 @@ class ArtefactTypeComment extends ArtefactType {
FROM {artefact} a JOIN {artefact_comment_comment} c ON a.id = c.artefact
WHERE '
.
$where
);
if
(
$result
->
count
<
1
)
{
return
$result
;
}
if
(
$lastpage
)
{
// Ignore $offset and just get the last page of feedback
$offset
=
(
ceil
(
$count
/
$limit
)
-
1
)
*
$limit
;
}
if
(
$result
->
count
>
0
)
{
if
(
$lastpage
)
{
// Ignore $offset and just get the last page of feedback
$offset
=
(
ceil
(
$count
/
$limit
)
-
1
)
*
$limit
;
}
$comments
=
get_records_sql_assoc
(
'
SELECT
a.id, a.author, a.authorname, a.ctime, a.description, c.private, c.deletedby
FROM {artefact} a JOIN {artefact_comment_comment} c ON a.id = c.artefact
WHERE '
.
$where
.
'
ORDER BY a.ctime'
,
array
(),
$offset
,
$limit
);
$comments
=
get_records_sql_assoc
(
'
SELECT
a.id, a.author, a.authorname, a.ctime, a.description, c.private, c.deletedby
FROM {artefact} a JOIN {artefact_comment_comment} c ON a.id = c.artefact
WHERE '
.
$where
.
'
ORDER BY a.ctime'
,
array
(),
$offset
,
$limit
);
$files
=
ArtefactType
::
attachments_from_id_list
(
array_keys
(
$comments
));
$files
=
ArtefactType
::
attachments_from_id_list
(
array_keys
(
$comments
));
if
(
$files
)
{
safe_require
(
'artefact'
,
'file'
);
foreach
(
$files
as
&
$file
)
{
$comments
[
$file
->
artefact
]
->
files
[]
=
$file
;
if
(
$files
)
{
safe_require
(
'artefact'
,
'file'
);
foreach
(
$files
as
&
$file
)
{
$comments
[
$file
->
artefact
]
->
attachments
[]
=
$file
;
}
}
}
$result
->
data
=
array_values
(
$comments
);
$result
->
data
=
array_values
(
$comments
);
}
self
::
build_html
(
$result
);
return
$result
;
}
public
static
function
build_html
(
&
$data
)
{
foreach
(
$data
->
data
as
&
$item
)
{
$item
->
date
=
format_date
(
strtotime
(
$item
->
ctime
),
'strftimedatetime'
);
$item
->
message
=
clean_html
(
$item
->
message
);
$item
->
name
=
$item
->
author
?
display_name
(
$item
->
author
)
:
$item
->
authorname
;
// @todo: Multiple attachments
if
(
!
empty
(
$item
->
attachment
))
{
$item
->
attachid
=
$item
->
attachment
;
$item
->
attachtitle
=
$item
->
title
;
$item
->
attachsize
=
display_size
(
$item
->
size
);
if
(
!
empty
(
$item
->
attachments
))
{
if
(
$data
->
isowner
)
{
$item
->
attachmessage
=
get_string
(
'feedbackattachmessage'
,
'view'
,
get_string
(
'feedbackattachdirname'
,
'view'
));
// @todo: move strings to comment artefact
// @todo: files attached to comments are no longer always 'assessment' files,
// so change the string.
$item
->
attachmessage
=
get_string
(
'feedbackattachmessage'
,
'view'
,
get_string
(
'feedbackattachdirname'
,
'view'
)
);
}
foreach
(
$item
->
attachments
as
&
$a
)
{
$a
->
attachid
=
$a
->
attachment
;
$a
->
attachtitle
=
$a
->
title
;
$a
->
attachsize
=
display_size
(
$a
->
size
);
}
}
if
(
$item
->
private
)
{
$item
->
pubmessage
=
get_string
(
'thisfeedbackisprivate'
,
'view'
);
}
else
if
(
!
$item
->
private
&&
$data
->
canedit
)
{
$item
->
pubmessage
=
get_string
(
'thisfeedbackispublic'
,
'view'
);
$item
->
makeprivateform
=
pieform
(
make_private_form
(
$item
->
id
));
}
}
$extradata
=
array
(
'view'
=>
$data
->
view
);
$data
->
jsonscript
=
'artefact/comment/comments.json.php'
;
if
(
!
empty
(
$data
->
artefact
))
{
$data
->
baseurl
=
get_config
(
'wwwroot'
)
.
'view/artefact.php?view='
.
$data
->
view
.
'&artefact='
.
$data
->
artefact
;
$data
->
jsonscript
=
'view/artefactfeedback.json.php'
;
$extradata
[
'artefact'
]
=
$data
->
artefact
;
}
else
{
$data
->
baseurl
=
get_config
(
'wwwroot'
)
.
'view/view.php?id='
.
$data
->
view
;
$data
->
jsonscript
=
'view/viewfeedback.json.php'
;
}
$smarty
=
smarty_core
();
$smarty
->
assign_by_ref
(
'data'
,
$data
->
data
);
$smarty
->
assign
(
'canedit'
,
$data
->
canedit
);
$smarty
->
assign
(
'baseurl'
,
$data
->
baseurl
);
$data
->
tablerows
=
$smarty
->
fetch
(
'
view/feedback
list.tpl'
);
$data
->
tablerows
=
$smarty
->
fetch
(
'
artefact:comment:comment
list.tpl'
);
$pagination
=
build_pagination
(
array
(
'id'
=>
'feedback_pagination'
,
'class'
=>
'center'
,
...
...
@@ -263,4 +292,32 @@ class ArtefactTypeComment extends ArtefactType {
}
function
make_private_form
(
$feedbackid
)
{
return
array
(
'name'
=>
'make_private'
,
'renderer'
=>
'oneline'
,
'class'
=>
'makeprivate'
,
'elements'
=>
array
(
'feedback'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$feedbackid
),
'submit'
=>
array
(
'type'
=>
'submit'
,
'name'
=>
'make_private_submit'
,
'value'
=>
get_string
(
'makeprivate'
,
'view'
),
),
),
);
}
function
make_private_submit
(
Pieform
$form
,
$values
)
{
global
$SESSION
,
$view
,
$artefact
;
if
(
isset
(
$artefact
)
&&
$artefact
instanceof
ArtefactType
)
{
update_record
(
'artefact_feedback'
,
(
object
)
array
(
'public'
=>
0
,
'id'
=>
(
int
)
$values
[
'feedback'
]));
$SESSION
->
add_ok_msg
(
get_string
(
'feedbackchangedtoprivate'
,
'view'
));
redirect
(
get_config
(
'wwwroot'
)
.
'view/artefact.php?view='
.
$view
->
get
(
'id'
)
.
'&artefact='
.
$artefact
->
get
(
'id'
));
}
update_record
(
'view_feedback'
,
(
object
)
array
(
'public'
=>
0
,
'id'
=>
(
int
)
$values
[
'feedback'
]));
$SESSION
->
add_ok_msg
(
get_string
(
'feedbackchangedtoprivate'
,
'view'
));
redirect
(
get_config
(
'wwwroot'
)
.
'view/view.php?id='
.
$view
->
get
(
'id'
));
}
?>
htdocs/artefact/comment/theme/raw/commentlist.tpl
View file @
a6748eaf
{
foreach
from
=
$data
item
=
item
}
<tr
class=
"
{
cycle
name
=
rows
values
=
'r0,r1'
}
"
>
<td>
{
include
file
=
"comment.tpl"
comment
=
$item
}
{
$item
->
description
|
clean_html
}
{
if
$item
->
attachmessage
}
<div>
{
$item
->
attachmessage
}
</div>
{/
if
}
<div
class=
"details"
>
{
if
$item
->
author
}
<div
class=
"icon"
><a
href=
"
{
$WWWROOT
}
user/view.php?id=
{
$item
->
author
|
escape
}
"
>
<img
src=
"
{
$WWWROOT
}
thumb.php?type=profileicon&id=
{
$item
->
author
|
escape
}
&maxsize=20"
valign=
"middle"
alt=
"
{
$item
->
author
|
display_name
}
"
>
</a></div>
<a
href=
"
{
$WWWROOT
}
user/view.php?id=
{
$item
->
author
|
escape
}
"
>
{
$item
->
author
|
display_name
}
</a>
{
else
}
{
$item
->
authorname
|
escape
}
{/
if
}
|
{
$item
->
date
|
escape
}
{
if
$item
->
pubmessage
}
|
{
$item
->
pubmessage
|
escape
}{
if
$item
->
makeprivateform
}{
$item
->
makeprivateform
}{/
if
}
{/
if
}
{
foreach
$item
->
attachments
item
=
a
}
|
{
str
tag
=
attachment
section
=
view
}
:
<a
href=
"
{
$WWWROOT
}
artefact/file/download.php?file=
{
$a
->
attachid
}
"
>
{
$a
->
attachtitle
|
escape
}
</a>
(
{
$a
->
attachsize
|
escape
}
)
{/
foreach
}
</div>
</td>
</tr>
{/
foreach
}
htdocs/lib/view.php
View file @
a6748eaf
...
...
@@ -2656,75 +2656,6 @@ class View {
return
false
;
}
public
function
get_feedback
(
$limit
=
10
,
$offset
=
0
,
$lastpage
=
false
)
{
global
$USER
;
$userid
=
$USER
->
get
(
'id'
);
$viewid
=
$this
->
id
;
$canedit
=
$USER
->
can_edit_view
(
$this
);
$count
=
count_records_sql
(
'
SELECT COUNT(*)
FROM {view_feedback}
WHERE view = '
.
$viewid
.
(
!
$canedit
?
' AND (public = 1 OR author = '
.
$userid
.
')'
:
''
));
if
(
$lastpage
)
{
// Ignore $offset and just get the last page of feedback
$offset
=
(
ceil
(
$count
/
$limit
)
-
1
)
*
$limit
;
}
$feedback
=
get_records_sql_array
(
'
SELECT
f.id, f.author, f.authorname, f.ctime, f.message, f.public, f.attachment, a.title, af.size
FROM {view_feedback} f
LEFT OUTER JOIN {artefact} a ON f.attachment = a.id
LEFT OUTER JOIN {artefact_file_files} af ON af.artefact = a.id
WHERE view = '
.
$viewid
.
(
!
$canedit
?
' AND (f.public = 1 OR f.author = '
.
$userid
.
')'
:
''
)
.
'
ORDER BY id'
,
''
,
$offset
,
$limit
);
if
(
$feedback
)
{
foreach
(
$feedback
as
&
$f
)
{
if
(
$f
->
public
&&
$canedit
)
{
$f
->
pubmessage
=
get_string
(
'thisfeedbackispublic'
,
'view'
);
$f
->
makeprivateform
=
pieform
(
make_private_form
(
$f
->
id
));
}
else
if
(
!
$f
->
public
)
{
$f
->
pubmessage
=
get_string
(
'thisfeedbackisprivate'
,
'view'
);
}
}
}
return
(
object
)
array
(
'count'
=>
$count
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'lastpage'
=>
$lastpage
,
'data'
=>
$feedback
?
$feedback
:
array
(),
'view'
=>
$viewid
,
'canedit'
=>
$canedit
,
'isowner'
=>
$userid
&&
$userid
==
$this
->
get
(
'owner'
),
);
}
public
function
get_comments
(
$limit
=
10
,
$offset
=
0
,
$lastpage
=
false
)
{
global
$USER
;
$userid
=
$USER
->
get
(
'id'
);
$viewid
=
$this
->
id
;
$canedit
=
$USER
->
can_edit_view
(
$this
);
safe_require
(
'artefact'
,
'comment'
);
$result
=
ArtefactTypeComment
::
get_comments
(
$limit
,
$offset
,
$lastpage
,
$userid
,
$canedit
,
$viewid
);
if
(
$result
->
data
)
{
foreach
(
$result
->
data
as
&
$f
)
{
if
(
$f
->
private
)
{
$f
->
pubmessage
=
get_string
(
'thisfeedbackisprivate'
,
'view'
);
}
else
if
(
!
$f
->
private
&&
$canedit
)
{
$f
->
pubmessage
=
get_string
(
'thisfeedbackispublic'
,
'view'
);
$f
->
makeprivateform
=
pieform
(
make_private_form
(
$f
->
id
));
}
}
}
$result
->
isowner
=
$userid
&&
$userid
==
$this
->
get
(
'owner'
);
return
$result
;
}
public
function
display_title
(
$long
=
true
,
$titlelink
=
true
)
{
if
(
$this
->
type
==
'profile'
)
{
$title
=
display_name
(
$this
->
owner
,
null
,
true
);
...
...
@@ -3003,34 +2934,6 @@ function add_feedback_form_cancel_submit(Pieform $form) {
));
}
function
make_private_form
(
$feedbackid
)
{
return
array
(
'name'
=>
'make_private'
,
'renderer'
=>
'oneline'
,
'class'
=>
'makeprivate'
,
'elements'
=>
array
(
'feedback'
=>
array
(
'type'
=>
'hidden'
,
'value'
=>
$feedbackid
),
'submit'
=>
array
(
'type'
=>
'submit'
,
'name'
=>
'make_private_submit'
,
'value'
=>
get_string
(
'makeprivate'
,
'view'
),
),
),
);
}
function
make_private_submit
(
Pieform
$form
,
$values
)
{
global
$SESSION
,
$view
,
$artefact
;
if
(
isset
(
$artefact
)
&&
$artefact
instanceof
ArtefactType
)
{
update_record
(
'artefact_feedback'
,
(
object
)
array
(
'public'
=>
0
,
'id'
=>
(
int
)
$values
[
'feedback'
]));
$SESSION
->
add_ok_msg
(
get_string
(
'feedbackchangedtoprivate'
,
'view'
));
redirect
(
get_config
(
'wwwroot'
)
.
'view/artefact.php?view='
.
$view
->
get
(
'id'
)
.
'&artefact='
.
$artefact
->
get
(
'id'
));
}
update_record
(
'view_feedback'
,
(
object
)
array
(
'public'
=>
0
,
'id'
=>
(
int
)
$values
[
'feedback'
]));
$SESSION
->
add_ok_msg
(
get_string
(
'feedbackchangedtoprivate'
,
'view'
));
redirect
(
get_config
(
'wwwroot'
)
.
'view/view.php?id='
.
$view
->
get
(
'id'
));
}
function
objection_form
()
{
$form
=
array
(
'name'
=>
'objection_form'
,
...
...
htdocs/theme/raw/templates/view/view.tpl
View file @
a6748eaf
...
...
@@ -22,12 +22,12 @@
{
if
$tags
}
<div
class=
"tags"
>
{
str
tag
=
tags
}
:
{
list_tags
owner
=
$owner
tags
=
$tags
}
</div>
{/
if
}
<div>
{
$releaseform
}
</div>
<table
id=
"feedbacktable"
class=
"fullwidth table"
>
<thead><tr><th>
{
str
tag
=
"
feedback
"
section
=
"
view
"
}
</th></tr></thead>
<thead><tr><th>
{
str
tag
=
"
Comments
"
section
=
"
artefact.comment
"
}
</th></tr></thead>
<tbody>
{
$
feedback
->
tablerows
}
{
$
comments
->
tablerows
}
</tbody>
</table>
{
$
feedback
->
pagination
}
{
$
comments
->
pagination
}
<div
id=
"viewmenu"
>
{
include
file
=
"view/viewmenu.tpl"
}
</div>
...
...
htdocs/view/view.php
View file @
a6748eaf
...
...
@@ -134,8 +134,8 @@ function releaseview_submit() {
$viewbeingwatched
=
(
int
)
record_exists
(
'usr_watchlist_view'
,
'usr'
,
$USER
->
get
(
'id'
),
'view'
,
$viewid
);
$feedback
=
$view
->
get_feedback
(
$limit
,
$offset
);
build_feedback_html
(
$feedback
);
safe_require
(
'artefact'
,
'comment'
);
$comments
=
ArtefactTypeComment
::
get_comments
(
$limit
,
$offset
,
false
,
$view
);
$anonfeedback
=
!
$USER
->
is_logged_in
()
&&
(
$usertoken
||
$viewid
==
get_view_from_token
(
get_cookie
(
'viewaccess:'
.
$viewid
)));
if
(
$USER
->
is_logged_in
()
||
$anonfeedback
)
{
...
...
@@ -167,7 +167,7 @@ $smarty = smarty(
$javascript
=
<<<EOF
var viewid = {$viewid};
addLoadEvent(function () {
paginator = {$
feedback
->pagination_js}
paginator = {$
comments
->pagination_js}
});
EOF;
...
...
@@ -175,7 +175,7 @@ $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty
->
assign
(
'new'
,
$new
);
$smarty
->
assign
(
'viewid'
,
$viewid
);
$smarty
->
assign
(
'viewtype'
,
$viewtype
);
$smarty
->
assign
(
'
feedback'
,
$feedback
);
$smarty
->
assign
(
'
comments'
,
$comments
);
$smarty
->
assign
(
'owner'
,
$owner
);
$smarty
->
assign
(
'tags'
,
$view
->
get
(
'tags'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment