Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moodle 4.3 branch #30 #31

Merged
merged 4 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
## Moodle block for marking your favourite pages as bookmarks

In brief, the MFreak block `user_favorites` gives the user a method to mark pages as favourite.
In brief, the ldesignmedia block `user_favorites` gives the user a method to mark pages as favourite.

Special thanks to Gemma Lesterhuis ([Lesterhuis Training & Consultancy](https://ltnc.nl/)) for develop & design, useful
input, bug reports and beta testing

![MFreak.nl](https://MFreak.nl/logo_small.png)
![ldesignmedia.nl](https://ldesignmedia.nl/logo_small.png)
![Lesterhuis Training & Consultancy](https://ldesignmedia.nl/logo_small_ltnc.png)

* Author: Luuk Verhoeven, [MFreak.nl](https://MFreak.nl/)
* Author: Luuk Verhoeven, [ldesignmedia.nl](https://ldesignmedia.nl/)
* Author: Gemma Lesterhuis, [Lesterhuis Training & Consultancy](https://ltnc.nl/)
* Min. required: Moodle 4.2
* Supports PHP: 7.4

![Moodle402](https://img.shields.io/badge/moodle-4.2-brightgreen.svg)

## Screens

![Adding](https://content.screencast.com/users/LuukVerhoeven/folders/Snagit/media/0a62b7d5-c369-453f-9a63-fff5d2c24f9b/10.27.2018-12.40.GIF)
![10 27 2018-12 40](https://github.com/Lesterhuis-Training-en-Consultancy/moodle-block-user_favorites/assets/995760/2f2c2157-dbfa-4a17-9c5b-cd77ba55070c)

## List of features
- Using external AJAX requests for saving loading and ordering user favourites.
Expand All @@ -35,16 +34,13 @@ input, bug reports and beta testing
4. Install the plugin


### Changelog

##### 4.2 (27-10-2023)
* Updated external_api namespace loading from core_external.
* No longer backwards compatible.
## Changelog

See [Changelog](CHANGELOG.md) file for details

## Security

If you discover any security related issues, please email [luuk@MFreak.nl](mailto:luuk@MFreak.nl) instead of using the
If you discover any security related issues, please email [luuk@ldesignmedia.nl](mailto:luuk@ldesignmedia.nl) instead of using the
issue tracker.

## License
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;
Loading