]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14458 - optgroups Fields and Other in search menu; removed unused search code...
authorskodak <skodak>
Mon, 21 Apr 2008 14:17:02 +0000 (14:17 +0000)
committerskodak <skodak>
Mon, 21 Apr 2008 14:17:02 +0000 (14:17 +0000)
mod/data/field.php
mod/data/lib.php
mod/data/styles.php
mod/data/view.php

index 5a3d9b22063a274e356794dd82abfad145dc3e50..6be2f07ff76eee8bc8c33bf25996bbc31d5cacec 100755 (executable)
 
     if ($id) {
         if (! $cm = get_coursemodule_from_id('data', $id)) {
-            print_error('Course Module ID was incorrect');
+            error('Course Module ID was incorrect');
         }
         if (! $course = get_record('course', 'id', $cm->course)) {
-            print_error('Course is misconfigured');
+            error('Course is misconfigured');
         }
         if (! $data = get_record('data', 'id', $cm->instance)) {
-            print_error('Course module is incorrect');
+            error('Course module is incorrect');
         }
 
     } else {
         if (! $data = get_record('data', 'id', $d)) {
-            print_error('Data ID is incorrect');
+            error('Data ID is incorrect');
         }
         if (! $course = get_record('course', 'id', $data->course)) {
-            print_error('Course is misconfigured');
+            error('Course is misconfigured');
         }
         if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
-            print_error('Course Module ID was incorrect');
+            error('Course Module ID was incorrect');
         }
     }
 
                             $rec->defaultsort = 0;
                             $rec->defaultsortdir = 0;
                             if (!update_record('data', $rec)) {
-                                print_error('There was an error updating the database');
+                                error('There was an error updating the database');
                             }
                         }
 
                 if (update_record('data', $rec)) {
                     redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2);
                 } else {
-                    print_error('There was an error updating the database');
+                    error('There was an error updating the database');
                 }
                 exit;
             }
 
 
         echo '<div class="fieldadd">';
-        echo get_string('newfield','data').': ';
+        echo '<label for="fieldform_jump">'.get_string('newfield','data').'</label>';
         popup_form($CFG->wwwroot.'/mod/data/field.php?d='.$data->id.'&amp;mode=new&amp;sesskey='.
                 sesskey().'&amp;newtype=', $menufield, 'fieldform', '', 'choose');
         helpbutton('fields', get_string('addafield','data'), 'data');
         echo '</div>';
 
+        echo '<div class="sortdefault">';
+        echo '<form id="sortdefault" action="'.$CFG->wwwroot.'/mod/data/field.php" method="get">';
+        echo '<div>';
+        echo '<input type="hidden" name="d" value="'.$data->id.'" />';
+        echo '<input type="hidden" name="mode" value="sort" />';
+        echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+        echo '<label for="defaultsort">'.get_string('defaultsortfield','data').'</label>';
+        echo '<select id="defaultsort" name="defaultsort">';
         if ($fields = get_records('data_fields','dataid',$data->id)) {
-            echo '<div class="sortdefault">';
-            echo '<form id="sortdefault" action="'.$CFG->wwwroot.'/mod/data/field.php" method="get">';
-            echo '<fieldset class="invisiblefieldset">';
-            echo '<input type="hidden" name="d" value="'.$data->id.'" />';
-            echo '<input type="hidden" name="mode" value="sort" />';
-            echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-            echo '&nbsp;'.get_string('defaultsortfield','data').':';
-            echo '<select name="defaultsort"><option value="0">'.get_string('dateentered','data').'</option>';
+            echo '<optgroup label="'.get_string('fields', 'data').'">';
             foreach ($fields as $field) {
-                if ($field->id == $data->defaultsort) {
+                if ($data->defaultsort == $field->id) {
                     echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
                 } else {
                     echo '<option value="'.$field->id.'">'.$field->name.'</option>';
                 }
             }
-            echo '</select>';
-            echo '&nbsp;';
-
-            $options = array(0 => get_string('ascending', 'data'),
-                             1 => get_string('descending', 'data'));
-            choose_from_menu($options, 'defaultsortdir', $data->defaultsortdir, '');
-            echo '<input type="submit" value="'.get_string('go').'" />';
-            echo '</fieldset>';
-            echo '</form>';
-            echo '</div>';
+            echo '</optgroup>';
         }
+        $options = array();
+        $options[DATA_TIMEADDED]    = get_string('timeadded', 'data');
+// TODO: we will need to change defaultsort db to unsinged to make these work in 2.0
+/*        $options[DATA_TIMEMODIFIED] = get_string('timemodified', 'data');
+        $options[DATA_FIRSTNAME]    = get_string('authorfirstname', 'data');
+        $options[DATA_LASTNAME]     = get_string('authorlastname', 'data');
+        if ($data->approval and has_capability('mod/data:approve', $context)) {
+            $options[DATA_APPROVED] = get_string('approved', 'data');
+        }*/
+        echo '<optgroup label="'.get_string('other', 'data').'">';
+        foreach ($options as $key => $name) {
+            if ($data->defaultsort == $key) {
+                echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
+            } else {
+                echo '<option value="'.$key.'">'.$name.'</option>';
+            }
+        }
+        echo '</optgroup>';
+        echo '</select>';
 
+        $options = array(0 => get_string('ascending', 'data'),
+                         1 => get_string('descending', 'data'));
+        choose_from_menu($options, 'defaultsortdir', $data->defaultsortdir, '');
+        echo '<input type="submit" value="'.get_string('save', 'data').'" />';
+        echo '</div>';
+        echo '</form>';
+        echo '</div>';
 
     }
 
index 63bbc958db67d276aa00a04518ede75dd346e034..6bd98ad0d6c69bb9b5b8190d13fab5858b5af07c 100755 (executable)
@@ -29,6 +29,8 @@ define ('DATA_PERPAGE_SINGLE', 1);
 define ('DATA_FIRSTNAME', -1);
 define ('DATA_LASTNAME', -2);
 define ('DATA_APPROVED', -3);
+define ('DATA_TIMEADDED', 0);
+define ('DATA_TIMEMODIFIED', -4);
 
 class data_field_base {     /// Base class for Database Field Types (see field/*/field.class.php)
 
@@ -1064,17 +1066,27 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
     echo ';" >&nbsp;&nbsp;&nbsp;<label for="pref_search">'.get_string('search').'</label> <input type="text" size="16" name="search" id= "pref_search" value="'.s($search).'" /></div>';
     echo '&nbsp;&nbsp;&nbsp;<label for="pref_sortby">'.get_string('sortby').'</label> ';
     //foreach field, print the option
-    $fields = get_records('data_fields','dataid',$data->id, 'name');
-    $options = array();
-    foreach ($fields as $field) {
-        $options[$field->id] = $field->name;
+    echo '<select name="sort" id="pref_sortby">';
+    if ($fields = get_records('data_fields','dataid',$data->id, 'name')) {
+        echo '<optgroup label="'.get_string('fields', 'data').'">';
+        foreach ($fields as $field) {
+            if ($field->id == $sort) {
+                echo '<option value="'.$field->id.'" selected="selected">'.$field->name.'</option>';
+            } else {
+                echo '<option value="'.$field->id.'">'.$field->name.'</option>';
+            }
+        }
+        echo '</optgroup>';
     }
-    $options[DATA_FIRSTNAME] = get_string('authorfirstname', 'data');
-    $options[DATA_LASTNAME] = get_string('authorlastname', 'data');
+    $options = array();
+    $options[DATA_TIMEADDED]    = get_string('timeadded', 'data');
+    $options[DATA_TIMEMODIFIED] = get_string('timemodified', 'data');
+    $options[DATA_FIRSTNAME]    = get_string('authorfirstname', 'data');
+    $options[DATA_LASTNAME]     = get_string('authorlastname', 'data');
     if ($data->approval and has_capability('mod/data:approve', $context)) {
         $options[DATA_APPROVED] = get_string('approved', 'data');
     }
-    echo '<select name="sort" id="pref_sortby"><option value="0">'.get_string('dateentered','data').'</option>';
+    echo '<optgroup label="'.get_string('other', 'data').'">';
     foreach ($options as $key => $name) {
         if ($key == $sort) {
             echo '<option value="'.$key.'" selected="selected">'.$name.'</option>';
@@ -1082,6 +1094,7 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
             echo '<option value="'.$key.'">'.$name.'</option>';
         }
     }
+    echo '</optgroup>';
     echo '</select>';
     echo '<label for="pref_order" class="accesshide">'.get_string('order').'</label>';
     echo '<select id="pref_order" name="order">';
index 6f64125fbd69b3342bb695f0fec3258ffee9167b..79a5ec90b556a9bb8630ab67f13ee656cc96cb26 100644 (file)
   text-align: right;
 }
 
+.mod-data-field .fieldadd,
+.mod-data-field .sortdefault {
+  margin-bottom: 1em;
+  margin-top: 1em;
+}
+
+.mod-data-field .fieldadd select,
+.mod-data-field .sortdefault select {
+  margin-left: 1em;
+}
+
 .mod-data-field .fieldname {
   width:300px;
 }
index bb5cab3c2ebf4abcc94711df145f8aa39baf79de..066f3b42364fb4ec7c0515132ff7914a3048f6cd 100755 (executable)
         $ilike = sql_ilike(); //Be case-insensitive
 
     /// Find the field we are sorting on
-        if ($sort <= 0) {
+        if ($sort <= 0 or !$sortfield = data_get_field_from_id($sort, $data)) {
 
             switch ($sort) {
                 case DATA_LASTNAME:
                 case DATA_APPROVED:
                     $ordering = "r.approved $order, r.timecreated $order";
                     break;
+                case DATA_TIMEMODIFIED:
+                    $ordering = "r.timemodified $order";
+                    break;
+                case DATA_TIMEADDED:
                 default:
+                    $sort     = 0;
                     $ordering = "r.timecreated $order";
             }
 
                 $searchselect = ' ';
             }
 
-        } else if ($sort > 0 and $sortfield = data_get_field_from_id($sort, $data)) {
+        } else {
 
             $sortcontent = $sortfield->get_sort_field();
             $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
             } else {
                 $searchselect = ' ';
             }
-
-        } else if ($search) {
-            $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
-            $count = ' COUNT(DISTINCT c.recordid) ';
-            $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
-            $where =  'WHERE c.recordid = r.id
-                         AND r.userid = u.id
-                         AND r.dataid = '.$data->id;
-            $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) {
-                    if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
-                        $searchselect .= " AND $val->field $ilike '%{$val->data}%'";
-                        continue;
-                    }
-                    $tables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
-                    $where .= ' AND c'.$key.'.recordid = r.id ';
-                    $searchselect .= ' AND ('.$val->sql.') ';
-                }
-            } else {
-                $searchselect = " AND (c.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
-            }
-
-
-        } else {
-            $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
-            $count = ' COUNT(r.id) ';
-            $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
-            $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;
-            }
         }
 
-
     /// To actually fetch the records
 
         $fromsql    = "FROM $tables $where $groupselect $approveselect $searchselect";