Skip to content

Commit

Permalink
V 5
Browse files Browse the repository at this point in the history
  • Loading branch information
fmido88 authored Feb 3, 2024
1 parent 89737d4 commit bc67275
Show file tree
Hide file tree
Showing 14 changed files with 1,192 additions and 579 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Wallet Enrollment for Moodle #
==========
## V 5.0.0 ##
- Overall code improvement.
- Add a category based wallet.
- Enhance all operations and coupon validation.
- using caches to store balance data to avoid multiple requests.
- Add enrol page view event.
- using ajax to view any user wallet balance from charger form.
- Fix negative balance bug.

## V 4.5.0 ##
- Add option to display users with capabilities to credit other users wallets in topping up option, this is helpful in case no payment account exists.
- Fix: In case of no topping up options available, nothing will be displayed even the policy.

## V 4.4.0 ##
- Fix exception thrown when add another instance.
- Confirmation page before purchase the course.
- Fix wrong enrolments due to multiple instances.
- Fix wrong enrollments due to multiple instances.

## V 4.3.0 ##
- Fix exception thrown when no availability specified or disabled.
Expand Down
17 changes: 11 additions & 6 deletions confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
require_once(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');

use enrol_wallet\util\instance;
use enrol_wallet\util\balance;
use enrol_wallet\util\balance_op;

global $USER;

require_login(null, false);
Expand All @@ -40,8 +44,9 @@
redirect(new moodle_url('/course/view.php', ['id' => $courseid]));
}

$helper = new instance($instanceid);
$wallet = new enrol_wallet_plugin;
$instance = $wallet->get_instance_by_id($instanceid);
$instance = $helper->get_instance();
$course = get_course($courseid);

$params = [
Expand Down Expand Up @@ -109,13 +114,13 @@
$params['confirm'] = true;
$confirmurl = new moodle_url('/enrol/wallet/confirm.php', $params);
$confirmbutton = new single_button($confirmurl, get_string('confirm'));

$balance = balance::create_from_instance($instance);
$a = [
'balance' => enrol_wallet\transactions::get_user_balance($USER->id),
'cost' => $wallet::get_cost_after_discount($USER->id, $instance),
'balance' => $balance->get_valid_balance(),
'cost' => $helper->get_cost_after_discount(),
'currency' => $instance->currency,
'course' => $course->fullname,
'policy' => '',
'course' => $course->fullname,
'policy' => '',
];

// Display refund policy if enabled.
Expand Down
17 changes: 11 additions & 6 deletions extendlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @copyright 2023 Mo Farouk <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use enrol_wallet\util\balance;
/**
* To add the category and node information into the my profile page.
* If is a regular user, it show the balance, refund policy and topping up options.
Expand Down Expand Up @@ -135,7 +135,7 @@ function enrol_wallet_extend_navigation_frontpage(navigation_node $parentnode, s
$hassiteconfig = has_capability('moodle/site:config', $context);

$any = ($captransactions || $capcredit || $capbulkedit || $capcouponview || $capcouponcreate);
$ismoodle = (get_config('enrol_wallet', 'walletsource') == enrol_wallet\transactions::SOURCE_MOODLE);
$ismoodle = (get_config('enrol_wallet', 'walletsource') == balance::MOODLE);

if ($hassiteconfig && $any) {

Expand Down Expand Up @@ -311,7 +311,7 @@ function enrol_wallet_validate_extend_signup_form($data) {
function enrol_wallet_update_wordpress_user($user) {
// Check the wallet source first.
$source = get_config('enrol_wallet', 'walletsource');
if ($source == enrol_wallet\transactions::SOURCE_WORDPRESS) {
if ($source == balance::WP) {
// Create or update corresponding user in wordpress.
$wordpress = new \enrol_wallet\wordpress;
$wordpress->create_wordpress_user($user, $user->password);
Expand Down Expand Up @@ -407,7 +407,8 @@ function enrol_wallet_before_standard_top_of_body_html() {

// Check the conditions.
$condition = get_config('enrol_wallet', 'noticecondition');
$balance = \enrol_wallet\transactions::get_user_balance($USER->id);
$op = new balance();
$balance = $op->get_total_balance();
if ($balance !== false && is_numeric($balance) && $balance <= (int)$condition) {
// Display the warning.
\core\notification::warning(get_string('lowbalancenotification', 'enrol_wallet', $balance));
Expand All @@ -424,15 +425,19 @@ function enrol_wallet_after_require_login() {
if (isguestuser() || empty($USER->id)) {
return;
}

$source = get_config('enrol_wallet', 'walletsource');
if ($source != balance::WP) {
return;
}
// Prevent multiple calls.
$done = get_user_preferences('enrol_wallet_wploggedin', false, $USER);
if ($done) {
return;
}

if (isset($SESSION->wantsurl)) {
$return = (new moodle_url($SESSION->wantsurl))->out(false);
$return = $SESSION->wantsurl;
unset($SESSION->wantsurl);
} else {
$return = (new moodle_url('/'))->out(false);
}
Expand Down
8 changes: 5 additions & 3 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/enrol/wallet/lib.php");

use enrol_wallet\util\balance;

/**
* wallet enrolment external functions.
*
Expand Down Expand Up @@ -185,11 +187,12 @@ public static function enrol_user($courseid, $instanceid = 0) {
} else {
$costafter = $enrol->get_cost_after_discount($USER->id, $instance);
$cost = $instance->cost;
$balance = \enrol_wallet\transactions::get_user_balance($USER->id);
$balance = balance::create_from_instance($instance);

$a = [
'cost_before' => $cost,
'cost_after' => $costafter,
'user_balance' => $balance,
'user_balance' => $balance->get_valid_balance(),
];
if ($enrolstatus == \enrol_wallet_plugin::INSUFFICIENT_BALANCE) {
$enrolstatus = get_string('insufficient_balance', 'enrol_wallet', $a);
Expand Down Expand Up @@ -225,5 +228,4 @@ public static function enrol_user_returns() {
]
);
}

}
2 changes: 1 addition & 1 deletion extrasettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$capcouponcreate = has_capability('enrol/wallet:createcoupon', $context);
$capcouponedit = has_capability('enrol/wallet:editcoupon', $context);

$ismoodle = (get_config('enrol_wallet', 'walletsource') == enrol_wallet\transactions::SOURCE_MOODLE);
$ismoodle = (get_config('enrol_wallet', 'walletsource') == enrol_wallet\util\balance::MOODLE);
// Adding these pages for only users with required capability.
// These aren't appear to user's with capabilities, Only admins!.
// That is because enrolment plugins not loading the settings unless the user has the capability moodle/site:config.
Expand Down
Loading

0 comments on commit bc67275

Please sign in to comment.