mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-78267 core: Move shared MoodleNet code to abstract
This commit is contained in:
parent
9cd44cbf4c
commit
b3ffe8432b
@ -54,6 +54,7 @@ class activity_sender extends resource_sender {
|
||||
) {
|
||||
parent::__construct($cmid, $userid, $moodlenetclient, $oauthclient, $shareformat);
|
||||
[$this->course, $this->cminfo] = get_course_and_cm_from_cmid($cmid);
|
||||
$this->packager = new activity_packager($this->cminfo, $this->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,21 +138,6 @@ class activity_sender extends resource_sender {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for sharing, in the format specified.
|
||||
*
|
||||
* @return stored_file
|
||||
*/
|
||||
protected function prepare_share_contents(): stored_file {
|
||||
switch ($this->shareformat) {
|
||||
case self::SHARE_FORMAT_BACKUP:
|
||||
// If sharing the activity as a backup, prepare the packaged backup.
|
||||
return (new activity_packager($this->cminfo, $this->userid))->get_package();
|
||||
default:
|
||||
throw new \coding_exception("Unknown share format: {$this->shareformat}'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event to the admin logs for an outbound share attempt.
|
||||
*
|
||||
|
@ -54,6 +54,7 @@ class course_sender extends resource_sender {
|
||||
parent::__construct($courseid, $userid, $moodlenetclient, $oauthclient, $shareformat);
|
||||
$this->course = get_course($courseid);
|
||||
$this->coursecontext = \core\context\course::instance($courseid);
|
||||
$this->packager = new course_packager($this->course, $this->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,19 +121,6 @@ class course_sender extends resource_sender {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for sharing, in the format specified.
|
||||
*
|
||||
* @return stored_file
|
||||
*/
|
||||
protected function prepare_share_contents(): stored_file {
|
||||
$packager = new course_packager($this->course, $this->userid);
|
||||
return match ($this->shareformat) {
|
||||
self::SHARE_FORMAT_BACKUP => $packager->get_package(),
|
||||
default => throw new \coding_exception("Unknown share format: {$this->shareformat}'"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an event to the admin logs for an outbound share attempt.
|
||||
*
|
||||
|
@ -45,6 +45,9 @@ abstract class resource_sender {
|
||||
*/
|
||||
protected stdClass $course;
|
||||
|
||||
/** @var resource_packager Resource packager. */
|
||||
protected resource_packager $packager;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
@ -91,5 +94,10 @@ abstract class resource_sender {
|
||||
*
|
||||
* @return stored_file
|
||||
*/
|
||||
abstract protected function prepare_share_contents(): stored_file;
|
||||
protected function prepare_share_contents(): stored_file {
|
||||
return match ($this->shareformat) {
|
||||
self::SHARE_FORMAT_BACKUP => $this->packager->get_package(),
|
||||
default => throw new \coding_exception("Unknown share format: {$this->shareformat}'"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user