Skip to content

Commit 65d9614

Browse files
author
cusen_01
committed
Initial commit
0 parents  commit 65d9614

32 files changed

+5157
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
moodle-mod_ratingallocate
2+
============================
3+
Module which lets you add an activity to courses, in which users can rate choices. You may then distribute the users fairly to the choices by maximising overall 'hapiness' in terms of ratings.
4+
This may be an alternative to the choice activity or first-come-first-served.
5+
6+
7+
Installation
8+
============
9+
this is an activity plugin and should go into mod/ratingallocate
10+
11+
Usage
12+
============
13+
14+
Add an activity instance. Set mandatory parameters are timespan, in which users can give ratings, choices, which the users will have to rate and the strategy,
15+
which form will be presented to the users to rate.
16+
After the rating period has finished, you can distribute the users automatically or manually. Upon publishing the results, users will be able to see which choice they have been associated with
17+
18+
Moodle version
19+
======================
20+
Tested with moodle 2.7.2+ (20140911).
21+
22+
Algorithm
23+
=========
24+
This module uses a modified Edmonds-karp algorithm to solve the minimum-cost flow problem. Augmenting paths are found using Bellman-Ford, but the user ratings are multiplied with -1 first.
25+
26+
Worst-Case complexity is O(m^2n^2) with m,n being number of edges (#users+#choices+#ratings_users_gave) and nodes (2+#users+#choices) in the graph.
27+
Distributing 500 users to 21 choices takes around 11sec.
28+

db/access.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Capability definitions for the ratingallocate module
19+
*
20+
* The capabilities are loaded into the database table when the module is
21+
* installed or updated. Whenever the capability definitions are updated,
22+
* the module version number should be bumped up.
23+
*
24+
* The system has four possible values for a capability:
25+
* CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
26+
*
27+
* It is important that capability names are unique. The naming convention
28+
* for capabilities that are specific to modules and blocks is as follows:
29+
* [mod/block]/<plugin_name>:<capabilityname>
30+
*
31+
* component_name should be the same as the directory name of the mod or block.
32+
*
33+
* Core moodle capabilities are defined thus:
34+
* moodle/<capabilityclass>:<capabilityname>
35+
*
36+
* Examples: mod/forum:viewpost
37+
* block/recent_activity:view
38+
* moodle/site:deleteuser
39+
*
40+
* The variable name for the capability definitions array is $capabilities
41+
*
42+
* @package mod_ratingallocate
43+
* @copyright 2014 M Schulze
44+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45+
*/
46+
defined('MOODLE_INTERNAL') || die();
47+
48+
$capabilities = array(
49+
/* * *************************** remove these comment marks and modify the code as needed
50+
51+
'mod/ratingallocate:addinstance' => array(
52+
'riskbitmask' => RISK_XSS,
53+
54+
'captype' => 'write',
55+
'contextlevel' => CONTEXT_COURSE,
56+
'archetypes' => array(
57+
'editingteacher' => CAP_ALLOW,
58+
'manager' => CAP_ALLOW
59+
),
60+
'clonepermissionsfrom' => 'moodle/course:manageactivities'
61+
),
62+
63+
'mod/ratingallocate:view' => array(
64+
'captype' => 'read',
65+
'contextlevel' => CONTEXT_MODULE,
66+
'legacy' => array(
67+
'guest' => CAP_ALLOW,
68+
'student' => CAP_ALLOW,
69+
'teacher' => CAP_ALLOW,
70+
'editingteacher' => CAP_ALLOW,
71+
'admin' => CAP_ALLOW
72+
)
73+
),
74+
75+
'mod/ratingallocate:submit' => array(
76+
'riskbitmask' => RISK_SPAM,
77+
'captype' => 'write',
78+
'contextlevel' => CONTEXT_MODULE,
79+
'legacy' => array(
80+
'student' => CAP_ALLOW
81+
)
82+
),
83+
* **************************** */
84+
// );
85+
86+
'mod/ratingallocate:addinstance' => array(
87+
'riskbitmask' => RISK_XSS | RISK_PERSONAL,
88+
'contextlevel' => CONTEXT_COURSE,
89+
'captype' => 'write',
90+
'archetypes' => array(
91+
'editingteacher' => CAP_ALLOW,
92+
'manager' => CAP_ALLOW
93+
),
94+
'clonepermissionsfrom' => 'moodle/course:manageactivities'
95+
),
96+
'mod/ratingallocate:give_rating' => array(
97+
'contextlevel' => CONTEXT_MODULE,
98+
'captype' => 'write',
99+
'archetypes' => array(
100+
'student' => CAP_ALLOW
101+
)
102+
),
103+
'mod/ratingallocate:group_teacher' => array(
104+
'contextlevel' => CONTEXT_MODULE,
105+
'captype' => 'read'
106+
),
107+
'mod/ratingallocate:start_distribution' => array(
108+
'contextlevel' => CONTEXT_MODULE,
109+
'riskbitmask' => RISK_PERSONAL,
110+
'captype' => 'write',
111+
'archetypes' => array(
112+
'editingteacher' => CAP_ALLOW,
113+
'manager' => CAP_ALLOW
114+
)
115+
),
116+
);
117+
118+
119+

db/install.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This file replaces the legacy STATEMENTS section in db/install.xml,
19+
* lib.php/modulename_install() post installation hook and partially defaults.php
20+
*
21+
* @package mod_ratingallocate
22+
* @copyright 2014 M Schulze
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/**
27+
* Post installation procedure
28+
*
29+
* @see upgrade_plugins_modules()
30+
*/
31+
function xmldb_ratingallocate_install() {
32+
}
33+
34+
/**
35+
* Post installation recovery procedure
36+
*
37+
* @see upgrade_plugins_modules()
38+
*/
39+
function xmldb_ratingallocate_install_recovery() {
40+
}

db/install.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<XMLDB PATH="mod/ratingallocate/db" VERSION="20140918" COMMENT="XMLDB file for Moodle mod/ratingallocate"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
5+
>
6+
<TABLES>
7+
<TABLE NAME="ratingallocate" COMMENT="Default comment for ratingallocate, please edit me">
8+
<FIELDS>
9+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
10+
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Course ratingallocate activity belongs to"/>
11+
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="name field for moodle instances"/>
12+
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="General introduction of the ratingallocate activity"/>
13+
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Format of the intro field (MOODLE, HTML, MARKDOWN...)"/>
14+
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
15+
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
16+
<FIELD NAME="accesstimestart" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
17+
<FIELD NAME="accesstimestop" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
18+
<FIELD NAME="setting" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="settings for the selected strategy"/>
19+
<FIELD NAME="strategy" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="die geawehlte Strategie"/>
20+
<FIELD NAME="publishdate" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
21+
<FIELD NAME="publishdate_show" TYPE="int" LENGTH="4" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
22+
<FIELD NAME="published" TYPE="int" LENGTH="4" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="shall the results of the allocation be shown"/>
23+
</FIELDS>
24+
<KEYS>
25+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
26+
</KEYS>
27+
<INDEXES>
28+
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
29+
</INDEXES>
30+
</TABLE>
31+
<TABLE NAME="ratingallocate_choices" COMMENT="Default comment for the table, please edit me">
32+
<FIELDS>
33+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
34+
<FIELD NAME="ratingallocateid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="reference to the instance of ratingallocate it belongs to"/>
35+
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
36+
<FIELD NAME="explanation" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
37+
<FIELD NAME="maxsize" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="10" SEQUENCE="false"/>
38+
<FIELD NAME="active" TYPE="int" LENGTH="4" NOTNULL="false" DEFAULT="1" SEQUENCE="false" COMMENT="ob man in die Wahl bewerten kann oder ob sie &quot;versteckt&quot; ist"/>
39+
</FIELDS>
40+
<KEYS>
41+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
42+
<KEY NAME="ratingallocateid" TYPE="foreign" FIELDS="ratingallocateid" REFTABLE="ratingallocate" REFFIELDS="id"/>
43+
</KEYS>
44+
</TABLE>
45+
<TABLE NAME="ratingallocate_ratings" COMMENT="Default comment for the table, please edit me">
46+
<FIELDS>
47+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
48+
<FIELD NAME="choiceid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
49+
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
50+
<FIELD NAME="rating" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="rating given"/>
51+
</FIELDS>
52+
<KEYS>
53+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
54+
<KEY NAME="choiceid" TYPE="foreign" FIELDS="choiceid" REFTABLE="ratingallocate_choices" REFFIELDS="id"/>
55+
</KEYS>
56+
</TABLE>
57+
<TABLE NAME="ratingallocate_allocations" COMMENT="Default comment for the table, please edit me">
58+
<FIELDS>
59+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
60+
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
61+
<FIELD NAME="ratingallocateid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="instance of the ratingallocate problem"/>
62+
<FIELD NAME="choiceid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
63+
</FIELDS>
64+
<KEYS>
65+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
66+
<KEY NAME="ratingallocateid" TYPE="foreign" FIELDS="ratingallocateid" REFTABLE="ratingallocate" REFFIELDS="id"/>
67+
<KEY NAME="choiceid" TYPE="foreign" FIELDS="choiceid" REFTABLE="choices" REFFIELDS="id"/>
68+
</KEYS>
69+
</TABLE>
70+
</TABLES>
71+
</XMLDB>

db/log.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Definition of log events
19+
*
20+
* NOTE: this is an example how to insert log event during installation/update.
21+
* It is not really essential to know about it, but these logs were created as example
22+
* in the previous 1.9 NEWMODULE.
23+
*
24+
* @package mod_ratingallocate
25+
* @copyright 2014 M Schulze
26+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
defined('MOODLE_INTERNAL') || die();
29+
30+
global $DB;
31+
32+
$logs = array(
33+
array('module' => 'ratingallocate', 'action' => 'add', 'mtable' => 'ratingallocate', 'field' => 'name'),
34+
array('module' => 'ratingallocate', 'action' => 'update', 'mtable' => 'ratingallocate', 'field' => 'name'),
35+
array('module' => 'ratingallocate', 'action' => 'view', 'mtable' => 'ratingallocate', 'field' => 'name'),
36+
array('module' => 'ratingallocate', 'action' => 'view all', 'mtable' => 'ratingallocate', 'field' => 'name')
37+
);

db/uninstall.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* @see uninstall_plugin()
19+
*
20+
* @package mod_ratingallocate
21+
* @copyright 2014 M Schulze
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
/**
26+
* Custom uninstallation procedure
27+
*/
28+
function xmldb_ratingallocate_uninstall() {
29+
return true;
30+
}

0 commit comments

Comments
 (0)