## Blocks: Coupon

block_coupon
Maintained by Sebsoft Plugins, Rogier van Dongen
The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon.
523 sites
73 fans

SEBSOFT COUPON PLUGIN

The Sebsoft Coupon Plugin offers you the possibility to create coupons for various levels

of course access. Using a coupon code, users will be enrolled into courses that are attached to the coupon. That way, you can use the coupon system as voucher or vouchering system for your course(s).

There are a few different ways of generating coupons:

- Course level: this means one or more course(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be enroled in every course the coupon

is attached to.

A nice extra feature is, when groups are configured for a certain course, you can configure which

course group the coupon is for. When a user claims the coupon, he or she will be added to that specific

group in the course. This makes it possible to separate coupon users from regular users.

You could also make specific course groups every time you generate a batch of new coupons, so there's

some way of matching a batch of coupons to a group of users. The possibilities are numerous.

- Cohort level: this means one or more cohort(s) need to be selected for which the coupon is valid.

Once the coupon code is entered by a user, he or she will be added as a cohort member for every

cohort the coupon is attached to.

NOTE: When generating cohort level coupons, there is a possibility to "connect" extra courses to

a given cohort. One MUST know that upon doing this, the courses will at that point be added to

the cohort enrolment sync. Without knowing this little fact, it could be "unexpected" behavior,

even though it's a logical step.

Furthermore, coupons can be generated on two "access" levels:

- Personalized. The base of this, is either a CSV is uploaded, or a CSV is given directly in a textbox.

The needed user information for every coupon to be generated will be the user's name, email address

and gender.

These coupons will then be generated and sent off to the appropriate users using a background task.

- Bulk: The base of this is simple: you generate a certain amount of access coupons, which will then

be emailed to the pre-configured recipient or (if allowed) to an emailaddress that can be freely entered.

- WARNING:

Wherever possible, please use PNG images.

Also, whenever possible, do NOT use images that have an alpha channel.

This will MASSIVELY slow down processing time, due to internal conversion of images by TCPDF.

On our tests, for a 300 DPI image on A4 format (2480 x 3508 pixels) with an alpha channel,

rendering a single PDF took around 25 seconds. Taking the alpha channel out of the image,

rendering a single PDF was reduced to around 3 seconds.

This means the PNG images should _always_ be stored as 24-bit true colour images.

_Do not use 32-bit_ (true colour + transparency)!

Furthermore, whenever possible, have the coupon generator create a single PDF with all

coupons (this is only applicable when generating coupons in "bulk" mode). The process of

generating coupons has been optimized to only "use" the image 1 time when creating any amount

of coupons in a single PDF. If you choose the option to create a seperate PDF for every coupon,

the image will have to be rendered for each and every PDF.

This has 2 major downfalls:

1. Every PDF will roughly have a slightly bigger size than the image size (in our tests, 350 - 400 kB per PDF)

2. Every PDF takes the full amount of time to render.

Effectively, this means the following (using fictitious sizes):

10 coupons, single PDF -> result is around 400 kB, rendering takes around 3-4 seconds.

10 coupons, seperate PDFs -> result is around 4 MB, rendering takes around 35-40 seconds.

INSTALLATION INSTRUCTIONS

- Copy the coupon folder to your blocks directory.

- Go to the moodle admin pages (you will probably be confronted with it anyway) and install the plugin

- Configure the main settings for the plugin.

- We're set up for usage!

PLACEMENT OF THE PLUGIN

There are only two pages you can add the coupon block on. This is the site's frontpage

or the user dashboard (my) page. The main reason for this is because the block is the

"frontend" for users to enter their coupon or voucher code.

Administrators and users with the correct capabilities will also see the links to

the coupon administration pages and the coupon generator page.

GENERAL CONSIDERATIONS

There's two main configurations to consider when generating coupons.

For course type coupons, this plugin attempts to enrol a user through use of Moodle's

internal function "enrol_try_internal_enrol".

The Moodle documentation shows it will attempt to enrol you using manual enrolment.

For this reason manual enrolment MUST be enabled for these courses.

For cohort type coupons, a user is made a member of a cohort. That's all there is to it.

Surprise though, if you want to actually make a user have access to a course, you

probably want to configure cohort enrolment for the course.

For those paying attention, creating cohort type coupons thus enables a simple

way of enrolling users into multiple courses at once just by configuring the right

cohort enrolments in multiple courses.

That's still not to say course coupons can't be used in a similar way (using meta courses).

### Contributors

Rogier van Dongen

### Awards

• Mon, Sep 14, 2020, 6:18 PM
Dear Brendan,
Thanks for the heads up, the first service call is basically the correct one, but there seems to be something wrong with the result of the call (which you may have noticed due to the "invalid response value" error).
The cohort enrolment is not cleaned up as far as I can see (i.e. it does not remove the enrolment).
I'll be looking into these issues and a new version can be expected soon where both of these will be addressed.
Cheers,
Rogier
• Mon, Sep 14, 2020, 11:14 PM
Another new version is here!
This time we've looked into and fixed the issues as indicated by Brendan as shown above (mon, sept 7th 2020).
Cheers! Rogier
• Tue, Sep 22, 2020, 4:13 PM
Hello there,
I've installed the plugin on moodle 3.9.1, works great, however, I have an issue with Personalised coupons, they got generated, but are not sent. Can any one help me in this?
I chose to generate coupons to non-registered users so that they can sign up using the coupon code using (https://mymoodle.localhost/blocks/coupon/view/signup.php?id=37)
Appreciated!
George
• Tue, Sep 22, 2020, 4:28 PM
Hi George,
Can you confirm your background tasks are running? Sending of personalised coupons is done apart from the coupon generating process due to the possibly lenghty process.
If you have access to the database tables themselves (if not you could install the local_adminer plugin to get access from within moodle but you'd have to know the db credentials), can you also see if the "issend" (excuse the typo) field is marked 0 or 1? You should also be able to see this through the coupon overview tables in the plugin itself. If marked as 0 (or "no"), they're definitiely not sent. If marked as 1 (or "yes") they should have been sent out and the problem is likely to be beyond the plugin scope.
Cheers,
Rogier
• Tue, Sep 22, 2020, 5:02 PM
Hi Rogier,
I checked the database tables, the issend was set to 0. I forced run the background tasks using the cron.php, then the everything went fine, the emails were sent and the status "issend" is set to 0.
Thanks for the useful hint and help.
Regards,
George.
• Tue, Sep 22, 2020, 5:03 PM
Correction to the previous post - the new status "issend" is set to 1
• Thu, Oct 22, 2020, 7:13 PM
Thanks for making the update for the cohort clean-up, however I am still having an issue with the coupon not removing users from a cohort. I have installed the latest version of the coupon plugin and have run a test where I do the following:
1) Create a coupon with enrolment in a cohort and set the enrolment period to 5 minutes.
2) Log in as a user and redeem the coupon - the user is then added to the cohort and has access to all the courses associated with it.
3) Wait 5 minutes to see if the user loses access to the courses. This doesn't happen and checking the cohort the user remains added to it, seemingly indefinitely.

