Commit c0244b6d authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1316917: New approach to star rating using bootstrap glyphs



This is a slimmer / stripped down system for doing jquery ratings.

Instead of relying on styling radio buttons it relies on bootstrap
glyphs and a hidden input field.

The code is also controlled by a pieform element

See lib/form/elements/ratings.php for more info about that part

It also has some new settings in the Extensions -> artefact -> comment
config form. They include settign the colour for the star icon, or
using a different icon, eg hearts/thumbs up, and the number of ratings
to show (3 - 12)

behatnotneeded

Change-Id: Ibf529efcb9a665c9f303242ed12d0c7b3dee2356
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit d1bf622a)
parent 247cb6b9
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ $elements['message'] = array(
);
if (get_config_plugin('artefact', 'comment', 'commentratings')) {
    $elements['rating'] = array(
        'type'  => 'radio',
        'type'  => 'ratings',
        'title' => get_string('rating', 'artefact.comment'),
        'options' => array('1' => '', '2' => '', '3' => '', '4' => '', '5' => ''),
        'class' => 'star',
        'defaultvalue' => $comment->get('rating'),
    );
}
+12 −1
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ $string['commentmadepublic'] = "Comment made public";
$string['commentdeletedauthornotification'] = "Your comment on %s was deleted:\n%s";
$string['commentdeletednotificationsubject'] = 'Comment on %s deleted';
$string['commentnotinview'] = 'Comment %d not in page %d';
$string['commentratings'] = 'Enable comment ratings';
$string['commentremoved'] = 'Comment removed';
$string['commentremovedbyauthor'] = 'Comment removed by the author';
$string['commentremovedbyowner'] = 'Comment removed by the owner';
@@ -112,3 +111,15 @@ To see %s online, follow this link:

$string['artefactdefaultpermissions'] = 'Default comment permission';
$string['artefactdefaultpermissionsdescription'] = 'The selected artefact types will have comments enabled on creation. Users can override these settings for individual artefacts.';

// Extension config form
$string['commentratings'] = 'Enable comment ratings';
$string['ratingicons'] = 'Icon to use to display ratings';
$string['ratinglength'] = 'Number of rating choices';
$string['ratingcolour'] = 'Colour';
$string['ratingcolourdesc'] = 'The colour to display the rating choices in. A chosen rating will display the icon in the solid colour, and an unchosen one will display the colour in the icon outline.';
$string['star'] = 'Star';
$string['heart'] = 'Heart';
$string['thumbsup'] = 'Thumbs up';
$string['ok'] = 'Tick';
$string['ratingexample'] = 'Generated example';
+4 −4
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Comment ratings</h3>

<p>Turn this on to enable 5-star ratings on artefacts and pages.</p>

<p>Note that ratings cannot be on their own and require either a comment or
a file attachment.</p>
<p>Turn this on to enable ratings on artefacts and pages.</p>
<p>You can choose a rating scale from 3 to 12 items, the icon, and the icon colour to use. </p>
<p>If you change the number of rating choices, please note that the ratings themselves will not be recalculated to fit that new scale.</p>
<p>Note that ratings cannot be on their own and require either a comment or a file attachment.</p>
+56 −5
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@ require_once('activity.php');
require_once('license.php');

define('MIN_RATING', 1);
define('MAX_RATING', 5);
$maxrating = get_config_plugin('artefact', 'comment', 'ratinglength');
define('MAX_RATING', $maxrating ? $maxrating : 5);

