From 0dec3f97b5c4530192c5d7fbe4a81e3b73786c92 Mon Sep 17 00:00:00 2001 From: Peter Mayer Date: Mon, 16 Oct 2023 18:48:18 +0200 Subject: [PATCH] Fix coding style errors --- classes/event/course_module_viewed.php | 1 - classes/helper.php | 4 - classes/helper_add_page.php | 6 -- classes/plugininfo/mootimetertool.php | 3 +- classes/toolhelper.php | 91 ------------------- db/upgrade.php | 2 +- lib.php | 9 -- mod_form.php | 8 -- tools/quiz/classes/external/get_answers.php | 8 -- .../classes/external/store_answeroption.php | 11 +-- tools/quiz/classes/quiz.php | 52 +++-------- .../classes/external/store_answer.php | 15 ++- tools/wordcloud/classes/wordcloud.php | 33 ++----- view.php | 4 +- 14 files changed, 35 insertions(+), 212 deletions(-) diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index d4c9a690..9700126d 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -24,7 +24,6 @@ */ namespace mod_mootimeter\event; -defined('MOODLE_INTERNAL') || die(); /** * The mod_mootimeter course module viewed event class. diff --git a/classes/helper.php b/classes/helper.php index d8306ef6..13b083fd 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -27,9 +27,6 @@ use coding_exception; use dml_exception; -use stdClass; - -defined('MOODLE_INTERNAL') || die(); /** * The mod_mootimeter helper class. @@ -221,7 +218,6 @@ public function get_rendered_page_content(object $page, object $cm, bool $withwr 'cmid' => $cm->id, 'title' => s($page->title), 'question' => s(self::get_tool_config($page, 'question')), - // 'isNewPage' => s($page->isNewPage), 'isediting' => $PAGE->user_is_editing(), ]; $params = array_merge($params, $toolhelper->get_renderer_params($page)); diff --git a/classes/helper_add_page.php b/classes/helper_add_page.php index 6dd289a4..f89fb1d6 100644 --- a/classes/helper_add_page.php +++ b/classes/helper_add_page.php @@ -25,12 +25,6 @@ namespace mod_mootimeter; -use coding_exception; -use dml_exception; -use stdClass; - -defined('MOODLE_INTERNAL') || die(); - /** * The mod_mootimeter helper class to add new page. * diff --git a/classes/plugininfo/mootimetertool.php b/classes/plugininfo/mootimetertool.php index 5fa0733a..9fd2ffa0 100644 --- a/classes/plugininfo/mootimetertool.php +++ b/classes/plugininfo/mootimetertool.php @@ -24,7 +24,6 @@ */ namespace mod_mootimeter\plugininfo; -defined('MOODLE_INTERNAL') || die(); use coding_exception; use cache_exception; @@ -140,7 +139,7 @@ public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $ return; } - if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) { + if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) { return; } diff --git a/classes/toolhelper.php b/classes/toolhelper.php index f6f83d3e..219d9d23 100644 --- a/classes/toolhelper.php +++ b/classes/toolhelper.php @@ -25,13 +25,9 @@ namespace mod_mootimeter; -defined('MOODLE_INTERNAL') || die(); - use coding_exception; use cache_exception; -use core\plugininfo\base, core_plugin_manager, moodle_url; use dml_exception; -use stdClass; /** * The toolhelper methods must be implemented of each tool. @@ -77,15 +73,6 @@ abstract public function get_renderer_params(object $page); */ abstract public function get_col_settings_tool(object $page); - /** - * Get the settings definitions. - * - * @param object $page - * @return array - * @deprecated since 28.09.2023 - */ - // abstract public function get_tool_setting_definitions(object $page); - /** * Will be executed after the page is created. * @param object $page @@ -93,84 +80,6 @@ abstract public function get_col_settings_tool(object $page); */ abstract public function hook_after_new_page_created(object $page); - /** - * Get renderes setting output. - * - * @param mixed $page - * @return string - * @deprecated since 28.09.2023 - */ - // public function get_tool_settings($page): string { - // global $OUTPUT; - - // $settings = $this->get_tool_setting_definitions($page); - // return $OUTPUT->render_from_template("mod_mootimeter/settings", $settings); - // } - - /** - * Get all tool settings parameters. - * - * @param object $page - * @return array - * @throws coding_exception - * @deprecated since 28.09.2023 - */ - // public function get_tool_settings_parameters(object $page): array { - - // $settings = $this->get_tool_setting_definitions($page); - - // $parameters = []; - - // if (empty($settings['settingsarray'])) { - // return $parameters; - // } - - // foreach ($settings['settingsarray'] as $setting) { - - // foreach ($setting as $key => $value) { - // switch ($key) { - // case 'text': - // $parameters[$setting['name']] = [ - // 'tool' => $page->tool, - // 'type' => $key, - // 'pageid' => $page->id, - // 'name' => $setting['name'], - // 'value' => optional_param($setting['name'], "", PARAM_TEXT), - // ]; - // break; - // case 'number': - // $parameters[$setting['name']] = [ - // 'tool' => $page->tool, - // 'type' => $key, - // 'pageid' => $page->id, - // 'name' => $setting['name'], - // 'value' => optional_param($setting['name'], "", PARAM_INT), - // ]; - // break; - // case 'select': - // $parameters[$setting['name']] = [ - // 'tool' => $page->tool, - // 'type' => $key, - // 'pageid' => $page->id, - // 'name' => $setting['name'], - // 'value' => optional_param($setting['name'], "", PARAM_TEXT), - // ]; - // break; - // case 'checkbox': - // $parameters[$setting['name']] = [ - // 'tool' => $page->tool, - // 'type' => $key, - // 'pageid' => $page->id, - // 'name' => $setting['name'], - // 'value' => optional_param($setting['name'], "", PARAM_INT), - // ]; - // break; - // } - // } - // } - // return $parameters; - // } - /** * Checks if a select option is selected. * diff --git a/db/upgrade.php b/db/upgrade.php index 670ae539..acadc33b 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -71,7 +71,7 @@ function xmldb_mootimeter_upgrade($oldversion) { $dbman->drop_field($table, $field); } - // Create new field question + // Create new field question. $field = new xmldb_field('question', XMLDB_TYPE_TEXT, null, null, null, null, null, 'title'); // Conditionally launch add field question. diff --git a/lib.php b/lib.php index 9896a9ac..43e76b76 100644 --- a/lib.php +++ b/lib.php @@ -298,15 +298,6 @@ function mootimeter_extend_navigation($mootimeternode, $course, $module, $cm) { * @param navigation_node $mootimeternode {@see navigation_node} */ function mootimeter_extend_settings_navigation($settingsnav, $mootimeternode = null) { - - // Keeping this for documentation purposes. - - // if (has_capability('mod/mootimeter:moderator', $settingsnav->get_page()->cm->context)) { - // $url = new moodle_url('/mod/mootimeter/teacherview.php', ['id' => $settingsnav->get_page()->cm->id]); - // $linktext = - // get_string("teacherview", "mod_mootimeter"); - // $mootimeternode->add($linktext, $url); - // } } /** diff --git a/mod_form.php b/mod_form.php index feccce94..9f711f96 100644 --- a/mod_form.php +++ b/mod_form.php @@ -64,14 +64,6 @@ public function definition() { // Adding the standard "intro" and "introformat" fields. $this->standard_intro_elements(); - // Adding the rest of mod_mootimeter settings, spreading all them into this fieldset - // ... or adding more fieldsets ('header' elements) if needed for better logic. - // $mform->addElement('static', 'label1', 'mootimetersettings', get_string('mootimetersettings', 'mod_mootimeter')); - // $mform->addElement('header', 'mootimeterfieldset', get_string('mootimeterfieldset', 'mod_mootimeter')); - - // Add standard grading elements. - // $this->standard_grading_coursemodule_elements(); - // Add standard elements. $this->standard_coursemodule_elements(); diff --git a/tools/quiz/classes/external/get_answers.php b/tools/quiz/classes/external/get_answers.php index ea3e6716..71c08730 100644 --- a/tools/quiz/classes/external/get_answers.php +++ b/tools/quiz/classes/external/get_answers.php @@ -90,14 +90,6 @@ public static function execute(int $pageid): array { public static function execute_returns() { return new external_single_structure( [ - // 'values' => new external_multiple_structure( - // new external_value(PARAM_INT, 'Answer options count'), - // "Answervalues" - // ), - // 'labels'=>new external_multiple_structure( - // new external_value(PARAM_TEXT, 'Answer options text'), - // "Answerlabels" - // ), 'values' => new external_value(PARAM_TEXT, 'Answer options count'), 'labels' => new external_value(PARAM_TEXT, 'Answer options text'), 'chartsettings' => new external_value(PARAM_TEXT, 'chartsettings'), diff --git a/tools/quiz/classes/external/store_answeroption.php b/tools/quiz/classes/external/store_answeroption.php index 5dd52e8b..69e986ce 100644 --- a/tools/quiz/classes/external/store_answeroption.php +++ b/tools/quiz/classes/external/store_answeroption.php @@ -100,19 +100,10 @@ public static function execute(int $pageid, int $aoid, string $value, string $id } /** - * Describes the return structure of the service.. + * Describes the return structure of the service. * * @return external_multiple_structure */ public static function execute_returns() { - // return new external_multiple_structure( - // new external_single_structure( - // [ - // 'cmid' => new external_value(PARAM_INT, 'ID'), - // 'numerrors' => new external_value(PARAM_INT, 'Number of errors.'), - // 'numchecks' => new external_value(PARAM_INT, 'Number of checks.'), - // ] - // ) - // ); } } diff --git a/tools/quiz/classes/quiz.php b/tools/quiz/classes/quiz.php index 546dea95..fbd393ff 100644 --- a/tools/quiz/classes/quiz.php +++ b/tools/quiz/classes/quiz.php @@ -242,7 +242,8 @@ public function get_content_menu_tool(object $page) { 'data-iconenabled = "fa-check-square-o"', 'data-icondisabled = "fa-square-o"', 'data-tooltipenabled = "' . get_string('tooltip_content_menu_answercorrection', 'mootimetertool_quiz') . '"', - 'data-tooltipdisabled = "' . get_string('tooltip_content_menu_answercorrection_disabled', 'mootimetertool_quiz') . '"', + 'data-tooltipdisabled = "' . + get_string('tooltip_content_menu_answercorrection_disabled', 'mootimetertool_quiz') . '"', ]; $params['icon-check'] = [ 'id' => 'toggleshowanswercorrectionid', @@ -251,7 +252,10 @@ public function get_content_menu_tool(object $page) { ]; if (!empty(self::get_tool_config($page->id, 'showanswercorrection'))) { $params['icon-check']['icon'] = "fa-check-square-o"; - $params['icon-check']['tooltip'] = get_string('tooltip_content_menu_answercorrection_disabled', 'mootimetertool_quiz'); + $params['icon-check']['tooltip'] = get_string( + 'tooltip_content_menu_answercorrection_disabled', + 'mootimetertool_quiz' + ); } else if (empty(self::get_tool_config($page->id, 'showanswercorrection'))) { $params['icon-check']['icon'] = "fa-square-o"; $params['icon-check']['tooltip'] = get_string('tooltip_content_menu_answercorrection', 'mootimetertool_quiz'); @@ -276,18 +280,6 @@ public function get_content_menu_tool(object $page) { ]; } - // if ( - // has_capability('mod/mootimeter:moderator', \context_module::instance($PAGE->cm->id)) - // && self::get_tool_config($page->id, 'showresult') == self::MTMT_VIEW_RESULT_TEACHERPERMISSION - // ) { - - // if (empty(self::get_tool_config($page->id, 'showonteacherpermission'))) { - // $params['icon-eye']['additional_class'] = " disabled"; - // } else if (!empty(self::get_tool_config($page->id, 'showonteacherpermission'))) { - // $params['icon-eye']['additional_class'] .= ""; - // } - // } - return $OUTPUT->render_from_template("mod_mootimeter/elements/snippet_content_menu", $params); } @@ -318,30 +310,6 @@ public function remove_answer_option(int $pageid, int $aoid): array { return $return; } - /** - * Get quiztype. - * - * @param int $pageid - * @return string - * @deprecated - */ - public function get_quiztype(int $pageid): string { - if (!empty(self::get_tool_config($pageid, 'ispoll'))) { - switch (self::get_tool_config($pageid, 'ispoll')) { - case self::MTMT_IS_QUIZ: - $ispoll = "isquiz"; - break; - default: - $ispoll = "ispoll"; - break; - } - } else { - $ispoll = "ispoll"; - } - - return $ispoll; - } - /** * Get all parameters that are necessary for rendering the tools view. * @@ -350,7 +318,7 @@ public function get_quiztype(int $pageid): string { * @deprecated */ public function get_renderer_params(object $page) { - global $USER, $PAGE; + global $USER; // Parameter for initial wordcloud rendering. $params['pageid'] = $page->id; @@ -384,9 +352,11 @@ public function get_renderer_params(object $page) { 'pageid' => $page->id, $inputtype . '_with_label_name' => 'multipleanswers[]', $inputtype . '_with_label_value' => $answeroption->id, - $inputtype . '_with_label_additional_class' => 'mootimeter_settings_selector mootimeter-highlighter mootimeter-success', + $inputtype . '_with_label_additional_class' => 'mootimeter_settings_selector ' . + 'mootimeter-highlighter mootimeter-success', $inputtype . '_with_label_checked' => (in_array($answeroption->id, $useransweroptionsid)) ? "checked" : "", - $inputtype . '_with_label_additional_attribut' => (self::get_tool_config($page->id, 'showanswercorrection')) ? "disabled" : "", + $inputtype . '_with_label_additional_attribut' => (self::get_tool_config($page->id, 'showanswercorrection')) ? + "disabled" : "", ]; } diff --git a/tools/wordcloud/classes/external/store_answer.php b/tools/wordcloud/classes/external/store_answer.php index 6ea37946..595e6cbf 100644 --- a/tools/wordcloud/classes/external/store_answer.php +++ b/tools/wordcloud/classes/external/store_answer.php @@ -73,7 +73,10 @@ public static function execute(int $pageid, string $answer): array { ]); if (empty($answer) && strlen($answer) == 0) { - return ['code' => helper::ERRORCODE_EMPTY_ANSWER, 'string' => get_string('error_empty_answers', 'mootimetertool_wordcloud')]; + return ['code' => helper::ERRORCODE_EMPTY_ANSWER, 'string' => get_string( + 'error_empty_answers', + 'mootimetertool_wordcloud' + ), ]; } $helper = new helper(); @@ -84,12 +87,18 @@ public static function execute(int $pageid, string $answer): array { $submittedanswers = $wordcloud->get_user_answers('mtmt_wordcloud_answers', $page->id, 'answer', $USER->id); if (count($submittedanswers) >= $maxnumberofanswers && $maxnumberofanswers != 0) { - return ['code' => helper::ERRORCODE_TO_MANY_ANSWERS, 'string' => get_string('error_to_many_answers', 'mootimetertool_wordcloud')]; + return ['code' => helper::ERRORCODE_TO_MANY_ANSWERS, 'string' => get_string( + 'error_to_many_answers', + 'mootimetertool_wordcloud' + ), ]; } $submittedanswers = $wordcloud->get_answer_list_array($page->id, $USER->id); if (!helper::get_tool_config($page->id, "allowduplicateanswers") && in_array($answer, $submittedanswers)) { - return ['code' => helper::ERRORCODE_DUPLICATE_ANSWER, 'string' => get_string('error_no_duplicate_answers', 'mootimetertool_wordcloud')]; + return ['code' => helper::ERRORCODE_DUPLICATE_ANSWER, 'string' => get_string( + 'error_no_duplicate_answers', + 'mootimetertool_wordcloud' + ), ]; } $wordcloud->insert_answer($page, $answer); diff --git a/tools/wordcloud/classes/wordcloud.php b/tools/wordcloud/classes/wordcloud.php index 19386803..3037037a 100644 --- a/tools/wordcloud/classes/wordcloud.php +++ b/tools/wordcloud/classes/wordcloud.php @@ -139,7 +139,6 @@ public function get_answer_list_array(int $pageid, int $userid = 0): array { } return array_keys($DB->get_records_menu('mtmt_wordcloud_answers', $params, "", "answer")); - } /** @@ -164,7 +163,7 @@ public function get_renderer_params(object $page) { 'pill' => $element->answer, 'additional_class' => 'mootimeter-pill-inline', ]; - }, $this->get_user_answers('mtmt_wordcloud_answers' , $page->id, 'answer', $USER->id))); + }, $this->get_user_answers('mtmt_wordcloud_answers', $page->id, 'answer', $USER->id))); $params['input_answer'] = [ 'mtm-input-id' => 'mootimeter_type_answer', @@ -207,7 +206,10 @@ public function get_col_settings_tool(object $page) { 'min' => 0, 'pageid' => $page->id, 'ajaxmethode' => "mod_mootimeter_store_setting", - 'value' => (empty(self::get_tool_config($page->id, "maxinputsperuser"))) ? 0 : self::get_tool_config($page->id, "maxinputsperuser"), + 'value' => (empty(self::get_tool_config($page->id, "maxinputsperuser"))) ? 0 : self::get_tool_config( + $page->id, + "maxinputsperuser" + ), ]; $params['settings']['allowduplicateanswers'] = [ @@ -220,27 +222,6 @@ public function get_col_settings_tool(object $page) { 'cb_with_label_checked' => (\mod_mootimeter\helper::get_tool_config($page, 'allowduplicateanswers') ? "checked" : ""), ]; - // These settings may be obsolete. - // $params['settings']['showonteacherpermission'] = [ - // 'cb_with_label_id' => 'showonteacherpermission', - // 'pageid' => $page->id, - // 'cb_with_label_text' => get_string('showresultteacherpermission', 'mootimetertool_wordcloud'), - // 'cb_with_label_name' => 'showonteacherpermission', - // 'cb_with_label_additional_class' => 'mootimeter_settings_selector', - // 'cb_with_label_ajaxmethode' => "mod_mootimeter_store_setting", - // 'cb_with_label_checked' => (\mod_mootimeter\helper::get_tool_config($page, 'showonteacherpermission') ? "checked" : ""), - // ]; - - // $params['settings']['showresultlive'] = [ - // 'cb_with_label_id' => 'showresultlive', - // 'pageid' => $page->id, - // 'cb_with_label_text' => get_string('showresultlive', 'mootimetertool_wordcloud'), - // 'cb_with_label_name' => 'showresultlive', - // 'cb_with_label_additional_class' => 'mootimeter_settings_selector', - // 'cb_with_label_ajaxmethode' => "mod_mootimeter_store_setting", - // 'cb_with_label_checked' => (\mod_mootimeter\helper::get_tool_config($page, 'showresultlive') ? "checked" : ""), - // ]; - return $OUTPUT->render_from_template("mootimetertool_wordcloud/view_settings", $params); } @@ -278,10 +259,10 @@ public function get_last_update_time(int $pageid): int { public function delete_page_tool(object $page) { global $DB; try { - // Table not written yet + // Table not written yet. $DB->delete_records('mtmt_wordcloud_answers', ['pageid' => $page->id]); } catch (\Exception $e) { - // Todo handling + // Todo handling. echo 'Something went wrong'; return false; } diff --git a/view.php b/view.php index bf2f1492..186aea55 100644 --- a/view.php +++ b/view.php @@ -34,7 +34,7 @@ $isresultpage = optional_param('r', false, PARAM_BOOL); $helper = new \mod_mootimeter\helper(); -// Check if the provided pageid already exists / else throw error +// Check if the provided pageid already exists / else throw error. if (!empty($pageid)) { $DB->get_record('mootimeter_pages', ['id' => $pageid], '*', MUST_EXIST); } @@ -74,7 +74,7 @@ } // If there is only one page. Redirect to this page if there is no pageid set. -if(count($pages) == 1 && empty($pageid) && $action != "addpage"){ +if (count($pages) == 1 && empty($pageid) && $action != "addpage") { $page = array_pop($pages); redirect(new moodle_url('/mod/mootimeter/view.php', ['id' => $cm->id, 'pageid' => $page->id])); }