]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13397 Implemented the requiredentries parameter (previously not implemented)...
authornicolasconnault <nicolasconnault>
Tue, 12 Feb 2008 16:04:57 +0000 (16:04 +0000)
committernicolasconnault <nicolasconnault>
Tue, 12 Feb 2008 16:04:57 +0000 (16:04 +0000)
lang/en_utf8/data.php
mod/data/view.php

index 4d23c617a5363f1ac2ce1bb8170afb6714b676a5..4144ce332464a2146b53f985f3b1e8e3e8af53a8 100644 (file)
@@ -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!';
index b29ffdfcc8af123a7f60808de71775c98f118822..a018a33c49617fe0690ab622b68c52f283ba7127 100755 (executable)
                 }
             }
         }
+    
+    // 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){
 
             $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 ';
             $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.' ';
             $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.' ';
             $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;
+            }
         }