diff --git a/mod/feedback/analysis.php b/mod/feedback/analysis.php index 5a79c00d78c..78f46d52b39 100644 --- a/mod/feedback/analysis.php +++ b/mod/feedback/analysis.php @@ -127,11 +127,10 @@ if($check_anonymously) { foreach($items as $item) { if($item->hasvalue == 0) continue; echo ''; + //get the class of item-typ - $itemclass = 'feedback_item_'.$item->typ; - //get the instance of the item-class - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); + $itemnr++; if($feedback->autonumbering) { $printnr = $itemnr.'.'; diff --git a/mod/feedback/analysis_course.php b/mod/feedback/analysis_course.php index 3ea09ba3902..a6ccf103cab 100644 --- a/mod/feedback/analysis_course.php +++ b/mod/feedback/analysis_course.php @@ -168,10 +168,7 @@ if ($courseitemfilter > 0) { if($item->hasvalue == 0) continue; echo '
'; //get the class from item-typ - $itemclass = 'feedback_item_'.$item->typ; - //get the instance of the item-class - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $itemnr++; if($feedback->autonumbering) { $printnr = $itemnr.'.'; diff --git a/mod/feedback/analysis_to_excel.php b/mod/feedback/analysis_to_excel.php index baf26c5b6b6..de2923da7ca 100644 --- a/mod/feedback/analysis_to_excel.php +++ b/mod/feedback/analysis_to_excel.php @@ -185,9 +185,7 @@ if (empty($items)) { } foreach($items as $item) { //get the class of item-typ - $itemclass = 'feedback_item_'.$item->typ; - //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $rowOffset1 = $itemobj->excelprint_item($worksheet1, $rowOffset1, $xlsFormats, $item, $mygroupid, $coursefilter); } @@ -295,8 +293,7 @@ function feedback_excelprint_detailed_items(&$worksheet, $xlsFormats, $completed foreach($items as $item) { $value = $DB->get_record('feedback_value', array('item'=>$item->id, 'completed'=>$completed->id)); - $itemclass = 'feedback_item_'.$item->typ; - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $printval = $itemobj->get_printval($item, $value); // $worksheet->setFormat(''); diff --git a/mod/feedback/edit_item.php b/mod/feedback/edit_item.php index b50446a95c8..2a0807fa9a3 100644 --- a/mod/feedback/edit_item.php +++ b/mod/feedback/edit_item.php @@ -84,8 +84,7 @@ if($id and $item = $DB->get_record('feedback_item', array('id'=>$id))) { require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php'); -$itemclass = 'feedback_item_'.$typ; -$itemobj = new $itemclass(); +$itemobj = feedback_get_item_class($typ); $itemobj->build_editform($item, $feedback, $cm); @@ -124,48 +123,6 @@ if(isset($error)) { feedback_print_errors(); $itemobj->show_editform(); -/* -echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); - echo '
'; - echo ''; - -//this div makes the buttons stand side by side -echo '
'; -$itemclass = 'feedback_item_'.$typ; -$itemobj = new $itemclass(); -$itemobj->show_edit($item, $usehtmleditor); -echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - -//choose the position -$lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); -echo get_string('position', 'feedback').' '; -echo '
'; - -////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////////////// -if(!empty($item->id)){ - echo ''; - echo ''; -}else{ - echo ''; - echo ''; -} -echo ''; -echo ''; -////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////////////// -*/ // echo $OUTPUT->box_end(); if ($typ!='label') { diff --git a/mod/feedback/item/captcha/lib.php b/mod/feedback/item/captcha/lib.php index c334a75d902..fb87fe4ea82 100644 --- a/mod/feedback/item/captcha/lib.php +++ b/mod/feedback/item/captcha/lib.php @@ -5,74 +5,73 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); class feedback_item_captcha extends feedback_item_base { var $type = "captcha"; var $commonparams; - var $item_form; - var $item; + var $item_form = false; + var $item = false; + var $feedback = false; function init() { } function build_editform($item, $feedback, $cm) { - global $DB, $CFG; - require_once('captcha_form.php'); - - //get the lastposition number of the feedback_items - $position = $item->position; - $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); - if($position == -1){ - $i_formselect_last = $lastposition + 1; - $i_formselect_value = $lastposition + 1; - $item->position = $lastposition + 1; - }else { - $i_formselect_last = $lastposition; - $i_formselect_value = $item->position; - } - //the elements for position dropdownlist - $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); + global $DB; - $item->presentation = empty($item->presentation) ? 3 : $item->presentation; - $item->required = 1; + $editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$cm->id)); - //all items for dependitem - $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); - $commonparams = array('cmid'=>$cm->id, - 'id'=>isset($item->id) ? $item->id : NULL, - 'typ'=>$item->typ, - 'items'=>$feedbackitems, - 'feedback'=>$feedback->id); + //ther are no settings for recaptcha + if(isset($item->id) AND $item->id > 0) { + notice(get_string('there_are_no_settings_for_recaptcha', 'feedback'), $editurl->out()); + exit; + } + + //only one recaptcha can be in a feedback + if($DB->record_exists('feedback_item', array('feedback'=>$feedback->id, 'typ'=>$this->type))) { + notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out()); + exit; + } + + $this->item = $item; + $this->feedback = $feedback; + $this->item_form = true; //dummy + + $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); - //build the form - $this->item_form = new feedback_captcha_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position)); + $this->item->feedback = $feedback->id; + $this->item->template = 0; + $this->item->name = get_string('captcha', 'feedback'); + $this->item->label = get_string('captcha', 'feedback'); + $this->item->presentation = ''; + $this->item->typ = $this->type; + $this->item->hasvalue = $this->get_hasvalue(); + $this->item->position = $lastposition + 1; + $this->item->required = 1; + $this->item->dependitem = 0; + $this->item->dependvalue = ''; + $this->item->options = ''; } - //this function only can used after the call of build_editform() function show_editform() { - $this->item_form->display(); } function is_cancelled() { - return $this->item_form->is_cancelled(); + return false; } function get_data() { - if($this->item = $this->item_form->get_data()) { - return true; - } - return false; + return true; } function save_item() { global $DB; - if(!$item = $this->item_form->get_data()) { + if(!$this->item) { return false; } - $item->hasvalue = $this->get_hasvalue(); if(!$item->id) { - $item->id = $DB->insert_record('feedback_item', $item); + $item->id = $DB->insert_record('feedback_item', $this->item); }else { - $DB->update_record('feedback_item', $item); + $DB->update_record('feedback_item', $this->item); } return $DB->get_record('feedback_item', array('id'=>$item->id)); @@ -91,7 +90,7 @@ class feedback_item_captcha extends feedback_item_base { return $itemnr; } - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { + function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { return $rowOffset; } @@ -103,13 +102,10 @@ class feedback_item_captcha extends feedback_item_base { * @return void */ function print_item_preview($item) { - global $SESSION, $CFG, $DB, $OUTPUT; + global $DB; $align = right_to_left() ? 'right' : 'left'; - $presentation = $item->presentation; - $SESSION->feedback->item->captcha->charcount = $presentation; - $cmid = 0; $feedbackid = $item->feedback; if($feedbackid > 0) { @@ -119,36 +115,14 @@ class feedback_item_captcha extends feedback_item_base { } } - if(isset($SESSION->feedback->item->captcha->checked)) { - $checked = $SESSION->feedback->item->captcha->checked == true; - unset($SESSION->feedback->item->captcha->checked); - }else { - $checked = false; - } - - $requiredmark = ($item->required == 1)?'':''; + $requiredmark = ''; //print the question and label echo ''; - //print the presentation - echo ''; } /** @@ -161,13 +135,11 @@ class feedback_item_captcha extends feedback_item_base { * @return void */ function print_item_complete($item, $value = '', $highlightrequire = false) { - global $SESSION, $CFG, $DB, $OUTPUT; + global $SESSION, $CFG, $DB, $USER; + require_once($CFG->libdir.'/recaptchalib.php'); $align = right_to_left() ? 'right' : 'left'; - $presentation = $item->presentation; - $SESSION->feedback->item->captcha->charcount = $presentation; - $cmid = 0; $feedbackid = $item->feedback; if($feedbackid > 0) { @@ -177,42 +149,57 @@ class feedback_item_captcha extends feedback_item_base { } } - if(isset($SESSION->feedback->item->captcha->checked)) { - $checked = $SESSION->feedback->item->captcha->checked == true; - unset($SESSION->feedback->item->captcha->checked); - }else { - $checked = false; - } - //check if an false value even the value is not required - if(!$item->required AND $value != '' AND $SESSION->feedback->item->captcha->checkchar != $value) { + if($highlightrequire AND !$this->check_value($value, $item)) { $falsevalue = true; }else { $falsevalue = false; } - if(($highlightrequire AND $item->required AND !$checked) OR $falsevalue) { - $highlight = ' missingrequire'; + if($falsevalue) { + $highlight = 'missingrequire'; }else { $highlight = ''; } - $requiredmark = ($item->required == 1)?'':''; + $requiredmark = ''; - //print the question and label - echo ''; + return; + } + + $strincorrectpleasetryagain = get_string('incorrectpleasetryagain', 'auth'); + $strenterthewordsabove = get_string('enterthewordsabove', 'auth'); + $strenterthenumbersyouhear = get_string('enterthenumbersyouhear', 'auth'); + $strgetanothercaptcha = get_string('getanothercaptcha', 'auth'); + $strgetanaudiocaptcha = get_string('getanaudiocaptcha', 'auth'); + $strgetanimagecaptcha = get_string('getanimagecaptcha', 'auth'); + + $recaptureoptions = Array('theme'=>'custom', 'custom_theme_widget'=>'recaptcha_widget'); + $html = html_writer::script(js_writer::set_variable('RecaptchaOptions', $recaptureoptions)); + $html .= ' + + '; + //we have to rename the challengefield + $captchahtml = recaptcha_get_html($CFG->recaptchapublickey, NULL); + echo $html.$captchahtml; } /** @@ -224,57 +211,52 @@ class feedback_item_captcha extends feedback_item_base { * @return void */ function print_item_show_value($item, $value = '') { - global $SESSION, $CFG, $DB, $OUTPUT; + global $DB; $align = right_to_left() ? 'right' : 'left'; - $presentation = $item->presentation; - $SESSION->feedback->item->captcha->charcount = $presentation; - $cmid = 0; - - if(isset($SESSION->feedback->item->captcha->checked)) { - $checked = $SESSION->feedback->item->captcha->checked == true; - unset($SESSION->feedback->item->captcha->checked); - }else { - $checked = false; + $feedbackid = $item->feedback; + if($feedbackid > 0) { + $feedback = $DB->get_record('feedback', array('id'=>$feedbackid)); + if($cm = get_coursemodule_from_instance("feedback", $feedback->id, $feedback->course)) { + $cmid = $cm->id; + } } - $requiredmark = ($item->required == 1)?'':''; + $requiredmark = ''; //print the question and label echo ''; - - //print the presentation - echo ''; } function check_value($value, $item) { - global $SESSION; - //if the item is not required, so the check is true if no value is given - if((!isset($value) OR $value == '') AND $item->required != 1) return true; - if($SESSION->feedback->item->captcha->checkchar == $value) { - $SESSION->feedback->item->captcha->checked = true; + global $SESSION, $CFG, $USER; + require_once($CFG->libdir.'/recaptchalib.php'); + + $challenge = optional_param('recaptcha_challenge_field', '', PARAM_RAW); + + if($value == $USER->sesskey AND $challenge == '') { return true; } + $remoteip = getremoteaddr(null); + $response = recaptcha_check_answer($CFG->recaptchaprivatekey, $remoteip, $challenge, $value); + if($response->is_valid) { + $SESSION->feedback->captchacheck = $USER->sesskey; + return true; + } + unset($SESSION->feedback->captchacheck); + return false; } function create_value($data) { - $data = clean_text($data); - return $data; + global $USER; + return $USER->sesskey; } //compares the dbvalue with the dependvalue @@ -288,11 +270,14 @@ class feedback_item_captcha extends feedback_item_base { } function get_presentation($data) { - return $data->count_of_nums; + return ''; } function get_hasvalue() { return 1; } + + function can_switch_require() { + return false; + } } -?> diff --git a/mod/feedback/item/feedback_item_class.php b/mod/feedback/item/feedback_item_class.php index e84623da312..ddcfcd71496 100644 --- a/mod/feedback/item/feedback_item_class.php +++ b/mod/feedback/item/feedback_item_class.php @@ -1,64 +1,41 @@ init(); - } /** - * Fake constructor to keep PHP5 happy + * constructor * */ function __construct() { - $this->feedback_item_base(); + $this->init(); } - /** - * prints the item-related sequenz on the edit-item form - * - * @param $item the db-object from feedback_item - * @param $usehtmleditor defines whether the editor should be shown or not - */ - function show_edit($item, $usehtmleditor = false) { + //this function only can used after the call of build_editform() + function show_editform() { + $this->item_form->display(); + } + + function is_cancelled() { + return $this->item_form->is_cancelled(); } - /** - * returns an Array with three values(typ, name, XXX) - * XXX is also an Array (count of responses on type $this->type) - * each element is a structure (answertext, answercount) - * @param $item the db-object from feedback_item - * @param $groupid if given - * @param $courseid if given - * @return array - */ - function get_analysed($item, $groupid = false, $courseid = false) { - return array(); - } - - /** - * @param object $item the db-object from feedback_item - * @param string $value a item-related value from feedback_values - * @return string - */ - function get_printval($item, $value) { - return ''; - } - - /** - * @param $item the db-object from feedback_item - * @param string $itemnr - * @param integer $groupid - * @param integer $courseid - * @return integer the new itemnr - */ - function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { - return 0; + function get_data() { + if($this->item = $this->item_form->get_data()) { + return true; + } + return false; } + + abstract function init(); + abstract function build_editform($item, $feedback, $cm); + abstract function save_item(); + abstract function check_value($value, $item); + abstract function create_value($data); + abstract function compare_value($item, $dbvalue, $dependvalue); + abstract function get_presentation($data); + abstract function get_hasvalue(); + abstract function can_switch_require(); /** * @param object $worksheet a reference to the pear_spreadsheet-object @@ -68,36 +45,91 @@ class feedback_item_base { * @param integer $courseid * @return integer the new rowOffset */ - function excelprint_item(&$worksheet, $rowOffset, $item, $groupid, $courseid = false) { - return $rowOffset; - } + abstract function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false); - function print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ - } + /** + * @param $item the db-object from feedback_item + * @param string $itemnr + * @param integer $groupid + * @param integer $courseid + * @return integer the new itemnr + */ + abstract function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false); + + /** + * @param object $item the db-object from feedback_item + * @param string $value a item-related value from feedback_values + * @return string + */ + abstract function get_printval($item, $value); + + /** + * returns an Array with three values(typ, name, XXX) + * XXX is also an Array (count of responses on type $this->type) + * each element is a structure (answertext, answercount) + * @param $item the db-object from feedback_item + * @param $groupid if given + * @param $courseid if given + * @return array + */ + abstract function get_analysed($item, $groupid = false, $courseid = false); + + /** + * print the item at the edit-page of feedback + * + * @global object + * @param object $item + * @return void + */ + abstract function print_item_preview($item); + + /** + * print the item at the complete-page of feedback + * + * @global object + * @param object $item + * @param string $value + * @param bool $highlightrequire + * @return void + */ + abstract function print_item_complete($item, $value = '', $highlightrequire = false); - function check_value($value, $item) { - return true; - } + /** + * print the item at the complete-page of feedback + * + * @global object + * @param object $item + * @param string $value + * @return void + */ + abstract function print_item_show_value($item, $value = ''); - function create_value($data) { - return ''; - } - - function get_presentation($data) { - return ''; - } - - function get_hasvalue() { - return 0; - } } //a dummy class to realize pagebreaks class feedback_item_pagebreak extends feedback_item_base { var $type = "pagebreak"; - function init() { - } + function show_editform() {} + function is_cancelled() {} + function get_data() {} + function init() {} + function build_editform($item, $feedback, $cm) {} + function save_item() {} + function check_value($value, $item) {} + function create_value($data) {} + function compare_value($item, $dbvalue, $dependvalue) {} + function get_presentation($data) {} + function get_hasvalue() {} + function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {} + function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {} + function get_printval($item, $value) {} + function get_analysed($item, $groupid = false, $courseid = false) {} + function print_item_preview($item) {} + function print_item_complete($item, $value = '', $highlightrequire = false) {} + function print_item_show_value($item, $value = '') {} + function can_switch_require(){} + } diff --git a/mod/feedback/item/info/lib.php b/mod/feedback/item/info/lib.php index 56fdecaed12..e3ac71b4b6e 100644 --- a/mod/feedback/item/info/lib.php +++ b/mod/feedback/item/info/lib.php @@ -306,5 +306,8 @@ class feedback_item_info extends feedback_item_base { function get_hasvalue() { return 1; } + + function can_switch_require() { + return false; + } } -?> diff --git a/mod/feedback/item/label/lib.php b/mod/feedback/item/label/lib.php index 5e85944c103..3ed84e27943 100644 --- a/mod/feedback/item/label/lib.php +++ b/mod/feedback/item/label/lib.php @@ -208,5 +208,14 @@ class feedback_item_label extends feedback_item_base { function get_hasvalue() { return 0; } + + function can_switch_require() { + return false; + } + + function check_value($value, $item) {} + function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {} + function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {} + function get_printval($item, $value) {} + function get_analysed($item, $groupid = false, $courseid = false) {} } -?> \ No newline at end of file diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index 29db52175be..ff7d41f8377 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -700,6 +700,8 @@ class feedback_item_multichoice extends feedback_item_base { return false; } + + function can_switch_require() { + return true; + } } - -?> diff --git a/mod/feedback/item/multichoicerated/lib.php b/mod/feedback/item/multichoicerated/lib.php index 8ea36fc263f..9d361fc890b 100644 --- a/mod/feedback/item/multichoicerated/lib.php +++ b/mod/feedback/item/multichoicerated/lib.php @@ -582,6 +582,8 @@ class feedback_item_multichoicerated extends feedback_item_base { return false; } + function can_switch_require() { + return true; + } } -?> diff --git a/mod/feedback/item/numeric/lib.php b/mod/feedback/item/numeric/lib.php index bbca8099a9e..4daae15336e 100644 --- a/mod/feedback/item/numeric/lib.php +++ b/mod/feedback/item/numeric/lib.php @@ -411,5 +411,8 @@ class feedback_item_numeric extends feedback_item_base { function get_hasvalue() { return 1; } + + function can_switch_require() { + return true; + } } -?> diff --git a/mod/feedback/item/textarea/lib.php b/mod/feedback/item/textarea/lib.php index 7a45e45e0f4..bc22d8f7470 100644 --- a/mod/feedback/item/textarea/lib.php +++ b/mod/feedback/item/textarea/lib.php @@ -85,7 +85,7 @@ class feedback_item_textarea extends feedback_item_base { //liefert eine Struktur ->name, ->data = array(mit Antworten) - function get_analysed($item, $groupid, $courseid = false) { + function get_analysed($item, $groupid = false, $courseid = false) { global $DB; $aVal = null; @@ -270,5 +270,8 @@ class feedback_item_textarea extends feedback_item_base { function get_hasvalue() { return 1; } + + function can_switch_require() { + return true; + } } -?> diff --git a/mod/feedback/item/textfield/lib.php b/mod/feedback/item/textfield/lib.php index 669c2a89a4a..526f3f11c6e 100644 --- a/mod/feedback/item/textfield/lib.php +++ b/mod/feedback/item/textfield/lib.php @@ -264,5 +264,8 @@ class feedback_item_textfield extends feedback_item_base { function get_hasvalue() { return 1; } + + function can_switch_require() { + return true; + } } -?> diff --git a/mod/feedback/lang/en/feedback.php b/mod/feedback/lang/en/feedback.php index 9100b41cc0b..6b9a558967d 100644 --- a/mod/feedback/lang/en/feedback.php +++ b/mod/feedback/lang/en/feedback.php @@ -198,6 +198,7 @@ $string['numeric_range_to'] = 'Range to'; $string['of'] = 'of'; $string['oldvaluespreserved'] = 'All old questions and the assigned values will be preserved'; $string['oldvalueswillbedeleted'] = 'The current questions and all your user\'s responses will be deleted'; +$string['only_one_captcha_allowed'] = 'Only one captcha is allowed in a feedback'; $string['overview'] = 'Overview'; $string['page'] = 'Page'; $string['page_after_submit'] = 'Page after submit'; @@ -262,6 +263,7 @@ $string['textarea_width'] = 'Width'; $string['textfield'] = 'Short text answer'; $string['textfield_maxlength'] = 'Maximum characters accepted'; $string['textfield_size'] = 'Textfield width'; +$string['there_are_no_settings_for_recaptcha'] = 'There are no settings for captcha'; $string['this_feedback_is_already_submitted'] = 'You\'ve already completed this activity.'; $string['timeclose'] = 'Time to close'; $string['timeclose_help'] = 'You can specify times when the feedback is accessible for people to answer the questions. If the checkbox is not ticked there is no limit defined.'; diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 6730400ca75..b49009d79d5 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -1113,6 +1113,25 @@ function feedback_get_template_list($course, $onlyown = false) { //////////////////////////////////////////////// //////////////////////////////////////////////// +/** + * load the lib.php from item-plugin-dir and returns the instance of the itemclass + * + * @global object + * @param object $item + * @return object the instanz of itemclass + */ +function feedback_get_item_class($typ) { + global $CFG; + + //get the class of item-typ + $itemclass = 'feedback_item_'.$typ; + //get the instance of item-class + if (!class_exists($itemclass)) { + require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php'); + } + return new $itemclass(); +} + /** * load the available item plugins from given subdirectory of $CFG->dirroot * the default is "mod/feedback/item" @@ -1213,10 +1232,7 @@ function feedback_create_item($data) { $item->label = get_string('no_itemlabel', 'feedback'); } - //get the used class from item-typ - $itemclass = 'feedback_item_'.$data->typ; - //get the instance of the item class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($data->typ); // $item->presentation = $itemobj->get_presentation($data); $item->presentation = ''; //the date comes from postupdate() of the itemobj @@ -1320,9 +1336,14 @@ function feedback_delete_all_items($feedbackid){ * @return boolean */ function feedback_switch_item_required($item) { - global $DB; + global $DB, $CFG; - return $DB->set_field('feedback_item', 'required', (int)!(bool)$item->required, array('id'=>$item->id)); + $itemobj = feedback_get_item_class($item->typ); + + if($itemobj->can_switch_require()) { + $DB->set_field('feedback_item', 'required', (int)!(bool)$item->required, array('id'=>$item->id)); + } + return true; } /** @@ -1457,13 +1478,8 @@ function feedback_print_item_preview($item){ if($item->typ == 'pagebreak') { return; } - //get the class of the given item-typ - $itemclass = 'feedback_item_'.$item->typ; - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $itemobj->print_item_preview($item); } @@ -1482,13 +1498,8 @@ function feedback_print_item_complete($item, $value = false, $highlightrequire = return; } - //get the class of the given item-typ - $itemclass = 'feedback_item_'.$item->typ; - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $itemobj->print_item_complete($item, $value, $highlightrequire); } @@ -1506,13 +1517,8 @@ function feedback_print_item_show_value($item, $value = false){ return; } - //get the class of the given item-typ - $itemclass = 'feedback_item_'.$item->typ; - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); $itemobj->print_item_show_value($item, $value); } @@ -1833,12 +1839,9 @@ function feedback_compare_item_value($completedid, $itemid, $dependvalue, $tmp = //get the class of the given item-typ $item = $DB->get_record('feedback_item', array('id'=>$itemid)); - $itemclass = 'feedback_item_'.$item->typ; - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } + //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); return $itemobj->compare_value($item, $dbvalue, $dependvalue); //true or false } @@ -1882,15 +1885,8 @@ function feedback_check_values($firstitem, $lastitem) { return false; } - //get the class of the item-typ - $itemclass = 'feedback_item_'.$item->typ; - - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } - //get the instance of the item-class - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); //now we let check the value by the item-class if(!$itemobj->check_value($value, $item)) { @@ -1951,13 +1947,7 @@ function feedback_create_values($usrid, $timemodified, $tmp = false, $guestid = $value->course_id = $courseid; //get the class of item-typ - $itemclass = 'feedback_item_'.$item->typ; - - //get the instance of item-class - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); //the kind of values can be absolutely different so we run create_value directly by the item-class $value->value = $itemobj->create_value($itemvalue); @@ -2003,13 +1993,7 @@ function feedback_update_values($completed, $tmp = false) { $newvalue->course_id = $courseid; //get the class of item-typ - $itemclass = 'feedback_item_'.$item->typ; - - //get the instance of item-class - if (!class_exists($itemclass)) { - require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); - } - $itemobj = new $itemclass(); + $itemobj = feedback_get_item_class($item->typ); //the kind of values can be absolutely different so we run create_value directly by the item-class $newvalue->value = $itemobj->create_value($itemvalue);