Skip to content

Commit

Permalink
OU wiki participation, word count #1217
Browse files Browse the repository at this point in the history
Developed by Catalyst.
  • Loading branch information
sammarshallou committed Oct 14, 2011
1 parent 2f6889a commit faa93fd
Show file tree
Hide file tree
Showing 40 changed files with 2,848 additions and 342 deletions.
2 changes: 1 addition & 1 deletion annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function newAnnotation(newtext) {
// we need the number of the next form textarea
var annotationcount = document.getElementById('annotationcount');
var annotationnum = parseInt(annotationcount.firstChild.nodeValue) + 1;

//create the new form section
var newfitem = document.createElement('div');
newfitem.id = 'newfitem'+annotationnum;
Expand Down
2 changes: 1 addition & 1 deletion annotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
}

print get_string('advice_annotate', 'ouwiki');
$data = $ouwikioutput->ouwiki_print_page($subwiki, $cm, $pageversion, false, 'annotate');
$data = $ouwikioutput->ouwiki_print_page($subwiki, $cm, $pageversion, false, 'annotate', $ouwiki->enablewordcount);
echo $data[0];
$annotations = $data[1];

Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/backup_ouwiki_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated
$ouwiki = new backup_nested_element('ouwiki', array('id'), array('name', 'subwikis', 'intro', 'editbegin', 'editend', 'annotation' , 'introformat', 'completionedits', 'completionpages'));
$ouwiki = new backup_nested_element('ouwiki', array('id'), array('name', 'subwikis', 'intro', 'editbegin', 'editend', 'annotation' , 'introformat', 'completionedits', 'completionpages', 'enablewordcount'));

$subwikis = new backup_nested_element('subs');

