Skip to content

Commit

Permalink
V 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
fmido88 authored Jun 27, 2023
1 parent b909978 commit 673387d
Show file tree
Hide file tree
Showing 27 changed files with 747 additions and 428 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Wallet Enrollment for Moodle #
==========
## V 1.7.0 ##
- Add ability for editing coupons.
- Hide cheaper instances or non available enrol wallet instance in the same course.
- Fix and test logging in and out to wordpress.
- Bug fixes and enhancement.

## V 1.6.7 ##
- Fix and enhance coupons and transaction pages.

Expand Down
12 changes: 6 additions & 6 deletions classes/editselectedusers_operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function process(\course_enrolment_manager $manager, array $users, \stdCl
}

// Get all of the user enrolment id's.
$ueids = array();
$instances = array();
$ueids = [];
$instances = [];
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$ueids[] = $enrolment->id;
Expand All @@ -88,7 +88,7 @@ public function process(\course_enrolment_manager $manager, array $users, \stdCl

list($ueidsql, $params) = $DB->get_in_or_equal($ueids, SQL_PARAMS_NAMED);

$updatesql = array();
$updatesql = [];
if ($status == ENROL_USER_ACTIVE || $status == ENROL_USER_SUSPENDED) {
$updatesql[] = 'status = :status';
$params['status'] = (int)$status;
Expand Down Expand Up @@ -126,13 +126,13 @@ public function process(\course_enrolment_manager $manager, array $users, \stdCl
$enrolment->enrol = 'wallet';
// Trigger event.
$event = \core\event\user_enrolment_updated::create(
array(
[
'objectid' => $enrolment->id,
'courseid' => $enrolment->courseid,
'context' => \context_course::instance($enrolment->courseid),
'relateduserid' => $user->id,
'other' => array('enrol' => 'wallet')
)
'other' => ['enrol' => 'wallet']
]
);
$event->trigger();
}
Expand Down
1 change: 1 addition & 0 deletions classes/event/transactions_triggered.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function get_description() {
$type = $this->other['type'];
if ($type == 'debit') {
return get_string('event_transaction_debit_description', 'enrol_wallet', $a);

} else if ($type == 'credit') {
$refundable = clean_param($this->other['refundable'], PARAM_BOOL);
$a->refundable = $refundable ? 'refundable' : 'not refundable';
Expand Down
4 changes: 3 additions & 1 deletion classes/form/applycoupon_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function definition() {
$mform = $this->_form;
$instance = $this->_customdata->instance;
$url = new \moodle_url('course/view.php', ['id' => $instance->courseid]);
$coupon = optional_param('coupon', '', PARAM_TEXT);

$wallet = enrol_get_plugin('wallet');
$coupon = $wallet->check_discount_coupon();
$coupongroup = [];

if (!empty($coupon)) {
Expand Down
2 changes: 1 addition & 1 deletion classes/form/insuf_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
require_once($CFG->libdir.'/formslib.php');

/**
* This is realy just a display for user that he has insufficient wallet ballance to enrol.
* This is really just a display for user that he has insufficient wallet ballance to enrol.
*/
class insuf_form extends \moodleform {

Expand Down
12 changes: 6 additions & 6 deletions classes/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static function transaction_notify($data) {
$time = userdate($data['timecreated']);

$a = (object)[
'type' => $type,
'amount' => $amount,
'before' => $before,
'type' => $type,
'amount' => $amount,
'before' => $before,
'balance' => $balance,
'desc' => $desc,
'time' => $time,
'desc' => $desc,
'time' => $time,
];
$user = \core_user::get_user($userid);
$message = new \core\message\message();
Expand All @@ -72,7 +72,7 @@ public static function transaction_notify($data) {
$message->smallmessage = $desc;
$message->notification = 1; // Because this is a notification generated from Moodle, not a user-to-user message.

$content = array('*' => array('header' => ' Wallet Transaction ', 'footer' => '')); // Extra content for specific processor.
$content = ['*' => ['header' => ' Wallet Transaction ', 'footer' => '']]; // Extra content for specific processor.
$message->set_additional_content('email', $content);

// Actually send the message.
Expand Down
38 changes: 26 additions & 12 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ public static function wallet_completion_awards(\core\event\course_completed $ev

// Insert the record.
$data = [
'userid' => $userid,
'userid' => $userid,
'courseid' => $courseid,
'grade' => $usergrade,
'grade' => $usergrade,
'maxgrade' => $maxgrade,
'percent' => $percentage,
'amount' => $award,
'percent' => $percentage,
'amount' => $award,
'timecreated' => time()
];
$id = $DB->insert_record('enrol_wallet_awards', $data);

// Trigger award event.
$eventdata = [
'context' => \context_course::instance($courseid),
'userid' => $userid,
'context' => \context_course::instance($courseid),
'userid' => $userid,
'relateduserid' => $userid,
'objectid' => $id,
'courseid' => $courseid,
'objectid' => $id,
'courseid' => $courseid,
'other' => [
'grade' => number_format($percentage, 2),
'grade' => number_format($percentage, 2),
'amount' => $award,
],
];
Expand Down Expand Up @@ -152,10 +152,10 @@ public static function wallet_gifting_new_user(\core\event\user_created $event)

// Trigger gifts event.
$eventdata = [
'context' => \context_system::instance(),
'userid' => $userid,
'context' => \context_system::instance(),
'userid' => $userid,
'relateduserid' => $userid,
'objectid' => $id,
'objectid' => $id,
'other' => [
'amount' => $giftvalue,
],
Expand Down Expand Up @@ -225,6 +225,13 @@ public static function login_to_wordpress(\core\event\user_loggedin $event) {
return;
}

$wordpressurl = get_config('enrol_wallet', 'wordpress_url');
$wordpressurl = clean_param($wordpressurl, PARAM_URL);
$allowed = get_config('enrol_wallet', 'wordpressloggins');
if (empty($allowed) || empty($wordpressurl)) {
return;
}

// Clone the old wantsurl.
$params = [];
if (isset($SESSION->wantsurl)) {
Expand Down Expand Up @@ -257,6 +264,13 @@ public static function logout_from_wordpress(\core\event\user_loggedout $event)
return;
}

$wordpressurl = get_config('enrol_wallet', 'wordpress_url');
$wordpressurl = clean_param($wordpressurl, PARAM_URL);
$allowed = get_config('enrol_wallet', 'wordpressloggins');
if (empty($allowed) || empty($wordpressurl)) {
return;
}

$params = [];
if (!empty($redirect)) {
$params['redirect'] = $redirect;
Expand Down
18 changes: 9 additions & 9 deletions classes/task/turn_non_refundable.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function check_transform_validation($data) {
$where = "userid = :userid AND type = :type AND timecreated >= :checktime";

$params = [
'userid' => $userid,
'type' => 'debit',
'userid' => $userid,
'type' => 'debit',
'checktime' => time() - $period,
];
$records = $DB->get_records_select('enrol_wallet_transactions', $where, $params, 'id DESC', 'id, amount');
Expand Down Expand Up @@ -137,13 +137,13 @@ public function apply_transformation($userid, $transform) {
}

$recorddata = [
'userid' => $userid,
'amount' => 0,
'type' => 'credit',
'balbefore' => $balance,
'balance' => $balance,
'norefund' => min($norefund + $transform, $balance),
'descripe' => 'Transform the transaction to nonrefundable due to expiring of refund period.'."\n",
'userid' => $userid,
'amount' => 0,
'type' => 'credit',
'balbefore' => $balance,
'balance' => $balance,
'norefund' => min($norefund + $transform, $balance),
'descripe' => get_string('nonrefundable_transform_desc', 'enrol_wallet'),
'timecreated' => time(),
];
$DB->insert_record('enrol_wallet_transactions', $recorddata);
Expand Down
72 changes: 36 additions & 36 deletions classes/transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public static function payment_topup($amount, $userid, $description = '', $charg
$oldnotrefund = self::get_nonrefund_balance($userid);

$recorddata = [
'userid' => $userid,
'type' => 'credit',
'amount' => $amount,
'balbefore' => $before,
'balance' => $newbalance,
'norefund' => $refundable ? $oldnotrefund : $amount + $oldnotrefund,
'descripe' => $description,
'userid' => $userid,
'type' => 'credit',
'amount' => $amount,
'balbefore' => $before,
'balance' => $newbalance,
'norefund' => $refundable ? $oldnotrefund : $amount + $oldnotrefund,
'descripe' => $description,
'timecreated' => time()
];

Expand Down Expand Up @@ -158,8 +158,8 @@ public static function debit($userid, float $amount, $coursename = '', $charger
global $DB;

$a = (object)[
'amount' => $amount,
'charger' => $charger,
'amount' => $amount,
'charger' => $charger,
'coursename' => $coursename,
];

Expand All @@ -172,13 +172,13 @@ public static function debit($userid, float $amount, $coursename = '', $charger
$oldnotrefund = self::get_nonrefund_balance($userid);

$recorddata = [
'userid' => $userid,
'type' => 'debit',
'amount' => $amount,
'balbefore' => $before,
'balance' => $newbalance,
'norefund' => ($newbalance >= $oldnotrefund) ? $oldnotrefund : $newbalance,
'descripe' => $description,
'userid' => $userid,
'type' => 'debit',
'amount' => $amount,
'balbefore' => $before,
'balance' => $newbalance,
'norefund' => ($newbalance >= $oldnotrefund) ? $oldnotrefund : $newbalance,
'descripe' => $description,
'timecreated' => time()
];

Expand Down Expand Up @@ -312,7 +312,7 @@ public static function get_coupon_value($coupon, $userid, $instanceid = 0, $appl
// Set the returning coupon data.
$coupondata = [
'value' => $couponrecord->value,
'type' => $couponrecord->type,
'type' => $couponrecord->type,
];

}
Expand Down Expand Up @@ -406,31 +406,31 @@ public static function mark_coupon_used($coupon, $userid, $instanceid) {
$couponrecord = $DB->get_record('enrol_wallet_coupons', ['code' => $coupon]);
$usage = $couponrecord->usetimes + 1;
$data = (object)[
'id' => $couponrecord->id,
'lastuse' => time(),
'id' => $couponrecord->id,
'lastuse' => time(),
'usetimes' => $usage,
];
$DB->update_record('enrol_wallet_coupons', $data);
}

// Logging the usage in the coupon usage table.
$logdata = (object)[
'code' => $coupon,
'type' => $couponrecord->type,
'value' => $couponrecord->value,
'userid' => $userid,
'code' => $coupon,
'type' => $couponrecord->type,
'value' => $couponrecord->value,
'userid' => $userid,
'instanceid' => $instanceid,
'timeused' => time(),
'timeused' => time(),
];
$id = $DB->insert_record('enrol_wallet_coupons_usage', $logdata);

$eventdata = [
'userid' => $userid,
'userid' => $userid,
'relateduserid' => $userid,
'objectid' => !empty($id) ? $id : null,
'other' => [
'code' => $coupon,
]
'objectid' => !empty($id) ? $id : null,
'other' => [
'code' => $coupon,
]
];

if (!empty($instanceid) && $instanceid != 0) {
Expand Down Expand Up @@ -465,15 +465,15 @@ private static function triger_transaction_event($amount, $type, $charger, $user
$context = \context_system::instance();

$eventarray = [
'context' => $context,
'objectid' => $id,
'userid' => $charger,
'context' => $context,
'objectid' => $id,
'userid' => $charger,
'relateduserid' => $userid,
'other' => [
'type' => $type,
'amount' => $amount,
'type' => $type,
'amount' => $amount,
'refundable' => $refundable,
'desc' => $desc,
'desc' => $desc,
],
];

Expand Down Expand Up @@ -501,7 +501,7 @@ private static function queue_transaction_transformation($id) {
$task = new \enrol_wallet\task\turn_non_refundable;
$task->set_custom_data(
[
'id' => $id,
'id' => $id,
'userid' => $record->userid,
'amount' => $record->amount,
]
Expand Down
Loading

0 comments on commit 673387d

Please sign in to comment.