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

Fix add feedback form to submit comment artefacts (no attachments yet)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 02426bbc
......@@ -32,8 +32,13 @@ $string['Comments'] = 'Comments';
$string['comment'] = 'comment';
$string['comments'] = 'comments';
$string['attachfile'] = "Attach file";
$string['feedbackchangedtoprivate'] = 'Feedback changed to private';
$string['feedbacksubmitted'] = 'Feedback submitted';
$string['makeprivate'] = 'Change to Private';
$string['makepublic'] = 'Make public';
$string['placefeedback'] = 'Place feedback';
$string['placefeedbacknotallowed'] = 'You are not allowed to place feedback on this View';
$string['thisfeedbackispublic'] = 'This feedback is public';
$string['thisfeedbackisprivate'] = 'This feedback is private';
......
......@@ -156,8 +156,7 @@ class ArtefactTypeComment extends ArtefactType {
return array('author', 'owner', 'admin');
}
public static function get_comments($limit, $offset, $lastpage, &$view=null, &$artefact=null) {
public static function get_comments($limit=10, $offset=0, $lastpage=false, &$view=null, &$artefact=null) {
global $USER;
$userid = $USER->get('id');
$viewid = $view->get('id');
......@@ -228,7 +227,7 @@ class ArtefactTypeComment extends ArtefactType {
public static function build_html(&$data) {
foreach ($data->data as &$item) {
$item->date = format_date(strtotime($item->ctime), 'strftimedatetime');
$item->date = format_date(strtotime($item->ctime), 'strftimedatetime');
if (!empty($item->attachments)) {
if ($data->isowner) {
// @todo: move strings to comment artefact
......@@ -251,7 +250,7 @@ class ArtefactTypeComment extends ArtefactType {
}
else if (!$item->private && $data->canedit) {
$item->pubmessage = get_string('thisfeedbackispublic', 'artefact.comment');
$item->makeprivateform = pieform(make_private_form($item->id));
$item->makeprivateform = pieform(self::make_private_form($item->id));
}
}
......@@ -290,22 +289,66 @@ class ArtefactTypeComment extends ArtefactType {
$data->pagination_js = $pagination['javascript'];
}
}
public static function add_comment_form($attachments=false) {
global $USER;
$form = array(
'name' => 'add_feedback_form',
'method' => 'post',
'class' => 'js-hidden',
'plugintype' => 'artefact',
'pluginname' => 'comment',
'jsform' => true,
'autofocus' => false,
'elements' => array(),
'jssuccesscallback' => 'addFeedbackSuccess',
);
if (!$USER->is_logged_in()) {
$form['elements']['authorname'] = array(
'type' => 'text',
'title' => get_string('name'),
'rules' => array(
'required' => true,
),
);
}
$form['elements']['message'] = array(
'type' => 'wysiwyg',
'title' => get_string('message'),
'rows' => 5,
'cols' => 80,
);
$form['elements']['ispublic'] = array(
'type' => 'checkbox',
'title' => get_string('makepublic', 'artefact.comment'),
);
if ($attachments) {
$form['elements']['attachment'] = array(
'type' => 'file',
'title' => get_string('attachfile', 'artefact.comment'),
);
}
$form['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('placefeedback', 'artefact.comment'), get_string('cancel')),
);
return $form;
}
function make_private_form($id) {
return array(
'name' => 'make_private',
'renderer' => 'oneline',
'class' => 'makeprivate',
'elements' => array(
'comment' => array('type' => 'hidden', 'value' => $id),
'submit' => array(
'type' => 'submit',
'name' => 'make_private_submit',
'value' => get_string('makeprivate', 'artefact.comment'),
public static function make_private_form($id) {
return array(
'name' => 'make_private',
'renderer' => 'oneline',
'class' => 'makeprivate',
'elements' => array(
'comment' => array('type' => 'hidden', 'value' => $id),
'submit' => array(
'type' => 'submit',
'name' => 'make_private_submit',
'value' => get_string('makeprivate', 'artefact.comment'),
),
),
),
);
);
}
}
function make_private_submit(Pieform $form, $values) {
......@@ -321,4 +364,121 @@ function make_private_submit(Pieform $form, $values) {
redirect(get_config('wwwroot') . 'view/view.php?id=' . $viewid);
}
function add_feedback_form_validate(Pieform $form, $values) {
global $USER, $view;
if (!$USER->is_logged_in()) {
$token = get_cookie('viewaccess:'.$view->get('id'));
if (!$token || get_view_from_token($token) != $view->get('id')) {
$form->set_error('message', get_string('placefeedbacknotallowed', 'artefact.comment'));
}
}
}
function add_feedback_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
$data = (object) array(
'title' => get_string('Comment', 'artefact.comment'),
'description' => $values['message'],
'private' => 1 - (int) $values['ispublic'],
);
if ($artefact) {
$data->onartefact = $artefact->get('id');
$data->owner = $artefact->get('owner');
$data->group = $artefact->get('group');
$data->institution = $artefact->get('institution');
}
else {
$data->onview = $view->get('id');
$data->owner = $view->get('owner');
$data->group = $view->get('group');
$data->institution = $view->get('institution');
}
if ($author = $USER->get('id')) {
$data->author = $author;
}
else {
$data->authorname = $values['authorname'];
}
db_begin();
$comment = new ArtefactTypeComment(0, $data);
$comment->commit();
if (0&&isset($values['attachment']) && is_array($values['attachment'])) {
require_once(get_config('libroot') . 'group.php');
require_once(get_config('libroot') . 'uploadmanager.php');
safe_require('artefact', 'file');
$groupid = $view->get('submittedgroup');
if (group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
$um = new upload_manager('attachment');
if ($error = $um->preprocess_file()) {
throw new UploadException($error);
}
$owner = $view->get('owner');
$ownerlang = get_user_language($owner);
$folderid = ArtefactTypeFolder::get_folder_id(
get_string_from_language($ownerlang, 'feedbackattachdirname', 'view'),
get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'view'),
null, true, $owner
);
$attachment = (object) array(
'owner' => $owner,
'parent' => $folderid,
'title' => ArtefactTypeFileBase::get_new_file_title($values['attachment']['name'], $folderid, $owner),
'size' => $values['attachment']['size'],
'filetype' => $values['attachment']['type'],
'oldextensin' => $um->original_filename_extension(),
'description' => get_string_from_language(
$ownerlang,
'feedbackonviewbytutorofgroup',
'view',
$view->get('title'),
display_name($USER),
get_field('group', 'name', 'id', $groupid)
),
);
try {
$data->attachment = ArtefactTypeFile::save_uploaded_file('attachment', $attachment);
}
catch (QuotaExceededException $e) {}
}
}
require_once('activity.php');
$data->message = html2text($data->description);
$data->view = $view->get('id');
activity_occurred('feedback', $data);
db_commit();
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
$newlist = ArtefactTypeComment::get_comments(10, 0, true, $view, $artefact);
}
else {
$goto = get_config('wwwroot') . 'view/view.php?id='.$view->get('id');
$newlist = ArtefactTypeComment::get_comments(10, 0, true, $view);
}
$form->reply(PIEFORM_OK, array(
'message' => get_string('feedbacksubmitted', 'artefact.comment'),
'goto' => $goto,
'data' => $newlist,
));
}
function add_feedback_form_cancel_submit(Pieform $form) {
global $view;
$form->reply(PIEFORM_OK, array(
'goto' => '/view/view.php?id=' . $view->get('id'),
));
}
?>
// The list of existing feedback.
function addFeedbackSuccess(form, data) {
alert('s');
addElementClass('add_feedback_form', 'hidden');
paginator.updateResults(data);
$('add_feedback_form_message').value = '';
......
......@@ -106,7 +106,6 @@ $string['addtowatchlist'] = 'Add View to watchlist';
$string['removefromwatchlist'] = 'Remove View from watchlist';
$string['alreadyinwatchlist'] = 'This View is already in your watchlist';
$string['attachedfileaddedtofolder'] = "The attached file %s has been added to your '%s' folder.";
$string['attachfile'] = "Attach file";
$string['complaint'] = 'Complaint';
$string['date'] = 'Date';
$string['feedback'] = 'Feedback';
......@@ -115,12 +114,8 @@ $string['feedbackattachdirdesc'] = 'Files attached to View assessments';
$string['feedbackattachmessage'] = 'The attached file has been added to your %s folder';
$string['feedbackonthisartefactwillbeprivate'] = 'Feedback on this artefact will only be visible to the owner.';
$string['feedbackonviewbytutorofgroup'] = 'Feedback on %s by %s of %s';
$string['feedbacksubmitted'] = 'Feedback submitted';
$string['makepublic'] = 'Make public';
$string['nopublicfeedback'] = 'No public feedback';
$string['notifysiteadministrator'] = 'Notify site administrator';
$string['placefeedback'] = 'Place feedback';
$string['placefeedbacknotallowed'] = 'You are not allowed to place feedback on this View';
$string['print'] = 'Print';
$string['reportobjectionablematerial'] = 'Report objectionable material';
$string['reportsent'] = 'Your report has been sent';
......
......@@ -652,7 +652,8 @@ class ActivityTypeUsermessage extends ActivityType {
class ActivityTypeFeedback extends ActivityType {
protected $view;
protected $artefact;
protected $onview;
protected $onartefact;
private $viewrecord;
private $artefactinstance;
......@@ -660,16 +661,17 @@ class ActivityTypeFeedback extends ActivityType {
/**
* @param array $data Parameters:
* - view (int)
* - artefact (int) (optional)
* - onview (int) (optional)
* - onartefact (int) (optional)
* - message (string)
*/
public function __construct($data, $cron=false) {
parent::__construct($data, $cron);
if (!empty($this->artefact)) { // feedback on artefact
if (!empty($this->onartefact)) { // feedback on artefact
$userid = null;
require_once(get_config('docroot') . 'artefact/lib.php');
$this->artefactinstance = artefact_instance_from_id($this->artefact);
$this->artefactinstance = artefact_instance_from_id($this->onartefact);
if ($this->artefactinstance->feedback_notify_owner()) {
$userid = $this->artefactinstance->get('owner');
}
......@@ -679,12 +681,12 @@ class ActivityTypeFeedback extends ActivityType {
}
}
else { // feedback on view.
if (!$this->viewrecord = get_record('view', 'id', $this->view)) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $this->view));
if (!$this->viewrecord = get_record('view', 'id', $this->onview)) {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $this->onview));
}
$userid = $this->viewrecord->owner;
if (empty($this->url)) {
$this->url = get_config('wwwroot') . 'view/view.php?id=' . $this->view;
$this->url = get_config('wwwroot') . 'view/view.php?id=' . $this->onview;
}
}
if ($userid) {
......@@ -693,7 +695,7 @@ class ActivityTypeFeedback extends ActivityType {
}
public function get_subject($user) {
if (!empty($this->artefact)) { // feedback on artefact
if (!empty($this->onartefact)) { // feedback on artefact
return get_string_from_language($user->lang, 'newfeedbackonartefact', 'activity')
. ' ' . $this->artefactinstance->get('title');
}
......
......@@ -2778,162 +2778,6 @@ function createview_cancel_submit(Pieform $form, $values) {
}
function add_feedback_form($attachments=false) {
global $USER;
$form = array(
'name' => 'add_feedback_form',
'method' => 'post',
'class' => 'js-hidden',
'plugintype' => 'core',
'pluginname' => 'view',
'jsform' => true,
'autofocus' => false,
'elements' => array(),
'jssuccesscallback' => 'addFeedbackSuccess',
);
if (!$USER->is_logged_in()) {
$form['elements']['authorname'] = array(
'type' => 'text',
'title' => get_string('name'),
'rules' => array(
'required' => true,
),
);
}
$form['elements']['message'] = array(
'type' => 'wysiwyg',
'title' => get_string('message'),
'rows' => 5,
'cols' => 80,
);
$form['elements']['ispublic'] = array(
'type' => 'checkbox',
'title' => get_string('makepublic', 'view'),
);
if ($attachments) {
$form['elements']['attachment'] = array(
'type' => 'file',
'title' => get_string('attachfile', 'view'),
);
}
$form['elements']['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('placefeedback', 'view'), get_string('cancel')),
);
return $form;
}
function add_feedback_form_validate(Pieform $form, $values) {
global $USER, $view;
if (!$USER->is_logged_in()) {
$token = get_cookie('viewaccess:'.$view->get('id'));
if (!$token || get_view_from_token($token) != $view->get('id')) {
$form->set_error('message', get_string('placefeedbacknotallowed', 'view'));
}
}
}
function add_feedback_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
$data = new StdClass;
$data->view = $view->get('id');
if ($artefact) {
$data->artefact = $artefact->get('id');
$table = 'artefact_feedback';
}
else {
$table = 'view_feedback';
}
$data->message = $values['message'];
$data->public = (int) $values['ispublic'];
$data->author = $USER->get('id');
if (!$data->author) {
unset($data->author);
$data->authorname = $values['authorname'];
}
$data->ctime = db_format_timestamp(time());
db_begin();
if (isset($values['attachment']) && is_array($values['attachment'])) {
require_once(get_config('libroot') . 'group.php');
require_once(get_config('libroot') . 'uploadmanager.php');
safe_require('artefact', 'file');
$groupid = $view->get('submittedgroup');
if (group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
$um = new upload_manager('attachment');
if ($error = $um->preprocess_file()) {
throw new UploadException($error);
}
$owner = $view->get('owner');
$ownerlang = get_user_language($owner);
$folderid = ArtefactTypeFolder::get_folder_id(
get_string_from_language($ownerlang, 'feedbackattachdirname', 'view'),
get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'view'),
null, true, $owner
);
$attachment = (object) array(
'owner' => $owner,
'parent' => $folderid,
'title' => ArtefactTypeFileBase::get_new_file_title($values['attachment']['name'], $folderid, $owner),
'size' => $values['attachment']['size'],
'filetype' => $values['attachment']['type'],
'oldextensin' => $um->original_filename_extension(),
'description' => get_string_from_language(
$ownerlang,
'feedbackonviewbytutorofgroup',
'view',
$view->get('title'),
display_name($USER),
get_field('group', 'name', 'id', $groupid)
),
);
try {
$data->attachment = ArtefactTypeFile::save_uploaded_file('attachment', $attachment);
}
catch (QuotaExceededException $e) {}
}
}
insert_record($table, $data, 'id', true);
require_once('activity.php');
unset($data->id);
$data->message = html2text($data->message);
activity_occurred('feedback', $data);
db_commit();
$newlist = null;
if ($artefact) {
$goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view='.$view->get('id');
$newlist = $artefact->get_feedback(10, null, $view->get('id'), true);
}
else {
$goto = get_config('wwwroot') . 'view/view.php?id='.$view->get('id');
$newlist = $view->get_feedback(10, null, true);
}
build_feedback_html($newlist);
$form->reply(PIEFORM_OK, array(
'message' => get_string('feedbacksubmitted', 'view'),
'goto' => $goto,
'data' => $newlist,
));
}
function add_feedback_form_cancel_submit(Pieform $form) {
global $view;
$form->reply(PIEFORM_OK, array(
'goto' => '/view/view.php?id=' . $view->get('id'),
));
}
function objection_form() {
$form = array(
'name' => 'objection_form',
......
......@@ -24,10 +24,10 @@
<table id="feedbacktable" class="fullwidth table">
<thead><tr><th>{str tag="Comments" section="artefact.comment"}</th></tr></thead>
<tbody>
{$comments->tablerows}
{$feedback->tablerows}
</tbody>
</table>
{$comments->pagination}
{$feedback->pagination}
<div id="viewmenu">
{include file="view/viewmenu.tpl"}
</div>
......
{if $LOGGEDIN || $anonfeedback}
<a id="add_feedback_link" href="">{str tag=placefeedback section=view}</a> |
<a id="add_feedback_link" href="">{str tag=placefeedback section=artefact.comment}</a> |
{/if}
{if $LOGGEDIN}
<a id="objection_link" href="">{str tag=reportobjectionablematerial section=view}</a> |
......
......@@ -61,6 +61,7 @@ else if ($usertoken) {
else {
$viewid = param_integer('id');
}
$new = param_boolean('new');
if (!can_view_view($viewid, null, $usertoken, $mnettoken)) {
......@@ -135,11 +136,11 @@ function releaseview_submit() {
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
$comments = ArtefactTypeComment::get_comments($limit, $offset, false, $view);
$feedback = 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) {
$addfeedbackform = pieform(add_feedback_form($allowattachments));
$addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($allowattachments));
}
if ($USER->is_logged_in()) {
$objectionform = pieform(objection_form());
......@@ -155,7 +156,7 @@ $stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_confi
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
$smarty = smarty(
array('paginator', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
array('paginator', 'viewmenu', 'artefact/resume/resumeshowhide.js'),
$stylesheets,
array(),
array(
......@@ -167,7 +168,7 @@ $smarty = smarty(
$javascript = <<<EOF
var viewid = {$viewid};
addLoadEvent(function () {
paginator = {$comments->pagination_js}
paginator = {$feedback->pagination_js}
});
EOF;
......@@ -175,7 +176,7 @@ $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('new', $new);
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtype', $viewtype);
$smarty->assign('comments', $comments);
$smarty->assign('feedback', $feedback);
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
......
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