|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 global $CHOICE_COLUMN_HEIGHT; 00026 $CHOICE_COLUMN_HEIGHT = 300; 00027 00029 global $CHOICE_COLUMN_WIDTH; 00030 $CHOICE_COLUMN_WIDTH = 300; 00031 00032 define('CHOICE_PUBLISH_ANONYMOUS', '0'); 00033 define('CHOICE_PUBLISH_NAMES', '1'); 00034 00035 define('CHOICE_SHOWRESULTS_NOT', '0'); 00036 define('CHOICE_SHOWRESULTS_AFTER_ANSWER', '1'); 00037 define('CHOICE_SHOWRESULTS_AFTER_CLOSE', '2'); 00038 define('CHOICE_SHOWRESULTS_ALWAYS', '3'); 00039 00040 define('CHOICE_DISPLAY_HORIZONTAL', '0'); 00041 define('CHOICE_DISPLAY_VERTICAL', '1'); 00042 00044 global $CHOICE_PUBLISH; 00045 $CHOICE_PUBLISH = array (CHOICE_PUBLISH_ANONYMOUS => get_string('publishanonymous', 'choice'), 00046 CHOICE_PUBLISH_NAMES => get_string('publishnames', 'choice')); 00047 00049 global $CHOICE_SHOWRESULTS; 00050 $CHOICE_SHOWRESULTS = array (CHOICE_SHOWRESULTS_NOT => get_string('publishnot', 'choice'), 00051 CHOICE_SHOWRESULTS_AFTER_ANSWER => get_string('publishafteranswer', 'choice'), 00052 CHOICE_SHOWRESULTS_AFTER_CLOSE => get_string('publishafterclose', 'choice'), 00053 CHOICE_SHOWRESULTS_ALWAYS => get_string('publishalways', 'choice')); 00054 00056 global $CHOICE_DISPLAY; 00057 $CHOICE_DISPLAY = array (CHOICE_DISPLAY_HORIZONTAL => get_string('displayhorizontal', 'choice'), 00058 CHOICE_DISPLAY_VERTICAL => get_string('displayvertical','choice')); 00059 00061 00070 function choice_user_outline($course, $user, $mod, $choice) { 00071 global $DB; 00072 if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id))) { 00073 $result = new stdClass(); 00074 $result->info = "'".format_string(choice_get_option_text($choice, $answer->optionid))."'"; 00075 $result->time = $answer->timemodified; 00076 return $result; 00077 } 00078 return NULL; 00079 } 00080 00089 function choice_user_complete($course, $user, $mod, $choice) { 00090 global $DB; 00091 if ($answer = $DB->get_record('choice_answers', array("choiceid" => $choice->id, "userid" => $user->id))) { 00092 $result = new stdClass(); 00093 $result->info = "'".format_string(choice_get_option_text($choice, $answer->optionid))."'"; 00094 $result->time = $answer->timemodified; 00095 echo get_string("answered", "choice").": $result->info. ".get_string("updated", '', userdate($result->time)); 00096 } else { 00097 print_string("notanswered", "choice"); 00098 } 00099 } 00100 00111 function choice_add_instance($choice) { 00112 global $DB; 00113 00114 $choice->timemodified = time(); 00115 00116 if (empty($choice->timerestrict)) { 00117 $choice->timeopen = 0; 00118 $choice->timeclose = 0; 00119 } 00120 00121 //insert answers 00122 $choice->id = $DB->insert_record("choice", $choice); 00123 foreach ($choice->option as $key => $value) { 00124 $value = trim($value); 00125 if (isset($value) && $value <> '') { 00126 $option = new stdClass(); 00127 $option->text = $value; 00128 $option->choiceid = $choice->id; 00129 if (isset($choice->limit[$key])) { 00130 $option->maxanswers = $choice->limit[$key]; 00131 } 00132 $option->timemodified = time(); 00133 $DB->insert_record("choice_options", $option); 00134 } 00135 } 00136 00137 return $choice->id; 00138 } 00139 00149 function choice_update_instance($choice) { 00150 global $DB; 00151 00152 $choice->id = $choice->instance; 00153 $choice->timemodified = time(); 00154 00155 00156 if (empty($choice->timerestrict)) { 00157 $choice->timeopen = 0; 00158 $choice->timeclose = 0; 00159 } 00160 00161 //update, delete or insert answers 00162 foreach ($choice->option as $key => $value) { 00163 $value = trim($value); 00164 $option = new stdClass(); 00165 $option->text = $value; 00166 $option->choiceid = $choice->id; 00167 if (isset($choice->limit[$key])) { 00168 $option->maxanswers = $choice->limit[$key]; 00169 } 00170 $option->timemodified = time(); 00171 if (isset($choice->optionid[$key]) && !empty($choice->optionid[$key])){//existing choice record 00172 $option->id=$choice->optionid[$key]; 00173 if (isset($value) && $value <> '') { 00174 $DB->update_record("choice_options", $option); 00175 } else { //empty old option - needs to be deleted. 00176 $DB->delete_records("choice_options", array("id"=>$option->id)); 00177 } 00178 } else { 00179 if (isset($value) && $value <> '') { 00180 $DB->insert_record("choice_options", $option); 00181 } 00182 } 00183 } 00184 00185 return $DB->update_record('choice', $choice); 00186 00187 } 00188 00197 function choice_prepare_options($choice, $user, $coursemodule, $allresponses) { 00198 global $DB; 00199 00200 $cdisplay = array('options'=>array()); 00201 00202 $cdisplay['limitanswers'] = true; 00203 $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id); 00204 00205 foreach ($choice->option as $optionid => $text) { 00206 if (isset($text)) { //make sure there are no dud entries in the db with blank text values. 00207 $option = new stdClass; 00208 $option->attributes = new stdClass; 00209 $option->attributes->value = $optionid; 00210 $option->text = $text; 00211 $option->maxanswers = $choice->maxanswers[$optionid]; 00212 $option->displaylayout = $choice->display; 00213 00214 if (isset($allresponses[$optionid])) { 00215 $option->countanswers = count($allresponses[$optionid]); 00216 } else { 00217 $option->countanswers = 0; 00218 } 00219 if ($DB->record_exists('choice_answers', array('choiceid' => $choice->id, 'userid' => $user->id, 'optionid' => $optionid))) { 00220 $option->attributes->checked = true; 00221 } 00222 if ( $choice->limitanswers && ($option->countanswers >= $option->maxanswers) && empty($option->attributes->checked)) { 00223 $option->attributes->disabled = true; 00224 } 00225 $cdisplay['options'][] = $option; 00226 } 00227 } 00228 00229 $cdisplay['hascapability'] = is_enrolled($context, NULL, 'mod/choice:choose'); //only enrolled users are allowed to make a choice 00230 00231 if ($choice->allowupdate && $DB->record_exists('choice_answers', array('choiceid'=> $choice->id, 'userid'=> $user->id))) { 00232 $cdisplay['allowupdate'] = true; 00233 } 00234 00235 return $cdisplay; 00236 } 00237 00246 function choice_user_submit_response($formanswer, $choice, $userid, $course, $cm) { 00247 global $DB, $CFG; 00248 require_once($CFG->libdir.'/completionlib.php'); 00249 00250 $current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid)); 00251 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00252 00253 $countanswers=0; 00254 if($choice->limitanswers) { 00255 // Find out whether groups are being used and enabled 00256 if (groups_get_activity_groupmode($cm) > 0) { 00257 $currentgroup = groups_get_activity_group($cm); 00258 } else { 00259 $currentgroup = 0; 00260 } 00261 if($currentgroup) { 00262 // If groups are being used, retrieve responses only for users in 00263 // current group 00264 global $CFG; 00265 $answers = $DB->get_records_sql(" 00266 SELECT 00267 ca.* 00268 FROM 00269 {choice_answers} ca 00270 INNER JOIN {groups_members} gm ON ca.userid=gm.userid 00271 WHERE 00272 optionid=? 00273 AND gm.groupid=?", array($formanswer, $currentgroup)); 00274 } else { 00275 // Groups are not used, retrieve all answers for this option ID 00276 $answers = $DB->get_records("choice_answers", array("optionid" => $formanswer)); 00277 } 00278 00279 if ($answers) { 00280 foreach ($answers as $a) { //only return enrolled users. 00281 if (is_enrolled($context, $a->userid, 'mod/choice:choose')) { 00282 $countanswers++; 00283 } 00284 } 00285 } 00286 $maxans = $choice->maxanswers[$formanswer]; 00287 } 00288 00289 if (!($choice->limitanswers && ($countanswers >= $maxans) )) { 00290 if ($current) { 00291 00292 $newanswer = $current; 00293 $newanswer->optionid = $formanswer; 00294 $newanswer->timemodified = time(); 00295 $DB->update_record("choice_answers", $newanswer); 00296 add_to_log($course->id, "choice", "choose again", "view.php?id=$cm->id", $choice->id, $cm->id); 00297 } else { 00298 $newanswer = NULL; 00299 $newanswer->choiceid = $choice->id; 00300 $newanswer->userid = $userid; 00301 $newanswer->optionid = $formanswer; 00302 $newanswer->timemodified = time(); 00303 $DB->insert_record("choice_answers", $newanswer); 00304 00305 // Update completion state 00306 $completion = new completion_info($course); 00307 if ($completion->is_enabled($cm) && $choice->completionsubmit) { 00308 $completion->update_state($cm, COMPLETION_COMPLETE); 00309 } 00310 add_to_log($course->id, "choice", "choose", "view.php?id=$cm->id", $choice->id, $cm->id); 00311 } 00312 } else { 00313 if (!($current->optionid==$formanswer)) { //check to see if current choice already selected - if not display error 00314 print_error('choicefull', 'choice'); 00315 } 00316 } 00317 } 00318 00324 function choice_show_reportlink($user, $cm) { 00325 $responsecount =0; 00326 foreach($user as $optionid => $userlist) { 00327 if ($optionid) { 00328 $responsecount += count($userlist); 00329 } 00330 } 00331 00332 echo '<div class="reportlink">'; 00333 echo "<a href=\"report.php?id=$cm->id\">".get_string("viewallresponses", "choice", $responsecount)."</a>"; 00334 echo '</div>'; 00335 } 00336 00347 function prepare_choice_show_results($choice, $course, $cm, $allresponses, $forcepublish=false) { 00348 global $CFG, $CHOICE_COLUMN_HEIGHT, $FULLSCRIPT, $PAGE, $OUTPUT, $DB; 00349 00350 $display = clone($choice); 00351 $display->coursemoduleid = $cm->id; 00352 $display->courseid = $course->id; 00353 00354 //overwrite options value; 00355 $display->options = array(); 00356 $totaluser = 0; 00357 foreach ($choice->option as $optionid => $optiontext) { 00358 $display->options[$optionid] = new stdClass; 00359 $display->options[$optionid]->text = $optiontext; 00360 $display->options[$optionid]->maxanswer = $choice->maxanswers[$optionid]; 00361 00362 if (array_key_exists($optionid, $allresponses)) { 00363 $display->options[$optionid]->user = $allresponses[$optionid]; 00364 $totaluser += count($allresponses[$optionid]); 00365 } 00366 } 00367 unset($display->option); 00368 unset($display->maxanswers); 00369 00370 $display->numberofuser = $totaluser; 00371 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00372 $display->viewresponsecapability = has_capability('mod/choice:readresponses', $context); 00373 $display->deleterepsonsecapability = has_capability('mod/choice:deleteresponses',$context); 00374 $display->fullnamecapability = has_capability('moodle/site:viewfullnames', $context); 00375 00376 if (empty($allresponses)) { 00377 echo $OUTPUT->heading(get_string("nousersyet")); 00378 return false; 00379 } 00380 00381 00382 $totalresponsecount = 0; 00383 foreach ($allresponses as $optionid => $userlist) { 00384 if ($choice->showunanswered || $optionid) { 00385 $totalresponsecount += count($userlist); 00386 } 00387 } 00388 00389 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00390 00391 $hascapfullnames = has_capability('moodle/site:viewfullnames', $context); 00392 00393 $viewresponses = has_capability('mod/choice:readresponses', $context); 00394 switch ($forcepublish) { 00395 case CHOICE_PUBLISH_NAMES: 00396 echo '<div id="tablecontainer">'; 00397 if ($viewresponses) { 00398 echo '<form id="attemptsform" method="post" action="'.$FULLSCRIPT.'" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \''.addslashes_js(get_string('deleteattemptcheck','quiz')).'\' : true);">'; 00399 echo '<div>'; 00400 echo '<input type="hidden" name="id" value="'.$cm->id.'" />'; 00401 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; 00402 echo '<input type="hidden" name="mode" value="overview" />'; 00403 } 00404 00405 echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">"; 00406 echo "<tr>"; 00407 00408 $columncount = array(); // number of votes in each column 00409 if ($choice->showunanswered) { 00410 $columncount[0] = 0; 00411 echo "<th class=\"col0 header\" scope=\"col\">"; 00412 print_string('notanswered', 'choice'); 00413 echo "</th>"; 00414 } 00415 $count = 1; 00416 foreach ($choice->option as $optionid => $optiontext) { 00417 $columncount[$optionid] = 0; // init counters 00418 echo "<th class=\"col$count header\" scope=\"col\">"; 00419 echo format_string($optiontext); 00420 echo "</th>"; 00421 $count++; 00422 } 00423 echo "</tr><tr>"; 00424 00425 if ($choice->showunanswered) { 00426 echo "<td class=\"col$count data\" >"; 00427 // added empty row so that when the next iteration is empty, 00428 // we do not get <table></table> error from w3c validator 00429 // MDL-7861 00430 echo "<table class=\"choiceresponse\"><tr><td></td></tr>"; 00431 if (!empty($allresponses[0])) { 00432 foreach ($allresponses[0] as $user) { 00433 echo "<tr>"; 00434 echo "<td class=\"picture\">"; 00435 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id)); 00436 echo "</td><td class=\"fullname\">"; 00437 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">"; 00438 echo fullname($user, $hascapfullnames); 00439 echo "</a>"; 00440 echo "</td></tr>"; 00441 } 00442 } 00443 echo "</table></td>"; 00444 } 00445 $count = 1; 00446 foreach ($choice->option as $optionid => $optiontext) { 00447 echo '<td class="col'.$count.' data" >'; 00448 00449 // added empty row so that when the next iteration is empty, 00450 // we do not get <table></table> error from w3c validator 00451 // MDL-7861 00452 echo '<table class="choiceresponse"><tr><td></td></tr>'; 00453 if (isset($allresponses[$optionid])) { 00454 foreach ($allresponses[$optionid] as $user) { 00455 $columncount[$optionid] += 1; 00456 echo '<tr><td class="attemptcell">'; 00457 if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) { 00458 echo '<input type="checkbox" name="attemptid[]" value="'. $user->id. '" />'; 00459 } 00460 echo '</td><td class="picture">'; 00461 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id)); 00462 echo '</td><td class="fullname">'; 00463 echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">"; 00464 echo fullname($user, $hascapfullnames); 00465 echo '</a>'; 00466 echo '</td></tr>'; 00467 } 00468 } 00469 $count++; 00470 echo '</table></td>'; 00471 } 00472 echo "</tr><tr>"; 00473 $count = 1; 00474 00475 if ($choice->showunanswered) { 00476 echo "<td></td>"; 00477 } 00478 00479 foreach ($choice->option as $optionid => $optiontext) { 00480 echo "<td align=\"center\" class=\"col$count count\">"; 00481 if ($choice->limitanswers) { 00482 echo get_string("taken", "choice").":"; 00483 echo $columncount[$optionid]; 00484 echo "<br/>"; 00485 echo get_string("limit", "choice").":"; 00486 echo $choice->maxanswers[$optionid]; 00487 } else { 00488 if (isset($columncount[$optionid])) { 00489 echo $columncount[$optionid]; 00490 } 00491 } 00492 echo "</td>"; 00493 $count++; 00494 } 00495 echo "</tr>"; 00496 00498 if ($viewresponses and has_capability('mod/choice:deleteresponses',$context)) { 00499 echo '<tr><td></td><td>'; 00500 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall').'</a> / '; 00501 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('deselectall').'</a> '; 00502 echo ' '; 00503 echo html_writer::label(get_string('withselected', 'choice'), 'menuaction'); 00504 echo html_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>get_string('withselectedusers')), array('id'=>'menuaction')); 00505 $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', '')); 00506 echo '<noscript id="noscriptmenuaction" style="display:inline">'; 00507 echo '<div>'; 00508 echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>'; 00509 echo '</td><td></td></tr>'; 00510 } 00511 00512 echo "</table></div>"; 00513 if ($viewresponses) { 00514 echo "</form></div>"; 00515 } 00516 break; 00517 } 00518 return $display; 00519 } 00520 00529 function choice_delete_responses($attemptids, $choice, $cm, $course) { 00530 global $DB, $CFG; 00531 require_once($CFG->libdir.'/completionlib.php'); 00532 00533 if(!is_array($attemptids) || empty($attemptids)) { 00534 return false; 00535 } 00536 00537 foreach($attemptids as $num => $attemptid) { 00538 if(empty($attemptid)) { 00539 unset($attemptids[$num]); 00540 } 00541 } 00542 00543 $completion = new completion_info($course); 00544 foreach($attemptids as $attemptid) { 00545 if ($todelete = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $attemptid))) { 00546 $DB->delete_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $attemptid)); 00547 // Update completion state 00548 if ($completion->is_enabled($cm) && $choice->completionsubmit) { 00549 $completion->update_state($cm, COMPLETION_INCOMPLETE, $attemptid); 00550 } 00551 } 00552 } 00553 return true; 00554 } 00555 00556 00566 function choice_delete_instance($id) { 00567 global $DB; 00568 00569 if (! $choice = $DB->get_record("choice", array("id"=>"$id"))) { 00570 return false; 00571 } 00572 00573 $result = true; 00574 00575 if (! $DB->delete_records("choice_answers", array("choiceid"=>"$choice->id"))) { 00576 $result = false; 00577 } 00578 00579 if (! $DB->delete_records("choice_options", array("choiceid"=>"$choice->id"))) { 00580 $result = false; 00581 } 00582 00583 if (! $DB->delete_records("choice", array("id"=>"$choice->id"))) { 00584 $result = false; 00585 } 00586 00587 return $result; 00588 } 00589 00599 function choice_get_participants($choiceid) { 00600 global $DB; 00601 00602 //Get students 00603 $students = $DB->get_records_sql("SELECT DISTINCT u.id, u.id 00604 FROM {user} u, 00605 {choice_answers} a 00606 WHERE a.choiceid = ? AND 00607 u.id = a.userid", array($choiceid)); 00608 00609 //Return students array (it contains an array of unique users) 00610 return ($students); 00611 } 00612 00621 function choice_get_option_text($choice, $id) { 00622 global $DB; 00623 00624 if ($result = $DB->get_record("choice_options", array("id" => $id))) { 00625 return $result->text; 00626 } else { 00627 return get_string("notanswered", "choice"); 00628 } 00629 } 00630 00638 function choice_get_choice($choiceid) { 00639 global $DB; 00640 00641 if ($choice = $DB->get_record("choice", array("id" => $choiceid))) { 00642 if ($options = $DB->get_records("choice_options", array("choiceid" => $choiceid), "id")) { 00643 foreach ($options as $option) { 00644 $choice->option[$option->id] = $option->text; 00645 $choice->maxanswers[$option->id] = $option->maxanswers; 00646 } 00647 return $choice; 00648 } 00649 } 00650 return false; 00651 } 00652 00656 function choice_get_view_actions() { 00657 return array('view','view all','report'); 00658 } 00659 00663 function choice_get_post_actions() { 00664 return array('choose','choose again'); 00665 } 00666 00667 00674 function choice_reset_course_form_definition(&$mform) { 00675 $mform->addElement('header', 'choiceheader', get_string('modulenameplural', 'choice')); 00676 $mform->addElement('advcheckbox', 'reset_choice', get_string('removeresponses','choice')); 00677 } 00678 00684 function choice_reset_course_form_defaults($course) { 00685 return array('reset_choice'=>1); 00686 } 00687 00697 function choice_reset_userdata($data) { 00698 global $CFG, $DB; 00699 00700 $componentstr = get_string('modulenameplural', 'choice'); 00701 $status = array(); 00702 00703 if (!empty($data->reset_choice)) { 00704 $choicessql = "SELECT ch.id 00705 FROM {choice} ch 00706 WHERE ch.course=?"; 00707 00708 $DB->delete_records_select('choice_answers', "choiceid IN ($choicessql)", array($data->courseid)); 00709 $status[] = array('component'=>$componentstr, 'item'=>get_string('removeresponses', 'choice'), 'error'=>false); 00710 } 00711 00713 if ($data->timeshift) { 00714 shift_course_mod_dates('choice', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid); 00715 $status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged'), 'error'=>false); 00716 } 00717 00718 return $status; 00719 } 00720 00731 function choice_get_response_data($choice, $cm, $groupmode) { 00732 global $CFG, $USER, $DB; 00733 00734 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00735 00737 if ($groupmode > 0) { 00738 $currentgroup = groups_get_activity_group($cm); 00739 } else { 00740 $currentgroup = 0; 00741 } 00742 00744 $allresponses = array(); 00745 00748 $allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup, user_picture::fields('u', array('idnumber')), 'u.lastname ASC,u.firstname ASC'); 00749 00751 $rawresponses = $DB->get_records('choice_answers', array('choiceid' => $choice->id)); 00752 00754 00755 if ($rawresponses) { 00756 foreach ($rawresponses as $response) { 00757 if (isset($allresponses[0][$response->userid])) { // This person is enrolled and in correct group 00758 $allresponses[0][$response->userid]->timemodified = $response->timemodified; 00759 $allresponses[$response->optionid][$response->userid] = clone($allresponses[0][$response->userid]); 00760 unset($allresponses[0][$response->userid]); // Remove from unanswered column 00761 } 00762 } 00763 } 00764 return $allresponses; 00765 } 00766 00772 function choice_get_extra_capabilities() { 00773 return array('moodle/site:accessallgroups'); 00774 } 00775 00787 function choice_supports($feature) { 00788 switch($feature) { 00789 case FEATURE_GROUPS: return true; 00790 case FEATURE_GROUPINGS: return true; 00791 case FEATURE_GROUPMEMBERSONLY: return true; 00792 case FEATURE_MOD_INTRO: return true; 00793 case FEATURE_COMPLETION_TRACKS_VIEWS: return true; 00794 case FEATURE_COMPLETION_HAS_RULES: return true; 00795 case FEATURE_GRADE_HAS_GRADE: return false; 00796 case FEATURE_GRADE_OUTCOMES: return false; 00797 case FEATURE_BACKUP_MOODLE2: return true; 00798 case FEATURE_SHOW_DESCRIPTION: return true; 00799 00800 default: return null; 00801 } 00802 } 00803 00810 function choice_extend_settings_navigation(settings_navigation $settings, navigation_node $choicenode) { 00811 global $PAGE; 00812 00813 if (has_capability('mod/choice:readresponses', $PAGE->cm->context)) { 00814 00815 $groupmode = groups_get_activity_groupmode($PAGE->cm); 00816 if ($groupmode) { 00817 groups_get_activity_group($PAGE->cm, true); 00818 } 00819 // We only actually need the choice id here 00820 $choice = new stdClass; 00821 $choice->id = $PAGE->cm->instance; 00822 $allresponses = choice_get_response_data($choice, $PAGE->cm, $groupmode); // Big function, approx 6 SQL calls per user 00823 00824 $responsecount =0; 00825 foreach($allresponses as $optionid => $userlist) { 00826 if ($optionid) { 00827 $responsecount += count($userlist); 00828 } 00829 } 00830 $choicenode->add(get_string("viewallresponses", "choice", $responsecount), new moodle_url('/mod/choice/report.php', array('id'=>$PAGE->cm->id))); 00831 } 00832 } 00833 00844 function choice_get_completion_state($course, $cm, $userid, $type) { 00845 global $CFG,$DB; 00846 00847 // Get choice details 00848 $choice = $DB->get_record('choice', array('id'=>$cm->instance), '*', 00849 MUST_EXIST); 00850 00851 // If completion option is enabled, evaluate it and return true/false 00852 if($choice->completionsubmit) { 00853 return $DB->record_exists('choice_answers', array( 00854 'choiceid'=>$choice->id, 'userid'=>$userid)); 00855 } else { 00856 // Completion option is not enabled so just return $type 00857 return $type; 00858 } 00859 } 00860 00867 function choice_page_type_list($pagetype, $parentcontext, $currentcontext) { 00868 $module_pagetype = array('mod-choice-*'=>get_string('page-mod-choice-x', 'choice')); 00869 return $module_pagetype; 00870 }