-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOODLE_311_STABLE UPDATE Add custom_completion.php Ensure events always sent
- Loading branch information
1 parent
a1e5b3b
commit f0a3152
Showing
11 changed files
with
131 additions
and
26 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,100 @@ | ||
<?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/>. | ||
|
||
/** | ||
* The mod_externalcontent module custom completion class. | ||
* | ||
* @package mod_externalcontent | ||
* @copyright 2019-2021 LushOnline | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_externalcontent\completion; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
if (!class_exists('\core_completion\activity_custom_completion')) { | ||
// New API does not exist in this site, so do nothing. | ||
return; | ||
} | ||
|
||
/** | ||
* The mod_externalcontent module custom completion. | ||
* | ||
* @package mod_externalcontent | ||
* @copyright 2019-2021 LushOnline | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class custom_completion extends \core_completion\activity_custom_completion { | ||
/** | ||
* Fetches the completion state for a given completion rule. | ||
* | ||
* @param string $rule The completion rule. | ||
* @return int The completion state. | ||
*/ | ||
public function get_state(string $rule): int { | ||
global $DB; | ||
|
||
$this->validate_rule($rule); | ||
// Get external content details. | ||
$externalcontent = $DB->get_record('externalcontent', array('id' => $this->cm->instance), '*', MUST_EXIST); | ||
|
||
switch ($rule) { | ||
case 'completionexternally': | ||
$params = array('userid' => $this->userid, 'externalcontentid' => $externalcontent->id, 'completed' => 1); | ||
$completed = $DB->record_exists('externalcontent_track', $params); | ||
|
||
$status = $completed ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; | ||
break; | ||
|
||
default : | ||
$status = COMPLETION_INCOMPLETE; | ||
break; | ||
} | ||
|
||
return $status; | ||
} | ||
|
||
/** | ||
* Fetch the list of custom completion rules that this module defines. | ||
* | ||
* @return array | ||
*/ | ||
public static function get_defined_custom_rules(): array { | ||
return ['completionexternally']; | ||
} | ||
|
||
/** | ||
* Returns an associative array of the descriptions of custom completion rules. | ||
* | ||
* @return array | ||
*/ | ||
public function get_custom_rule_descriptions(): array { | ||
return ['completionexternally' => get_string('eventcompletedexternally', 'externalcontent')]; | ||
} | ||
|
||
/** | ||
* Returns an array of all completion rules, in the order they should be displayed to users. | ||
* | ||
* @return array | ||
*/ | ||
public function get_sort_order(): array { | ||
return [ | ||
'completionview', | ||
'completionexternally', | ||
]; | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -46,4 +46,4 @@ | |
'capabilities' => 'mod/externalcontent:view', | ||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), | ||
), | ||
); | ||
); |
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
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
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
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
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 |
---|---|---|
|
@@ -216,4 +216,4 @@ public static function mark_completed($record) { | |
} | ||
return $response; | ||
} | ||
} | ||
} |
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
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