From: Matt L. v. a. <we...@ma...> - 2007-09-24 22:52:41
|
Log Message: ----------- Major code refactoring Modified Files: -------------- wwmoodle/wwassignment3/moodle/blocks/wwlink: block_wwlink.php config_instance.html Revision Data ------------- Index: config_instance.html =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/blocks/wwlink/config_instance.html,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/blocks/wwlink/config_instance.html -Lwwassignment3/moodle/blocks/wwlink/config_instance.html -u -r1.1 -r1.2 --- wwassignment3/moodle/blocks/wwlink/config_instance.html +++ wwassignment3/moodle/blocks/wwlink/config_instance.html @@ -0,0 +1,36 @@ +<?php + global $CFG; + $lib = $CFG->wwwroot . '/mod/wwassignment/locallib.php'; +?> +<table cellpadding="9" cellspacing="0" align="center"> + <?php if(!file_exists($lib)) { ?> + <tr valign="top"> + <td align="center"> + <?php echo '<strong>'.get_string('config_wwassigment_mod_missing','block_wwlink').'</strong>'; ?> + </td> + </tr> + <?php } else { ?> + <tr valign="top"> + + <td align="right"> + <?php print_string('config_select_webwork_course', 'block_wwlink'); ?> + </td> + <td align="center"> + <?php + require_once($lib); + $client = new wwassignment_client(); + $options = $client->options_course(true); + choose_from_menu($options,'webwork_link_id',empty($this->config->webwork_link_id) ? 0 : $this->config->webwork_link_id); + global $COURSE; + $courseid = $COURSE->id; + ?> + <input type="hidden" name="courseid" value="<?php echo $courseid;?>" /> + </td> + </tr> + <tr> + <td colspan="2" align="center"> + <input type="submit" value="<?php print_string('savechanges') ?>" /> + </td> + </tr> + <?php } ?> +</table> Index: block_wwlink.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/blocks/wwlink/block_wwlink.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/blocks/wwlink/block_wwlink.php -Lwwassignment3/moodle/blocks/wwlink/block_wwlink.php -u -r1.1 -r1.2 --- wwassignment3/moodle/blocks/wwlink/block_wwlink.php +++ wwassignment3/moodle/blocks/wwlink/block_wwlink.php @@ -0,0 +1,71 @@ +<?php + +/** +* @desc This block creates the tie between a Moodle course and a WeBWorK course +*/ +class block_wwlink extends block_base { + + /** + * @desc Sets the title of the block and the current version. + */ + function init() { + $this->title = get_string('blockname','block_wwlink'); + $this->version = 2007092100; + } + /** + * @desc Allows each instance of the block to have its own configuration settings. + */ + function instance_allow_config() { + return true; + } + + /** + * @desc Saves the form data from configuration into the wwassignment_bridge table. + */ + function instance_config_save($data) { + + $webworkcourse = $data->webwork_link_id; + $moodlecourse = $data->courseid; + + $wwassignmentbridge = new stdClass; + $wwassignmentbridge->course = $moodlecourse; + $wwassignmentbridge->webwork_course = $webworkcourse; + + //has this mapping been defined + $record = get_record('wwassignment_bridge','course',$moodlecourse); + if(!$record) { + //new one + insert_record('wwassignment_bridge',$wwassignmentbridge); + } else { + //update + $wwassignmentbridge->id = $record->id; + update_record('wwassignment_bridge',$wwassignmentbridge); + } + + return parent::instance_config_save($data); + } + + /** + * @desc Makes sure that the only place this block can be added is on course-view page. This insures one block per course. + */ + function applicable_formats() { + return array('all' => false, 'course-view' => true); + } + + /** + * @desc Prints the content of the block. Whether or not the course is connected to a moodle course. + */ + function get_content() { + global $COURSE; + + $courseid = $COURSE->id; + $record = get_record('wwassignment_bridge','course',$courseid); + if(!$record) { + $this->content->text = get_string('not_connected','block_wwlink'); + } else { + $this->content->text = get_string('connected','block_wwlink') . ' ' . $record->webwork_course; + } + return $this->content; + } +} +?> |