Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lbplanner/classes/helpers/config_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public static function set_default_active_year() {
*/
public static function add_customfield(): void {
// Check if the category is already created and only create it if it doesn't exist.
// Check if plugin "modcustomfields" is installed and create the category and the custom field.
// TODO: When the plugin gets uninstalled, the category should be deleted as well.
// TODO: Or check if it is already there when reinstalling.
if (!get_config('local_lbplanner', 'categoryid')) {

// Check if plugin "modcustomfields" is installed and create the category and the custom field.
if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) {

$handler = mod_handler::create();
Expand Down
74 changes: 27 additions & 47 deletions lbplanner/classes/helpers/modules_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

namespace local_lbplanner\helpers;

use block_accessreview\external\get_module_data;

use core_customfield\category;
use local_lbplanner\helpers\config_helper;
use core_customfield\category_controller;
use customfield_select\data_controller;
use customfield_select\field_controller;
use external_function_parameters;
use external_single_structure;
use external_value;
Expand All @@ -35,42 +40,6 @@
* Contains helper functions for working with modules.
*/
class modules_helper {

/**
* Table where modules are stored.
*/
const ASSIGN_TABLE = 'assign';

/**
* Table where max. and min. grades of the modules are stored.
*/
const GRADE_ITEMS_TABLE = 'grade_items';

/**
* Table where course modules are stored.
*/
const COURSE_MODULES_TABLE = 'course_modules';

/**
* Table where grades of the modules are stored.
*/
const GRADES_TABLE = 'assign_grades';

/**
* Table where grading scales are stored.
*/
const SCALE_TABLE = 'scale';

/**
* Table where submissions of the modules are stored.
*/
const SUBMISSIONS_TABLE = 'assign_submission';

/**
* Submitted status name of a submission.
*/
const SUBMISSION_STATUS_SUBMITTED = 'submitted';

/**
* The return structure of a module.
*
Expand Down Expand Up @@ -146,9 +115,10 @@ public static function map_status(bool $submitted, bool $done, bool $late): int
* Maps the given name to a module type.
*
* @param string $modulename The name of the module.
* @param int $cmid The coursemodule id of the module.
* @return integer The enum value for the module type.
*/
public static function determin_type(string $modulename): int {
public static function determin_type(string $modulename, int $cmid): int {
// Convert module name to uppercase.
$modulename = strtoupper($modulename);

Expand All @@ -170,6 +140,22 @@ public static function determin_type(string $modulename): int {
if (strpos($modulename, '[M]') !== false) {
return MODULE_TYPE::M;
}
$categorycontroller = category_controller::create(config_helper::get_category_id());
$datacontroller = $categorycontroller->get_handler()->get_instance_data($cmid)[0];
$type = intval($datacontroller->get('value'));
if ($type == 1) {
return MODULE_TYPE::GK;
} else if ($type == 2) {
return MODULE_TYPE::EK;
} else if ($type == 3) {
return MODULE_TYPE::GK;
} else if ($type == 4) {
return MODULE_TYPE::TEST;
} else if ($type == 5) {
return MODULE_TYPE::TEST;
} else if ($type == 6) {
return MODULE_TYPE::M;
}

// Return TYPE_NONE elswise.
return MODULE_TYPE::NONE;
Expand All @@ -182,15 +168,9 @@ public static function determin_type(string $modulename): int {
* @param int $courseid The id of the course.
* @return string The url of the module.
*/
public static function get_module_url(int $moduleid, int $courseid): string {
global $DB;

$view = $DB->get_record(
self::COURSE_MODULES_TABLE,
['course' => $courseid, 'instance' => $moduleid, 'module' => 1]
);

return strval(new moodle_url('/mod/assign/view.php?id='.$view->id));
public static function get_module_url(string $type, int $cmid): string {
$url = new moodle_url('/mod/'.$type.'/view.php', ['id' => $cmid]);
return $url->out(false);
}

/**
Expand Down
49 changes: 49 additions & 0 deletions lbplanner/classes/model/activity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
// This file is part of the local_lbplanner.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Collection of helper classes for handling modules
*
* @package local_lbplanner
* @subpackage helpers
* @copyright 2024 NecodeIT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_lbplanner\model;

class activity {
public $moduleid;
public $name;
public $courseid;
public $status;
public $type;
public $url;
public $grade;
public $deadline;
public $modtype;
public function __construct($moduleid, $name, $courseid, $status, $modtype, $type, $url, $grade, $deadline) {
$this->modtype = $modtype;
$this->moduleid = $moduleid;
$this->name = $name;
$this->courseid = $courseid;
$this->status = $status;
$this->type = $type;
$this->url = $url;
$this->grade = $grade;
$this->deadline = $deadline;
}
}

10 changes: 7 additions & 3 deletions lbplanner/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@

/**
* Upgrades the DB version
* right now it only sets the default active year
* This function does anything necessary to upgrade the plugin from an old version to the current version.
*
* @param mixed $oldversion (unused) the previous version to upgrade from
* @return bool true
*/
function xmldb_local_lbplanner_upgrade($oldversion): bool {
if ($oldversion < 2024022700) {
if ($oldversion < 2024022703) {
config_helper::set_default_active_year();
config_helper::add_customfield();
try {
config_helper::add_customfield();
} catch (coding_exception $e) {
new moodle_exception('error_adding_customfield', 'local_lbplanner', '', $e->getMessage());
}
}
return true;
}
Expand Down
75 changes: 51 additions & 24 deletions lbplanner/services/modules/get_all_course_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@

namespace local_lbplanner_services;


use core_completion\cm_completion_details;
use core_customfield\category_controller;
use core_external\external_single_structure;
use core_h5p\core;
use course_modinfo;
use customfield_select\data_controller;
use external_api;
use external_function_parameters;
use external_multiple_structure;
use external_value;
use local_lbplanner\model\activity;
use local_lbplanner\helpers\modules_helper;
use local_lbplanner\helpers\user_helper;
use stdClass;

/**
* Get all the modules of the given course.
Expand All @@ -38,45 +46,64 @@ class modules_get_all_course_modules extends external_api {
*/
public static function get_all_course_modules_parameters(): external_function_parameters {
return new external_function_parameters([
'courseid' => new external_value(PARAM_INT, 'The id of the course', VALUE_REQUIRED, null, NULL_NOT_ALLOWED),
'userid' => new external_value(PARAM_INT, 'The id of the user', VALUE_REQUIRED, null, NULL_NOT_ALLOWED),
'ekenabled' => new external_value(
PARAM_BOOL,
'Whether or not to include ek modules',
VALUE_REQUIRED,
false,
NULL_NOT_ALLOWED),
]);
'courseid' => new external_value(PARAM_INT, 'The id of the course', VALUE_REQUIRED, null, NULL_NOT_ALLOWED)]);
}

/**
* Returns all the modules inside a course.
*
* @param int $courseid The ID of the course
* @param int $userid The ID of the user
* @param bool $ekenabled whether or not to include ek modules
* @return array the modules
* @return array|null the modules
*/
public static function get_all_course_modules(int $courseid, int $userid, bool $ekenabled): array {
global $DB;

public static function get_all_course_modules(int $courseid): ?array {
global $DB, $USER, $CFG;
require_once($CFG->dirroot . '/course/lib.php');
// path to the module class which is in this plugin
self::validate_parameters(
self::get_all_course_modules_parameters(),
['courseid' => $courseid, 'userid' => $userid, 'ekenabled' => $ekenabled]
['courseid' => $courseid]
);

user_helper::assert_access($userid);

return modules_helper::get_all_course_modules($courseid, $userid, $ekenabled);
$activities = course_modinfo::get_array_of_activities(get_course($courseid));
$modules = [];
foreach ($activities as $activity) {
$modtype = $activity->mod;
if ($modtype !== 'assign' || $modtype !== 'quiz') {
continue;
}
$id = $activity->id;
$deadline = $activity->duedate;
$name = $activity->name;
$cmid = $activity->cm;
$url = modules_helper::get_module_url($modtype, $cmid);
$modules[] = new activity(
$id,
$name,
$courseid,
1,
$modtype,
modules_helper::determin_type($name, $cmid),
$url,
1,
$deadline
);
}
die(var_dump());
$test = new stdClass();
$test->id = 392;
die(var_dump(assign_get_user_grades($test, $USER->id)));
$completion = new \completion_info(get_course($courseid));
$courseandcm = get_course_and_cm_from_cmid(392, null, $courseid, $USER->id);
die(var_dump(get_course_and_cm_from_cmid(392, null, $courseid, $USER->id)));
die(var_dump(cm_completion_details::get_instance(get_fast_modinfo($courseid, $USER->id))->get_details()));
return $type;
}

/**
* Returns the structure of the module array.
* @return external_multiple_structure
*/
public static function get_all_course_modules_returns(): external_multiple_structure {
return new external_multiple_structure(
modules_helper::structure(),
);
public static function get_all_course_modules_returns() {
new external_value(PARAM_INT, 'Module ID');
}
}
15 changes: 4 additions & 11 deletions lbplanner/services/modules/get_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use external_function_parameters;
use external_single_structure;
use external_value;
use local_lbplanner\helpers\course_helper;
use local_lbplanner\helpers\modules_helper;
use local_lbplanner\helpers\plan_helper;
use local_lbplanner\helpers\user_helper;
Expand All @@ -40,29 +41,21 @@ class modules_get_module extends external_api {
public static function get_module_parameters(): external_function_parameters {
return new external_function_parameters([
'moduleid' => new external_value(PARAM_INT, 'The id of the module', VALUE_REQUIRED, null, NULL_NOT_ALLOWED),
'userid' => new external_value(PARAM_INT, 'The id of the user', VALUE_REQUIRED, null, NULL_NOT_ALLOWED),
]);
}

/**
* Returns the data for a module
*
* @param int $moduleid The ID of the course
* @param int $userid The ID of the user
* @return array the module
*/
public static function get_module(int $moduleid, int $userid): array {
public static function get_module(int $moduleid): array {
global $DB;

self::validate_parameters(self::get_module_parameters(), ['moduleid' => $moduleid, 'userid' => $userid]);
self::validate_parameters(self::get_module_parameters(), ['moduleid' => $moduleid]);

user_helper::assert_access($userid);

if (!$DB->record_exists(modules_helper::MDL_ASSIGN_TABLE, ['id' => $moduleid])) {
throw new \moodle_exception('Module not found');
}

return modules_helper::get_module($moduleid, $userid);
return modules_helper::get_module($moduleid);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

$plugin->component = 'local_lbplanner';
$plugin->release = 'Alpha v.'.$release;
$plugin->version = 2024031200;
$plugin->version = 2024031301;
$plugin->dependencies = [
// Depend upon version 2023110600 of local_modcustomfields.
'local_modcustomfields' => 2023110600,
Expand Down