Expand All @@ -49,7 +49,7 @@ protected function define_structure() {

$versions = new backup_nested_element('versions');

$version = new backup_nested_element('version', array('id'), array('xhtml', 'changestart', 'changesize', 'changeprevsize', 'deletedat', 'timecreated', 'userid'));
$version = new backup_nested_element('version', array('id'), array('xhtml', 'changestart', 'changesize', 'changeprevsize', 'deletedat', 'timecreated', 'userid', 'wordcount'));

$annotations = new backup_nested_element('annotations');

Expand Down
91 changes: 70 additions & 21 deletions backup/moodle2/restore_ouwiki_stepslib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -26,33 +25,37 @@
* Structure step to restore one ouwiki activity
*/
class restore_ouwiki_activity_structure_step extends restore_activity_structure_step {

protected function define_structure() {

$paths = array();
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('ouwiki', '/activity/ouwiki');
$paths[] = new restore_path_element('ouwiki_subwiki', '/activity/ouwiki/subs/subwiki');
$paths[] = new restore_path_element('ouwiki_page', '/activity/ouwiki/subs/subwiki/pages/page');
$paths[] = new restore_path_element('ouwiki_version', '/activity/ouwiki/subs/subwiki/pages/page/versions/version');
$paths[] = new restore_path_element('ouwiki_annotation', '/activity/ouwiki/subs/subwiki/pages/page/annotations/annotation');
$paths[] = new restore_path_element('ouwiki_link', '/activity/ouwiki/subs/subwiki/pages/page/versions/version/links/link');

// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}

protected function process_ouwiki($data) {
global $DB;

$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();

$data->editbegin = $this->apply_date_offset($data->editbegin);
$data->editend = $this->apply_date_offset($data->editend);

if (!isset($data->enablewordcount)) {
$data->enablewordcount = 1;
}

// insert the ouwiki record
$newitemid = $DB->insert_record('ouwiki', $data);
// immediately after inserting "activity" record, call this
Expand All @@ -61,29 +64,29 @@ protected function process_ouwiki($data) {

protected function process_ouwiki_subwiki($data) {
global $DB;

$data = (object)$data;
$oldid = $data->id;

$data->wikiid = $this->get_new_parentid('ouwiki');
$data->groupid = $this->get_mappingid('group', $data->groupid);
$data->userid = $this->get_mappingid('user', $data->userid);

// extra cleanup required - if values are 0 then set them to NULL
// extra cleanup required - if values are 0 then set them to null
if ($data->groupid == 0) {
$data->groupid = NULL;
$data->groupid = null;
}
if ($data->userid == 0) {
$data->userid = NULL;
$data->userid = null;
}

$newitemid = $DB->insert_record('ouwiki_subwikis', $data);
$this->set_mapping('ouwiki_subwiki', $oldid, $newitemid);
}

protected function process_ouwiki_page($data) {
global $DB;

$data = (object)$data;
$oldid = $data->id;

Expand All @@ -93,23 +96,29 @@ protected function process_ouwiki_page($data) {

$this->set_mapping('ouwiki_page', $oldid, $newitemid);
}

protected function process_ouwiki_version($data) {
global $DB;
global $DB, $CFG;

$data = (object)$data;
$oldid = $data->id;

$data->pageid = $this->get_new_parentid('ouwiki_page');

if (!isset($data->wordcount)) {
// calculate the wordcount if it doesn't exist
require_once($CFG->dirroot.'/mod/ouwiki/locallib.php');
$wordcount = ouwiki_count_words($data->xhtml);
$data->wordcount = $wordcount;
}

$newitemid = $DB->insert_record('ouwiki_versions', $data);
$this->set_mapping('ouwiki_version', $oldid, $newitemid, true);

// see if this version was the "currentversion" in the old database
$page = $DB->get_record('ouwiki_pages', array('id' => $data->pageid), 'id, currentversionid');

if ($oldid == $page->currentversionid) {
// update the page with the new version id
$page->currentversionid = $newitemid;
$DB->update_record('ouwiki_pages', $page);
}
Expand All @@ -120,7 +129,7 @@ protected function process_ouwiki_link($data) {

$data = (object)$data;
$oldid = $data->id;

$data->fromversionid = $this->get_new_parentid('ouwiki_version');
$data->topageid = $this->get_mappingid('ouwiki_page', $data->topageid);

Expand All @@ -139,14 +148,54 @@ protected function process_ouwiki_annotation($data) {
$newitemid = $DB->insert_record('ouwiki_annotations', $data);

}

protected function after_execute() {
global $DB;

// Add ouwiki related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_ouwiki', 'intro', null);

// Add post related files
$this->add_related_files('mod_ouwiki', 'attachment', 'ouwiki_version');
$this->add_related_files('mod_ouwiki', 'content', 'ouwiki_version');

// update firstversionid
$sql = 'SELECT v.pageid,
(SELECT MIN(id)
FROM {ouwiki_versions} v3
WHERE v3.pageid = p.id AND v3.deletedat IS NULL)
AS firstversionid
FROM {ouwiki_pages} p
JOIN {ouwiki_versions} v ON v.pageid = p.id
GROUP BY v.pageid, p.id ORDER BY v.pageid';
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
foreach ($rs as $entry) {
if (isset($entry->firstversionid)) {
$DB->set_field('ouwiki_pages', 'firstversionid', $entry->firstversionid,
array('id' => $entry->pageid));
}
}
}
$rs->close();

// update previousversionid
$sql = 'SELECT v.id AS versionid,
(SELECT MAX(v2.id)
FROM {ouwiki_versions} v2
WHERE v2.pageid = p.id AND v2.id < v.id)
AS previousversionid
FROM {ouwiki_pages} p
JOIN {ouwiki_versions} v ON v.pageid = p.id';
$rs = $DB->get_recordset_sql($sql);
if ($rs->valid()) {
foreach ($rs as $entry) {
if (isset($entry->previousversionid)) {
$DB->set_field('ouwiki_versions', 'previousversionid',
$entry->previousversionid, array('id' => $entry->versionid));
}
}
}
$rs->close();
}
}
26 changes: 25 additions & 1 deletion db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,29 @@
'coursecreator' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
)
),
'mod/ouwiki:viewparticipation' => array(

'riskbitmask' => 0,

'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
'mod/ouwiki:grade' => array(

'riskbitmask' => 0,

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
);
11 changes: 8 additions & 3 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<FIELD NAME="completionpages" TYPE="int" LENGTH="9" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki should be marked complete once user creates this many new pages of their own." PREVIOUS="editend" NEXT="completionedits"/>
<FIELD NAME="completionedits" TYPE="int" LENGTH="9" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki should be marked complete once user makes this many edits to the wiki." PREVIOUS="completionpages" NEXT="annotation"/>
<FIELD NAME="annotation" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki will use annotations." PREVIOUS="completionedits" NEXT="introformat"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="annotation"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="annotation" NEXT="enablewordcount"/>
<FIELD NAME="enablewordcount" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="introformat" NEXT="grade"/>
<FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="enablewordcount"/>
</FIELDS>
<KEYS>

Expand Down Expand Up @@ -53,7 +55,8 @@
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Title for the page. All pages must have a title except the start page for the wiki which is set NULL." PREVIOUS="subwikiid" NEXT="currentversionid"/>
<FIELD NAME="currentversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the most recent entry in ouwiki_versions. This is the entry that will appear when viewing the page normally. May be null if there are no versions of the page yet." PREVIOUS="title" NEXT="locked"/>

<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Allows the page to be locked. Introduced with the Annotations commenting system to allow page locking while editing annotations." PREVIOUS="currentversionid"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Allows the page to be locked. Introduced with the Annotations commenting system to allow page locking while editing annotations." PREVIOUS="currentversionid" NEXT="firstversionid"/>
<FIELD NAME="firstversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the entry in ouwiki_versions that first related to this page. This is used for participation calculations to help with query load at that point." PREVIOUS="locked" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_pages_fk_currentversionid"/>
Expand All @@ -74,7 +77,9 @@
<FIELD NAME="changeprevsize" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="If a section was edited, the previous size of the section (before editing) in bytes. Otherwise null." PREVIOUS="changesize" NEXT="deletedat"/>

<FIELD NAME="deletedat" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="timestamp when page version was deleted" PREVIOUS="changeprevsize" NEXT="xhtmlformat"/>
<FIELD NAME="xhtmlformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="deletedat"/>
<FIELD NAME="xhtmlformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="deletedat" NEXT="wordcount"/>
<FIELD NAME="wordcount" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="xhtmlformat" NEXT="previousversionid"/>
<FIELD NAME="previousversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the entry in ouwiki_versions of the previous version for the page. This is used for participation calculations to help with query load at that point." PREVIOUS="wordcount" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_versions_fk_pageid"/>
Expand Down
Loading

0 comments on commit faa93fd

Please sign in to comment.