Skip to content

Commit

Permalink
changes in local_o365
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Oct 25, 2024
1 parent 4fabcd4 commit bff7c36
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 81 deletions.
18 changes: 10 additions & 8 deletions local/o365/classes/webservices/create_onenoteassignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

defined('MOODLE_INTERNAL') || die();

use context_course;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;

global $CFG;

require_once($CFG->dirroot.'/course/modlib.php');
require_once($CFG->dirroot . '/course/modlib.php');

/**
* Create assignment API class.
Expand Down Expand Up @@ -65,12 +66,12 @@ public static function assignment_create_parameters() {
* @return array An array of parameters, if successful.
*/
public static function assignment_create($data) {
global $DB, $CFG;
global $CFG;

$params = self::validate_parameters(self::assignment_create_parameters(), ['data' => $data]);
$params = $params['data'];

$context = \context_course::instance($params['course']);
$context = context_course::instance($params['course']);
self::validate_context($context);

$defaults = [
Expand All @@ -97,8 +98,8 @@ public static function assignment_create($data) {
'modulename' => 'assign',
'course' => $course->id,
'section' => $params['section'],
'visible' => (int)$params['visible'],
'duedate' => (int)$params['duedate'],
'visible' => (int) $params['visible'],
'duedate' => (int) $params['duedate'],
'name' => $params['name'],
'cmidnumber' => '',
'introeditor' => ['text' => $params['intro'], 'format' => FORMAT_HTML, 'itemid' => null],
Expand All @@ -108,9 +109,10 @@ public static function assignment_create($data) {
];

$modinfo = array_merge($defaults, $modinfo);
$modinfo = create_module((object)$modinfo, $course);
$modinfo = create_module((object) $modinfo, $course);

$modinfo = utils::get_assignment_return_info($modinfo->coursemodule, $modinfo->course);

$modinfo = \local_o365\webservices\utils::get_assignment_return_info($modinfo->coursemodule, $modinfo->course);
return ['data' => [$modinfo]];
}

Expand All @@ -120,6 +122,6 @@ public static function assignment_create($data) {
* @return external_single_structure Object describing return parameters for this webservice method.
*/
public static function assignment_create_returns() {
return \local_o365\webservices\utils::get_assignment_return_info_schema();
return utils::get_assignment_return_info_schema();
}
}
9 changes: 6 additions & 3 deletions local/o365/classes/webservices/delete_onenoteassignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

defined('MOODLE_INTERNAL') || die();

use context_course;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;

global $CFG;

require_once($CFG->dirroot.'/course/modlib.php');
require_once($CFG->dirroot . '/course/modlib.php');

/**
* Delete assignment API class.
Expand Down Expand Up @@ -66,14 +67,15 @@ public static function assignment_delete($data) {
$params = self::validate_parameters(self::assignment_delete_parameters(), ['data' => $data]);
$params = $params['data'];

list($course, $module, $assign) = \local_o365\webservices\utils::verify_assignment($params['coursemodule'],
[$course, $module, $assign] = utils::verify_assignment($params['coursemodule'],
$params['course']);

$context = \context_course::instance($params['course']);
$context = context_course::instance($params['course']);
self::validate_context($context);

// Course_delete_module will throw exception if error, so we can return true b/c if we get there it was successful.
course_delete_module($module->id);

return ['result' => true];
}

Expand All @@ -86,6 +88,7 @@ public static function assignment_delete_returns() {
$params = [
'result' => new external_value(PARAM_BOOL, 'success/failure'),
];

return new external_single_structure($params);
}
}
4 changes: 3 additions & 1 deletion local/o365/classes/webservices/exception/assignnotfound.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

namespace local_o365\webservices\exception;

use moodle_exception;

/**
* Exception thrown when an associated assignment record is not found for a given course module.
*/
class assignnotfound extends \moodle_exception {
class assignnotfound extends moodle_exception {
/**
* Constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

namespace local_o365\webservices\exception;

use moodle_exception;

/**
* Exception thrown when a grade could not be saved in local_o365_update_grade.
*/
class couldnotsavegrade extends \moodle_exception {
class couldnotsavegrade extends moodle_exception {
/**
* Constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

namespace local_o365\webservices\exception;

use moodle_exception;

/**
* Exception thrown when a module is called that is not a OneNote assignment.
*/
class invalidassignment extends \moodle_exception {
class invalidassignment extends moodle_exception {
/**
* Constructor.
*
Expand Down
4 changes: 3 additions & 1 deletion local/o365/classes/webservices/exception/modulenotfound.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

namespace local_o365\webservices\exception;

use moodle_exception;

/**
* Exception thrown when a module that does not exist is called.
*/
class modulenotfound extends \moodle_exception {
class modulenotfound extends moodle_exception {
/**
* Constructor.
*
Expand Down
4 changes: 3 additions & 1 deletion local/o365/classes/webservices/exception/sectionnotfound.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

namespace local_o365\webservices\exception;

use moodle_exception;

/**
* Exception thrown when a course section that does not exist is used to update an assignment.
*/
class sectionnotfound extends \moodle_exception {
class sectionnotfound extends moodle_exception {
/**
* Constructor.
*
Expand Down
69 changes: 36 additions & 33 deletions local/o365/classes/webservices/read_assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace local_o365\webservices;

use assign;
use context_course;
use context_module;
use moodle_exception;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -36,12 +39,13 @@
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use moodle_url;

global $CFG;

require_once($CFG->dirroot.'/course/modlib.php');
require_once($CFG->dirroot.'/user/externallib.php');
require_once($CFG->dirroot.'/mod/assign/locallib.php');
require_once($CFG->dirroot . '/course/modlib.php');
require_once($CFG->dirroot . '/user/externallib.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');

/**
* Get a list of assignments in one or more courses.
Expand All @@ -68,7 +72,7 @@ public static function assignments_read_parameters() {
VALUE_DEFAULT,
[]
),
'capabilities' => new external_multiple_structure(
'capabilities' => new external_multiple_structure(
new external_value(PARAM_CAPABILITY, 'capability'),
'list of capabilities used to filter courses',
VALUE_DEFAULT,
Expand Down Expand Up @@ -147,7 +151,7 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
foreach ($courseids as $cid) {

try {
$context = \context_course::instance($cid);
$context = context_course::instance($cid);
self::validate_context($context);

// Check if this course was already loaded (by enrol_get_users_courses).
Expand All @@ -169,30 +173,30 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
}
}
$extrafields = 'm.id as assignmentid, ' .
'm.course, ' .
'm.nosubmissions, ' .
'm.submissiondrafts, ' .
'm.sendnotifications, '.
'm.sendlatenotifications, ' .
'm.sendstudentnotifications, ' .
'm.duedate, ' .
'm.allowsubmissionsfromdate, '.
'm.grade, ' .
'm.timemodified, '.
'm.completionsubmit, ' .
'm.cutoffdate, ' .
'm.teamsubmission, ' .
'm.requireallteammemberssubmit, '.
'm.teamsubmissiongroupingid, ' .
'm.blindmarking, ' .
'm.revealidentities, ' .
'm.attemptreopenmethod, '.
'm.maxattempts, ' .
'm.markingworkflow, ' .
'm.markingallocation, ' .
'm.requiresubmissionstatement, '.
'm.intro, '.
'm.introformat';
'm.course, ' .
'm.nosubmissions, ' .
'm.submissiondrafts, ' .
'm.sendnotifications, ' .
'm.sendlatenotifications, ' .
'm.sendstudentnotifications, ' .
'm.duedate, ' .
'm.allowsubmissionsfromdate, ' .
'm.grade, ' .
'm.timemodified, ' .
'm.completionsubmit, ' .
'm.cutoffdate, ' .
'm.teamsubmission, ' .
'm.requireallteammemberssubmit, ' .
'm.teamsubmissiongroupingid, ' .
'm.blindmarking, ' .
'm.revealidentities, ' .
'm.attemptreopenmethod, ' .
'm.maxattempts, ' .
'm.markingworkflow, ' .
'm.markingallocation, ' .
'm.requiresubmissionstatement, ' .
'm.intro, ' .
'm.introformat';
$coursearray = [];

foreach ($courses as $id => $course) {
Expand All @@ -206,7 +210,7 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
continue;
}

$context = \context_module::instance($module->id);
$context = context_module::instance($module->id);
try {
self::validate_context($context);
require_capability('mod/assign:view', $context);
Expand Down Expand Up @@ -263,7 +267,7 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
];

// Return or not intro and file attachments depending on the plugin settings.
$assign = new \assign($context, null, null);
$assign = new assign($context, null, null);

if ($assign->show_intro()) {

Expand All @@ -281,7 +285,7 @@ public static function assignments_read($courseids = [], $assignmentids = [], $c
$assignment['introattachments'][] = [
'filename' => $filename,
'mimetype' => $file->get_mimetype(),
'fileurl' => \moodle_url::make_webservice_pluginfile_url(
'fileurl' => moodle_url::make_webservice_pluginfile_url(
$context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0, '/', $filename)->out(false),
];
}
Expand Down Expand Up @@ -411,5 +415,4 @@ public static function assignments_read_returns() {
]
);
}

}
16 changes: 9 additions & 7 deletions local/o365/classes/webservices/read_courseusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace local_o365\webservices;

use context_course;
use context_helper;
use moodle_exception;
use stdClass;

Expand All @@ -38,7 +40,7 @@

global $CFG;

require_once($CFG->dirroot.'/course/modlib.php');
require_once($CFG->dirroot . '/course/modlib.php');

/**
* Get a list of students in a course by course id.
Expand Down Expand Up @@ -77,7 +79,7 @@ public static function courseusers_read_parameters() {
*/
public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber = 0, $userids = []) {
global $CFG, $DB;
require_once($CFG->dirroot.'/user/lib.php');
require_once($CFG->dirroot . '/user/lib.php');

$params = self::validate_parameters(
self::courseusers_read_parameters(),
Expand Down Expand Up @@ -112,7 +114,7 @@ public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber
return [];
}
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
$context = \context_course::instance($courseid);
$context = context_course::instance($courseid);
self::validate_context($context);

try {
Expand All @@ -121,15 +123,15 @@ public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
}

require_capability('moodle/course:viewparticipants', $context);

[$enrolledsql, $enrolledparams] = get_enrolled_sql($context, $withcapability);

// For user context preloading.
$ctxselect = ', ' . \context_helper::get_preload_record_columns_sql('ctx');
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
$enrolledparams['contextlevel'] = CONTEXT_USER;

Expand Down Expand Up @@ -166,7 +168,7 @@ public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber
}

// Get user info.
\context_helper::preload_from_record($user);
context_helper::preload_from_record($user);
if ($userdetails = user_get_user_details($user, $course, $userfields)) {
$users[] = $userdetails;
}
Expand All @@ -179,7 +181,7 @@ public static function courseusers_read($courseid, $limitfrom = 0, $limitnumber
/**
* Returns description of method result value
*
* @return external_description
* @return external_multiple_structure
*/
public static function courseusers_read_returns() {
return new external_multiple_structure(
Expand Down
Loading

0 comments on commit bff7c36

Please sign in to comment.