Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Assign feedback plugins

From MoodleDocs

Introduction

This page gives an overview of assignment feedback plugins.

Overview of an assignment feedback plugin

An assignment feedback plugin can do many things including providing feedback to students about a submission. The grading interface for the assignment module provides many hooks that allow plugins to add their own entries and participate in the grading workflow.

History

Assignment feedback plugins were added with the assignment module rewrite for Moodle 2.3.

Template

A good example is the "file" feedback plugin included with core because it uses most of the features of feedback plugins.

File structure

The files for a custom feedback plugin sit under "mod/assign/feedback/<pluginname>". A plugin should not include any custom files outside of it's own plugin folder. Note: The plugin name should be no longer than 13 characters - this is because the database tables for a submission plugin must be prefixed with "assignfeedback_" + pluginname (15 chars + X) and the table names can be no longer than 28 chars (thanks oracle). If a plugin requires multiple database tables, the plugin name will need to be shorter to allow different table names to fit under the 28 character limit. All examples in this document exclude the required copyright and license information from source files for brevity.


version.php

To start with we need to tell Moodle the version information for our new plugin so that it can be installed and upgraded correctly. This information is added to version.php as with any other type of Moodle plugin. The component name must begin with "assignfeedback_" to identify this as a feedback plugin.

See version.php for more information.

defined('MOODLE_INTERNAL') || die();                                                                                                
                                                                                                                                    
$plugin->version   = 2012112900;                                                                                                    
$plugin->requires  = 2012112900;                                                                                                    
$plugin->component = 'assignfeedback_file';

settings.php

The settings file allows us to add custom settings to the system wide configuration page for our plugin.

All feedback settings should be named 'assignfeedback_pluginname/settingname' in order for the setting to be associated with the plugin.

All feedback plugins should include one setting named 'default' to indicate if the plugin should be enabled by default when creating a new assignment.

$settings->add(new admin_setting_configcheckbox('assignfeedback_file/default',                                                      
                   new lang_string('default', 'assignfeedback_file'),                                                               
                   new lang_string('default_help', 'assignfeedback_file'), 0));                                                     
                                                                                                                                    

lang/en/feedback_pluginname.php

The language file for this plugin must have the same name as the component name (e.g. "feedback_file.php"). It should at least define a string for "pluginname". For example:

$string['pluginname'] = 'Awesome feedback';      

db/access.php

This is where any additional capabilities are defined if required. This file can be omitted if there are no capabilities added by the plugin.

See Activity_modules#access.php for more information.

$capabilities = array(
    'assignfeedback/dungeon:master' => array(
        'riskbitmask' => RISK_XSS,
        'captype' => 'write',
        'contextlevel' => CONTEXT_COURSE,
        'archetypes' => array(
            'editingteacher' => CAP_ALLOW,
            'manager' => CAP_ALLOW
        ),
        'clonepermissionsfrom' => 'moodle/course:manageactivities'
    ),
);

db/upgrade.php

This is where any upgrade code is defined.

See Activity_modules#upgrade.php for more infomation.

function xmldb_feedback_file_upgrade($oldversion) {
    global $CFG, $DB, $OUTPUT;

    $dbman = $DB->get_manager();
    if ($oldversion < 2012091800) {
        // Put upgrade code here

        // Savepoint reached.
        upgrade_plugin_savepoint(true, 2012091800, 'assignfeedback', 'file');
    }

    return true;
}

db/install.xml

This is where any database tables required to save this plugins data are defined. File submissions define a table that links to submission and contains a column to record the number of files.

<?xml version="1.0" encoding="UTF-8" ?>                                                                                             
<XMLDB PATH="mod/assign/feedback/file/db" VERSION="20120423" COMMENT="XMLDB file for Moodle mod/assign/feedback/file"               
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                                                           
    xsi:noNamespaceSchemaLocation="../../../../../lib/xmldb/xmldb.xsd"                                                              
>                                                                                                                                   
  <TABLES>                                                                                                                          
    <TABLE NAME="assignfeedback_file" COMMENT="Stores info about the number of files submitted by a grader.">                      
      <FIELDS>                                                                                                                      
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>                                                    
        <FIELD NAME="assignment" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>                               
        <FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>                                    
        <FIELD NAME="numfiles" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The number of files uploaded by a grader."/>
      </FIELDS>                                                                                                                     
      <KEYS>                                                                                                                        
        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Unique id for this feedback value."/>                               
        <KEY NAME="assignment" TYPE="foreign" FIELDS="assignment" REFTABLE="assign" REFFIELDS="id" COMMENT="The assignment instance this feedback relates to."/>
        <KEY NAME="grade" TYPE="foreign" FIELDS="grade" REFTABLE="assign_grades" REFFIELDS="id" COMMENT="The grade instance this feedback relates to."/>
      </KEYS>                                                                                                                       
    </TABLE>                                                                                                                        
  </TABLES>                                                                                                                         
</XMLDB>