From 3895529b74635577b3bb383eabfbc08b3fda0a75 Mon Sep 17 00:00:00 2001 From: Meirza Date: Thu, 19 Jan 2023 22:09:16 +0700 Subject: [PATCH] MDL-77350 badges: Added class properties that are not declared In PHP 8.2 and later, setting a value to an undeclared class property is deprecated and emits a deprecation notice. So we need to add missing class properties that still need to be declared. --- badges/classes/backpack_api2p1.php | 2 +- badges/classes/backpack_api2p1_mapping.php | 6 +++++ badges/classes/backpack_api_mapping.php | 6 +++++ badges/classes/badge.php | 27 +++++++++++++++++++ .../output/external_backpacks_page.php | 6 +++++ .../output/external_backpacks_table.php | 4 +-- badges/criteria/award_criteria.php | 18 +++++++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) diff --git a/badges/classes/backpack_api2p1.php b/badges/classes/backpack_api2p1.php index f3829089252..c5fec6f4128 100644 --- a/badges/classes/backpack_api2p1.php +++ b/badges/classes/backpack_api2p1.php @@ -81,7 +81,7 @@ class backpack_api2p1 { if (!empty($externalbackpack)) { $this->externalbackpack = $externalbackpack; $this->backpackapiversion = $externalbackpack->apiversion; - $this->get_clientid = $this->get_clientid($externalbackpack->oauth2_issuerid); + $this->get_clientid($externalbackpack->oauth2_issuerid); if (!($this->tokendata = $this->get_stored_token($externalbackpack->id)) && $this->backpackapiversion != OPEN_BADGES_V2P1) { diff --git a/badges/classes/backpack_api2p1_mapping.php b/badges/classes/backpack_api2p1_mapping.php index 7419f3b65e2..f2a5a4f2194 100644 --- a/badges/classes/backpack_api2p1_mapping.php +++ b/badges/classes/backpack_api2p1_mapping.php @@ -67,6 +67,12 @@ class backpack_api2p1_mapping { /** @var boolean Differentiate the function that can be called on a user backpack or a site backpack. */ private $isuserbackpack; + /** @var mixed List of parameters for this method. */ + protected $postparams; + + /** @var int OpenBadges version 1 or 2. */ + protected $backpackapiversion; + /** * Create a mapping. * diff --git a/badges/classes/backpack_api_mapping.php b/badges/classes/backpack_api_mapping.php index 4c10f672a77..36ec0bc2e28 100644 --- a/badges/classes/backpack_api_mapping.php +++ b/badges/classes/backpack_api_mapping.php @@ -79,6 +79,12 @@ class backpack_api_mapping { /** @var string Error string from authentication request. */ private static $authenticationerror = ''; + /** @var mixed List of parameters for this method. */ + protected $postparams; + + /** @var int OpenBadges version 1 or 2. */ + protected $backpackapiversion; + /** * Create a mapping. * diff --git a/badges/classes/badge.php b/badges/classes/badge.php index 284556154db..93ee6d32a03 100644 --- a/badges/classes/badge.php +++ b/badges/classes/badge.php @@ -129,6 +129,24 @@ class badge { /** @var array Badge criteria */ public $criteria = array(); + /** @var int|null Total users which have the award. Called from badges_get_badges() */ + public $awards; + + /** @var string|null The name of badge status. Called from badges_get_badges() */ + public $statstring; + + /** @var int|null The date the badges were issued. Called from badges_get_badges() */ + public $dateissued; + + /** @var string|null Unique hash. Called from badges_get_badges() */ + public $uniquehash; + + /** @var string|null Message format. Called from file_prepare_standard_editor() */ + public $messageformat; + + /** @var array Message editor. Called from file_prepare_standard_editor() */ + public $message_editor = []; + /** * Constructs with badge details. * @@ -240,7 +258,16 @@ class badge { foreach (get_object_vars($this) as $k => $v) { $fordb->{$k} = $v; } + // TODO: We need to making it more simple. + // Since the variables are not exist in the badge table, + // unsetting them is a must to avoid errors. unset($fordb->criteria); + unset($fordb->awards); + unset($fordb->statstring); + unset($fordb->dateissued); + unset($fordb->uniquehash); + unset($fordb->messageformat); + unset($fordb->message_editor); $fordb->timemodified = time(); if ($DB->update_record_raw('badge', $fordb)) { diff --git a/badges/classes/output/external_backpacks_page.php b/badges/classes/output/external_backpacks_page.php index 195658ce6c6..e1f309d6a63 100644 --- a/badges/classes/output/external_backpacks_page.php +++ b/badges/classes/output/external_backpacks_page.php @@ -39,6 +39,12 @@ use core_badges\external\backpack_exporter; */ class external_backpacks_page implements \renderable { + /** @var \moodle_url Badges backpacks URL. */ + protected $url; + + /** @var array List the backpacks at site level. */ + protected $backpacks = []; + /** * Constructor. * @param \moodle_url $url diff --git a/badges/classes/output/external_backpacks_table.php b/badges/classes/output/external_backpacks_table.php index 72393f18da9..46a54c6f553 100644 --- a/badges/classes/output/external_backpacks_table.php +++ b/badges/classes/output/external_backpacks_table.php @@ -48,9 +48,9 @@ class external_backpacks_table extends table_sql { public function __construct() { parent::__construct('backpacks'); - $this->context = \context_system::instance(); + $context = \context_system::instance(); // This object should not be used without the right permissions. - require_capability('moodle/badges:manageglobalsettings', $this->context); + require_capability('moodle/badges:manageglobalsettings', $context); // Define columns in the table. $this->define_table_columns(); diff --git a/badges/criteria/award_criteria.php b/badges/criteria/award_criteria.php index b568df3257e..ef55ade8c9f 100644 --- a/badges/criteria/award_criteria.php +++ b/badges/criteria/award_criteria.php @@ -128,6 +128,24 @@ abstract class award_criteria { */ public $params = array(); + /** + * Criteria type. + * @var string + */ + public $criteriatype; + + /** + * Required parameters. + * @var string + */ + public $required_param = ''; + + /** + * Optional parameters. + * @var array + */ + public $optional_params = []; + /** * The base constructor *