-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from integral-learning/feature/#33667-deadline…
…s-in-xapi-requests Feature/#33667 deadlines in xapi requests
- Loading branch information
Showing
9 changed files
with
580 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// 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/>. | ||
|
||
namespace mod_mumie\synchronization\context; | ||
|
||
/** | ||
* This class holds context for multiple MUMIE Tasks required for some XAPI requests. | ||
* | ||
* @package mod_mumie | ||
* @copyright 2017-2023 integral-learning GmbH (https://www.integral-learning.de/) | ||
* @author Tobias Goltz ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class context implements \JsonSerializable { | ||
/** | ||
* @var array | ||
*/ | ||
private array $objectcontexts; | ||
|
||
/** | ||
* Create a new instance. | ||
*/ | ||
public function __construct() { | ||
$this->objectcontexts = array(); | ||
} | ||
|
||
/** | ||
* Add a new ObjectContext to this context. | ||
* @param string $objectid | ||
* @param object_context $objectcontext | ||
* @return void | ||
*/ | ||
public function add_object_context(string $objectid, object_context $objectcontext): void { | ||
$this->objectcontexts[$objectid] = $objectcontext; | ||
} | ||
|
||
/** | ||
* Custom json serialization. | ||
* @return array | ||
*/ | ||
public function jsonSerialize() : array { | ||
return $this->objectcontexts; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
classes/grades/synchronization/context/context_provider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// 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/>. | ||
|
||
namespace mod_mumie\synchronization\context; | ||
|
||
use mod_mumie\locallib; | ||
use auth_mumie\user\mumie_user; | ||
use stdClass; | ||
|
||
/** | ||
* This class is used to create the context that is required for some XAPI requests. | ||
* | ||
* @package mod_mumie | ||
* @copyright 2017-2023 integral-learning GmbH (https://www.integral-learning.de/) | ||
* @author Tobias Goltz ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class context_provider { | ||
/** | ||
* Get context for a given list of MUMIE Tasks and users. | ||
* | ||
* @param array $mumietasks | ||
* @param array $users | ||
* @return context | ||
*/ | ||
public static function get_context(array $mumietasks, array $users): context { | ||
global $CFG; | ||
require_once($CFG->dirroot . "/mod/mumie/classes/grades/synchronization/context/context.php"); | ||
$context = new context(); | ||
foreach ($mumietasks as $mumietask) { | ||
if (self::requires_context($mumietask)) { | ||
$context->add_object_context( | ||
locallib::get_mumie_id($mumietask), | ||
self::create_object_context($mumietask, $users) | ||
); | ||
} | ||
} | ||
return $context; | ||
} | ||
|
||
/** | ||
* Check whether a MUMIE Task requires context for XAPI requests. | ||
* @param stdClass $mumie | ||
* @return bool | ||
*/ | ||
public static function requires_context(stdClass $mumie): bool { | ||
return str_starts_with($mumie->taskurl, "worksheet_") | ||
&& $mumie->duedate > 0; | ||
} | ||
|
||
/** | ||
* Create a new object_context instance for a given list of users. | ||
* | ||
* @param stdClass $mumie | ||
* @param array $users | ||
* @return object_context | ||
*/ | ||
private static function create_object_context(stdClass $mumie, array $users): object_context { | ||
global $CFG; | ||
require_once($CFG->dirroot . "/mod/mumie/classes/grades/synchronization/context/object_context.php"); | ||
$context = new object_context(); | ||
foreach ($users as $user) { | ||
$context->add_user_context($user->get_sync_id(), self::create_user_context($mumie, $user)); | ||
} | ||
return $context; | ||
} | ||
|
||
/** | ||
* Create a new user_context instance for a given user and MUMIE Task | ||
* @param stdClass $mumie | ||
* @param mumie_user $user | ||
* @return user_context | ||
*/ | ||
private static function create_user_context(stdClass $mumie, mumie_user $user): user_context { | ||
global $CFG; | ||
require_once($CFG->dirroot . "/mod/mumie/classes/grades/synchronization/context/user_context.php"); | ||
require_once($CFG->dirroot . '/mod/mumie/lib.php'); | ||
return new user_context(mumie_get_deadline_in_ms(locallib::get_effective_duedate($user->get_moodle_id(), $mumie))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// 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/>. | ||
|
||
namespace mod_mumie\synchronization\context; | ||
|
||
/** | ||
* This class represents a single MUMIE Tasks context required for some XAPI requests. | ||
* | ||
* @package mod_mumie | ||
* @copyright 2017-2023 integral-learning GmbH (https://www.integral-learning.de/) | ||
* @author Tobias Goltz ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class object_context implements \JsonSerializable { | ||
/** | ||
* @var array | ||
*/ | ||
private array $usercontexts; | ||
|
||
/** | ||
* Create a new instance. | ||
*/ | ||
public function __construct() { | ||
$this->usercontexts = array(); | ||
} | ||
|
||
/** | ||
* Add a new context for a given user. | ||
* @param string $userid | ||
* @param user_context $usercontext | ||
* @return void | ||
*/ | ||
public function add_user_context(string $userid, user_context $usercontext): void { | ||
$this->usercontexts[$userid] = $usercontext; | ||
} | ||
|
||
/** | ||
* Custom JSON serializer. | ||
* @return array | ||
*/ | ||
public function jsonSerialize() { | ||
return $this->usercontexts; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// 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/>. | ||
|
||
namespace mod_mumie\synchronization\context; | ||
|
||
/** | ||
* This class represents the context in which a user is working on a MUMIE Task. | ||
* | ||
* @package mod_mumie | ||
* @copyright 2017-2023 integral-learning GmbH (https://www.integral-learning.de/) | ||
* @author Tobias Goltz ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class user_context implements \JsonSerializable { | ||
/** | ||
* @var int | ||
*/ | ||
private int $deadline; | ||
|
||
/** | ||
* Create new instance. | ||
* @param int $deadline | ||
*/ | ||
public function __construct(int $deadline) { | ||
$this->deadline = $deadline; | ||
} | ||
|
||
/** | ||
* Custom JSON serializer. | ||
* @return array|mixed | ||
*/ | ||
public function jsonSerialize() { | ||
return get_object_vars($this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// 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/>. | ||
|
||
namespace mod_mumie\synchronization; | ||
|
||
use mod_mumie\synchronization\context\context; | ||
|
||
/** | ||
* This class represents the payload used in XAPI requests for MUMIE Task grade synchronization | ||
* | ||
* @package mod_mumie | ||
* @copyright 2017-2023 integral-learning GmbH (https://www.integral-learning.de/) | ||
* @author Tobias Goltz ([email protected]) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class payload implements \JsonSerializable { | ||
/** | ||
* @var array | ||
*/ | ||
private array $users; | ||
/** | ||
* @var string | ||
*/ | ||
private string $course; | ||
/** | ||
* @var array | ||
*/ | ||
private array $objectids; | ||
/** | ||
* @var int | ||
*/ | ||
private int $lastsync; | ||
/** | ||
* @var bool | ||
*/ | ||
private bool $includeall; | ||
/** | ||
* @var context | ||
*/ | ||
private context $context; | ||
|
||
/** | ||
* Create a new instance. | ||
* @param array $users | ||
* @param string $course | ||
* @param array $objectids | ||
* @param int $lastsync | ||
* @param bool $includeall | ||
*/ | ||
public function __construct(array $users, string $course, array $objectids, int $lastsync, bool $includeall) { | ||
$this->users = $users; | ||
$this->course = $course; | ||
$this->objectids = $objectids; | ||
$this->lastsync = $lastsync; | ||
$this->includeall = $includeall; | ||
} | ||
|
||
/** | ||
* Add context to the payload. | ||
* @param context $context | ||
* @return $this | ||
*/ | ||
public function with_context(context $context): payload { | ||
$this->context = $context; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Custom JSON serializer. | ||
* @return array | ||
*/ | ||
public function jsonSerialize(): array { | ||
$json = array( | ||
"users" => $this->users, | ||
"course" => $this->course, | ||
"objectIds" => $this->objectids, | ||
"lastSync" => $this->lastsync, | ||
"includeAll" => $this->includeall | ||
); | ||
if (isset($this->context)) { | ||
$json["context"] = $this->context; | ||
} | ||
return $json; | ||
} | ||
} |
Oops, something went wrong.