Permalink
Browse files

MDL-25178 glossary - add completionentries rule

  • Loading branch information...
1 parent ab6e797 commit dde5bfbcf7a618236cec1b77a21305c1ea6d763d @stronk7 stronk7 committed with skodak Nov 15, 2010
@@ -27,6 +27,13 @@
$newentry->approved = 1;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
$DB->update_record("glossary_entries", $newentry);
+
+ // Update completion state
+ $completion = new completion_info($course);
+ if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) {
+ $completion->update_state($cm, COMPLETION_COMPLETE, $entry->userid);
+ }
+
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid", $cm->id);
}
@@ -43,7 +43,7 @@ protected function define_structure() {
'allowcomments', 'allowprintview', 'usedynalink', 'defaultapproval',
'globalglossary', 'entbypage', 'editalways', 'rsstype',
'rssarticles', 'assessed', 'assesstimestart', 'assesstimefinish',
- 'scale', 'timecreated', 'timemodified'));
+ 'scale', 'timecreated', 'timemodified', 'completionentries'));
$entries = new backup_nested_element('entries');
View
5 mod/glossary/db/install.xml 100644 → 100755
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/glossary/db" VERSION="20100428" COMMENT="XMLDB file for Moodle mod/glossary"
+<XMLDB PATH="mod/glossary/db" VERSION="20101115" COMMENT="XMLDB file for Moodle mod/glossary"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -31,7 +31,8 @@
<FIELD NAME="assesstimefinish" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="assesstimestart" NEXT="scale"/>
<FIELD NAME="scale" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="assesstimefinish" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="scale" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="completionentries"/>
+ <FIELD NAME="completionentries" TYPE="int" LENGTH="9" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Non zero if a certain number of entries are required to mark this glossary complete for a user." PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -309,6 +309,22 @@ function xmldb_glossary_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2010111500, 'glossary');
}
+
+ if ($oldversion < 2010111501) {
+
+ // Define field completionentries to be added to glossary
+ $table = new xmldb_table('glossary');
+ $field = new xmldb_field('completionentries', XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified');
+
+ // Conditionally launch add field completionentries
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // glossary savepoint reached
+ upgrade_mod_savepoint(true, 2010111501, 'glossary');
+ }
+
return true;
}
@@ -96,6 +96,12 @@
$DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
$DB->delete_records("glossary_entries", array("id"=>$entry->id));
+ // Update completion state
+ $completion = new completion_info($course);
+ if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) {
+ $completion->update_state($cm, COMPLETION_INCOMPLETE, $entry->userid);
+ }
+
//delete glossary entry ratings
require_once($CFG->dirroot.'/rating/lib.php');
$delopt = new stdclass();
@@ -119,6 +119,13 @@
if (empty($entry->id)) {
//new entry
$entry->id = $DB->insert_record('glossary_entries', $entry);
+
+ // Update completion state
+ $completion = new completion_info($course);
+ if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
+ $completion->update_state($cm, COMPLETION_COMPLETE);
+ }
+
add_to_log($course->id, "glossary", "add entry",
"view.php?id=$cm->id&amp;mode=entry&amp;hook=$entry->id", $entry->id, $cm->id);
@@ -79,6 +79,8 @@
$string['comments'] = 'Comments';
$string['commentson'] = 'Comments on';
$string['commentupdated'] = 'The comment has been updated.';
+$string['completionentries'] = 'Student must create entries:';
+$string['completionentriesgroup'] = 'Require entries';
$string['concept'] = 'Concept';
$string['concepts'] = 'Concepts';
$string['configenablerssfeeds'] = 'This switch will enable the possibility of RSS feeds for all glossaries. You will still need to turn feeds on manually in the settings for each glossary.';
View
@@ -24,6 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/rating/lib.php');
+require_once($CFG->libdir . '/completionlib.php');
define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
@@ -2537,6 +2538,7 @@ function glossary_supports($feature) {
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_COMPLETION_HAS_RULES: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
case FEATURE_RATE: return true;
@@ -2546,6 +2548,42 @@ function glossary_supports($feature) {
}
}
+/**
+ * Obtains the automatic completion state for this glossary based on any conditions
+ * in glossary settings.
+ *
+ * @global object
+ * @global object
+ * @param object $course Course
+ * @param object $cm Course-module
+ * @param int $userid User ID
+ * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
+ * @return bool True if completed, false if not. (If no conditions, then return
+ * value depends on comparison type)
+ */
+function glossary_get_completion_state($course,$cm,$userid,$type) {
+ global $CFG, $DB;
+
+ // Get glossary details
+ if (!($glossary=$DB->get_record('glossary',array('id'=>$cm->instance)))) {
+ throw new Exception("Can't find glossary {$cm->instance}");
+ }
+
+ $result=$type; // Default return value
+
+ if ($glossary->completionentries) {
+ $value = $glossary->completionentries <=
+ $DB->count_records('glossary_entries',array('glossaryid'=>$glossary->id, 'userid'=>$userid, 'approved'=>1));
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+
+ return $result;
+}
+
function glossary_extend_navigation($navigation, $course, $module, $cm) {
global $CFG;
$navigation->add(get_string('standardview', 'glossary'), new moodle_url('/mod/glossary/view.php', array('id'=>$cm->id, 'mode'=>'letter')));
@@ -156,6 +156,45 @@ function definition_after_data() {
function data_preprocessing(&$default_values){
parent::data_preprocessing($default_values);
+
+ // Set up the completion checkboxes which aren't part of standard data.
+ // We also make the default value (if you turn on the checkbox) for those
+ // numbers to be 1, this will not apply unless checkbox is ticked.
+ $default_values['completionentriesenabled']=
+ !empty($default_values['completionentries']) ? 1 : 0;
+ if (empty($default_values['completionentries'])) {
+ $default_values['completionentries']=1;
+ }
+ }
+
+ function add_completion_rules() {
+ $mform =& $this->_form;
+
+ $group=array();
+ $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
+ $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
+ $mform->setType('completionentries', PARAM_INT);
+ $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
+ $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
+
+ return array('completionentriesgroup');
+ }
+
+ function completion_rule_enabled($data) {
+ return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
+ }
+
+ function get_data() {
+ $data = parent::get_data();
+ if (!$data) {
+ return false;
+ }
+ // Turn off completion settings if the checkboxes aren't ticked
+ $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
+ if (empty($data->completionentriesenabled) || !$autocompletion) {
+ $data->completionentries = 0;
+ }
+ return $data;
}
}
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2010111500;
+$module->version = 2010111501;
$module->requires = 2010080300; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)

0 comments on commit dde5bfb

Please sign in to comment.