diff --git a/lbplanner/classes/helpers/feedback_helper.php b/lbplanner/classes/helpers/feedback_helper.php deleted file mode 100644 index 8d83916..0000000 --- a/lbplanner/classes/helpers/feedback_helper.php +++ /dev/null @@ -1,109 +0,0 @@ -. - -namespace local_lbplanner\helpers; - -use external_function_parameters; -use external_single_structure; -use external_value; -use local_lbplanner\enums\CAPABILITY; -use stdClass; -use local_lbplanner\helpers\user_helper; - -// TODO: use enums. - -/** - * Helper class for feedback - * - * @package local_lbplanner - * @subpackage helpers - * @copyright 2024 NecodeIT - * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later - */ -class feedback_helper { - - /** - * Unread Feedback - */ - const STATUS_UNREAD = 0; - - /** - * Read Feedback - */ - const STATUS_READ = 1; - - /** - * The name of the table which is used by LP to store feedback in - */ - const LBPLANNER_FEEDBACK_TABLE = 'local_lbplanner_feedback'; - - /** - * The return structure of a feedback. - * - * @return external_single_structure The structure of a module. - */ - public static function structure(): external_single_structure { - return new external_single_structure( - [ - 'content' => new external_value(PARAM_TEXT, 'Content of the feedback'), - 'userid' => new external_value(PARAM_INT, 'The id of the user'), - 'type' => new external_value(PARAM_INT, 'The Type of the feedback'), - 'notes' => new external_value(PARAM_TEXT, 'Notes of the feedback'), - 'id' => new external_value(PARAM_INT, 'The id of the feedback'), - 'status' => new external_value(PARAM_INT, 'The status of the feedback'), - 'timestamp' => new external_value(PARAM_INT, 'The time when the feedback was created'), - 'lastmodified' => new external_value(PARAM_INT, 'The time when the feedback was last modified'), - 'lastmodifiedby' => new external_value(PARAM_INT, 'The id of the user who last modified the feedback'), - 'logfile' => new external_value(PARAM_TEXT, 'The logs of the feedback'), - ] - ); - } - - /** - * Gives back the feedback of the given feedbackid - * - * @param int $feedbackid The id of the feedback - * - * @return stdClass The feedback - */ - public static function get_feedback(int $feedbackid): stdClass { - global $DB; - return $DB->get_record(self::LBPLANNER_FEEDBACK_TABLE, ['id' => $feedbackid]); - } - - /** - * Checks if the user has access to feedback - * - * @throws \moodle_exception when the user has no access - */ - public static function assert_admin_access() { - if (!has_capability(CAPABILITY::ADMIN, \context_system::instance()) - && !has_capability(CAPABILITY::MANAGER, \context_system::instance()) - ) { - throw new \moodle_exception('Acces denied'); - } - } - - /** - * Returns all feedback records. - * - * @return array all feedback records - */ - public static function get_all_feedbacks(): array { - global $DB; - return $DB->get_records(self::LBPLANNER_FEEDBACK_TABLE); - } -} diff --git a/lbplanner/db/install.xml b/lbplanner/db/install.xml index 86012c1..5d9498c 100644 --- a/lbplanner/db/install.xml +++ b/lbplanner/db/install.xml @@ -95,25 +95,6 @@ - - - - - - - - - - - - - - - - - - -
diff --git a/lbplanner/db/services.php b/lbplanner/db/services.php index 8b7e11e..fa256e3 100644 --- a/lbplanner/db/services.php +++ b/lbplanner/db/services.php @@ -215,42 +215,6 @@ 'capabilities' => 'local/lb_planner:student', 'ajax' => true, ], - 'local_lbplanner_feedback_submit_feedback' => [ - 'classname' => 'local_lbplanner_services\feedback_submit_feedback', - 'methodname' => 'submit_feedback', - 'classpath' => 'local/lbplanner/services/feedback/submit_feedback.php', - 'description' => 'Add a feedback to the DB', - 'type' => 'write', - 'capabilities' => 'local/lb_planner:student', - 'ajax' => true, - ], - 'local_lbplanner_feedback_get_all_feedbacks' => [ - 'classname' => 'local_lbplanner_services\feedback_get_all_feedbacks', - 'methodname' => 'get_all_feedbacks', - 'classpath' => 'local/lbplanner/services/feedback/get_all_feedbacks.php', - 'description' => 'Get all the feedback from the DB', - 'type' => 'read', - 'capabilities' => 'local/lb_planner:admin, local/lb_planner:manager', - 'ajax' => true, - ], - 'local_lbplanner_feedback_update_feedback' => [ - 'classname' => 'local_lbplanner_services\feedback_update_feedback', - 'methodname' => 'update_feedback', - 'classpath' => 'local/lbplanner/services/feedback/update_feedback.php', - 'description' => 'Update the feedback of the given id', - 'type' => 'write', - 'capabilities' => 'local/lb_planner:admin, local/lb_planner:manager', - 'ajax' => true, - ], - 'local_lbplanner_feedback_delete_feedback' => [ - 'classname' => 'local_lbplanner_services\feedback_delete_feedback', - 'methodname' => 'delete_feedback', - 'classpath' => 'local/lbplanner/services/feedback/delete_feedback.php', - 'description' => 'Delete the feedback of the given id', - 'type' => 'write', - 'capabilities' => 'local/lb_planner:admin, local/lb_planner:manager', - 'ajax' => true, - ], 'local_lbplanner_plan_accept_invite' => [ 'classname' => 'local_lbplanner_services\plan_accept_invite', 'methodname' => 'accept_invite', @@ -359,10 +323,6 @@ 'local_lbplanner_plan_get_access', 'local_lbplanner_plan_update_access', 'local_lbplanner_user_delete_user', - 'local_lbplanner_feedback_submit_feedback', - 'local_lbplanner_feedback_delete_feedback', - 'local_lbplanner_feedback_get_all_feedbacks', - 'local_lbplanner_feedback_update_feedback', 'local_lbplanner_plan_accept_invite', 'local_lbplanner_plan_decline_invite', 'local_lbplanner_config_get_version', diff --git a/lbplanner/services/feedback/delete_feedback.php b/lbplanner/services/feedback/delete_feedback.php deleted file mode 100644 index 2c72351..0000000 --- a/lbplanner/services/feedback/delete_feedback.php +++ /dev/null @@ -1,75 +0,0 @@ -. - -namespace local_lbplanner_services; - -use external_api; -use external_multiple_structure; -use external_function_parameters; -use external_value; -use local_lbplanner\helpers\feedback_helper; - -/** - * Deletes feedback from the database. - * - * @package local_lbplanner - * @subpackage services_feedback - * @copyright 2024 necodeIT - * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later - */ -class feedback_delete_feedback extends external_api { - /** - * Parameters for delete_feedback. - * @return external_function_parameters - */ - public static function delete_feedback_parameters(): external_function_parameters { - return new external_function_parameters([ - 'feedbackid' => new external_value(PARAM_INT, 'ID of the feedback to delete', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - ]); - } - - /** - * Deletes feedback from the database. - * - * @param int $feedbackid ID of the feedback to delete - * @return void - * @throws \moodle_exception when feedback wasn't found - */ - public static function delete_feedback(int $feedbackid) { - global $DB, $USER; - - self::validate_parameters( - self::delete_feedback_parameters(), - ['feedbackid' => $feedbackid] - ); - - if (!$DB->record_exists(feedback_helper::LBPLANNER_FEEDBACK_TABLE, ['id' => $feedbackid])) { - throw new \moodle_exception('feedback_not_found'); - } - - feedback_helper::assert_admin_access(); - - $DB->delete_records(feedback_helper::LBPLANNER_FEEDBACK_TABLE, ['id' => $feedbackid]); - } - - /** - * Returns the structure of nothing. - * @return null - */ - public static function delete_feedback_returns() { - return null; - } -} diff --git a/lbplanner/services/feedback/get_all_feedbacks.php b/lbplanner/services/feedback/get_all_feedbacks.php deleted file mode 100644 index a955120..0000000 --- a/lbplanner/services/feedback/get_all_feedbacks.php +++ /dev/null @@ -1,60 +0,0 @@ -. - -namespace local_lbplanner_services; - -use external_api; -use external_function_parameters; -use external_multiple_structure; -use local_lbplanner\helpers\feedback_helper; - -/** - * Get all feedback from the database. - * - * @package local_lbplanner - * @subpackage services_feedback - * @copyright 2024 necodeIT - * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later - */ -class feedback_get_all_feedbacks extends external_api { - /** - * Parameters for get_all_feedbacks. - * @return external_function_parameters - */ - public static function get_all_feedbacks_parameters(): external_function_parameters { - return new external_function_parameters([]); - } - - /** - * Returns all feedbacks from the database. - * - * @return array all feedback objects - */ - public static function get_all_feedbacks(): array { - feedback_helper::assert_admin_access(); - return feedback_helper::get_all_feedbacks(); - } - - /** - * Returns the structure of the array of feedbacks. - * @return external_multiple_structure - */ - public static function get_all_feedbacks_returns(): external_multiple_structure { - return new external_multiple_structure( - feedback_helper::structure(), - ); - } -} diff --git a/lbplanner/services/feedback/submit_feedback.php b/lbplanner/services/feedback/submit_feedback.php deleted file mode 100644 index d826305..0000000 --- a/lbplanner/services/feedback/submit_feedback.php +++ /dev/null @@ -1,103 +0,0 @@ -. - -namespace local_lbplanner_services; - -use external_api; -use external_function_parameters; -use external_value; -use local_lbplanner\helpers\feedback_helper; - -/** - * Add feedback to the database. - * - * @package local_lbplanner - * @subpackage services_feedback - * @copyright 2024 necodeIT - * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later - */ -class feedback_submit_feedback extends external_api { - /** - * Parameters for submit_feedback. - * @return external_function_parameters - */ - public static function submit_feedback_parameters(): external_function_parameters { - return new external_function_parameters( - [ - 'type' => new external_value( - PARAM_INT, - 'type of Feedback (bug, typo, feature, other)', // TODO: use enums. - VALUE_REQUIRED, - null, - NULL_NOT_ALLOWED, - ), - 'content' => new external_value( - PARAM_TEXT, - 'feedback contents', - VALUE_REQUIRED, - null, - NULL_NOT_ALLOWED, - ), - 'logfile' => new external_value( - PARAM_TEXT, - 'file name of the associated log file', - VALUE_DEFAULT, - null, - NULL_NOT_ALLOWED, - ), - ] - ); - } - - /** - * Add feedback to the database. - * - * @param int $type type of Feedback - * @see feedback_helper - * @param string $content feedback contents - * @param string $logfile file name of the associated log file - * @return int The ID of the new feedback - */ - public static function submit_feedback(int $type, string $content, string $logfile): int { - global $DB, $USER; - - self::validate_parameters( - self::submit_feedback_parameters(), - ['type' => $type, 'content' => $content, 'logfile' => $logfile] - ); - - // TODO: validate $type. - - $id = $DB->insert_record(feedback_helper::LBPLANNER_FEEDBACK_TABLE, [ - 'content' => $content, - 'userid' => $USER->id, - 'type' => $type, - 'status' => feedback_helper::STATUS_UNREAD, - 'timestamp' => time(), - 'logfile' => $logfile, - ]); - - return $id; - } - - /** - * Returns the structure of the feedback ID. - * @return external_value - */ - public static function submit_feedback_returns(): external_value { - return new external_value(PARAM_INT, "The ID of the new feedback"); - } -} diff --git a/lbplanner/services/feedback/update_feedback.php b/lbplanner/services/feedback/update_feedback.php deleted file mode 100644 index a62c2f4..0000000 --- a/lbplanner/services/feedback/update_feedback.php +++ /dev/null @@ -1,90 +0,0 @@ -. - -namespace local_lbplanner_services; - -use external_api; -use external_function_parameters; -use external_value; -use gradereport_singleview\local\ui\feedback; -use local_lbplanner\helpers\feedback_helper; - -/** - * Updates feedback from the database. - * - * @package local_lbplanner - * @subpackage services_feedback - * @copyright 2024 necodeIT - * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later - */ -class feedback_update_feedback extends external_api { - /** - * Parameters for update_feedback. - * @return external_function_parameters - */ - public static function update_feedback_parameters(): external_function_parameters { - return new external_function_parameters([ - 'feedbackid' => - new external_value(PARAM_INT, 'ID of the feedback to be updated', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - 'notes' => new external_value(PARAM_TEXT, 'updated notes', VALUE_DEFAULT, null, NULL_ALLOWED), - 'status' => new external_value(PARAM_INT, 'updated status', VALUE_REQUIRED, null, NULL_NOT_ALLOWED), - ]); - } - - /** - * Updates feedback from the database. - * - * @param int $feedbackid ID of the feedback to be updated - * @param string $notes updated notes - * @param int $status updated status - * @see feedback_helper - * @return void - * @throws \moodle_exception when feedback not found or status invalid - */ - public static function update_feedback(int $feedbackid, string $notes, int $status) { - global $DB, $USER; - - self::validate_parameters( - self::update_feedback_parameters(), - ['feedbackid' => $feedbackid, 'notes' => $notes, 'status' => $status] - ); - - feedback_helper::assert_admin_access(); - - if (!$DB->record_exists(feedback_helper::LBPLANNER_FEEDBACK_TABLE, ['id' => $feedbackid])) { - throw new \moodle_exception('feedback_not_found'); - } - - $feedback = $DB->get_record(feedback_helper::LBPLANNER_FEEDBACK_TABLE, ['id' => $feedbackid], '*', MUST_EXIST); - $feedback->notes = $notes; - if ($status > 1 || $status < 0) { // TODO: use enum to validate. - throw new \moodle_exception('Invalid status'); - } - $feedback->status = $status; - $feedback->lastmodified = time(); - $feedback->lastmodifiedby = $USER->id; - - $DB->update_record(feedback_helper::LBPLANNER_FEEDBACK_TABLE, $feedback); - } - - /** - * Returns the structure of nothing. - * @return null - */ - public static function update_feedback_returns() { - return null; - } -}