Commit 6d38e451 authored by Francois Marier's avatar Francois Marier Committed by Richard Mansfield
Browse files

artefact/comment: add basic support for ratings



Ratings from 1 to 5 can now be added to a piece of feedback on
a view or artefact.
Signed-off-by: default avatarFrancois Marier <francois@catalyst.net.nz>
parent 980e3faf
......@@ -23,6 +23,7 @@
<FIELD NAME="private" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" UNSIGNED="true" />
<FIELD NAME="deletedby" TYPE="char" LENGTH="50" NOTNULL="false" />
<FIELD NAME="requestpublic" TYPE="char" LENGTH="50" NOTNULL="false" />
<FIELD NAME="rating" TYPE="int" LENGTH="10" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="artefactpk" TYPE="primary" FIELDS="artefact" />
......
......@@ -29,7 +29,15 @@ defined('INTERNAL') || die();
function xmldb_artefact_comment_upgrade($oldversion=0) {
return true;
}
$success = true;
if ($oldversion < 2011011201) {
$table = new XMLDBTable('artefact_comment_comment');
$field = new XMLDBField('rating');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED);
?>
$success = $success && add_field($table, $field);
}
return $success;
}
......@@ -75,6 +75,11 @@ $form = pieform(array(
'cols' => 80,
'defaultvalue' => $comment->get('description'),
),
'rating' => array(
'type' => 'text',
'title' => get_string('rating', 'artefact.comment'),
'defaultvalue' => $comment->get('rating'),
),
'ispublic' => array(
'type' => 'checkbox',
'title' => get_string('makepublic', 'artefact.comment'),
......@@ -94,6 +99,7 @@ function edit_comment_submit(Pieform $form, $values) {
db_begin();
$comment->set('description', $values['message']);
$comment->set('rating', valid_rating($values['rating']));
$comment->set('private', 1 - (int) $values['ispublic']);
$comment->commit();
......@@ -116,5 +122,3 @@ $smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('strdescription', get_string('editcommentdescription', 'artefact.comment', $maxage));
$smarty->assign('form', $form);
$smarty->display('artefact:comment:edit.tpl');
?>
......@@ -71,6 +71,7 @@ $string['moderatecomments'] = 'Moderate comments';
$string['moderatecommentsdescription'] = 'Comments will remain private until they are approved by you.';
$string['newfeedbacknotificationsubject'] = 'New feedback on %s';
$string['placefeedback'] = 'Place feedback';
$string['rating'] = 'Rating';
$string['reallydeletethiscomment'] = 'Are you sure you want to delete this comment?';
$string['thiscommentisprivate'] = 'This comment is private';
$string['typefeedback'] = 'Feedback';
......
......@@ -28,6 +28,22 @@ defined('INTERNAL') || die();
require_once('activity.php');
define('MIN_RATING', 1);
define('MAX_RATING', 5);
function valid_rating($ratingstr) {
if (empty($ratingstr)) {
return null;
}
$rating = intval($ratingstr);
if ($rating < MIN_RATING) {
return null;
}
return max(MIN_RATING, min(MAX_RATING, $rating));
}
class PluginArtefactComment extends PluginArtefact {
public static function get_artefact_types() {
......@@ -127,6 +143,7 @@ class ArtefactTypeComment extends ArtefactType {
protected $private;
protected $deletedby;
protected $requestpublic;
protected $rating;
public function __construct($id = 0, $data = null) {
parent::__construct($id, $data);
......@@ -158,6 +175,7 @@ class ArtefactTypeComment extends ArtefactType {
'private' => $this->get('private'),
'deletedby' => $this->get('deletedby'),
'requestpublic' => $this->get('requestpublic'),
'rating' => $this->get('rating'),
);
if ($new) {
......@@ -297,7 +315,7 @@ class ArtefactTypeComment extends ArtefactType {
$comments = get_records_sql_assoc('
SELECT
a.id, a.author, a.authorname, a.ctime, a.description,
c.private, c.deletedby, c.requestpublic,
c.private, c.deletedby, c.requestpublic, c.rating,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon
FROM {artefact} a
......@@ -370,7 +388,7 @@ class ArtefactTypeComment extends ArtefactType {
}
public static function build_html(&$data) {
global $USER;
global $USER, $THEME;
$candelete = $data->canedit || $USER->get('admin');
$deletedmessage = array();
foreach (self::deleted_messages() as $k => $v) {
......@@ -452,6 +470,12 @@ class ArtefactTypeComment extends ArtefactType {
);
}
}
if ($item->rating) {
$item->rating = valid_rating($item->rating);
$imageurl = $THEME->get_url("images/rating{$item->rating}.png", false, 'artefact/comment');
$item->ratingimage = '<img src="' . $imageurl . '" title="'. $item->rating . ' / 5">';
}
}
$extradata = array('view' => $data->view);
......@@ -526,6 +550,10 @@ class ArtefactTypeComment extends ArtefactType {
'rows' => 5,
'cols' => 80,
);
$form['elements']['rating'] = array(
'type' => 'text',
'title' => get_string('rating', 'artefact.comment'),
);
$form['elements']['ispublic'] = array(
'type' => 'checkbox',
'title' => get_string('makepublic', 'artefact.comment'),
......@@ -858,6 +886,10 @@ function add_feedback_form_submit(Pieform $form, $values) {
$data->private = (int) !$values['ispublic'];
}
if (isset($values['rating'])) {
$data->rating = valid_rating($values['rating']);
}
$comment = new ArtefactTypeComment(0, $data);
db_begin();
......
......@@ -14,6 +14,7 @@
{if $item->deletedmessage}
<span class="details">{str tag=commentremoved section=artefact.comment}</span>
{else}
{if $item->ratingimage}{$item->ratingimage|safe}{/if}
{$item->description|safe|clean_html}
{if $item->attachmessage}<div class="attachmessage">{$item->attachmessage}</div>{/if}
{/if}
......
......@@ -27,7 +27,5 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010100702;
$config->release = '0.0.1';
?>
$config->version = 2011011201;
$config->release = '0.0.2';
Supports Markdown
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