From: nicolasconnault Date: Tue, 12 Feb 2008 16:04:57 +0000 (+0000) Subject: MDL-13397 Implemented the requiredentries parameter (previously not implemented)... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=87518137bf15932a695904e03acabe37398121a2;p=moodle.git MDL-13397 Implemented the requiredentries parameter (previously not implemented). This includes a warning message and an SQL restriction on entries fetched for view.php; merging from MOODLE_19_STABLE --- diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php index 4d23c617a5..4144ce3324 100644 --- a/lang/en_utf8/data.php +++ b/lang/en_utf8/data.php @@ -75,6 +75,7 @@ $string['editordisable'] = 'Disable editor'; $string['emptyadd'] = 'The Add template is empty, generating a default form...'; $string['emptyaddform'] = 'You did not fill out any fields!'; $string['entries'] = 'Entries'; +$string['entrieslefttoadd'] = 'You must add $a more entry/entries before you can view other participants\' entries.'; $string['entry'] = 'Entry'; $string['entrysaved'] = 'Your entry has been saved'; $string['errormustbeteacher'] = 'You need to be a teacher to use this page!'; diff --git a/mod/data/view.php b/mod/data/view.php index b29ffdfcc8..a018a33c49 100755 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -327,6 +327,16 @@ } } } + + // Check the number of entries required against the number of entries already made (doesn't apply to teachers) + $requiredentries_allowed = true; + $numentries = data_numentries($data); + if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) { + $entriesleft = $data->requiredentries - $numentries; + $strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $entriesleft); + notify($strentrieslefttoadd); + $requiredentries_allowed = false; + } // If not teacher, check whether user has sufficient records to view if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){ @@ -360,7 +370,7 @@ $sortcontent = $sortfield->get_sort_field(); $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent); - + $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname, c.'.$sortcontent.', '.$sortcontentfull.' AS _order '; $count = ' COUNT(DISTINCT c.recordid) '; $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u '; @@ -372,6 +382,11 @@ $sortorder = ' ORDER BY _order '.$order.' , r.id ASC '; $searchselect = ''; + // If requiredentries is not reached, only show current user's entries + if (!$requiredentries_allowed) { + $where .= ' AND u.id = ' . $USER->id; + } + if (!empty($advanced)) { //If advanced box is checked. foreach($search_array as $key => $val) { //what does $search_array hold? $tables .= ', '.$CFG->prefix.'data_content c'.$key.' '; @@ -394,6 +409,11 @@ $sortorder = ' ORDER BY r.id ASC '; $searchselect = ''; + // If requiredentries is not reached, only show current user's entries + if (!$requiredentries_allowed) { + $where .= ' AND u.id = ' . $USER->id; + } + if (!empty($advanced)) { //Advanced search box again. foreach($search_array as $key => $val) { $tables .= ', '.$CFG->prefix.'data_content c'.$key.' '; @@ -413,6 +433,11 @@ $where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id '; $sortorder = ' ORDER BY r.timecreated '.$order. ' '; $searchselect = ' '; + + // If requiredentries is not reached, only show current user's entries + if (!$requiredentries_allowed) { + $where .= ' AND u.id = ' . $USER->id; + } }