Skip to content

Commit

Permalink
Update #86bwwnc0a - Update for Moodle 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentcornelis committed Feb 16, 2024
1 parent 4e34e99 commit 40d30c2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Types of changes
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.

## Version (4.3.0) - 2024-02-16
- Tested and refactored for Moodle (LMS) 4.3

## Version (4.2.0) - 2023-12-20
- Branche 4.2 for just 4.2 use
- Validation M4.2
Expand Down
6 changes: 3 additions & 3 deletions amd/src/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Tested in Moodle 3.5
* Tested in Moodle 3.5 / 3.9 / 4.2 / 4.3
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
Expand Down Expand Up @@ -164,7 +164,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/log', 'core/sortable_l
request[0].done(function(response) {
Log.log(response);
$('.block_user_favorites .content').html(response.content);
// Re-attach drag/drop callback on the new content to ensure sorting still works after content refresh
// Re-attach drag/drop callback on the new content to ensure sorting still works after content refresh.
attachDragDropHandlers();
}).fail(Notification.exception);

Expand Down Expand Up @@ -204,7 +204,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/log', 'core/sortable_l
});
// Instantiate new SortableList component. this only needs to happen once (i.e. not on refresh again).
new SortableList('ol#block_user_favorites-items');
// Attach the drag/drop callbacks
// Attach the drag/drop callbacks.
attachDragDropHandlers();
}
};
Expand Down
9 changes: 5 additions & 4 deletions classes/favorites.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
class favorites {

/**
* @var int
* @var int $userid User id
*/
protected $userid;
protected int $userid;

/**
* favorites constructor.
Expand Down Expand Up @@ -91,6 +91,7 @@ public function update_favorite(\stdClass $favorite, string $hash, int $userid):

/**
* Set an url
*
* This function will update if exists or create a new favorite.
*
* @param string $url
Expand Down Expand Up @@ -149,10 +150,10 @@ public function delete_by_hash(string $hash): void {
/**
* Get_all favorites.
*
* @return array|mixed
* @return array
* @throws dml_exception
*/
public function get_all() {
public function get_all(): array {
global $DB;

return $DB->get_records('block_user_favorites', ['userid' => $this->userid], 'sortorder ASC', '*');
Expand Down
25 changes: 16 additions & 9 deletions classes/output/output_favorites.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@
class output_favorites implements renderable, templatable {

/**
* @var favorites
* @var favorites $favorites Favorites
*/
protected $favorites;
protected favorites $favorites;

/**
* @var string
* @var string $currenturl Current URL
*/
protected $currenturl;
protected string $currenturl;

/**
* admin_catalog_product_output constructor.
* Admin catalog product output constructor.
*
* @param favorites $favorites
* @param string $currenturl
Expand All @@ -62,8 +63,9 @@ public function __construct(favorites $favorites, string $currenturl = '') {
}

/**
* Function to export the renderer data in a format that is suitable for a
* mustache template. This means:
* Function to export the renderer data in a format that is suitable for a mustache template.
*
* This means:
* 1. No complex types - only stdClass, array, int, string, float, bool
* 2. Any additional info that is required for the template is pre-calculated (e.g. capability checks).
*
Expand All @@ -81,13 +83,18 @@ public function export_for_template(renderer_base $output): stdClass {
$favorites = $this->favorites->get_all();
foreach ($favorites as $favorite) {

if ($this->currenturl == $favorite->url) {
$favoriteurls = [
$favorite->url,
$favorite->url . 'index.php',
];

if (in_array($this->currenturl, $favoriteurls, true)) {
$hascurrenturl = true;
}

$data[$favorite->hash] = [
'name' => $favorite->title,
'class' => ($this->currenturl == $favorite->url) ? 'active' : '',
'class' => (in_array($this->currenturl, $favoriteurls, true)) ? 'active' : '',
'url' => $favorite->url,
'hash' => $favorite->hash,
'sortorder' => $favorite->sortorder,
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2023112200;
$plugin->version = 2024021600;
$plugin->requires = 2023042401;
$plugin->component = 'block_user_favorites';
$plugin->release = '4.2.0';
$plugin->release = '4.3.0';
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 40d30c2

Please sign in to comment.