Skip to content

Commit

Permalink
initial conversion of workshop to new roles and capabilities framewor…
Browse files Browse the repository at this point in the history
…k; groups are not functional yet (did they ever work properly ?)
  • Loading branch information
skodak committed Sep 6, 2006
1 parent b649a19 commit 6b9a1fe
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 273 deletions.
16 changes: 10 additions & 6 deletions mod/workshop/assess.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
error("No coursemodule found");
}

require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/workshop:view', $context);

if (!$redirect) {
$redirect = urlencode($_SERVER["HTTP_REFERER"].'#sid='.$submission->id);
//seems not to work properly
// $redirect = urlencode($_SERVER["HTTP_REFERER"].'#sid='.$submission->id);
}

require_login($course->id, false, $cm);

$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
Expand Down Expand Up @@ -67,7 +71,7 @@
if (!$assessment = get_record("workshop_assessments", "submissionid", $submission->id, "userid",
$USER->id)) {
// if it's the teacher see if the user has done a self assessment if so copy it
if (isteacher($course->id) and ($assessment = get_record("workshop_assessments", "submissionid",
if (workshop_is_teacher($workshop) and ($assessment = get_record("workshop_assessments", "submissionid",
$submission->id, "userid", $submission->userid))) {
$assessment = workshop_copy_assessment($assessment, $submission, true);
// need to set owner of assessment
Expand All @@ -90,7 +94,7 @@
error("Could not insert workshop assessment!");
}
// if it's the teacher and the workshop is error banded set all the elements to Yes
if (isteacher($course->id) and ($workshop->gradingstrategy == 2)) {
if (workshop_is_teacher($workshop) and ($workshop->gradingstrategy == 2)) {
for ($i =0; $i < $workshop->nelements; $i++) {
unset($element);
$element->workshopid = $workshop->id;
Expand Down Expand Up @@ -130,13 +134,13 @@

print_header('', '', '', '', '<base target="_parent" />');
$title = '"'.$submission->title.'" ';
if (isteacher($course->id)) {
if (workshop_is_teacher($workshop)) {
$title .= ' '.get_string('by', 'workshop').' '.workshop_fullname($submission->userid, $course->id);
}
print_heading($title);
workshop_print_submission($workshop, $submission);

if (isteacher($course->id)) {
if (workshop_is_teacher($workshop)) {
echo '<br /><center><b>'.get_string('assessments', 'workshop').': </b><br />';
echo workshop_print_submission_assessments($workshop, $submission, "all");
echo '</center>';
Expand Down
58 changes: 19 additions & 39 deletions mod/workshop/assessments.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
}

require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/workshop:view', $context);

$navigation = "";
if ($course->category) {
Expand Down Expand Up @@ -125,9 +127,7 @@
error("Workshop Assessment ID and/or Element Number missing");
}

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
error("workshop assessment is misconfigured");
Expand Down Expand Up @@ -352,9 +352,7 @@
/*********************** admin list of asssessments (of a submission) (by teachers)**************/
elseif ($action == 'adminlist') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

if (empty($sid)) {
error ("Workshop asssessments: adminlist called with no sid");
Expand All @@ -368,9 +366,7 @@
/*********************** admin list of asssessments by a student (used by teachers only )******************/
elseif ($action == 'adminlistbystudent') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

if (empty($userid)) {
error ("Workshop asssessments: adminlistbystudent called with no userid");
Expand Down Expand Up @@ -450,9 +446,7 @@
/*********************** edit assessment elements (for teachers) ***********************/
elseif ($action == 'editelements') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

$count = count_records("workshop_grades", "workshopid", $workshop->id);
if ($count) {
Expand Down Expand Up @@ -635,9 +629,7 @@
/*************** grade all assessments (by teacher) ***************************/
elseif ($action == 'gradeallassessments') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

print_heading(get_string("gradingallassessments", "workshop"));
workshop_grade_assessments($workshop);
Expand All @@ -648,9 +640,7 @@
/*************** grade (student's) assessment (by teacher) ***************************/
elseif ($action == 'gradeassessment') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

print_heading_with_help(get_string("gradeassessment", "workshop"), "gradingassessments", "workshop");
// get assessment record
Expand Down Expand Up @@ -704,9 +694,7 @@
/*********************** insert/update assignment elements (for teachers)***********************/
elseif ($action == 'insertelements') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

$form = data_submitted();

Expand Down Expand Up @@ -821,9 +809,8 @@
/*********************** list assessments for grading (Student submissions)(by teachers)***********************/
elseif ($action == 'listungradedstudentsubmissions') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

workshop_list_ungraded_assessments($workshop, "student");
print_continue("view.php?id=$cm->id");
}
Expand All @@ -832,9 +819,8 @@
/*********************** list assessments for grading (Teacher submissions) (by teachers)***********************/
elseif ($action == 'listungradedteachersubmissions') {

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

workshop_list_ungraded_assessments($workshop, "teacher");
print_continue("view.php?id=$cm->id");
}
Expand All @@ -852,9 +838,7 @@
elseif ($action == 'regradestudentassessments' ) {

$timenow = time();
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);
// get all the submissions...
if ($submissions = get_records("workshop_submissions", "workshopid", $workshop->id)) {
foreach ($submissions as $submission) {
Expand All @@ -879,9 +863,7 @@
error("Workshop Assessment id and/or Stock Comment id missing");
}

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
error("workshop assessment is misconfigured");
Expand Down Expand Up @@ -1250,12 +1232,12 @@
workshop_grade_assessments($workshop);
} else { // it could be self assessment....
// now see if there's a corresponding assessment so that the gradinggrade can be set
if (isteacher($course->id)) {
if (workshop_is_teacher($workshop)) {
// see if there's are student assessments, if so set their gradinggrade
if ($assessments = workshop_get_assessments($submission)) {
foreach($assessments as $studentassessment) {
// skip if it's not a student assessment
if (!isstudent($course->id, $studentassessment->userid)) {
if (!workshop_is_student($workshop, $studentassessment->userid)) {
continue;
}
$gradinggrade = workshop_compare_assessments($workshop, $assessment, $studentassessment);
Expand All @@ -1266,7 +1248,7 @@
} else { //it's a student assessment, see if there's a corresponding teacher's assessment
if ($assessments = workshop_get_assessments($submission)) {
foreach($assessments as $teacherassessment) {
if (isteacher($course->id, $teacherassessment->userid)) {
if (workshop_is_teacher($workshop, $teacherassessment->userid)) {
$gradinggrade = workshop_compare_assessments($workshop, $assessment, $teacherassessment);
set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $assessment->id);
Expand Down Expand Up @@ -1335,9 +1317,7 @@
elseif ($action == 'updategrading') {
$timenow = time();

if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
require_capability('mod/workshop:manage', $context);

$form = (object)$_POST;

Expand Down
50 changes: 50 additions & 0 deletions mod/workshop/db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php // $Id$
/**
* Capability definitions for the workshop module.
*
* For naming conventions, see lib/db/access.php.
*/
$mod_workshop_capabilities = array(

'mod/workshop:view' => array(

'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

'mod/workshop:participate' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_ALLOW,
'teacher' => CAP_PREVENT,
'editingteacher' => CAP_PREVENT,
'coursecreator' => CAP_PREVENT,
'admin' => CAP_PREVENT
)
),

'mod/workshop:manage' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
'guest' => CAP_PREVENT,
'student' => CAP_PREVENT,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
)
);
10 changes: 7 additions & 3 deletions mod/workshop/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/workshop/db" VERSION="20060812" COMMENT="XMLDB file for Moodle mod/workshop">
<XMLDB PATH="mod/workshop/db" VERSION="20060905" COMMENT="XMLDB file for Moodle mod/workshop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="workshop" COMMENT="Defines workshop" NEXT="workshop_elements">
<FIELDS>
Expand Down Expand Up @@ -82,8 +85,9 @@
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="title" NEXT="mailed"/>
<FIELD NAME="mailed" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated" NEXT="description"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="mailed" NEXT="gradinggrade"/>
<FIELD NAME="gradinggrade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="description" NEXT="finalgrade"/>
<FIELD NAME="finalgrade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="gradinggrade" NEXT="late"/>
<FIELD NAME="gradinggrade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="description" NEXT="teachergraded"/>
<FIELD NAME="teachergraded" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="This field was only in upgrade, but not in install file, grrr." PREVIOUS="gradinggrade" NEXT="finalgrade"/>
<FIELD NAME="finalgrade" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="teachergraded" NEXT="late"/>
<FIELD NAME="late" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="finalgrade" NEXT="nassessments"/>
<FIELD NAME="nassessments" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="late"/>
</FIELDS>
Expand Down
10 changes: 9 additions & 1 deletion mod/workshop/db/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function workshop_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality

global $CFG;
global $CFG, $db;

if ($oldversion < 2003050400) {
execute_sql(" ALTER TABLE `{$CFG->prefix}workshop` CHANGE `graded` `agreeassessments` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL");
Expand Down Expand Up @@ -209,6 +209,14 @@ function workshop_upgrade($oldversion) {
$wtm->update( 'workshop','description','format' );
}

if ($oldversion < 2006090500) {
$columns = $db->MetaColumns($CFG->prefix.'workshop_assessments');
$columns = array_change_key_case($columns, CASE_LOWER);
if (!isset($columns['teachergraded'])) {
table_column('workshop_assessments', '', 'teachergraded', 'INTEGER', '4', 'UNSIGNED', '0', 'NOT NULL', 'gradinggrade');
}
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions mod/workshop/db/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ CREATE TABLE `prefix_workshop_assessments` (
`timeagreed` int(10) unsigned NOT NULL default '0',
`grade` float NOT NULL default '0',
`gradinggrade` int(3) NOT NULL default '0',
`teachergraded` int(3) NOT NULL default '0',
`mailed` tinyint(3) unsigned NOT NULL default '0',
`resubmission` tinyint(3) unsigned NOT NULL default '0',
`donotuse` tinyint(3) unsigned NOT NULL default '0',
Expand Down
10 changes: 9 additions & 1 deletion mod/workshop/db/postgres7.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function workshop_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality

global $CFG;
global $CFG, $db;

if ($oldversion < 2003050400) {
table_column("workshop","graded", "agreeassessments", "INT","2", "", "0" ,"NOT NULL");
Expand Down Expand Up @@ -237,6 +237,14 @@ function workshop_upgrade($oldversion) {
");
}

if ($oldversion < 2006090500) {
$columns = $db->MetaColumns($CFG->prefix.'workshop_assessments');
$columns = array_change_key_case($columns, CASE_LOWER);
if (!isset($columns['teachergraded'])) {
table_column('workshop_assessments', '', 'teachergraded', 'INTEGER', '4', 'UNSIGNED', '0', 'NOT NULL', 'gradinggrade');
}
}

return true;

}
Expand Down
1 change: 1 addition & 0 deletions mod/workshop/db/postgres7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE prefix_workshop (
releasegrades INT8 NOT NULL default'0',
grade INT8 NOT NULL default '0',
gradinggrade INT4 NOT NULL default '0',
teachergraded INT4 NOT NULL default '0',
ntassessments INT NOT NULL default '0',
assessmentcomps int4 NOT NULL default '2',
nsassessments INT NOT NULL default '0',
Expand Down
Loading

0 comments on commit 6b9a1fe

Please sign in to comment.