From: nicolasconnault Date: Mon, 27 Aug 2007 12:23:50 +0000 (+0000) Subject: MDL-10984 Added 3 elements to the Grade Export GUIs, and a stub for action to be... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=97599c0a3865aefc647ad9692e8a4b3b00b76eb0;p=moodle.git MDL-10984 Added 3 elements to the Grade Export GUIs, and a stub for action to be taken when the 'publish' checkbox is ticked (for xml export only ATM). --- diff --git a/grade/export/grade_export_form.php b/grade/export/grade_export_form.php index 658a481a5e..0c4fb62d55 100755 --- a/grade/export/grade_export_form.php +++ b/grade/export/grade_export_form.php @@ -11,10 +11,22 @@ class grade_export_form extends moodleform { } else { $plugin = 'unknown'; } + + $mform->addElement('header', 'options', get_string('options')); + $mform->addElement('advcheckbox', 'export_letters', get_string('exportletters', 'grades')); $mform->setDefault('export_letters', 0); - $mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'), - false, true, false, get_string("exportlettershelp", 'grades'))); + $mform->setHelpButton('export_letters', array(false, get_string('exportletters', 'grades'), false, true, false, get_string("exportlettershelp", 'grades'))); + + $mform->addElement('advcheckbox', 'publish', get_string('publish', 'grades')); + $mform->setDefault('publish', 0); + $mform->setHelpButton('publish', array(false, get_string('publish', 'grades'), false, true, false, get_string("publishhelp", 'grades'))); + + $mform->addElement('textarea', 'iplist', get_string('iplist', 'grades'), array('cols' => 40, 'rows' => 5)); + $mform->setHelpButton('iplist', array(false, get_string('iplist', 'grades'), false, true, false, get_string("iplisthelp", 'grades'))); + + $mform->addElement('password', 'password', get_string('password')); + $mform->setHelpButton('password', array(false, get_string('password', 'grades'), false, true, false, get_string("passwordhelp", 'grades'))); $mform->addElement('header', 'general', get_string('gradeitemsinc', 'grades')); // TODO: localize @@ -23,23 +35,23 @@ class grade_export_form extends moodleform { if ($grade_items = grade_item::fetch_all(array('courseid'=>$id))) { $noidnumber = false; foreach ($grade_items as $grade_item) { - + if ($plugin != 'xmlexport' || $grade_item->idnumber) { $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('selected'=>'selected'), array(0, $grade_item->id)); $element->setChecked(1); } else { $noidnumber = true; - $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id)); + $element = new HTML_QuickForm_advcheckbox('itemids[]', null, $grade_item->get_name(), array('disabled'=>'disabled'), array(0, $grade_item->id)); } - + $mform->addElement($element); } } - + if ($noidnumber) { - $mform->addElement('static', 'noidnumber', '', get_string('noidnumber')); + $mform->addElement('static', 'noidnumber', '', get_string('noidnumber')); } - + $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000); $mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize $mform->setType('previewrows', PARAM_INT); diff --git a/grade/export/lib.php b/grade/export/lib.php index 211ef42954..082854e3c6 100755 --- a/grade/export/lib.php +++ b/grade/export/lib.php @@ -56,6 +56,7 @@ class grade_export { var $columnidnumbers = array(); // Collect all gradeitem id numbers var $students = array(); var $course; // course + var $publish; // Whether to publish this data via URL, or dump it to browser as usual // common strings var $strgrades; @@ -68,7 +69,7 @@ class grade_export { * @param boolean $export_letters Whether to export letter grade_items as literal letters, or as numerical values * @note Exporting as letters will lead to data loss if that exported set it re-imported. */ - function grade_export($id, $itemids = '', $export_letters=false) { + function grade_export($id, $itemids = '', $export_letters=false, $publish=false) { global $CFG, $COURSE; if ($export_letters) { @@ -77,6 +78,7 @@ class grade_export { $letters = $report->get_grade_letters(); } + $this->publish = $publish; $this->strgrades = get_string("grades"); $this->strgrade = get_string("grade"); $this->itemids = $itemids; @@ -243,10 +245,10 @@ class grade_export { $i = 0; foreach ($this->grades as $studentid => $studentgrades) { - + // number of preview rows if ($i++ == $rows) { - break; + break; } echo ''; $student = $this->students[$studentid]; diff --git a/grade/export/txt/grade_export_txt.php b/grade/export/txt/grade_export_txt.php index dbc40f027c..9d0b8585c1 100755 --- a/grade/export/txt/grade_export_txt.php +++ b/grade/export/txt/grade_export_txt.php @@ -44,6 +44,8 @@ class grade_export_txt extends grade_export { global $CFG; + $retval = ''; + /// Whether this plugin is entitled to update export time if ($expplugins = explode(",", $CFG->gradeexport)) { if (in_array($this->format, $expplugins)) { @@ -62,7 +64,7 @@ class grade_export_txt extends grade_export { /// Print names of all the fields - echo get_string("firstname")."$this->separator". + $retval .= get_string("firstname")."$this->separator". get_string("lastname")."{$this->separator}". get_string("idnumber")."{$this->separator}". get_string("institution")."{$this->separator}". @@ -70,14 +72,14 @@ class grade_export_txt extends grade_export { get_string("email"); foreach ($this->columns as $column) { $column = strip_tags($column); - echo "{$this->separator}$column"; + $retval .= "{$this->separator}$column"; /// add a column_feedback column if ($feedback) { - echo "{$this->separator}{$column}_feedback"; + $retval .= "{$this->separator}{$column}_feedback"; } } - echo "{$this->separator}".get_string("total")."\n"; + $retval .= "{$this->separator}".get_string("total")."\n"; /// Print all the lines of data. foreach ($this->grades as $studentid => $studentgrades) { @@ -86,14 +88,14 @@ class grade_export_txt extends grade_export { if (empty($this->totals[$student->id])) { $this->totals[$student->id] = ''; } - echo "$student->firstname{$this->separator}$student->lastname{$this->separator}$student->idnumber{$this->separator}$student->institution{$this->separator}$student->department{$this->separator}$student->email"; + $retval .= "$student->firstname{$this->separator}$student->lastname{$this->separator}$student->idnumber{$this->separator}$student->institution{$this->separator}$student->department{$this->separator}$student->email"; foreach ($studentgrades as $gradeitemid => $grade) { $grade = strip_tags($grade); - echo "{$this->separator}$grade"; + $retval .= "{$this->separator}$grade"; if ($feedback) { - echo "{$this->separator}".array_shift($this->comments[$student->id]); + $retval .= "{$this->separator}".array_shift($this->comments[$student->id]); } /// if export flag needs to be set @@ -110,10 +112,12 @@ class grade_export_txt extends grade_export { $grade_grade->update(); } } - echo "{$this->separator}".$this->totals[$student->id]; - echo "\n"; + $retval .= "{$this->separator}".$this->totals[$student->id]; + $retval .= "\n"; } + echo $retval; + exit; } } diff --git a/grade/export/xml/grade_export_xml.php b/grade/export/xml/grade_export_xml.php index bcf47dfaba..c28e194727 100755 --- a/grade/export/xml/grade_export_xml.php +++ b/grade/export/xml/grade_export_xml.php @@ -30,11 +30,16 @@ class grade_export_xml extends grade_export { /** * To be implemented by child classes + * @param boolean $feedback + * @param boolean $publish Whether to output directly, or send as a file + * @return string */ function print_grades($feedback = false) { global $CFG; + $retval = ''; + /// Whether this plugin is entitled to update export time if ($expplugins = explode(",", $CFG->gradeexport)) { if (in_array($this->format, $expplugins)) { @@ -51,17 +56,14 @@ class grade_export_xml extends grade_export { /// Calculate file name $downloadfilename = clean_filename("{$this->course->shortname} $this->strgrades.xml"); - //header("Content-type: text/xml; charset=UTF-8"); - //header("Content-Disposition: attachment; filename=\"$downloadfilename\""); - /// time stamp to ensure uniqueness of batch export - echo ''; + $retval .= ''; foreach ($this->columnidnumbers as $index => $idnumber) { // studentgrades[] index should match with corresponding $index foreach ($this->grades as $studentid => $studentgrades) { - echo ''; + $retval .= ''; // state can be new, or regrade // require comparing of timestamps in db @@ -82,6 +84,7 @@ class grade_export_xml extends grade_export { $grade_grade = new grade_grade($params); // if exported, check grade_history, if modified after export, set state to regrade + $status = 'new'; if (!empty($grade_grade->exported)) { //TODO: use timemodified or something else instead /* if (record_exists_select('grade_history', 'itemid = '.$gradeitem->id.' AND userid = '.$studentid.' AND timemodified > '.$grade_grade->exported)) { @@ -94,16 +97,16 @@ class grade_export_xml extends grade_export { $status = 'new'; } - echo ''.$status.''; + $retval .= ''.$status.''; // only need id number - echo ''.$idnumber.''; + $retval .= ''.$idnumber.''; // this column should be customizable to use either student id, idnumber, uesrname or email. - echo ''.$studentid.''; - echo ''.$studentgrades[$index].''; + $retval .= ''.$studentid.''; + $retval .= ''.$studentgrades[$index].''; if ($feedback) { - echo ''.$this->comments[$studentid][$index].''; + $retval .= ''.$this->comments[$studentid][$index].''; } - echo ''; + $retval .= ''; // timestamp this if needed if ($export) { @@ -113,7 +116,15 @@ class grade_export_xml extends grade_export { } } } - echo ''; + $retval .= ''; + + if ($this->publish) { + header("Content-type: text/xml; charset=UTF-8"); + header("Content-Disposition: attachment; filename=\"$downloadfilename\""); + } + + echo $retval; + exit; } } diff --git a/grade/export/xml/index.php b/grade/export/xml/index.php index 98b7183c2a..0af3bc51d1 100755 --- a/grade/export/xml/index.php +++ b/grade/export/xml/index.php @@ -47,6 +47,7 @@ $navigation = grade_build_nav(__FILE__, $actionstr, array('courseid' => $course- print_header($course->shortname.': '.get_string('grades'), $course->fullname, $navigation); print_grade_plugin_selector($id, 'export', 'xml'); + // process post information if (($data = data_submitted()) && confirm_sesskey()) { @@ -58,7 +59,12 @@ if (($data = data_submitted()) && confirm_sesskey()) { // print the grades on screen for feedbacks - $export = new grade_export($id, $data->itemids, $data->export_letters); + $export = new grade_export($id, $data->itemids, $data->export_letters, $data->publish); + + if ($data->publish) { + // Record an entry in the 'published' table: people can now access this data by URL + } + $export->display_grades($feedback, $data->previewrows); // this redirect should trigger a download prompt diff --git a/index.php b/index.php index de0dad8da5..8923cb02ae 100644 --- a/index.php +++ b/index.php @@ -105,8 +105,8 @@ BLOCK_L_MAX_WIDTH); $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH); - - print_header($SITE->fullname, $SITE->fullname, 'home', '', + $navigation = build_navigation(array(array('name' => get_string('home'), 'link' => null, 'type' => 'misc'))); + print_header($SITE->fullname, $SITE->fullname, $navigation, '', '', true, '', user_login_string($SITE).$langmenu);