I have tried running the cron.php to see if this is needed to remove the users but that doesn't help.
• Tue, Oct 27, 2020, 2:29 PM
Hello.
On the "Site administration / Messaging / Notification settings" page, I understand that there are two notification settings for coupons available.
- Personal coupons sent out notification

What is the difference between them?

Also, if I have both enabled, I receive two e-mails or web notifications with the same text when a coupon is issued.
Is this correct behavior?
• Mon, Nov 2, 2020, 5:31 PM
@Brendan,
The scheduled task is set to only run every 15 minutes and is based on the "lastruntime" of the task. I'd advise to first set the task to run every minute and re-run one or two times.
The very first run will never clean up anything due to the nature of tasks (the "lastruntime" value will always be 0 for the first run so determination of possible removals would be based on 1970-01-01; which is more than unlikely to return any results).
I've set up a new case on various Moodle installations to confirm the process and for me it works like a charm (after setting the task to run every minute).
The user is removed from the cohort and as a result unenrolled from the course.
If you still run into issues, please pass me a message again.
Cheers, Rogier
• Mon, Nov 2, 2020, 6:11 PM
@Hiro,
This is not really intended behaviour but more then likely a side effect that is caused by adding more functionality to the plugin. Thanks for noticing it, I'll see if I can phase out the double messages in one of the next version.
Cheers, Rogier
• Mon, Nov 9, 2020, 8:11 AM
Hello Rogier,
I'm looking forward to the fix.
Regards,
• Thu, Nov 12, 2020, 5:39 PM
Hello Rogier,
Sorry for the repeated questions.
Can you tell me the difference between the following settings on the "Site Administration/Messaging/Notification Settings" page?

I'm considering using it differently.
If you have published documentation, I'd be happy to let me know.
Regards,
• Thu, Nov 19, 2020, 2:33 PM
Please accept my apology if this has already been considered and replied to.
Is there a way I can create a custom coupon string instead of the random string generated by this plugin? I would be better to know what a coupon code is when creating & sending them out.
• Wed, Nov 25, 2020, 8:12 PM
I'm facing a real big problem here in my installation...

1.Coupons are generated correctly (checked on moodledata dir)
2.Coupons files are not included in the email sent
3. When visualizing the coupons download page, it doesn't show the download link. It shows a {$a} instead (look like a variable or parameter that should render the link. On this page, if add, at the end of the address the parameter dl=1, download starts and then works. It was used to work fine in the past versions. I'm using 3.8 moodle. Help please. 👊🏻 😉 Felipe Garbin • Thu, Nov 26, 2020, 12:55 PM Still about the above trouble... The notification received: "The coupon(s) you requested have been generated You should have received an e-mail containing the link to download the generated coupons. You can also choose to download your coupons directly by clicking {$a}"