From dd232d0100232ba2972f6dcac063cfe3d3b1a4ee Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 3 Jun 2007 12:22:23 +0000 Subject: [PATCH] MDL-9549 some more grading and rating improvements, cleanup and fixes --- mod/glossary/lib.php | 32 ++++++++++-------- mod/glossary/rate.php | 76 +++++++++++++++++++------------------------ mod/glossary/view.php | 32 +++++++++--------- 3 files changed, 67 insertions(+), 73 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 059337f678..b458887fe6 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -72,7 +72,6 @@ function glossary_add_instance($glossary) { $glossary->timecreated = time(); $glossary->timemodified = $glossary->timecreated; - $glossary->courseid = $glossary->course; //Check displayformat is a valid one $formats = get_list_of_plugins('mod/glossary/formats','TEMPLATE'); @@ -107,7 +106,6 @@ function glossary_update_instance($glossary) { $glossary->timemodified = time(); $glossary->id = $glossary->instance; - $glossary->courseid = $glossary->course; if (empty($glossary->userating)) { $glossary->assessed = 0; @@ -145,8 +143,6 @@ function glossary_delete_instance($id) { return false; } - $glossary->courseid = $glossary->course; - $result = true; # Delete any dependent records here # @@ -365,7 +361,7 @@ function glossary_update_grades($grade_item=null, $userid=0, $deleteifnone=true) } } else { - $sql = "SELECT g.*, cm.idnumber as cmidnumber, g.course as courseid + $sql = "SELECT g.*, cm.idnumber as cmidnumber FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id"; if ($rs = get_recordset_sql($sql)) { @@ -386,35 +382,43 @@ function glossary_update_grades($grade_item=null, $userid=0, $deleteifnone=true) /** * Return (create if needed) grade item for given glossary * - * @param object $glossary object with extra cmidnumber and courseid property + * @param object $glossary object with optional cmidnumber * @return object grade_item */ function glossary_grade_item_get($glossary) { - if ($items = grade_get_items($glossary->courseid, 'mod', 'glossary', $glossary->id)) { + if ($items = grade_get_items($glossary->course, 'mod', 'glossary', $glossary->id)) { if (count($items) > 1) { debugging('Multiple grade items present!'); } $grade_item = reset($items); + } else { + if (!isset($glossary->cmidnumber)) { + if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { + error("Course Module ID was incorrect"); + } + $glossary->cmidnumber = $cm->idnumber; + } if (!$itemid = glossary_grade_item_create($glossary)) { error('Can not create grade item!'); } $grade_item = grade_item::fetch('id', $itemid); } + return $grade_item; } /** * Update grade item for given glossary * - * @param object $glossary object with extra cmidnumber and courseid property + * @param object $glossary object with extra cmidnumber * @return object grade_item */ function glossary_grade_item_update($glossary) { $grade_item = glossary_grade_item_get($glossary); - $grade_item->name = $glossary->name; - $grade_item->cmidnumber = $glossary->cmidnumber; + $grade_item->name = $glossary->name; + $grade_item->idnumber = $glossary->cmidnumber; if (!$glossary->assessed) { //how to indicate no grading? @@ -436,11 +440,11 @@ function glossary_grade_item_update($glossary) { /** * Create grade item for given glossary * - * @param object $glossary object with extra cmidnumber and courseid property + * @param object $glossary object with extra cmidnumber * @return object grade_item */ function glossary_grade_item_create($glossary) { - $params = array('courseid' =>$glossary->courseid, + $params = array('courseid' =>$glossary->course, 'itemtype' =>'mod', 'itemmodule' =>'glossary', 'iteminstance'=>$glossary->id, @@ -468,11 +472,11 @@ function glossary_grade_item_create($glossary) { /** * Delete grade item for given glossary * - * @param object $glossary object with extra cmidnumber and courseid property + * @param object $glossary object * @return object grade_item */ function glossary_grade_item_delete($glossary) { - if ($grade_items = grade_get_items($glossary->courseid, 'mod', 'glossary', $glossary->id)) { + if ($grade_items = grade_get_items($glossary->course, 'mod', 'glossary', $glossary->id)) { foreach($grade_items as $grade_item) { $grade_item->delete(); } diff --git a/mod/glossary/rate.php b/mod/glossary/rate.php index 15b789ad20..245e34bd7c 100644 --- a/mod/glossary/rate.php +++ b/mod/glossary/rate.php @@ -3,26 +3,48 @@ // Collect ratings, store them, then return to where we came from - require_once("../../config.php"); - require_once("lib.php"); + require_once('../../config.php'); + require_once('lib.php'); + $glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from - $id = required_param('id', PARAM_INT); // The course these ratings are part of + if (!$glossary = get_record('glossary', 'id', $glossaryid)) { + error("Incorrect glossary id"); + } - if (! $course = get_record("course", "id", $id)) { + if (!$course = get_record('course', 'id', $glossary->course)) { error("Course ID was incorrect"); } - require_login($course); + if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { + error("Course Module ID was incorrect"); + } + + require_login($course, false, $cm); if (isguestuser()) { error("Guests are not allowed to rate entries."); } - $returnurl = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : null; + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + if (!$glossary->assessed) { + error("Rating of items not allowed!"); + } + + if ($glossary->assessed == 2) { + require_capability('mod/glossary:rate', $context); + } - $glossary = false; - if ($data = data_submitted("$CFG->wwwroot/mod/glossary/view.php")) { // form submitted + $grade_item = glossary_grade_item_get($glossary); + + if (!empty($_SERVER['HTTP_REFERER'])) { + $returnurl = $_SERVER['HTTP_REFERER']; + } else { + $returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id; + } + + if ($data = data_submitted()) { // form submitted foreach ((array)$data as $entryid => $rating) { if (!is_numeric($entryid)) { continue; @@ -30,42 +52,14 @@ if (!$entry = get_record('glossary_entries', 'id', $entryid)) { continue; } - if (!$glossary) { - if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) { - error('Incorrect glossary id'); - } - if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) { - error("Course Module ID was incorrect"); - } - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - - require_login($course, false, $cm); - - if (!$glossary->assessed) { - error('Rating of items not allowed!'); - } - if ($glossary->assessed == 2 and !has_capability('mod/glossary:rate', $context)) { - error('You can not rate items!'); - } - - // add extra info into glossary object - $glossary->courseid = $course->id; - $glossary->cmidnumber = $cm->idnumber; - - $grade_item = glossary_grade_item_get($glossary); - - if (empty($returnurl)) { - $returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id; - } - } if ($entry->glossaryid != $glossary->id) { - error('This is not valid entry!!'); + error("This is not valid entry!"); } if ($glossary->assesstimestart and $glossary->assesstimefinish) { if ($entry->timecreated < $glossary->assesstimestart or $entry->timecreated > $glossary->assesstimefinish) { - // we can not grade this, ignore it - this should not happen anyway unless teachr changes setting + // we can not rate this, ignore it - this should not happen anyway unless teacher changes setting continue; } } @@ -89,6 +83,7 @@ } glossary_update_grades($grade_item, $entry->userid); } + } else if ($rating >= 0) { $newrating = new object(); $newrating->userid = $USER->id; @@ -103,11 +98,6 @@ } } - if (!$glossary) { - // something wrong happended - no rating changed/added - error('Incorrect ratings submitted'); - } - redirect($returnurl, get_string("ratingssaved", "glossary")); } else { diff --git a/mod/glossary/view.php b/mod/glossary/view.php index b37f55c063..2a4774ecbc 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -230,21 +230,21 @@ /// If we are in approval mode, prit special header if ($tab == GLOSSARY_APPROVAL_VIEW) { require_capability('mod/glossary:approve', $context); - + $crumbs[] = array('name' => $strwaitingapproval, 'link' => '', 'type' => 'title'); $navigation = build_navigation($crumbs); - - print_header_simple(format_string($glossary->name), "", $navigation, "", "", true, + + print_header_simple(format_string($glossary->name), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); print_heading($strwaitingapproval); } else { /// Print standard header $navigation = build_navigation($crumbs); - print_header_simple(format_string($glossary->name), "", $navigation, "", "", true, + print_header_simple(format_string($glossary->name), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); } -/// All this depends if whe have $showcommonelements +/// All this depends if whe have $showcommonelements if ($showcommonelements) { /// To calculate available options $availableoptions = ''; @@ -263,7 +263,7 @@ $availableoptions .= ' / '; } $availableoptions .='' . - 'wwwroot . '/mod/glossary/export.php?id=' . $cm->id . '&mode='.$mode . '&hook=' . urlencode($hook) . '"' . ' title="' . s(get_string('exportentries', 'glossary')) . '">' . get_string('exportentries', 'glossary') . '' . @@ -278,7 +278,7 @@ $availableoptions .= '
'; } $availableoptions .='' . - 'wwwroot . '/mod/glossary/view.php?id=' . $cm->id . '&mode=approval' . '"' . ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' . get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')' . @@ -293,7 +293,7 @@ /// If rss are activated at site and glossary level and this glossary has rss defined, show link if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) { - + $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true)); if (empty($USER->id)) { $userid = 0; @@ -302,7 +302,7 @@ } print_box_start('rsslink'); rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext); - print_box_end(); + print_box_end(); } /// The print icon @@ -310,7 +310,7 @@ if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) { print_box_start('printicon'); echo " id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">\""."; - print_box_end(); + print_box_end(); } } /// End glossary controls @@ -411,7 +411,7 @@ echo "
"; echo "
"; - echo "id\" />"; + echo "id\" />"; } foreach ($allentries as $entry) { @@ -422,8 +422,8 @@ // Reduce pivot to 1cc if necessary if ( !$fullpivot ) { $upperpivot = $textlib->substr($upperpivot, 0, 1); - } - + } + // if there's a group break if ( $currentpivot != $upperpivot ) { @@ -498,15 +498,15 @@ print_scale_menu_helpbutton($course->id, $scale ); } } - echo "
"; + echo ""; } if (!empty($formsent)) { // close the form properly if used echo ""; - echo "
"; + echo ""; } - + if ( $paging ) { echo '
'; echo '
'; -- 2.39.5