Skip to content
Browse files

Added the 'delete' methods back nessicary to change $field to optional.

  • Loading branch information...
1 parent 2c50dc0 commit ff96b9df7e1ef6e078864c5ba9738a52397f684d cap2501 committed Aug 30, 2006
Showing with 121 additions and 86 deletions.
  1. +121 −86 course/format/topics/commands.php
View
207 course/format/topics/commands.php
@@ -8,8 +8,8 @@
$courseid = required_param('courseId', PARAM_INT);
$class = required_param('class', PARAM_ALPHA);
-$field = required_param('field', PARAM_ALPHA);
+$field = optional_param('field', '', PARAM_ALPHA);
$instanceid = optional_param('instanceId', 0, PARAM_INT);
$value = optional_param('value', 0, PARAM_INT);
$column = optional_param('column', 0, PARAM_ALPHA);
@@ -34,104 +34,139 @@
// OK, now let's process the parameters and do stuff
$dataobject = NULL;
-
-switch ($class) {
- case 'block':
- switch ($field) {
- case 'visible':
- $dataobject->id = $instanceid;
- $dataobject->visible = $value;
- if (!update_record('block_instance',$dataobject)) {
- error('Failed to update block!');
+switch($_SERVER['REQUEST_METHOD']){
+ case 'POST':
+ switch ($class) {
+ case 'block':
+ switch ($field) {
+ case 'visible':
+ $dataobject->id = $instanceid;
+ $dataobject->visible = $value;
+ if (!update_record('block_instance',$dataobject)) {
+ error('Failed to update block!');
+ }
+ break;
+
+ case 'position':
+ $dataobject->id = $instanceid;
+ $dataobject->position = $column;
+ $dataobject->weight = $value;
+ if (!update_record('block_instance',$dataobject)) {
+ error('Failed to update block!');
+ }
+ break;
}
break;
-
- case 'position':
- $dataobject->id = $instanceid;
- $dataobject->position = $column;
- $dataobject->weight = $value;
- if (!update_record('block_instance',$dataobject)) {
- error('Failed to update block!');
- }
- break;
- }
- break;
-
-
- case 'section':
-
- if (!$dataobject->id = get_field('course_sections','id','course',$course->id,'section',$id)) {
- error('Bad Section ID');
- }
-
- switch ($field) {
-
- case 'visible':
- $dataobject->visible = $value;
- if (!update_record('course_sections',$dataobject)) {
- error('Failed to update section');
- }
- break;
-
-
- case 'sequence':
- $dataobject->sequence = $sequence;
- if (!update_record('course_sections',$dataobject)) {
- error('Failed to update section');
+
+
+ case 'section':
+
+ if (!$dataobject->id = get_field('course_sections','id','course',$course->id,'section',$id)) {
+ error('Bad Section ID');
}
- break;
-
- case 'all':
- $dataobject->summary = make_dangerous($summary);
- $dataobject->sequence = $sequence;
- $dataobject->visible = $visible;
- if (!update_record('course_sections',$dataobject)) {
- error('Failed to update section');
- }
- break;
- }
- break;
-
- case 'resource':
- switch($field) {
- case 'visible':
- $dataobject->id = $id;
- $dataobject->visible = $value;
- if (!update_record('course_modules',$dataobject)) {
- error('Failed to update activity');
+
+ switch ($field) {
+
+ case 'visible':
+ $dataobject->visible = $value;
+ if (!update_record('course_sections',$dataobject)) {
+ error('Failed to update section');
+ }
+ break;
+
+
+ case 'sequence':
+ $dataobject->sequence = $sequence;
+ if (!update_record('course_sections',$dataobject)) {
+ error('Failed to update section');
+ }
+ break;
+
+ case 'all':
+ $dataobject->summary = make_dangerous($summary);
+ $dataobject->sequence = $sequence;
+ $dataobject->visible = $visible;
+ if (!update_record('course_sections',$dataobject)) {
+ error('Failed to update section');
+ }
+ break;
+
+ case 'swap':
+ $dataobject->summary = make_dangerous($summary);
+ $dataobject->sequence = $sequence;
+ $dataobject->visible = $visible;
+ if (!update_record('course_sections',$dataobject)) {
+ error('Failed to update section');
+ }
+ break;
+
+
}
break;
-
- case 'groupmode':
- $dataobject->id = $id;
- $dataobject->groupmode = $value;
- if (!update_record('course_modules',$dataobject)) {
- error('Failed to update activity');
+
+ case 'resource':
+ switch($field) {
+ case 'visible':
+ $dataobject->id = $id;
+ $dataobject->visible = $value;
+ if (!update_record('course_modules',$dataobject)) {
+ error('Failed to update activity');
+ }
+ break;
+
+ case 'groupmode':
+ $dataobject->id = $id;
+ $dataobject->groupmode = $value;
+ if (!update_record('course_modules',$dataobject)) {
+ error('Failed to update activity');
+ }
+ break;
+
+ case 'section':
+ $dataobject->id = $id;
+ $dataobject->section = $value;
+ if (!update_record('course_modules',$dataobject)) {
+ error('Failed to update activity');
+ }
+ break;
}
break;
-
- case 'section':
- $dataobject->id = $id;
- $dataobject->section = $value;
- if (!update_record('course_modules',$dataobject)) {
- error('Failed to update activity');
+
+ case 'course':
+ switch($field) {
+ case 'marker':
+ $dataobject->id = $course->id;
+ $dataobject->marker = $value;
+ if (!update_record('course',$dataobject)) {
+ error('Failed to update course');
+ }
+ break;
}
break;
}
break;
-
- case 'course':
- switch($field) {
- case 'marker':
- $dataobject->id = $course->id;
- $dataobject->marker = $value;
- if (!update_record('course',$dataobject)) {
- error('Failed to update course');
- }
- break;
+
+ case 'DELETE':
+ switch ($class) {
+ case 'block':
+ delete_records('block_instance','id',$instanceid);
+ break;
+
+ case 'section':
+ $dataobject->id = get_field('course_sections','id','course',$course->id,'section',$id);
+ $dataobject->summary = '';
+ $dataobject->sequence = '';
+ $dataobject->visible = '1';
+ update_record('course_sections',$dataobject);
+ break;
+
+ case 'resource':
+ delete_records('course_modules','id',$id);
+ break;
}
break;
-}
+
+}

0 comments on commit ff96b9d

Please sign in to comment.
Something went wrong with that request. Please try again.