Commit aaa8feb0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Rewrite get_feedback function on views to use comment artefacts


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d7272f0b
......@@ -156,6 +156,64 @@ class ArtefactTypeComment extends ArtefactType {
return array('author', 'owner', 'admin');
}
public static function get_comments($limit, $offset, $lastpage, $userid, $canedit,
$viewid=null, $artefactid=null) {
$result = (object) array(
'limit' => $limit,
'offset' => $offset,
'lastpage' => $lastpage,
'view' => $viewid,
'artefact' => $artefactid,
'canedit' => $canedit,
'data' => array(),
);
if (!empty($viewid)) {
$where = 'c.onview = ' . (int) $viewid;
}
else {
$where = 'c.onartefact = ' . (int) $artefactid;
}
if (!$canedit) {
$where .= ' AND (c.private = 0 OR a.author = ' . (int) $userid . ')';
}
$result->count = count_records_sql('
SELECT COUNT(*)
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;
}
$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));
// Todo: get attachment file sizes
if ($files) {
safe_require('artefact', 'file');
foreach ($files as &$file) {
$comments[$file->artefact]->files[] = $file;
}
}
$result->data = array_values($comments);
return $result;
}
public static function build_html(&$data) {
foreach ($data->data as &$item) {
$item->date = format_date(strtotime($item->ctime), 'strftimedatetime');
......
......@@ -2699,6 +2699,32 @@ class View {
);
}
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment