From: Chris S. <san...@us...> - 2005-06-21 18:02:15
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10117/scripts Modified Files: stackDatabase.php Log Message: Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** stackDatabase.php 21 Jun 2005 14:52:26 -0000 1.19 --- stackDatabase.php 21 Jun 2005 15:43:17 -0000 1.20 *************** *** 115,120 **** } ! $question_order = 'ORDER BY questionName, questionKeywords, questionID '; ! // Build the query to the database. $query = 'SELECT --- 115,120 ---- } ! $question_order = stack_db_question_filter_quearyfrag($filter); ! // Build the query to the database. $query = 'SELECT *************** *** 210,214 **** global $_PHP_SELF; ! $question_order = 'ORDER BY questionName, questionKeywords, questionID '; $query = 'SELECT questionID, questionName, questionKeywords FROM stackQuestion '.$question_order; $result = stack_db_query($query); --- 210,214 ---- global $_PHP_SELF; ! $question_order = stack_db_question_filter_quearyfrag($filter); $query = 'SELECT questionID, questionName, questionKeywords FROM stackQuestion '.$question_order; $result = stack_db_query($query); *************** *** 259,271 **** } /** * The HTML necessary for the top of the question bank table, to include the filter interactions. * * @return void */ function stack_db_question_filter_tablehead($action,$filter,$quizid=0) { ! echo "<thead>\n<tr>\n"; if ('edit'==$action) { echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th>Last edit</th>'; --- 259,324 ---- } + /** + * Write the MySQL queary fragment to order the questions in a more flexible way + * + * @param array $filter The question bank filter array. + * @return string $queryfrag + */ + function stack_db_question_filter_quearyfrag($filter) { + + // 'ORDER BY questionName, questionKeywords, questionID '; + $queryfrag = ' ORDER BY questionID'; + + // First level + if ('NONE' != $filter['order1']) { + $queryfrag = ' ORDER BY '.$filter['order1']; + + // Second level + if ('NONE' != $filter['order2'] and $filter['order1'] != $filter['order2']) { + $queryfrag .= ', '.$filter['order2']; + + // Third level + if ('NONE' != $filter['order3'] and + $filter['order1'] != $filter['order3'] and + $filter['order2'] != $filter['order3']) { + $queryfrag .= ', '.$filter['order3']; + } + } + } + return $queryfrag; + } /** * The HTML necessary for the top of the question bank table, to include the filter interactions. * + * @param string $action The required action when the form is submitted. eg edit, edit_metadata, try, add_quiz + * @param array $filter The question bank filter array. + * @param int $quizid The ID number of the quiz, if any, to add these questions to. * @return void */ function stack_db_question_filter_tablehead($action,$filter,$quizid=0) { ! echo "<thead>\n"; ! ! // Print the interactions for ordering the output of the queary. ! echo "<tr><th></th><th colspan='2'>Order output by:</th> </tr>\n"; ! ! $fields1 = array('questionName', 'questionKeywords', 'questionID','questionDescription','questionDateLastEdited','NONE'); ! $fields2 = array('order1','order2','order3'); ! $fields3 = array('1st','2nd','3rd'); ! ! foreach ($fields2 as $no => $fn){ ! echo "<tr><th>{$fields3[$no]} </th>\n"; ! echo '<th colspan="2"><select name="bank_filter['.$fn.']">'; ! foreach ($fields1 as $key) { ! if ($key == $filter[$fn]) { ! echo "\n <option value='$key' selected>".get_string('stackQuestion_'.$key,'stack')."</option>"; ! } else { ! echo "\n <option value='$key'>".get_string('stackQuestion_'.$key,'stack')."</option>"; ! } ! } ! echo "\n</select></th>\n</tr>\n"; ! } ! if ('edit'==$action) { echo '<th></th><th>ID</th><th>Name</th> <th>Key words</th> <th></th><th>Last edit</th>'; *************** *** 287,293 **** echo '<th><input type="text" name="bank_filter[kw]" value="'.$filter['kw'].'" /></th>'; if ($filter['case_sense']) { ! echo "<th>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' checked='TRUE' /></th>"; } else { ! echo "<th>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' /></th>"; } echo "</tr></thead>\n"; --- 340,346 ---- echo '<th><input type="text" name="bank_filter[kw]" value="'.$filter['kw'].'" /></th>'; if ($filter['case_sense']) { ! echo "<th colspan='2'>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' checked='TRUE' /></th>"; } else { ! echo "<th colspan='2'>Case sensitive <input type='checkbox' name='bank_filter[case_sense]' value='TRUE' /></th>"; } echo "</tr></thead>\n"; |