function valid_rating($ratingstr) {
    if (empty($ratingstr)) {
@@ -870,6 +871,10 @@ class ArtefactTypeComment extends ArtefactType {
        $smarty->assign('viewid', $data->view);
        $smarty->assign('baseurl', $data->baseurl);
        $smarty->assign('onview', $onview);
        $icon = get_config_plugin('artefact', 'comment', 'ratingicon');
        $smarty->assign('star', $icon ? $icon : 'star');
        $colour = get_config_plugin('artefact', 'comment', 'ratingcolour');
        $smarty->assign('colour', $colour ? $colour : '#DBB80E');

        $data->tablerows = $smarty->fetch('artefact:comment:commentlist.tpl');

@@ -934,10 +939,8 @@ class ArtefactTypeComment extends ArtefactType {
        );
        if (get_config_plugin('artefact', 'comment', 'commentratings')) {
            $form['elements']['rating'] = array(
                'type'  => 'radio',
                'type'  => 'ratings',
                'title' => get_string('rating', 'artefact.comment'),
                'options' => array('1' => '', '2' => '', '3' => '', '4' => '', '5' => ''),
                'class' => 'star',
            );
        }
        $form['elements']['ispublic'] = array(
@@ -1081,6 +1084,10 @@ class ArtefactTypeComment extends ArtefactType {
    }

    public static function get_config_options() {
        $length = get_config_plugin('artefact', 'comment', 'ratinglength');
        $length = empty($length) ? 5 : $length;
        $colour = get_config_plugin('artefact', 'comment', 'ratingcolour');
        $colour = empty($colour) ? '#DBB80E' : $colour;
        $elements =  array(
            'commentratings' => array(
                'type'  => 'switchbox',
@@ -1088,6 +1095,48 @@ class ArtefactTypeComment extends ArtefactType {
                'defaultvalue' => get_config_plugin('artefact', 'comment', 'commentratings'),
                'help'  => true,
            ),
            'ratingicon' => array(
                'type' => 'select',
                'title' => get_string('ratingicons', 'artefact.comment'),
                'defaultvalue' => get_config_plugin('artefact', 'comment', 'ratingicon'),
                'options' => array(
                    'star' => get_string('star', 'artefact.comment'),
                    'heart' => get_string('heart', 'artefact.comment'),
                    'thumbs-up' => get_string('thumbsup', 'artefact.comment'),
                    'check-circle' => get_string('ok', 'artefact.comment'),
                ),
            ),
            'ratinglength' => array(
                'type' => 'select',
                'title' => get_string('ratinglength', 'artefact.comment'),
                'defaultvalue' => $length,
                'options' => array(
                    '3' => '3',
                    '4' => '4',
                    '5' => '5',
                    '6' => '6',
                    '7' => '7',
                    '8' => '8',
                    '9' => '9',
                    '10' => '10',
                    '11' => '11',
                    '12' => '12',
                ),
            ),
            'ratingcolour' => array(
                'type' => 'color',
                'title' => get_string('ratingcolour', 'artefact.comment'),
                'defaultvalue' => $colour,
                'description' => get_string('ratingcolourdesc', 'artefact.comment'),
            ),
            'ratingexample' => array(
                'type'  => 'ratings',
                'title' => get_string('ratingexample', 'artefact.comment'),
                'readonly' => true,
                'defaultvalue' => ceil($length / 2),
                'iconempty' => true,
                'officon' => 'dummy',
            ),
        );
        return array(
            'name'     => 'commentconfig',
@@ -1098,7 +1147,9 @@ class ArtefactTypeComment extends ArtefactType {
    }

    public static function save_config_options($form, $values) {
        foreach (array('commentratings') as $settingname) {
        $valid = array('commentratings', 'ratingicon', 'ratinglength',
                       'ratingcolour');
        foreach ($valid as $settingname) {
            set_config_plugin('artefact', 'comment', $settingname, $values[$settingname]);
        }
    }

htdocs/js/README.Mahara

deleted100644 → 0
+0 −12
Original line number Diff line number Diff line
jquery.rating.js
=================

Website: http://code.google.com/p/jquery-star-rating-plugin/
Version: 3.14

Changes:

* Added a pager hook for reskining
* Changed name and path of images in theme/raw/style/jquery.rating.css
* Remove the $.browser check for IE8 & older (because jQuery no longer ships it by default, and
  we no longer support IE8.)
 No newline at end of file
Loading