From 5be392bd10cf7258cc963083ab35462ce1a9046e Mon Sep 17 00:00:00 2001 From: cap2501 Date: Tue, 5 Sep 2006 00:47:47 +0000 Subject: [PATCH] Updated so nothing in the database is being manipulated directly except for the block position. look into moving this functionality into the blocks_execute_action. --- course/format/topics/commands.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/course/format/topics/commands.php b/course/format/topics/commands.php index f34aa6dcc5..60afbe6fac 100644 --- a/course/format/topics/commands.php +++ b/course/format/topics/commands.php @@ -3,6 +3,8 @@ require_once('../../../config.php'); require_once($CFG->dirroot.'/course/lib.php'); +require_once($CFG->libdir .'/pagelib.php'); +require_once($CFG->libdir .'/blocklib.php'); // Initialise ALL the incoming parameters here, up front. @@ -26,6 +28,13 @@ if (!$course = get_record('course', 'id', $courseid)) { error('Course does not exist'); } +$PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); +$pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); + +if(!empty($instanceid)){ + $instance = blocks_find_instance($instanceid, $pageblocks); +} + require_login($course->id); $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -39,14 +48,10 @@ $dataobject = NULL; 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!'); - } + case 'block': + switch ($field) { + case 'visible': + blocks_execute_action($PAGE, $pageblocks, 'toggle', $instance); break; case 'position': @@ -120,8 +125,8 @@ switch($_SERVER['REQUEST_METHOD']){ case 'DELETE': switch ($class) { - case 'block': - delete_records('block_instance','id',$instanceid); + case 'block': + blocks_execute_action($PAGE, $pageblocks, 'delete', $instance); break; case 'resource': -- 2.39.5