Compare commits
377 commits
MOODLE_31_
...
MOODLE_311
Author | SHA1 | Date | |
---|---|---|---|
6ac6ba53c1 | |||
bd2a78b94b | |||
87b79503c8 | |||
7c33e659b4 | |||
8cc6693b24 | |||
6bb72f655f | |||
b9c5e95f7a | |||
|
311e243ca5 | ||
|
5ba1b2b40f | ||
|
4ca9f05fc1 | ||
|
2a9640b5a3 | ||
|
18eab896bd | ||
|
9e38411434 | ||
|
8464ba6259 | ||
|
92a3bcb0c3 | ||
|
3b1cd64703 | ||
|
383054be39 | ||
|
80dc7395c3 | ||
|
b684fee9f4 | ||
|
95274bfad6 | ||
|
75fe6b4cdd | ||
|
8b8a358790 | ||
|
a1f0e6dec7 | ||
|
f1cf599f31 | ||
|
afcea89c82 | ||
|
5e3135324c | ||
|
c6c4e6f6a7 | ||
|
25d398ce22 | ||
|
cf11f765b0 | ||
|
6d966df56c | ||
|
e4458872fa | ||
|
26802e9262 | ||
|
0de67035a3 | ||
|
11225ff1fa | ||
|
bd361d2434 | ||
|
659e065a2f | ||
|
991ef9b0e3 | ||
|
a68f1b9487 | ||
|
8145e020e4 | ||
|
e65cf7e9c2 | ||
|
345c6e438b | ||
|
1343d64310 | ||
|
0208efa585 | ||
|
1a6d370d3f | ||
|
69a3436faa | ||
|
9f320984c6 | ||
|
0122cc1138 | ||
|
4ca04d204d | ||
|
ff16abfd7c | ||
|
1859ffa651 | ||
|
47061f8737 | ||
|
6e89c1d921 | ||
|
22081dffb0 | ||
|
2e58b24daa | ||
|
8446a2e10a | ||
|
ae2df6c9ed | ||
|
2e881e32c9 | ||
|
dcbb07e2f3 | ||
|
350b18dda6 | ||
|
a9f83a2579 | ||
|
a81b6e4fd5 | ||
|
8515c5bd9e | ||
|
b70224c0e4 | ||
|
a38678c691 | ||
|
35350fe454 | ||
|
fd4d992602 | ||
|
361b156f4a | ||
|
e9b30dac79 | ||
|
be202676c9 | ||
|
da49799857 | ||
|
842b0910e2 | ||
|
8c0e00419c | ||
|
c1615cbd16 | ||
|
438dfd868f | ||
|
a262adfc6e | ||
|
2b4f385333 | ||
|
62dcd9576d | ||
|
9a2edca684 | ||
|
0c89ff9547 | ||
|
27f5a74cb3 | ||
|
a8eca647fe | ||
|
695798ca6f | ||
|
632dba8fb2 | ||
|
0a390df7ff | ||
|
46ca744d32 | ||
|
60b247f441 | ||
|
6a19ec83e9 | ||
|
e52422b922 | ||
|
2dc05b8b81 | ||
|
c95b058049 | ||
|
c69d4822cc | ||
|
a884f948d3 | ||
|
6af1757084 | ||
|
0f62eb30b5 | ||
|
66148c70f6 | ||
|
98307310cf | ||
|
05f12a3dde | ||
|
7107b67856 | ||
|
9e386f19c3 | ||
|
eec256cd01 | ||
|
4ab2c04b29 | ||
|
784ca08fb1 | ||
|
31d1f9a36d | ||
|
05c1c00cc0 | ||
|
3e26a6b7c1 | ||
|
4679c79e37 | ||
|
15b8061261 | ||
|
2a16dbe1c0 | ||
|
f2524610f0 | ||
|
db10a589f1 | ||
|
a0bc5ffa04 | ||
|
d5ba284e64 | ||
|
f68658d675 | ||
|
28975d4625 | ||
|
2cdae3f45c | ||
|
9cf95f5104 | ||
|
f0a25193ba | ||
|
bd135ef579 | ||
|
6a1f55c98a | ||
|
9df6c9d71e | ||
|
8ba89c18ce | ||
|
a5eea57644 | ||
|
f172ad029b | ||
|
59b87d19ac | ||
|
849d6645fd | ||
|
ac8a49bcca | ||
|
f6b9e48691 | ||
|
080e53d13a | ||
|
b89010ffd1 | ||
|
8296796519 | ||
|
9f953fc928 | ||
|
36d178bda3 | ||
|
7756d928ac | ||
|
7611196fa3 | ||
|
68838944fa | ||
|
7dd18f75e2 | ||
|
7e60325e17 | ||
|
688d243eee | ||
|
0d67b87908 | ||
|
38def6bfb4 | ||
|
cbf9997f3e | ||
|
8358280c6c | ||
|
557a2aee18 | ||
|
88dcb9142a | ||
|
1fbf233111 | ||
|
3450388a36 | ||
|
5b44544e74 | ||
|
597659e23e | ||
|
c31f31a63d | ||
|
fafb0159d8 | ||
|
6e091e9fd6 | ||
|
4ac9615514 | ||
|
d0bca80d35 | ||
|
386592d27b | ||
|
a7441e8b1b | ||
|
fbe8024438 | ||
|
4e30f1e851 | ||
|
5a9d9792df | ||
|
19d0bf5dc8 | ||
|
b26e8c92b9 | ||
|
b6ce73637c | ||
|
1a172b9065 | ||
|
7436054c17 | ||
|
0b0b37ed35 | ||
|
1ac494df93 | ||
|
f0733f4e7d | ||
|
8467b847b2 | ||
|
4f4a999439 | ||
|
b808ff4ead | ||
|
14e369b775 | ||
|
1746ec47dc | ||
|
a6b180454f | ||
|
813fae127c | ||
|
a05996d656 | ||
|
2ea80b1084 | ||
|
544c6ed67b | ||
|
85e84348fc | ||
|
7c333442ee | ||
|
61d0bd433f | ||
|
f8a55869b5 | ||
|
5807d5e2dd | ||
|
7002818fca | ||
|
7b40489019 | ||
|
2cee556f9f | ||
|
b211a06bd5 | ||
|
ed2eccd430 | ||
|
7ebb5b0ab5 | ||
|
13ddab941f | ||
|
9e9192c7fc | ||
|
32338c9aa7 | ||
|
2bfb6b53e0 | ||
|
5182ab60e2 | ||
|
a55b253cff | ||
|
cf93b540d6 | ||
|
97e44d3d1d | ||
|
9834d7f4b8 | ||
|
255743f9e0 | ||
|
988af1c457 | ||
|
76a20a80e0 | ||
|
ff02ba71aa | ||
|
7ae3101ea1 | ||
|
2ebb734145 | ||
|
e6d74ec047 | ||
|
c8939ae526 | ||
|
fcaf1fefd5 | ||
|
706912c52f | ||
|
7de488d638 | ||
|
804b0ec359 | ||
|
d169b6958c | ||
|
b797b659f5 | ||
|
13ab862856 | ||
|
64865aff4e | ||
|
210e61e227 | ||
|
ee301654d3 | ||
|
13c1998c49 | ||
|
b254116e4d | ||
|
26ea75479f | ||
|
9f2a36d983 | ||
|
9440dea72c | ||
|
ef285e6075 | ||
|
39ccef311e | ||
|
91da92f10d | ||
|
54212da3d2 | ||
|
2500fada80 | ||
|
f3cff401b5 | ||
|
47f1102545 | ||
|
c395c7dadc | ||
|
6926280807 | ||
|
973d81b697 | ||
|
002cebd47c | ||
|
5d6e1e4250 | ||
|
86551f18c7 | ||
|
51c0741ecb | ||
|
ef67beadf6 | ||
|
9d68fcead2 | ||
|
bc527a0669 | ||
|
8fbc6a0f13 | ||
|
9a21f67089 | ||
|
e7a7f0aef5 | ||
|
de2709ae54 | ||
|
c18c84b0df | ||
|
3727ff4fbd | ||
|
9a32a99f65 | ||
|
74d0fb363f | ||
|
2868082e9e | ||
|
7bff2c5367 | ||
|
033fdc7ee2 | ||
|
05df874d2a | ||
|
32cbb26a21 | ||
|
308b8d1e19 | ||
|
2687ee737f | ||
|
08a385fc85 | ||
|
3b2a45d755 | ||
|
be9c466f4a | ||
|
7a20d0778b | ||
|
c61e687080 | ||
|
ab32f72644 | ||
|
3c6a8b97f3 | ||
|
f0b8292779 | ||
|
3620b5543d | ||
|
b301b44748 | ||
|
13eb4509de | ||
|
b43d7d33ea | ||
|
4958b07f07 | ||
|
1e977bbf31 | ||
|
787e370907 | ||
|
78931854ee | ||
|
666ed6b2d4 | ||
|
b14ccbba57 | ||
|
52d1613902 | ||
|
60398c42aa | ||
|
09d7812fe1 | ||
|
82b430f5aa | ||
|
65179d6b8b | ||
|
981fd1828c | ||
|
759df979c8 | ||
|
750a787214 | ||
|
cbfe09f60a | ||
|
6c4b77925b | ||
|
cc22ebbac2 | ||
|
f3d48abee5 | ||
|
e2a814a315 | ||
|
9813efbac5 | ||
|
20126a0fa2 | ||
|
7a40ebfc77 | ||
|
c08800020c | ||
|
531cb0aefe | ||
|
909d376b95 | ||
|
a211f97931 | ||
|
3461c9585d | ||
|
f8d7781158 | ||
|
2d1bc8a70c | ||
|
2b2c16d3df | ||
|
9f061fab01 | ||
|
1e35923b43 | ||
|
43a4b8b8e7 | ||
|
2b79d6c58b | ||
|
5c1f1aa812 | ||
|
fedfe95080 | ||
|
3120130437 | ||
|
538093223d | ||
|
93d28a53fb | ||
|
1bd610d43f | ||
|
fa69bcc604 | ||
|
efd5b7107c | ||
|
461a05ea69 | ||
|
a165092d7d | ||
|
48bb4e23b9 | ||
|
bbce9f1364 | ||
|
3c7c32e619 | ||
|
44b3a77a5f | ||
|
1bb5ad0409 | ||
|
971a3fdbfe | ||
|
b626e4fd43 | ||
|
9c589163a2 | ||
|
429b8c819c | ||
|
87ee9f10ce | ||
|
5299a83209 | ||
|
a5bcc985ee | ||
|
8db4a75b52 | ||
|
c968d38927 | ||
|
052b7b874f | ||
|
1a134d7319 | ||
|
da6c723830 | ||
|
1f219af560 | ||
|
a943caf007 | ||
|
d0a0fc5abc | ||
|
1ac7c1ffb6 | ||
|
5c64d11446 | ||
|
d35cd7890d | ||
|
3c937be003 | ||
|
02fba86de2 | ||
|
38d023b8db | ||
|
2b70dde263 | ||
|
58ce316221 | ||
|
f9cd560567 | ||
|
9ce2be7bb6 | ||
|
f55ceec649 | ||
|
16b0f69acb | ||
|
106fd9671e | ||
|
7d2664991f | ||
|
4f4be1f918 | ||
|
72c3b278e3 | ||
|
2b27f564b8 | ||
|
c8d0e0491d | ||
|
10310523c6 | ||
|
f83e3dca58 | ||
|
bbc749fa49 | ||
|
fdc5bde3d4 | ||
|
db879187bf | ||
|
e31236cbf2 | ||
|
3be613e8c6 | ||
|
ca08fe954a | ||
|
7e6fa8103f | ||
|
5bed5517e6 | ||
|
14e051702d | ||
|
7e1dcd3cf7 | ||
|
ee3bdf7c18 | ||
|
dabc959826 | ||
|
e6f26a3661 | ||
|
a09fc76ef4 | ||
|
bfc3780933 | ||
|
a81137daca | ||
|
a925687e09 | ||
|
f2f3206321 | ||
|
04510e2627 | ||
|
13fc5dfa4f | ||
|
ceb2d5623f | ||
|
ed2ef13c7f | ||
|
831996de4b | ||
|
77d05865d7 | ||
|
6fb3230e54 | ||
|
f3f9fef1a4 | ||
|
a41c443135 | ||
|
433fd8b43b | ||
|
c5859e433f | ||
|
a3c67401fd |
165 changed files with 7933 additions and 1109 deletions
120
.github/workflows/moodle-ci.yml
vendored
Normal file
120
.github/workflows/moodle-ci.yml
vendored
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
name: Moodle Plugin CI
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:9.6
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: 'postgres'
|
||||||
|
POSTGRES_HOST_AUTH_METHOD: 'trust'
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:10.5
|
||||||
|
env:
|
||||||
|
MYSQL_USER: 'root'
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: '7.4'
|
||||||
|
moodle-branch: 'MOODLE_311_STABLE'
|
||||||
|
database: pgsql
|
||||||
|
- php: '7.4'
|
||||||
|
moodle-branch: 'MOODLE_311_STABLE'
|
||||||
|
database: mariadb
|
||||||
|
- php: '7.3'
|
||||||
|
moodle-branch: 'MOODLE_311_STABLE'
|
||||||
|
database: pgsql
|
||||||
|
- php: '7.3'
|
||||||
|
moodle-branch: 'MOODLE_311_STABLE'
|
||||||
|
database: mariadb
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: plugin
|
||||||
|
|
||||||
|
- name: Setup PHP ${{ matrix.php }}
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php }}
|
||||||
|
coverage: none
|
||||||
|
|
||||||
|
- name: Initialise moodle-plugin-ci
|
||||||
|
run: |
|
||||||
|
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
|
||||||
|
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
|
||||||
|
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
|
||||||
|
sudo locale-gen en_AU.UTF-8
|
||||||
|
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Install moodle-plugin-ci
|
||||||
|
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
|
||||||
|
env:
|
||||||
|
DB: ${{ matrix.database }}
|
||||||
|
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
|
||||||
|
MUSTACHE_IGNORE_NAMES: 'mobile_*.mustache'
|
||||||
|
|
||||||
|
- name: PHP Lint
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phplint
|
||||||
|
|
||||||
|
- name: PHP Copy/Paste Detector
|
||||||
|
continue-on-error: true # This step will show errors but will not fail
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpcpd
|
||||||
|
|
||||||
|
- name: PHP Mess Detector
|
||||||
|
continue-on-error: true # This step will show errors but will not fail
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpmd
|
||||||
|
|
||||||
|
- name: Moodle Code Checker
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci codechecker --max-warnings 0
|
||||||
|
|
||||||
|
- name: Moodle PHPDoc Checker
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci phpdoc
|
||||||
|
|
||||||
|
- name: Validating
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci validate
|
||||||
|
|
||||||
|
- name: Check upgrade savepoints
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci savepoints
|
||||||
|
|
||||||
|
- name: Mustache Lint
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci mustache
|
||||||
|
|
||||||
|
- name: Grunt
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci grunt --max-lint-warnings 0
|
||||||
|
|
||||||
|
- name: PHPUnit tests
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: |
|
||||||
|
moodle-plugin-ci phpunit
|
||||||
|
cd moodle
|
||||||
|
vendor/bin/phpunit --fail-on-risky --disallow-test-output --filter tool_dataprivacy_metadata_registry_testcase
|
||||||
|
vendor/bin/phpunit --fail-on-risky --disallow-test-output --filter core_externallib_testcase
|
||||||
|
vendor/bin/phpunit --fail-on-risky --disallow-test-output --testsuite core_privacy_testsuite --filter provider_testcase
|
||||||
|
|
||||||
|
- name: Behat features
|
||||||
|
if: ${{ always() }}
|
||||||
|
run: moodle-plugin-ci behat --profile chrome
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
vendor/
|
||||||
|
*.swp
|
39
.travis.yml
39
.travis.yml
|
@ -1,39 +0,0 @@
|
||||||
language: php
|
|
||||||
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.composer/cache
|
|
||||||
|
|
||||||
php:
|
|
||||||
- 5.4
|
|
||||||
- 7.0
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- MOODLE_BRANCH=MOODLE_31_STABLE
|
|
||||||
matrix:
|
|
||||||
- DB=pgsql
|
|
||||||
- DB=mysqli
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- phpenv config-rm xdebug.ini
|
|
||||||
- cd ../..
|
|
||||||
- composer selfupdate
|
|
||||||
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^1
|
|
||||||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
|
||||||
|
|
||||||
install:
|
|
||||||
- moodle-plugin-ci install
|
|
||||||
|
|
||||||
script:
|
|
||||||
- moodle-plugin-ci phplint
|
|
||||||
- moodle-plugin-ci codechecker
|
|
||||||
- moodle-plugin-ci csslint
|
|
||||||
- moodle-plugin-ci shifter
|
|
||||||
- moodle-plugin-ci jshint
|
|
||||||
- moodle-plugin-ci validate
|
|
||||||
- moodle-plugin-ci phpunit
|
|
||||||
- moodle-plugin-ci behat
|
|
||||||
|
|
252
CHANGES.md
252
CHANGES.md
|
@ -2,21 +2,249 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
Note - All hash comments refer to the issue number. Eg. #169 refers to https://github.com/markn86/moodle-mod_customcert/issues/169.
|
Note - All hash comments refer to the issue number. Eg. #169 refers to https://github.com/mdjnelson/moodle-mod_customcert/issues/169.
|
||||||
|
|
||||||
|
## [3.11.2] - 2021-??-??
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix places not using the multi-language filter (#433).
|
||||||
|
- Fix user IDs in the issue table not being mapped during restore (#449).
|
||||||
|
- Fix emails displaying HTML entities encoded (#457).
|
||||||
|
- Fix error message when we have custom profile fields (#465).
|
||||||
|
- Respect multiple languages in manage template page title (#467).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- You can now choose the course short or full name to display (#415).
|
||||||
|
- You can now select the alignment for all text elements (#121).
|
||||||
|
|
||||||
|
## [3.11.1] - 2021-06-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Usage of deprecated functions (#423)
|
||||||
|
|
||||||
|
## [3.10.1] - 2021-06-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Usage of github actions (#407).
|
||||||
|
- The ability to show the description on the course page (#406).
|
||||||
|
- The ability to choose how to deliver the certificate (#401).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Managers are now able to download their students' certificates (#412).
|
||||||
|
- Users being able to view the certificate before the required time set (#403).
|
||||||
|
- Fixed the issue with displaying PDF when debugging is ON (#420).
|
||||||
|
- Using incorrect context when sending emails (#402).
|
||||||
|
- Use `cron_setup_user` when sending emails (#414).
|
||||||
|
|
||||||
|
## [3.8.5] - 2020-11-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added ability to select outcomes in the Grade element (#329).
|
||||||
|
- The Grade Item Name element now works with all grade items, whereas before it was just activities (#346).
|
||||||
|
- Added enrolment start and end dates to the date element (#328).
|
||||||
|
- Added username to userfield form element (#390).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Removed unnecessary and confusing 'exampledata' string.
|
||||||
|
- Do not email those who can manage the certificate (#376).
|
||||||
|
- Do not force the PDF to be downloaded, instead send the file inline to the browser (#153).
|
||||||
|
- Updated the 'emailstudents_help', 'emailteachers_help' and 'emailothers_help' strings to warn users about prematurely emailing the certificate (#276).
|
||||||
|
- Do not email out certificates that contain no elements (#276).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Certificates now get marked as viewed via the mobile app (#342).
|
||||||
|
- Custom fields not displaying properly (#359).
|
||||||
|
- Fix repositioning elements page when resizing the browser (#343).
|
||||||
|
- Prevent error when duplicate issues exist when using the code element (#363).
|
||||||
|
- Implemented get_objectid_mapping for the course_module_viewed.php event to avoid warning (#374).
|
||||||
|
- Fixed exception being thrown when loading a template that has an image element but no image selected (#369).
|
||||||
|
- Fixed issue with PDF being generated without a name (#333).
|
||||||
|
|
||||||
|
## [3.8.4] - 2020-03-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added extra Behat steps for new elements (#309).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- When copying a site template the site images are also copied to the course context and then those copied images are used.
|
||||||
|
Before, the elements would simply point to the site images. However, this meant when performing a backup/restore the
|
||||||
|
images were not stored in the backup file (#298).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the displaying of names of a custom user field (#326).
|
||||||
|
- Do not allow '0' as a value for width or height in QR code (#321).
|
||||||
|
|
||||||
|
## [3.8.3] - 2020-03-09
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed foreign key violation (#331).
|
||||||
|
|
||||||
|
## [3.8.2] - 2019-12-16
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added subplugins.json file (#312).
|
||||||
|
- Re-added 'code' column to user report (#264).
|
||||||
|
- Add 'userfullname' variable for email subject (#316).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Do not fail if multiple certificate issues (#304) and (#295).
|
||||||
|
|
||||||
|
## [3.7.1] - 2019-06-17
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added new custom course field element (#274).
|
||||||
|
- Added ability to specify the current date for date related elements (#289).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- String improvements for the 'Date range' element.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Use negative numbers for constants in the 'Date range' element. The reason being that we may have a module
|
||||||
|
that has an id matching one of these positive values. Sites which are using the 'Date range' element (sites
|
||||||
|
which are **not** using this element do **not** have to do anything) will need to re-edit each element, select
|
||||||
|
the date item again and save. An upgrade step was not created because it is impossible to tell if the site does
|
||||||
|
actually want the constant or if they actually want the date for the module.
|
||||||
|
|
||||||
|
## [3.6.2] - 2019-05-28
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Always send emails from the 'noreplyuser' (#165).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added QR code element (#146).
|
||||||
|
- Added Date range element (#185).
|
||||||
|
- Added the number of certificates issued above the report (#266).
|
||||||
|
- Added new capability to control who can be issued a certificate (#270).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Failures when running unit tests for multiple activities (#282).
|
||||||
|
- Check that a certificate is valid before downloading on 'My certificates' page (#269).
|
||||||
|
|
||||||
|
## [3.6.1] - 2018-12-31
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Make it clear what element values are just an example when previewing the PDF (#144).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Missing implementation for privacy provider (#260).
|
||||||
|
- Use course module context when calling format_string/text (#200).
|
||||||
|
- Exception being thrown when adding the 'teachername' element to site template (#261).
|
||||||
|
|
||||||
|
## [3.5.5] - 2018-12-20
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- GDPR: Add support for removal of users from a context (see MDL-62560) (#252).
|
||||||
|
- Images can be made transparent (#186).
|
||||||
|
- Set default values of activity instance settings (#180).
|
||||||
|
- Allow element plugins to control if they can be added to a certificate (#225).
|
||||||
|
- Allow element plugins to have their own admin settings (#213).
|
||||||
|
- Added plaintext language variants for email bodies (#231).
|
||||||
|
- Added possibility to selectively disable activity instance settings (#179).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Allow verification of deleted users (#159).
|
||||||
|
- The 'element' field in the 'customcert_elements' table has been changed from a Text field to varchar(255) (#241).
|
||||||
|
- The 'Completion date' option in the 'date' element is only displayed when completion is enabled (#160).
|
||||||
|
- Instead of assuming 2 decimal points for percentages, we now make use of the decimal value setting, which the
|
||||||
|
function `grade_format_gradevalue` does by default if no decimal value is passed.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Issue with scales not displaying correctly (#242).
|
||||||
|
- The report now respects the setting 'Show user identity' (#224).
|
||||||
|
- Removed incorrect course reset logic (#223).
|
||||||
|
- Description strings referring to the wrong setting (#254).
|
||||||
|
|
||||||
|
## [3.5.4] - 2018-07-13
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Use custom fonts if present (#211).
|
||||||
|
- Fix broken SQL on Oracle in the email certificate task (#187).
|
||||||
|
- Fixed exception when clicking 'Add page' when template has not been saved (#154).
|
||||||
|
- Only email teachers who are enrolled within the course (#176).
|
||||||
|
- Only display teachers who are enrolled within the course in the dropdown (#171).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Multiple UX improvements to both the browser and mobile views (#207).
|
||||||
|
- One big change here is combining the report and activity view page into one.
|
||||||
|
- Allow short dates with leading zeros (#210).
|
||||||
|
|
||||||
|
## [3.5.3] - 2018-06-26
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Respect filters in the 'My certificates' and 'Verify certificate' pages (#197).
|
||||||
|
- Fixed reference to 'mod/certificate' capability.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Multiple UX improvements to both the browser and mobile views (#203).
|
||||||
|
|
||||||
|
## [3.5.2] - 2018-06-07
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Hotfix to prevent misalignment of 'text' elements after last release (#196).
|
||||||
|
|
||||||
|
## [3.5.1] - 2018-06-06
|
||||||
|
### Added
|
||||||
|
- Mobile app support (#70).
|
||||||
|
```
|
||||||
|
This allows students to view the activity and download
|
||||||
|
their certificate. It also allows teachers to view the
|
||||||
|
list of issued certificates, with the ability to revoke
|
||||||
|
any.
|
||||||
|
|
||||||
|
This is for the soon-to-be released Moodle Mobile v3.5.0
|
||||||
|
(not to be confused with your Moodle site version) and
|
||||||
|
will not work on Mobile versions earlier than this.
|
||||||
|
|
||||||
|
If you are running a Moodle site on version 3.4 or below
|
||||||
|
you will need to install the local_mobile plugin in order
|
||||||
|
for this to work.
|
||||||
|
|
||||||
|
If you are running a Moodle site on version 3.0 or below
|
||||||
|
then you will need to upgrade.
|
||||||
|
```
|
||||||
|
- More font sizes (#148).
|
||||||
|
- Added new download icon.
|
||||||
|
```
|
||||||
|
This was done because the core 'import' icon was mapped
|
||||||
|
to the Font Awesome icon 'fa-level-up' which did not look
|
||||||
|
appropriate. So, a new icon was added and that was mapped
|
||||||
|
to the 'fa-download' icon.
|
||||||
|
```
|
||||||
|
### Fixed
|
||||||
|
- No longer display the 'action' column and user picture URL when downloading the user report (#192).
|
||||||
|
- Elements no longer ignore filters (#170).
|
||||||
|
|
||||||
|
## [3.4.1] - 2018-05-17
|
||||||
|
### Added
|
||||||
|
- GDPR Compliance (#189).
|
||||||
|
|
||||||
## [3.1.21] - 2018-05-17
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Race condition on certificate issues in scheduled task (#173).
|
- Race condition on certificate issues in scheduled task (#173).
|
||||||
- Ensure we backup the 'verifyany' setting (#169).
|
- Ensure we backup the 'verifyany' setting (#169).
|
||||||
- Fixed encoding content links used by restore (#166).
|
- Fixed encoding content links used by restore (#166).
|
||||||
|
|
||||||
## [3.1.20] - 2018-01-23
|
## [3.3.9] - 2017-11-13
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- The fatal error ```Can't use method return value in write context``` would occur in PHP < 5.5 . Note - this fix does not need
|
|
||||||
to be applied to newer branches as the Moodle versions require PHP > 5.5.
|
|
||||||
|
|
||||||
## [3.1.17] - 2017-11-13
|
|
||||||
### Added
|
### Added
|
||||||
- Added capability ```mod/customcert:verifyallcertificates``` that provides a user with the ability to verify any certificate
|
- Added capability ```mod/customcert:verifyallcertificates``` that provides a user with the ability to verify any certificate
|
||||||
on the site by simply visiting the ```mod/customcert/verify_certificate.php``` page, rather than having to go to the
|
on the site by simply visiting the ```mod/customcert/verify_certificate.php``` page, rather than having to go to the
|
||||||
|
@ -35,7 +263,7 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g
|
||||||
### Fixed
|
### Fixed
|
||||||
- Added missing string used in course reset.
|
- Added missing string used in course reset.
|
||||||
|
|
||||||
## [3.1.16] - 2017-09-04
|
## [3.3.8] - 2017-09-04
|
||||||
### Added
|
### Added
|
||||||
- New digital signature element (uses existing functionality in the TCPDF library).
|
- New digital signature element (uses existing functionality in the TCPDF library).
|
||||||
- Ability to duplicate site templates via the manage templates page.
|
- Ability to duplicate site templates via the manage templates page.
|
||||||
|
@ -51,7 +279,7 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g
|
||||||
- Added missing ```confirm_sesskey()``` checks.
|
- Added missing ```confirm_sesskey()``` checks.
|
||||||
- Minor bug fixes.
|
- Minor bug fixes.
|
||||||
|
|
||||||
## [3.1.15] - 2017-08-11
|
## [3.3.7] - 2017-08-11
|
||||||
### Added
|
### Added
|
||||||
- Added much needed Behat test coverage.
|
- Added much needed Behat test coverage.
|
||||||
|
|
||||||
|
@ -66,6 +294,6 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g
|
||||||
### Fixed
|
### Fixed
|
||||||
- Issue where the date an activity was graded was not displaying at all.
|
- Issue where the date an activity was graded was not displaying at all.
|
||||||
|
|
||||||
## [3.1.14] - 2017-08-05
|
## [3.3.6] - 2017-08-05
|
||||||
### Changed
|
### Changed
|
||||||
- Renamed the column 'size' in the table 'customcert_elements' to 'fontsize' due to 'size' being a reserved word in Oracle.
|
- Renamed the column 'size' in the table 'customcert_elements' to 'fontsize' due to 'size' being a reserved word in Oracle.
|
||||||
|
|
674
LICENSE.md
Normal file
674
LICENSE.md
Normal file
|
@ -0,0 +1,674 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
@ -6,6 +6,8 @@ This activity allows the dynamic generation of PDF certificates with complete cu
|
||||||
|
|
||||||
There are two installation methods that are available.
|
There are two installation methods that are available.
|
||||||
|
|
||||||
|
First, make sure that wkhtmltopdf is installed on your server and available on $PATH.
|
||||||
|
|
||||||
Follow one of these, then log into your Moodle site as an administrator and visit the notifications page to complete the install.
|
Follow one of these, then log into your Moodle site as an administrator and visit the notifications page to complete the install.
|
||||||
|
|
||||||
### Git
|
### Git
|
||||||
|
@ -15,7 +17,7 @@ This requires Git being installed. If you do not have Git installed, please visi
|
||||||
Once you have Git installed, simply visit your Moodle mod directory and clone the repository using the following command.
|
Once you have Git installed, simply visit your Moodle mod directory and clone the repository using the following command.
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/markn86/moodle-mod_customcert.git customcert
|
git clone https://github.com/mdjnelson/moodle-mod_customcert.git customcert
|
||||||
```
|
```
|
||||||
|
|
||||||
Then checkout the branch corresponding to the version of Moodle you are using with the following command. Make sure to replace MOODLE_32_STABLE with the version of Moodle you are using.
|
Then checkout the branch corresponding to the version of Moodle you are using with the following command. Make sure to replace MOODLE_32_STABLE with the version of Moodle you are using.
|
||||||
|
@ -36,4 +38,4 @@ Visit the [wiki page](https://docs.moodle.org/en/Custom_certificate_module "Wiki
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Licensed under the [GNU GPL License](http://www.gnu.org/copyleft/gpl.html).
|
Licensed under the [GNU GPL License](http://www.gnu.org/copyleft/gpl.html).
|
||||||
|
|
2
ajax.php
2
ajax.php
|
@ -54,4 +54,4 @@ foreach ($values as $value) {
|
||||||
$element->posx = $value->posx;
|
$element->posx = $value->posx;
|
||||||
$element->posy = $value->posy;
|
$element->posy = $value->posy;
|
||||||
$DB->update_record('customcert_elements', $element);
|
$DB->update_record('customcert_elements', $element);
|
||||||
}
|
}
|
||||||
|
|
3
amd/build/dialogue.min.js
vendored
3
amd/build/dialogue.min.js
vendored
|
@ -1 +1,2 @@
|
||||||
define(["core/yui"],function(a){var b=function(b,c,d,e,f){this.yuiDialogue=null;var g=this;"undefined"==typeof f&&(f=!1),a.use("moodle-core-notification","timers",function(){var h="480px";f&&(h="800px"),g.yuiDialogue=new M.core.dialogue({headerContent:b,bodyContent:c,draggable:!0,visible:!1,center:!0,modal:!0,width:h}),g.yuiDialogue.after("visibleChange",function(b){b.newVal?"undefined"!=typeof d&&a.soon(function(){d(g),g.yuiDialogue.centerDialogue()}):"undefined"!=typeof e&&a.soon(function(){e(g)})}),g.yuiDialogue.show()})};return b.prototype.close=function(){this.yuiDialogue.hide(),this.yuiDialogue.destroy()},b.prototype.getContent=function(){return this.yuiDialogue.bodyNode.getDOMNode()},b});
|
define ("mod_customcert/dialogue",["core/yui"],function(a){var b=function(b,c,d,e,f){this.yuiDialogue=null;var g=this;if("undefined"==typeof f){f=!1}a.use("moodle-core-notification","timers",function(){var h="480px";if(f){h="800px"}g.yuiDialogue=new M.core.dialogue({headerContent:b,bodyContent:c,draggable:!0,visible:!1,center:!0,modal:!0,width:h});g.yuiDialogue.after("visibleChange",function(b){if(b.newVal){if("undefined"!=typeof d){a.soon(function(){d(g);g.yuiDialogue.centerDialogue()})}}else{if("undefined"!=typeof e){a.soon(function(){e(g)})}}});g.yuiDialogue.show()})};b.prototype.close=function(){this.yuiDialogue.hide();this.yuiDialogue.destroy()};b.prototype.getContent=function(){return this.yuiDialogue.bodyNode.getDOMNode()};return b});
|
||||||
|
//# sourceMappingURL=dialogue.min.js.map
|
||||||
|
|
1
amd/build/dialogue.min.js.map
Normal file
1
amd/build/dialogue.min.js.map
Normal file
File diff suppressed because one or more lines are too long
3
amd/build/rearrange-area.min.js
vendored
3
amd/build/rearrange-area.min.js
vendored
|
@ -1 +1,2 @@
|
||||||
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),void 0,!0)}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d),this._setPositionInForm(b);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=parseInt(a("#id_refpoint").val()),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",f);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,f,h,i),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()})},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j}g=Math.round(parseFloat(g/this.PIXELSINMM)),h=Math.round(parseFloat(h/this.PIXELSINMM)),d.val(g),e.val(h)}},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
|
define ("mod_customcert/rearrange-area",["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,f,g,h,i){var j=function(b){this._node=a(b);this._setEvents()};j.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0;j.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1;j.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2;j.prototype.PIXELSINMM=3.779527559055;j.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))};j.prototype._editElement=function(a){var e=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid");c.loadFragment("mod_customcert","editelement",h,{elementid:e}).done(function(a,c){g.get_string("editelement","mod_customcert").done(function(f){b.use("moodle-core-formchangechecker",function(){new d(f,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,e,a,c),void 0,!0)}.bind(this))}.bind(this))}.bind(this)).fail(f.exception)};j.prototype._editElementDialogueConfig=function(b,c,d,g){h.replaceNode("#elementcontent",c,d);this._setPositionInForm(b);var i=a(g.getContent());i.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state();this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),e=parseInt(a("#id_refpoint").val()),f="";if(e==this.CUSTOMCERT_REF_POINT_TOPLEFT){f="refpoint-left"}else if(e==this.CUSTOMCERT_REF_POINT_TOPCENTER){f="refpoint-center"}else if(e==this.CUSTOMCERT_REF_POINT_TOPRIGHT){f="refpoint-right"}d.empty().append(c);d.removeClass();d.addClass("element "+f);d.attr("data-refpoint",e);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,e,h,i);g.close()}.bind(this))}.bind(this)).fail(f.exception);c.preventDefault()}.bind(this));i.on("click","#id_cancel",function(a){g.close();a.preventDefault()})};j.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM;e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;if(h&&g>h){g=h}switch(c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2;break;}f.setX(d);f.setY(e)};j.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j;break;}g=Math.round(parseFloat(g/this.PIXELSINMM));h=Math.round(parseFloat(h/this.PIXELSINMM));d.val(g);e.val(h)}};j.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=i.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]};j.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=i.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]};return{init:function init(a){new j(a)}}});
|
||||||
|
//# sourceMappingURL=rearrange-area.min.js.map
|
||||||
|
|
1
amd/build/rearrange-area.min.js.map
Normal file
1
amd/build/rearrange-area.min.js.map
Normal file
File diff suppressed because one or more lines are too long
|
@ -18,7 +18,6 @@
|
||||||
* use the YUI version in AMD code until it is replaced.
|
* use the YUI version in AMD code until it is replaced.
|
||||||
*
|
*
|
||||||
* @module mod_customcert/dialogue
|
* @module mod_customcert/dialogue
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* AMD module used when rearranging a custom certificate.
|
* AMD module used when rearranging a custom certificate.
|
||||||
*
|
*
|
||||||
* @module mod_customcert/rearrange-area
|
* @module mod_customcert/rearrange-area
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -105,7 +104,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
||||||
// All done.
|
// All done.
|
||||||
popup.close();
|
popup.close();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this)).fail(notification.exception);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class backup_customcert_activity_task extends backup_activity_task {
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
static public function encode_content_links($content) {
|
public static function encode_content_links($content) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
$base = preg_quote($CFG->wwwroot, "/");
|
$base = preg_quote($CFG->wwwroot, "/");
|
||||||
|
|
|
@ -59,7 +59,7 @@ class backup_customcert_activity_structure_step extends backup_activity_structur
|
||||||
$element = new backup_nested_element('element', array('id'), array(
|
$element = new backup_nested_element('element', array('id'), array(
|
||||||
'pageid', 'name', 'element', 'data', 'font', 'fontsize',
|
'pageid', 'name', 'element', 'data', 'font', 'fontsize',
|
||||||
'colour', 'posx', 'posy', 'width', 'refpoint', 'sequence',
|
'colour', 'posx', 'posy', 'width', 'refpoint', 'sequence',
|
||||||
'timecreated', 'timemodified'));
|
'alignment', 'timecreated', 'timemodified'));
|
||||||
|
|
||||||
// The issues.
|
// The issues.
|
||||||
$issues = new backup_nested_element('issues');
|
$issues = new backup_nested_element('issues');
|
||||||
|
|
|
@ -53,7 +53,7 @@ class restore_customcert_activity_task extends restore_activity_task {
|
||||||
/**
|
/**
|
||||||
* Define the contents in the activity that must be processed by the link decoder.
|
* Define the contents in the activity that must be processed by the link decoder.
|
||||||
*/
|
*/
|
||||||
static public function define_decode_contents() {
|
public static function define_decode_contents() {
|
||||||
$contents = array();
|
$contents = array();
|
||||||
|
|
||||||
$contents[] = new restore_decode_content('customcert', array('intro'), 'customcert');
|
$contents[] = new restore_decode_content('customcert', array('intro'), 'customcert');
|
||||||
|
@ -64,7 +64,7 @@ class restore_customcert_activity_task extends restore_activity_task {
|
||||||
/**
|
/**
|
||||||
* Define the decoding rules for links belonging to the activity to be executed by the link decoder.
|
* Define the decoding rules for links belonging to the activity to be executed by the link decoder.
|
||||||
*/
|
*/
|
||||||
static public function define_decode_rules() {
|
public static function define_decode_rules() {
|
||||||
$rules = array();
|
$rules = array();
|
||||||
|
|
||||||
$rules[] = new restore_decode_rule('CUSTOMCERTVIEWBYID', '/mod/customcert/view.php?id=$1', 'course_module');
|
$rules[] = new restore_decode_rule('CUSTOMCERTVIEWBYID', '/mod/customcert/view.php?id=$1', 'course_module');
|
||||||
|
@ -75,19 +75,19 @@ class restore_customcert_activity_task extends restore_activity_task {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the restore log rules that will be applied by the {@link restore_logs_processor} when restoring
|
* Define the restore log rules that will be applied by the {@see restore_logs_processor} when restoring
|
||||||
* customcert logs. It must return one array of {@link restore_log_rule} objects.
|
* customcert logs. It must return one array of {@see restore_log_rule} objects.
|
||||||
*
|
*
|
||||||
* @return array the restore log rules
|
* @return array the restore log rules
|
||||||
*/
|
*/
|
||||||
static public function define_restore_log_rules() {
|
public static function define_restore_log_rules() {
|
||||||
$rules = array();
|
$rules = array();
|
||||||
|
|
||||||
$rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}');
|
$rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}');
|
||||||
$rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}');
|
$rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}');
|
||||||
$rules[] = new restore_log_rule('customcert', 'view', 'view.php?id={course_module}', '{customcert}');
|
$rules[] = new restore_log_rule('customcert', 'view', 'view.php?id={course_module}', '{customcert}');
|
||||||
$rules[] = new restore_log_rule('customcert', 'received', 'report.php?a={customcert}', '{customcert}');
|
$rules[] = new restore_log_rule('customcert', 'received', 'view.php?id={course_module}', '{customcert}');
|
||||||
$rules[] = new restore_log_rule('customcert', 'view report', 'report.php?id={customcert}', '{customcert}');
|
$rules[] = new restore_log_rule('customcert', 'view report', 'view.php?id={course_module}', '{customcert}');
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ class restore_customcert_activity_structure_step extends restore_activity_struct
|
||||||
|
|
||||||
$data->customcertid = $this->get_new_parentid('customcert');
|
$data->customcertid = $this->get_new_parentid('customcert');
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
||||||
|
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||||
|
|
||||||
$newitemid = $DB->insert_record('customcert_issues', $data);
|
$newitemid = $DB->insert_record('customcert_issues', $data);
|
||||||
$this->set_mapping('customcert_issue', $oldid, $newitemid);
|
$this->set_mapping('customcert_issue', $oldid, $newitemid);
|
||||||
|
|
|
@ -80,4 +80,4 @@ class admin_setting_link extends \admin_setting_configtext {
|
||||||
return format_admin_setting($this, $this->visiblename,
|
return format_admin_setting($this, $this->visiblename,
|
||||||
\html_writer::link($this->link, $this->linkname), $this->description, true, '', null, $query);
|
\html_writer::link($this->link, $this->linkname), $this->description, true, '', null, $query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,16 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
*/
|
*/
|
||||||
class certificate {
|
class certificate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the file inline to the browser.
|
||||||
|
*/
|
||||||
|
const DELIVERY_OPTION_INLINE = 'I';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send to the browser and force a file download
|
||||||
|
*/
|
||||||
|
const DELIVERY_OPTION_DOWNLOAD = 'D';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string the print protection variable
|
* @var string the print protection variable
|
||||||
*/
|
*/
|
||||||
|
@ -102,23 +112,20 @@ class certificate {
|
||||||
public static function get_fonts() {
|
public static function get_fonts() {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
// Array to store the available fonts.
|
require_once($CFG->libdir . '/pdflib.php');
|
||||||
$options = array();
|
|
||||||
|
|
||||||
// Location of fonts in Moodle.
|
$arrfonts = [];
|
||||||
$fontdir = "$CFG->dirroot/lib/tcpdf/fonts";
|
$pdf = new \pdf();
|
||||||
// Check that the directory exists.
|
$fontfamilies = $pdf->get_font_families();
|
||||||
if (file_exists($fontdir)) {
|
foreach ($fontfamilies as $fontfamily => $fontstyles) {
|
||||||
// Get directory contents.
|
foreach ($fontstyles as $fontstyle) {
|
||||||
$fonts = new \DirectoryIterator($fontdir);
|
$fontstyle = strtolower($fontstyle);
|
||||||
// Loop through the font folder.
|
if ($fontstyle == 'r') {
|
||||||
foreach ($fonts as $font) {
|
$filenamewoextension = $fontfamily;
|
||||||
// If it is not a file, or either '.' or '..', or
|
} else {
|
||||||
// the extension is not php, or we can not open file,
|
$filenamewoextension = $fontfamily . $fontstyle;
|
||||||
// skip it.
|
|
||||||
if (!$font->isFile() || $font->isDot() || ($font->getExtension() != 'php')) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
$fullpath = \TCPDF_FONTS::_getfontpath() . $filenamewoextension;
|
||||||
// Set the name of the font to null, the include next should then set this
|
// Set the name of the font to null, the include next should then set this
|
||||||
// value, if it is not set then the file does not include the necessary data.
|
// value, if it is not set then the file does not include the necessary data.
|
||||||
$name = null;
|
$name = null;
|
||||||
|
@ -127,25 +134,24 @@ class certificate {
|
||||||
$displayname = null;
|
$displayname = null;
|
||||||
// Some of the TCPDF files include files that are not present, so we have to
|
// Some of the TCPDF files include files that are not present, so we have to
|
||||||
// suppress warnings, this is the TCPDF libraries fault, grrr.
|
// suppress warnings, this is the TCPDF libraries fault, grrr.
|
||||||
@include("$fontdir/$font");
|
@include($fullpath . '.php');
|
||||||
// If no $name variable in file, skip it.
|
// If no $name variable in file, skip it.
|
||||||
if (is_null($name)) {
|
if (is_null($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Remove the extension of the ".php" file that contains the font information.
|
|
||||||
$filename = basename($font, ".php");
|
|
||||||
// Check if there is no display name to use.
|
// Check if there is no display name to use.
|
||||||
if (is_null($displayname)) {
|
if (is_null($displayname)) {
|
||||||
// Format the font name, so "FontName-Style" becomes "Font Name - Style".
|
// Format the font name, so "FontName-Style" becomes "Font Name - Style".
|
||||||
$displayname = preg_replace("/([a-z])([A-Z])/", "$1 $2", $name);
|
$displayname = preg_replace("/([a-z])([A-Z])/", "$1 $2", $name);
|
||||||
$displayname = preg_replace("/([a-zA-Z])-([a-zA-Z])/", "$1 - $2", $displayname);
|
$displayname = preg_replace("/([a-zA-Z])-([a-zA-Z])/", "$1 - $2", $displayname);
|
||||||
}
|
}
|
||||||
$options[$filename] = $displayname;
|
|
||||||
}
|
|
||||||
ksort($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $options;
|
$arrfonts[$filenamewoextension] = $displayname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ksort($arrfonts);
|
||||||
|
|
||||||
|
return $arrfonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +175,7 @@ class certificate {
|
||||||
* @param int $userid
|
* @param int $userid
|
||||||
* @return int the total time spent in seconds
|
* @return int the total time spent in seconds
|
||||||
*/
|
*/
|
||||||
public static function get_course_time($courseid, $userid = 0) {
|
public static function get_course_time(int $courseid, int $userid = 0): int {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
if (empty($userid)) {
|
if (empty($userid)) {
|
||||||
|
@ -221,7 +227,7 @@ class certificate {
|
||||||
$totaltime = 0;
|
$totaltime = 0;
|
||||||
}
|
}
|
||||||
$delay = $log->$timefield - $lasthit;
|
$delay = $log->$timefield - $lasthit;
|
||||||
if ($delay > ($CFG->sessiontimeout * 60)) {
|
if ($delay > $CFG->sessiontimeout) {
|
||||||
// The difference between the last log and the current log is more than
|
// The difference between the last log and the current log is more than
|
||||||
// the timeout Register session value so that we have found a session!
|
// the timeout Register session value so that we have found a session!
|
||||||
$login = $log->$timefield;
|
$login = $log->$timefield;
|
||||||
|
@ -264,11 +270,20 @@ class certificate {
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
||||||
|
|
||||||
// Return the issues.
|
// Return the issues.
|
||||||
$ufields = \user_picture::fields('u');
|
$context = \context_module::instance($cm->id);
|
||||||
$sql = "SELECT $ufields, ci.id as issueid, ci.code, ci.timecreated
|
$extrafields = \core_user\fields::for_identity($context)->get_required_fields();
|
||||||
|
|
||||||
|
$ufields = \core_user\fields::for_userpic()->including(...$extrafields);
|
||||||
|
[
|
||||||
|
'selects' => $userfieldsselects,
|
||||||
|
'joins' => $userfieldsjoin,
|
||||||
|
'params' => $userfieldsparams
|
||||||
|
] = (array) $ufields->get_sql('u', true);
|
||||||
|
$allparams = array_merge($allparams, $userfieldsparams);
|
||||||
|
$sql = "SELECT ci.id as issueid, ci.code, ci.timecreated $userfieldsselects
|
||||||
FROM {user} u
|
FROM {user} u
|
||||||
INNER JOIN {customcert_issues} ci
|
INNER JOIN {customcert_issues} ci ON u.id = ci.userid
|
||||||
ON u.id = ci.userid
|
$userfieldsjoin
|
||||||
WHERE u.deleted = 0
|
WHERE u.deleted = 0
|
||||||
AND ci.customcertid = :customcertid
|
AND ci.customcertid = :customcertid
|
||||||
$conditionssql";
|
$conditionssql";
|
||||||
|
|
|
@ -64,6 +64,7 @@ class edit_element_form extends \moodleform {
|
||||||
$mform->addHelpButton('name', 'elementname', 'customcert');
|
$mform->addHelpButton('name', 'elementname', 'customcert');
|
||||||
|
|
||||||
$this->element = \mod_customcert\element_factory::get_element_instance($element);
|
$this->element = \mod_customcert\element_factory::get_element_instance($element);
|
||||||
|
$this->element->set_edit_element_form($this);
|
||||||
$this->element->render_form_elements($mform);
|
$this->element->render_form_elements($mform);
|
||||||
|
|
||||||
$this->add_action_buttons(true);
|
$this->add_action_buttons(true);
|
||||||
|
|
|
@ -80,18 +80,20 @@ class edit_form extends \moodleform {
|
||||||
$this->add_customcert_page_elements($page);
|
$this->add_customcert_page_elements($page);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link to add another page.
|
// Link to add another page, only display it when the template has been created.
|
||||||
$addpagelink = new \moodle_url('/mod/customcert/edit.php',
|
if (isset($this->_customdata['tid'])) {
|
||||||
array(
|
$addpagelink = new \moodle_url('/mod/customcert/edit.php',
|
||||||
'tid' => $this->tid,
|
array(
|
||||||
'aid' => 1,
|
'tid' => $this->tid,
|
||||||
'action' => 'addpage',
|
'aid' => 1,
|
||||||
'sesskey' => sesskey()
|
'action' => 'addpage',
|
||||||
)
|
'sesskey' => sesskey()
|
||||||
);
|
)
|
||||||
$icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert'));
|
);
|
||||||
$addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert'));
|
$icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert'));
|
||||||
$mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage')));
|
$addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert'));
|
||||||
|
$mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage')));
|
||||||
|
}
|
||||||
|
|
||||||
// Add the submit buttons.
|
// Add the submit buttons.
|
||||||
$group = array();
|
$group = array();
|
||||||
|
@ -245,7 +247,7 @@ class edit_form extends \moodleform {
|
||||||
// Create a table to display these elements.
|
// Create a table to display these elements.
|
||||||
$table = new \html_table();
|
$table = new \html_table();
|
||||||
$table->attributes = array('class' => 'generaltable elementstable');
|
$table->attributes = array('class' => 'generaltable elementstable');
|
||||||
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), get_string('actions'));
|
||||||
$table->align = array('left', 'left', 'left');
|
$table->align = array('left', 'left', 'left');
|
||||||
// Loop through and add the elements to the table.
|
// Loop through and add the elements to the table.
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
/**
|
/**
|
||||||
* Class element
|
* Class element
|
||||||
*
|
*
|
||||||
* All customercert element plugins are based on this class.
|
* All customcert element plugins are based on this class.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_customcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||||
|
@ -37,6 +37,21 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
*/
|
*/
|
||||||
abstract class element {
|
abstract class element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The left alignment constant.
|
||||||
|
*/
|
||||||
|
const ALIGN_LEFT = 'L';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The centered alignment constant.
|
||||||
|
*/
|
||||||
|
const ALIGN_CENTER = 'C';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The right alignment constant.
|
||||||
|
*/
|
||||||
|
const ALIGN_RIGHT = 'R';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \stdClass $element The data for the element we are adding - do not use, kept for legacy reasons.
|
* @var \stdClass $element The data for the element we are adding - do not use, kept for legacy reasons.
|
||||||
*/
|
*/
|
||||||
|
@ -97,11 +112,21 @@ abstract class element {
|
||||||
*/
|
*/
|
||||||
protected $refpoint;
|
protected $refpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The alignment.
|
||||||
|
*/
|
||||||
|
protected $alignment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool $showposxy Show position XY form elements?
|
* @var bool $showposxy Show position XY form elements?
|
||||||
*/
|
*/
|
||||||
protected $showposxy;
|
protected $showposxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var edit_element_form Element edit form instance.
|
||||||
|
*/
|
||||||
|
private $editelementform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -125,6 +150,7 @@ abstract class element {
|
||||||
$this->width = $element->width;
|
$this->width = $element->width;
|
||||||
$this->refpoint = $element->refpoint;
|
$this->refpoint = $element->refpoint;
|
||||||
$this->showposxy = isset($showposxy) && $showposxy;
|
$this->showposxy = isset($showposxy) && $showposxy;
|
||||||
|
$this->set_alignment($element->alignment ?? self::ALIGN_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,11 +252,36 @@ abstract class element {
|
||||||
return $this->refpoint;
|
return $this->refpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the alignment.
|
||||||
|
*
|
||||||
|
* @return string The current alignment value.
|
||||||
|
*/
|
||||||
|
public function get_alignment() {
|
||||||
|
return $this->alignment ?? self::ALIGN_LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the alignment.
|
||||||
|
*
|
||||||
|
* @param string $alignment The new alignment.
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if the provided new alignment is not valid.
|
||||||
|
*/
|
||||||
|
protected function set_alignment(string $alignment) {
|
||||||
|
$validvalues = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT);
|
||||||
|
if (!in_array($alignment, $validvalues)) {
|
||||||
|
throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " .
|
||||||
|
implode(', ', $validvalues));
|
||||||
|
}
|
||||||
|
$this->alignment = $alignment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
* Can be overridden if more functionality is needed.
|
* Can be overridden if more functionality is needed.
|
||||||
*
|
*
|
||||||
* @param edit_element_form $mform the edit_form instance.
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
// Render the common elements.
|
// Render the common elements.
|
||||||
|
@ -240,6 +291,8 @@ abstract class element {
|
||||||
element_helper::render_form_element_position($mform);
|
element_helper::render_form_element_position($mform);
|
||||||
}
|
}
|
||||||
element_helper::render_form_element_width($mform);
|
element_helper::render_form_element_width($mform);
|
||||||
|
element_helper::render_form_element_refpoint($mform);
|
||||||
|
element_helper::render_form_element_alignment($mform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,7 +312,8 @@ abstract class element {
|
||||||
'posx' => $this->posx,
|
'posx' => $this->posx,
|
||||||
'posy' => $this->posy,
|
'posy' => $this->posy,
|
||||||
'width' => $this->width,
|
'width' => $this->width,
|
||||||
'refpoint' => $this->refpoint
|
'refpoint' => $this->refpoint,
|
||||||
|
'alignment' => $this->get_alignment()
|
||||||
];
|
];
|
||||||
foreach ($properties as $property => $value) {
|
foreach ($properties as $property => $value) {
|
||||||
if (!is_null($value) && $mform->elementExists($property)) {
|
if (!is_null($value) && $mform->elementExists($property)) {
|
||||||
|
@ -305,15 +359,16 @@ abstract class element {
|
||||||
$element = new \stdClass();
|
$element = new \stdClass();
|
||||||
$element->name = $data->name;
|
$element->name = $data->name;
|
||||||
$element->data = $this->save_unique_data($data);
|
$element->data = $this->save_unique_data($data);
|
||||||
$element->font = (isset($data->font)) ? $data->font : null;
|
$element->font = $data->font ?? null;
|
||||||
$element->fontsize = (isset($data->fontsize)) ? $data->fontsize : null;
|
$element->fontsize = $data->fontsize ?? null;
|
||||||
$element->colour = (isset($data->colour)) ? $data->colour : null;
|
$element->colour = $data->colour ?? null;
|
||||||
if ($this->showposxy) {
|
if ($this->showposxy) {
|
||||||
$element->posx = (isset($data->posx)) ? $data->posx : null;
|
$element->posx = $data->posx ?? null;
|
||||||
$element->posy = (isset($data->posy)) ? $data->posy : null;
|
$element->posy = $data->posy ?? null;
|
||||||
}
|
}
|
||||||
$element->width = (isset($data->width)) ? $data->width : null;
|
$element->width = $data->width ?? null;
|
||||||
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
|
$element->refpoint = $data->refpoint ?? null;
|
||||||
|
$element->alignment = $data->alignment ?? self::ALIGN_LEFT;
|
||||||
$element->timemodified = time();
|
$element->timemodified = time();
|
||||||
|
|
||||||
// Check if we are updating, or inserting a new element.
|
// Check if we are updating, or inserting a new element.
|
||||||
|
@ -352,6 +407,16 @@ abstract class element {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This defines if an element plugin can be added to a certificate.
|
||||||
|
* Can be overridden if an element plugin wants to take over the control.
|
||||||
|
*
|
||||||
|
* @return bool returns true if the element can be added, false otherwise
|
||||||
|
*/
|
||||||
|
public static function can_add() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
|
@ -361,7 +426,7 @@ abstract class element {
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public abstract function render($pdf, $preview, $user);
|
abstract public function render($pdf, $preview, $user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the element in html.
|
* Render the element in html.
|
||||||
|
@ -373,7 +438,7 @@ abstract class element {
|
||||||
*
|
*
|
||||||
* @return string the html
|
* @return string the html
|
||||||
*/
|
*/
|
||||||
public abstract function render_html();
|
abstract public function render_html();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles deleting any data this element may have introduced.
|
* Handles deleting any data this element may have introduced.
|
||||||
|
@ -411,4 +476,27 @@ abstract class element {
|
||||||
return $this->element->$name;
|
return $this->element->$name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set edit form instance for the custom cert element.
|
||||||
|
*
|
||||||
|
* @param \mod_customcert\edit_element_form $editelementform
|
||||||
|
*/
|
||||||
|
public function set_edit_element_form(edit_element_form $editelementform) {
|
||||||
|
$this->editelementform = $editelementform;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get edit form instance for the custom cert element.
|
||||||
|
*
|
||||||
|
* @return \mod_customcert\edit_element_form
|
||||||
|
*/
|
||||||
|
public function get_edit_element_form() {
|
||||||
|
if (empty($this->editelementform)) {
|
||||||
|
throw new \coding_exception('Edit element form instance is not set.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->editelementform;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,19 @@ class element_factory {
|
||||||
$classname = '\\customcertelement_' . $element->element . '\\element';
|
$classname = '\\customcertelement_' . $element->element . '\\element';
|
||||||
|
|
||||||
$data = new \stdClass();
|
$data = new \stdClass();
|
||||||
$data->id = isset($element->id) ? $element->id : null;
|
$data->id = $element->id ?? null;
|
||||||
$data->pageid = isset($element->pageid) ? $element->pageid : null;
|
$data->pageid = $element->pageid ?? null;
|
||||||
$data->name = isset($element->name) ? $element->name : get_string('pluginname', 'customcertelement_' . $element->element);
|
$data->name = $element->name ?? get_string('pluginname', 'customcertelement_' . $element->element);
|
||||||
$data->element = $element->element;
|
$data->element = $element->element;
|
||||||
$data->data = isset($element->data) ? $element->data : null;
|
$data->data = $element->data ?? null;
|
||||||
$data->font = isset($element->font) ? $element->font : null;
|
$data->font = $element->font ?? null;
|
||||||
$data->fontsize = isset($element->fontsize) ? $element->fontsize : null;
|
$data->fontsize = $element->fontsize ?? null;
|
||||||
$data->colour = isset($element->colour) ? $element->colour : null;
|
$data->colour = $element->colour ?? null;
|
||||||
$data->posx = isset($element->posx) ? $element->posx : null;
|
$data->posx = $element->posx ?? null;
|
||||||
$data->posy = isset($element->posy) ? $element->posy : null;
|
$data->posy = $element->posy ?? null;
|
||||||
$data->width = isset($element->width) ? $element->width : null;
|
$data->width = $element->width ?? null;
|
||||||
$data->refpoint = isset($element->refpoint) ? $element->refpoint : null;
|
$data->refpoint = $element->refpoint ?? null;
|
||||||
|
$data->alignment = $element->alignment ?? null;
|
||||||
|
|
||||||
// Ensure the necessary class exists.
|
// Ensure the necessary class exists.
|
||||||
if (class_exists($classname)) {
|
if (class_exists($classname)) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ class element_helper {
|
||||||
$w = $element->get_width();
|
$w = $element->get_width();
|
||||||
$refpoint = $element->get_refpoint();
|
$refpoint = $element->get_refpoint();
|
||||||
$actualwidth = $pdf->GetStringWidth($content);
|
$actualwidth = $pdf->GetStringWidth($content);
|
||||||
|
$alignment = $element->get_alignment();
|
||||||
|
|
||||||
if ($w and $w < $actualwidth) {
|
if ($w and $w < $actualwidth) {
|
||||||
$actualwidth = $w;
|
$actualwidth = $w;
|
||||||
|
@ -104,7 +105,7 @@ class element_helper {
|
||||||
$w += 0.0001;
|
$w += 0.0001;
|
||||||
}
|
}
|
||||||
$pdf->setCellPaddings(0, 0, 0, 0);
|
$pdf->setCellPaddings(0, 0, 0, 0);
|
||||||
$pdf->writeHTMLCell($w, 0, $x, $y, $content, 0, 0, false, true);
|
$pdf->writeHTMLCell($w, 0, $x, $y, $content, 0, 0, false, true, $alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +135,7 @@ class element_helper {
|
||||||
/**
|
/**
|
||||||
* Helper function to render the font elements.
|
* Helper function to render the font elements.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
*/
|
*/
|
||||||
public static function render_form_element_font($mform) {
|
public static function render_form_element_font($mform) {
|
||||||
$mform->addElement('select', 'font', get_string('font', 'customcert'), \mod_customcert\certificate::get_fonts());
|
$mform->addElement('select', 'font', get_string('font', 'customcert'), \mod_customcert\certificate::get_fonts());
|
||||||
|
@ -151,7 +152,7 @@ class element_helper {
|
||||||
/**
|
/**
|
||||||
* Helper function to render the colour elements.
|
* Helper function to render the colour elements.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
*/
|
*/
|
||||||
public static function render_form_element_colour($mform) {
|
public static function render_form_element_colour($mform) {
|
||||||
$mform->addElement('customcert_colourpicker', 'colour', get_string('fontcolour', 'customcert'));
|
$mform->addElement('customcert_colourpicker', 'colour', get_string('fontcolour', 'customcert'));
|
||||||
|
@ -163,7 +164,7 @@ class element_helper {
|
||||||
/**
|
/**
|
||||||
* Helper function to render the position elements.
|
* Helper function to render the position elements.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
*/
|
*/
|
||||||
public static function render_form_element_position($mform) {
|
public static function render_form_element_position($mform) {
|
||||||
$mform->addElement('text', 'posx', get_string('posx', 'customcert'), array('size' => 10));
|
$mform->addElement('text', 'posx', get_string('posx', 'customcert'), array('size' => 10));
|
||||||
|
@ -179,23 +180,49 @@ class element_helper {
|
||||||
/**
|
/**
|
||||||
* Helper function to render the width element.
|
* Helper function to render the width element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
*/
|
*/
|
||||||
public static function render_form_element_width($mform) {
|
public static function render_form_element_width($mform) {
|
||||||
$mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10));
|
$mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10));
|
||||||
$mform->setType('width', PARAM_INT);
|
$mform->setType('width', PARAM_INT);
|
||||||
$mform->setDefault('width', 0);
|
$mform->setDefault('width', 0);
|
||||||
$mform->addHelpButton('width', 'elementwidth', 'customcert');
|
$mform->addHelpButton('width', 'elementwidth', 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to render the refpoint element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
|
*/
|
||||||
|
public static function render_form_element_refpoint($mform) {
|
||||||
$refpointoptions = array();
|
$refpointoptions = array();
|
||||||
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('topleft', 'customcert');
|
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('topleft', 'customcert');
|
||||||
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('topcenter', 'customcert');
|
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('topcenter', 'customcert');
|
||||||
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('topright', 'customcert');
|
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('topright', 'customcert');
|
||||||
|
|
||||||
$mform->addElement('select', 'refpoint', get_string('refpoint', 'customcert'), $refpointoptions);
|
$mform->addElement('select', 'refpoint', get_string('refpoint', 'customcert'), $refpointoptions);
|
||||||
$mform->setType('refpoint', PARAM_INT);
|
$mform->setType('refpoint', PARAM_INT);
|
||||||
$mform->setDefault('refpoint', self::CUSTOMCERT_REF_POINT_TOPCENTER);
|
$mform->setDefault('refpoint', self::CUSTOMCERT_REF_POINT_TOPCENTER);
|
||||||
$mform->addHelpButton('refpoint', 'refpoint', 'customcert');
|
$mform->addHelpButton('refpoint', 'refpoint', 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to render the alignment form element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit_form instance.
|
||||||
|
*/
|
||||||
|
public static function render_form_element_alignment($mform) {
|
||||||
|
$alignmentoptions = array();
|
||||||
|
$alignmentoptions[element::ALIGN_LEFT] = get_string('alignleft', 'customcert');
|
||||||
|
$alignmentoptions[element::ALIGN_CENTER] = get_string('aligncenter', 'customcert');
|
||||||
|
$alignmentoptions[element::ALIGN_RIGHT] = get_string('alignright', 'customcert');
|
||||||
|
|
||||||
|
$mform->addElement('select', 'alignment', get_string('alignment', 'customcert'), $alignmentoptions);
|
||||||
|
$mform->setType('alignment', PARAM_ALPHA);
|
||||||
|
$mform->setDefault('alignment', element::ALIGN_LEFT);
|
||||||
|
$mform->addHelpButton('alignment', 'alignment', 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to performs validation on the colour element.
|
* Helper function to performs validation on the colour element.
|
||||||
*
|
*
|
||||||
|
@ -383,6 +410,27 @@ class element_helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that returns the context for this element.
|
||||||
|
*
|
||||||
|
* @param int $elementid The element id
|
||||||
|
* @return \context The context
|
||||||
|
*/
|
||||||
|
public static function get_context(int $elementid) : \context {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$sql = "SELECT ct.contextid
|
||||||
|
FROM {customcert_templates} ct
|
||||||
|
INNER JOIN {customcert_pages} cp
|
||||||
|
ON ct.id = cp.templateid
|
||||||
|
INNER JOIN {customcert_elements} ce
|
||||||
|
ON cp.id = ce.pageid
|
||||||
|
WHERE ce.id = :elementid";
|
||||||
|
$contextid = $DB->get_field_sql($sql, array('elementid' => $elementid), MUST_EXIST);
|
||||||
|
|
||||||
|
return \context::instance_by_id($contextid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the list of possible elements to add.
|
* Return the list of possible elements to add.
|
||||||
*
|
*
|
||||||
|
@ -412,8 +460,11 @@ class element_helper {
|
||||||
$classname = '\\customcertelement_' . $foldername . '\\element';
|
$classname = '\\customcertelement_' . $foldername . '\\element';
|
||||||
// Ensure the necessary class exists.
|
// Ensure the necessary class exists.
|
||||||
if (class_exists($classname)) {
|
if (class_exists($classname)) {
|
||||||
$component = "customcertelement_{$foldername}";
|
// Additionally, check if the user is allowed to add the element at all.
|
||||||
$options[$foldername] = get_string('pluginname', $component);
|
if ($classname::can_add()) {
|
||||||
|
$component = "customcertelement_{$foldername}";
|
||||||
|
$options[$foldername] = get_string('pluginname', $component);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,70 +480,40 @@ class element_helper {
|
||||||
* @return array the array of gradeable items in the course
|
* @return array the array of gradeable items in the course
|
||||||
*/
|
*/
|
||||||
public static function get_grade_items($course) {
|
public static function get_grade_items($course) {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Array to store the grade items.
|
// Array to store the grade items.
|
||||||
$modules = array();
|
$arrgradeitems = array();
|
||||||
|
|
||||||
// Collect course modules data.
|
|
||||||
$modinfo = get_fast_modinfo($course);
|
|
||||||
$mods = $modinfo->get_cms();
|
|
||||||
$sections = $modinfo->get_section_info_all();
|
|
||||||
|
|
||||||
// Create the section label depending on course format.
|
|
||||||
$sectionlabel = get_string('section');
|
|
||||||
if ($course->format == 'topics') {
|
|
||||||
$sectionlabel = get_string('topic');
|
|
||||||
} else if ($course->format == 'weeks') {
|
|
||||||
$sectionlabel = get_string('week');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through each course section.
|
|
||||||
for ($i = 0; $i <= count($sections) - 1; $i++) {
|
|
||||||
// Confirm the index exists, should always be true.
|
|
||||||
if (isset($sections[$i])) {
|
|
||||||
// Get the individual section.
|
|
||||||
$section = $sections[$i];
|
|
||||||
// Get the mods for this section.
|
|
||||||
$sectionmods = explode(",", $section->sequence);
|
|
||||||
// Loop through the section mods.
|
|
||||||
foreach ($sectionmods as $sectionmod) {
|
|
||||||
// Should never happen unless DB is borked.
|
|
||||||
if (empty($mods[$sectionmod])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$mod = $mods[$sectionmod];
|
|
||||||
$instance = $DB->get_record($mod->modname, array('id' => $mod->instance));
|
|
||||||
// Get the grade items for this activity.
|
|
||||||
if ($gradeitems = grade_get_grade_items_for_activity($mod)) {
|
|
||||||
$moditem = grade_get_grades($course->id, 'mod', $mod->modname, $mod->instance);
|
|
||||||
$gradeitem = reset($moditem->items);
|
|
||||||
if (isset($gradeitem->grademax)) {
|
|
||||||
$modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Get other non-module related grade items.
|
||||||
if ($gradeitems = \grade_item::fetch_all(['courseid' => $course->id])) {
|
if ($gradeitems = \grade_item::fetch_all(['courseid' => $course->id])) {
|
||||||
$arrgradeitems = [];
|
|
||||||
foreach ($gradeitems as $gi) {
|
foreach ($gradeitems as $gi) {
|
||||||
// Skip the course and mod items since we already have them.
|
if ($gi->is_course_item()) {
|
||||||
if ($gi->itemtype == 'mod' || $gi->itemtype == 'course') {
|
continue; // Skipping for legacy reasons - this was added to individual elements.
|
||||||
continue;
|
}
|
||||||
|
|
||||||
|
if ($gi->is_external_item()) {
|
||||||
|
$cm = get_coursemodule_from_instance($gi->itemmodule, $gi->iteminstance, $course->id);
|
||||||
|
$modcontext = \context_module::instance($cm->id);
|
||||||
|
$modname = format_string($cm->name, true, array('context' => $modcontext));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($gi->is_external_item() && !$gi->is_outcome_item()) {
|
||||||
|
// Due to legacy reasons we are storing the course module ID here rather than the grade item id.
|
||||||
|
// If we were to change we would need to provide upgrade steps to convert cm->id to gi->id.
|
||||||
|
$arrgradeitems[$cm->id] = get_string('activity', 'mod_customcert') . ' : ' . $gi->get_name();
|
||||||
|
} else if ($gi->is_external_item() && $gi->is_outcome_item()) {
|
||||||
|
// Get the name of the activity.
|
||||||
|
$optionname = get_string('gradeoutcome', 'mod_customcert') . ' : ' . $modname . " - " . $gi->get_name();
|
||||||
|
$arrgradeitems['gradeitem:' . $gi->id] = $optionname;
|
||||||
|
} else {
|
||||||
|
$arrgradeitems['gradeitem:' . $gi->id] = get_string('gradeitem', 'grades') . ' : ' . $gi->get_name(true);
|
||||||
}
|
}
|
||||||
$arrgradeitems['gradeitem:' . $gi->id] = get_string('gradeitem', 'grades') . ' : ' . $gi->get_name(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alphabetise this.
|
// Alphabetise this.
|
||||||
asort($arrgradeitems);
|
asort($arrgradeitems);
|
||||||
|
|
||||||
// Merge results.
|
|
||||||
$modules = $modules + $arrgradeitems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $modules;
|
return $arrgradeitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -510,18 +531,12 @@ class element_helper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define how many decimals to display.
|
|
||||||
$decimals = 2;
|
|
||||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
|
||||||
$decimals = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid));
|
$grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid));
|
||||||
|
|
||||||
return new grade_information(
|
return new grade_information(
|
||||||
$courseitem->get_name(),
|
$courseitem->get_name(),
|
||||||
$grade->finalgrade,
|
$grade->finalgrade,
|
||||||
grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat, $decimals),
|
grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat),
|
||||||
$grade->get_dategraded()
|
$grade->get_dategraded()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -545,37 +560,44 @@ class element_helper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
$params = [
|
||||||
|
'itemtype' => 'mod',
|
||||||
|
'itemmodule' => $module->name,
|
||||||
|
'iteminstance' => $cm->instance,
|
||||||
|
'courseid' => $cm->course,
|
||||||
|
'itemnumber' => 0
|
||||||
|
];
|
||||||
|
$gradeitem = \grade_item::fetch($params);
|
||||||
|
|
||||||
if (empty($gradeitem)) {
|
if (empty($gradeitem)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define how many decimals to display.
|
$grade = grade_get_grades(
|
||||||
$decimals = 2;
|
$cm->course,
|
||||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
'mod',
|
||||||
$decimals = 0;
|
$module->name,
|
||||||
|
$cm->instance,
|
||||||
|
$userid
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isset($grade->items[0]->grades[$userid])) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = new \grade_item();
|
$gradebookgrade = $grade->items[0]->grades[$userid];
|
||||||
$item->gradetype = GRADE_TYPE_VALUE;
|
|
||||||
$item->courseid = $cm->course;
|
|
||||||
$itemproperties = reset($gradeitem->items);
|
|
||||||
foreach ($itemproperties as $key => $value) {
|
|
||||||
$item->$key = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$objgrade = $item->grades[$userid];
|
|
||||||
|
|
||||||
$dategraded = null;
|
$dategraded = null;
|
||||||
if (!empty($objgrade->dategraded)) {
|
if (!empty($gradebookgrade->dategraded)) {
|
||||||
$dategraded = $objgrade->dategraded;
|
$dategraded = $gradebookgrade->dategraded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$displaygrade = grade_format_gradevalue($gradebookgrade->grade, $gradeitem, true, $gradeformat);
|
||||||
|
|
||||||
return new grade_information(
|
return new grade_information(
|
||||||
$item->name,
|
$gradeitem->get_name(),
|
||||||
$objgrade->grade,
|
$gradebookgrade->grade,
|
||||||
grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat, $decimals),
|
$displaygrade,
|
||||||
$dategraded
|
$dategraded
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -593,18 +615,12 @@ class element_helper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define how many decimals to display.
|
|
||||||
$decimals = 2;
|
|
||||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
|
||||||
$decimals = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid));
|
$grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid));
|
||||||
|
|
||||||
return new grade_information(
|
return new grade_information(
|
||||||
$gradeitem->get_name(),
|
$gradeitem->get_name(),
|
||||||
$grade->finalgrade,
|
$grade->finalgrade,
|
||||||
grade_format_gradevalue($grade->finalgrade, $gradeitem, true, $gradeformat, $decimals),
|
grade_format_gradevalue($grade->finalgrade, $gradeitem, true, $gradeformat),
|
||||||
$grade->get_dategraded()
|
$grade->get_dategraded()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,23 @@ class course_module_viewed extends \core\event\course_module_viewed {
|
||||||
$this->data['objecttable'] = 'customcert';
|
$this->data['objecttable'] = 'customcert';
|
||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public static function get_objectid_mapping() {
|
||||||
|
return array('db' => 'customcert', 'restore' => 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function get_other_mapping() {
|
||||||
|
// No need to map.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,4 +174,57 @@ class external extends \external_api {
|
||||||
public static function get_element_html_returns() {
|
public static function get_element_html_returns() {
|
||||||
return new \external_value(PARAM_RAW, 'The HTML');
|
return new \external_value(PARAM_RAW, 'The HTML');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the delete_issue() parameters.
|
||||||
|
*
|
||||||
|
* @return \external_function_parameters
|
||||||
|
*/
|
||||||
|
public static function delete_issue_parameters() {
|
||||||
|
return new \external_function_parameters(
|
||||||
|
array(
|
||||||
|
'certificateid' => new \external_value(PARAM_INT, 'The certificate id'),
|
||||||
|
'issueid' => new \external_value(PARAM_INT, 'The issue id'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles deleting a customcert issue.
|
||||||
|
*
|
||||||
|
* @param int $certificateid The certificate id.
|
||||||
|
* @param int $issueid The issue id.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function delete_issue($certificateid, $issueid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'certificateid' => $certificateid,
|
||||||
|
'issueid' => $issueid
|
||||||
|
];
|
||||||
|
self::validate_parameters(self::delete_issue_parameters(), $params);
|
||||||
|
|
||||||
|
$certificate = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST);
|
||||||
|
$issue = $DB->get_record('customcert_issues', ['id' => $issueid, 'customcertid' => $certificateid], '*', MUST_EXIST);
|
||||||
|
|
||||||
|
$cm = get_coursemodule_from_instance('customcert', $certificate->id, 0, false, MUST_EXIST);
|
||||||
|
|
||||||
|
// Make sure the user has the required capabilities.
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
self::validate_context($context);
|
||||||
|
require_capability('mod/customcert:manage', $context);
|
||||||
|
|
||||||
|
// Delete the issue.
|
||||||
|
return $DB->delete_records('customcert_issues', ['id' => $issue->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the delete_issue result value.
|
||||||
|
*
|
||||||
|
* @return \external_value
|
||||||
|
*/
|
||||||
|
public static function delete_issue_returns() {
|
||||||
|
return new \external_value(PARAM_BOOL, 'True if successful, false otherwise');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
64
classes/helper.php
Normal file
64
classes/helper.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides helper functionality.
|
||||||
|
*
|
||||||
|
* @package mod_customcert
|
||||||
|
* @copyright 2021 Mark Nelson <mdjnelson@gmail.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_customcert;
|
||||||
|
|
||||||
|
use core_user\fields;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class helper.
|
||||||
|
*
|
||||||
|
* Helper functionality for this module.
|
||||||
|
*
|
||||||
|
* @package mod_customcert
|
||||||
|
* @copyright 2021 Mark Nelson <mdjnelson@gmail.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class helper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A centralised location for the all name fields.
|
||||||
|
*
|
||||||
|
* Returns a sql string snippet.
|
||||||
|
*
|
||||||
|
* @param string $tableprefix table query prefix to use in front of each field.
|
||||||
|
* @return string All name fields.
|
||||||
|
*/
|
||||||
|
public static function get_all_user_name_fields(string $tableprefix = ''): string {
|
||||||
|
$alternatenames = [];
|
||||||
|
foreach (fields::get_name_fields() as $field) {
|
||||||
|
$alternatenames[$field] = $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tableprefix) {
|
||||||
|
foreach ($alternatenames as $key => $altname) {
|
||||||
|
$alternatenames[$key] = $tableprefix . '.' . $altname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(',', $alternatenames);
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,19 +47,23 @@ class load_template_form extends \moodleform {
|
||||||
|
|
||||||
// Get the context.
|
// Get the context.
|
||||||
$context = $this->_customdata['context'];
|
$context = $this->_customdata['context'];
|
||||||
|
$syscontext = \context_system::instance();
|
||||||
|
|
||||||
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
||||||
|
|
||||||
// Display a link to the manage templates page.
|
// Display a link to the manage templates page.
|
||||||
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', \context_system::instance())) {
|
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', $syscontext)) {
|
||||||
$link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'),
|
$link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'),
|
||||||
get_string('managetemplates', 'customcert'));
|
get_string('managetemplates', 'customcert'));
|
||||||
$mform->addElement('static', 'managetemplates', '', $link);
|
$mform->addElement('static', 'managetemplates', '', $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
$templates = $DB->get_records_menu('customcert_templates',
|
$arrtemplates = $DB->get_records_menu('customcert_templates', ['contextid' => $syscontext->id], 'name ASC', 'id, name');
|
||||||
array('contextid' => \context_system::instance()->id), 'name ASC', 'id, name');
|
if ($arrtemplates) {
|
||||||
if ($templates) {
|
$templates = [];
|
||||||
|
foreach ($arrtemplates as $key => $template) {
|
||||||
|
$templates[$key] = format_string($template, true, ['context' => $context]);
|
||||||
|
}
|
||||||
$group = array();
|
$group = array();
|
||||||
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
||||||
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
||||||
|
|
|
@ -77,7 +77,7 @@ class manage_templates_table extends \table_sql {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function col_name($template) {
|
public function col_name($template) {
|
||||||
return $template->name;
|
return format_string($template->name, true, ['context' => $this->context]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -94,7 +94,10 @@ class my_certificates_table extends \table_sql {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function col_name($certificate) {
|
public function col_name($certificate) {
|
||||||
return $certificate->name;
|
$cm = get_coursemodule_from_instance('customcert', $certificate->id);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
return format_string($certificate->name, true, ['context' => $context]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +107,10 @@ class my_certificates_table extends \table_sql {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function col_coursename($certificate) {
|
public function col_coursename($certificate) {
|
||||||
return $certificate->coursename;
|
$cm = get_coursemodule_from_instance('customcert', $certificate->id);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
return format_string($certificate->coursename, true, ['context' => $context]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +142,7 @@ class my_certificates_table extends \table_sql {
|
||||||
public function col_download($certificate) {
|
public function col_download($certificate) {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
|
|
||||||
$icon = new \pix_icon('i/import', get_string('download'));
|
$icon = new \pix_icon('download', get_string('download'), 'customcert');
|
||||||
$link = new \moodle_url('/mod/customcert/my_certificates.php',
|
$link = new \moodle_url('/mod/customcert/my_certificates.php',
|
||||||
array('userid' => $this->userid,
|
array('userid' => $this->userid,
|
||||||
'certificateid' => $certificate->id,
|
'certificateid' => $certificate->id,
|
||||||
|
|
|
@ -102,12 +102,14 @@ class email_certificate implements \renderable, \templatable {
|
||||||
if ($this->isstudent) {
|
if ($this->isstudent) {
|
||||||
$data->emailgreeting = get_string('emailstudentgreeting', 'customcert', $this->userfullname);
|
$data->emailgreeting = get_string('emailstudentgreeting', 'customcert', $this->userfullname);
|
||||||
$data->emailbody = get_string('emailstudentbody', 'customcert', $info);
|
$data->emailbody = get_string('emailstudentbody', 'customcert', $info);
|
||||||
|
$data->emailbodyplaintext = get_string('emailstudentbodyplaintext', 'customcert', $info);
|
||||||
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
|
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
|
||||||
$data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'customcert');
|
$data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'customcert');
|
||||||
} else {
|
} else {
|
||||||
$data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert');
|
$data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert');
|
||||||
$data->emailbody = get_string('emailnonstudentbody', 'customcert', $info);
|
$data->emailbody = get_string('emailnonstudentbody', 'customcert', $info);
|
||||||
$data->emailcertificatelink = new \moodle_url('/mod/customcert/report.php', array('id' => $this->cmid));
|
$data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'customcert', $info);
|
||||||
|
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
|
||||||
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert');
|
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
213
classes/output/mobile.php
Normal file
213
classes/output/mobile.php
Normal file
|
@ -0,0 +1,213 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the mobile output class for the custom certificate.
|
||||||
|
*
|
||||||
|
* @package mod_customcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_customcert\output;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mobile output class for the custom certificate.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class mobile {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the initial page when viewing the activity for the mobile app.
|
||||||
|
*
|
||||||
|
* @param array $args Arguments from tool_mobile_get_content WS
|
||||||
|
* @return array HTML, javascript and other data
|
||||||
|
*/
|
||||||
|
public static function mobile_view_activity($args) {
|
||||||
|
global $OUTPUT, $DB, $USER;
|
||||||
|
|
||||||
|
$args = (object) $args;
|
||||||
|
$versionname = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';
|
||||||
|
|
||||||
|
$cmid = $args->cmid;
|
||||||
|
$groupid = empty($args->group) ? 0 : (int) $args->group; // By default, group 0.
|
||||||
|
|
||||||
|
// Capabilities check.
|
||||||
|
$cm = get_coursemodule_from_id('customcert', $cmid);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
self::require_capability($cm, $context, 'mod/customcert:view');
|
||||||
|
|
||||||
|
// Set some variables we are going to be using.
|
||||||
|
$certificate = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$certificate->name = format_string($certificate->name);
|
||||||
|
list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro,
|
||||||
|
$certificate->introformat, $context->id, 'mod_customcert', 'intro');
|
||||||
|
|
||||||
|
// Get any issues this person may have.
|
||||||
|
$issue = false;
|
||||||
|
if ($issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id],
|
||||||
|
'timecreated DESC')) {
|
||||||
|
$issue = reset($issues);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredtimemet = true;
|
||||||
|
$canmanage = has_capability('mod/customcert:manage', $context);
|
||||||
|
if ($certificate->requiredtime && !$canmanage) {
|
||||||
|
if (\mod_customcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) {
|
||||||
|
$requiredtimemet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileurl = "";
|
||||||
|
if ($requiredtimemet) {
|
||||||
|
$fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id,
|
||||||
|
'userid' => $USER->id]);
|
||||||
|
$fileurl = $fileurl->out(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$showreport = false;
|
||||||
|
$groups = [];
|
||||||
|
$recipients = [];
|
||||||
|
if (has_capability('mod/customcert:viewreport', $context)) {
|
||||||
|
$showreport = true;
|
||||||
|
|
||||||
|
// Get the groups (if any) to display - also sets active group.
|
||||||
|
$groups = self::get_groups($cm, $groupid, $USER->id);
|
||||||
|
$groupmode = groups_get_activity_groupmode($cm);
|
||||||
|
if (has_capability('moodle/site:accessallgroups', $context)) {
|
||||||
|
$groupmode = 'aag';
|
||||||
|
}
|
||||||
|
|
||||||
|
$recipients = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0);
|
||||||
|
foreach ($recipients as $recipient) {
|
||||||
|
$recipient->displayname = fullname($recipient);
|
||||||
|
$recipient->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id,
|
||||||
|
'userid' => $recipient->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'certificate' => $certificate,
|
||||||
|
'cmid' => $cm->id,
|
||||||
|
'issue' => $issue,
|
||||||
|
'showgroups' => !empty($groups),
|
||||||
|
'groups' => array_values($groups),
|
||||||
|
'canmanage' => $canmanage,
|
||||||
|
'requiredtimemet' => $requiredtimemet,
|
||||||
|
'fileurl' => $fileurl,
|
||||||
|
'showreport' => $showreport,
|
||||||
|
'hasrecipients' => !empty($recipients),
|
||||||
|
'recipients' => array_values($recipients),
|
||||||
|
'numrecipients' => count($recipients),
|
||||||
|
'currenttimestamp' => time()
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'templates' => [
|
||||||
|
[
|
||||||
|
'id' => 'main',
|
||||||
|
'html' => $OUTPUT->render_from_template("mod_customcert/mobile_view_activity_page_$versionname", $data),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'javascript' => '',
|
||||||
|
'otherdata' => [
|
||||||
|
'group' => $groupid,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of groups to be displayed (if applicable) for the activity.
|
||||||
|
*
|
||||||
|
* The groups API is a mess hence the hackiness.
|
||||||
|
*
|
||||||
|
* @param \stdClass $cm The course module
|
||||||
|
* @param int $groupid The group id
|
||||||
|
* @param int $userid The user id
|
||||||
|
* @return array The array of groups, may be empty.
|
||||||
|
*/
|
||||||
|
protected static function get_groups($cm, $groupid, $userid) {
|
||||||
|
$arrgroups = [];
|
||||||
|
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||||
|
if ($groups = groups_get_activity_allowed_groups($cm, $userid)) {
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $context)) {
|
||||||
|
$allparticipants = new \stdClass();
|
||||||
|
$allparticipants->id = 0;
|
||||||
|
$allparticipants->name = get_string('allparticipants');
|
||||||
|
$allparticipants->selected = $groupid === 0;
|
||||||
|
$arrgroups[0] = $allparticipants;
|
||||||
|
}
|
||||||
|
self::update_active_group($groupmode, $groupid, $groups, $cm);
|
||||||
|
// Detect which group is selected.
|
||||||
|
foreach ($groups as $gid => $group) {
|
||||||
|
$group->selected = $gid == $groupid;
|
||||||
|
$arrgroups[] = $group;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arrgroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the active group in the session.
|
||||||
|
*
|
||||||
|
* This is a hack. We can't call groups_get_activity_group to update the active group as it relies
|
||||||
|
* on optional_param('group' .. which we won't have when using the mobile app.
|
||||||
|
*
|
||||||
|
* @param int $groupmode The group mode we are in, eg. NOGROUPS, VISIBLEGROUPS
|
||||||
|
* @param int $groupid The id of the group that has been selected
|
||||||
|
* @param array $allowedgroups The allowed groups this user can access
|
||||||
|
* @param \stdClass $cm The course module
|
||||||
|
*/
|
||||||
|
private static function update_active_group($groupmode, $groupid, $allowedgroups, $cm) {
|
||||||
|
global $SESSION;
|
||||||
|
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
if (has_capability('moodle/site:accessallgroups', $context)) {
|
||||||
|
$groupmode = 'aag';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($groupid == 0) {
|
||||||
|
// The groups are only all visible in VISIBLEGROUPS mode or if the user can access all groups.
|
||||||
|
if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $context)) {
|
||||||
|
$SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($allowedgroups && array_key_exists($groupid, $allowedgroups)) {
|
||||||
|
$SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = $groupid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirms the user is logged in and has the specified capability.
|
||||||
|
*
|
||||||
|
* @param \stdClass $cm
|
||||||
|
* @param \context $context
|
||||||
|
* @param string $cap
|
||||||
|
*/
|
||||||
|
protected static function require_capability(\stdClass $cm, \context $context, string $cap) {
|
||||||
|
require_login($cm->course, false, $cm, true, true);
|
||||||
|
require_capability($cap, $context);
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,12 +69,15 @@ class verify_certificate_result implements templatable, renderable {
|
||||||
* @param \stdClass $result
|
* @param \stdClass $result
|
||||||
*/
|
*/
|
||||||
public function __construct($result) {
|
public function __construct($result) {
|
||||||
|
$cm = get_coursemodule_from_instance('customcert', $result->certificateid);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
$this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid,
|
$this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid,
|
||||||
'course' => $result->courseid));
|
'course' => $result->courseid));
|
||||||
$this->userfullname = fullname($result);
|
$this->userfullname = fullname($result);
|
||||||
$this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid));
|
$this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid));
|
||||||
$this->coursefullname = $result->coursefullname;
|
$this->coursefullname = format_string($result->coursefullname, true, ['context' => $context]);
|
||||||
$this->certificatename = $result->certificatename;
|
$this->certificatename = format_string($result->certificatename, true, ['context' => $context]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,4 +44,44 @@ class customcertelement extends base {
|
||||||
public function is_uninstall_allowed() {
|
public function is_uninstall_allowed() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads plugin settings to the settings tree.
|
||||||
|
*
|
||||||
|
* @param \part_of_admin_tree $adminroot
|
||||||
|
* @param string $parentnodename
|
||||||
|
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
|
||||||
|
*/
|
||||||
|
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
|
||||||
|
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
|
||||||
|
$ADMIN = $adminroot;
|
||||||
|
$plugininfo = $this;
|
||||||
|
|
||||||
|
if (!$this->is_installed_and_upgraded()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$section = $this->get_settings_section_name();
|
||||||
|
$settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', false);
|
||||||
|
|
||||||
|
include($this->full_path('settings.php'));
|
||||||
|
$ADMIN->add($parentnodename, $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the settings section name.
|
||||||
|
*
|
||||||
|
* @return null|string the settings section name.
|
||||||
|
*/
|
||||||
|
public function get_settings_section_name() {
|
||||||
|
if (file_exists($this->full_path('settings.php'))) {
|
||||||
|
return 'customcertelement_' . $this->name;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
298
classes/privacy/provider.php
Normal file
298
classes/privacy/provider.php
Normal file
|
@ -0,0 +1,298 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for mod_customcert.
|
||||||
|
*
|
||||||
|
* @package mod_customcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
namespace mod_customcert\privacy;
|
||||||
|
|
||||||
|
use core_privacy\local\metadata\collection;
|
||||||
|
use core_privacy\local\request\approved_contextlist;
|
||||||
|
use core_privacy\local\request\approved_userlist;
|
||||||
|
use core_privacy\local\request\contextlist;
|
||||||
|
use core_privacy\local\request\helper;
|
||||||
|
use core_privacy\local\request\transform;
|
||||||
|
use core_privacy\local\request\userlist;
|
||||||
|
use core_privacy\local\request\writer;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for mod_customcert.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements
|
||||||
|
\core_privacy\local\metadata\provider,
|
||||||
|
\core_privacy\local\request\plugin\provider,
|
||||||
|
\core_privacy\local\request\core_userlist_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the fields which contain personal data.
|
||||||
|
*
|
||||||
|
* @param collection $items a reference to the collection to use to store the metadata.
|
||||||
|
* @return collection the updated collection of metadata items.
|
||||||
|
*/
|
||||||
|
public static function get_metadata(collection $items) : collection {
|
||||||
|
$items->add_database_table(
|
||||||
|
'customcert_issues',
|
||||||
|
[
|
||||||
|
'userid' => 'privacy:metadata:customcert_issues:userid',
|
||||||
|
'customcertid' => 'privacy:metadata:customcert_issues:customcertid',
|
||||||
|
'code' => 'privacy:metadata:customcert_issues:code',
|
||||||
|
'emailed' => 'privacy:metadata:customcert_issues:emailed',
|
||||||
|
'timecreated' => 'privacy:metadata:customcert_issues:timecreated',
|
||||||
|
],
|
||||||
|
'privacy:metadata:customcert_issues'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of contexts that contain user information for the specified user.
|
||||||
|
*
|
||||||
|
* @param int $userid the userid.
|
||||||
|
* @return contextlist the list of contexts containing user info for the user.
|
||||||
|
*/
|
||||||
|
public static function get_contexts_for_userid(int $userid) : contextlist {
|
||||||
|
$sql = "SELECT c.id
|
||||||
|
FROM {context} c
|
||||||
|
INNER JOIN {course_modules} cm
|
||||||
|
ON cm.id = c.instanceid
|
||||||
|
AND c.contextlevel = :contextlevel
|
||||||
|
INNER JOIN {modules} m
|
||||||
|
ON m.id = cm.module
|
||||||
|
AND m.name = :modulename
|
||||||
|
INNER JOIN {customcert} customcert
|
||||||
|
ON customcert.id = cm.instance
|
||||||
|
INNER JOIN {customcert_issues} customcertissues
|
||||||
|
ON customcertissues.customcertid = customcert.id
|
||||||
|
WHERE customcertissues.userid = :userid";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'modulename' => 'customcert',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'userid' => $userid,
|
||||||
|
];
|
||||||
|
$contextlist = new contextlist();
|
||||||
|
$contextlist->add_from_sql($sql, $params);
|
||||||
|
|
||||||
|
return $contextlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of users who have data within a context.
|
||||||
|
*
|
||||||
|
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
|
||||||
|
*/
|
||||||
|
public static function get_users_in_context(userlist $userlist) {
|
||||||
|
$context = $userlist->get_context();
|
||||||
|
|
||||||
|
if (!$context instanceof \context_module) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all users who have a custom certificate.
|
||||||
|
$sql = "SELECT customcertissues.userid
|
||||||
|
FROM {course_modules} cm
|
||||||
|
JOIN {modules} m
|
||||||
|
ON m.id = cm.module AND m.name = :modname
|
||||||
|
JOIN {customcert} customcert
|
||||||
|
ON customcert.id = cm.instance
|
||||||
|
JOIN {customcert_issues} customcertissues
|
||||||
|
ON customcertissues.customcertid = customcert.id
|
||||||
|
WHERE cm.id = :cmid";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'cmid' => $context->instanceid,
|
||||||
|
'modname' => 'customcert',
|
||||||
|
];
|
||||||
|
|
||||||
|
$userlist->add_from_sql('userid', $sql, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export personal data for the given approved_contextlist. User and context information is contained within the contextlist.
|
||||||
|
*
|
||||||
|
* @param approved_contextlist $contextlist a list of contexts approved for export.
|
||||||
|
*/
|
||||||
|
public static function export_user_data(approved_contextlist $contextlist) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Filter out any contexts that are not related to modules.
|
||||||
|
$cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
|
||||||
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||||
|
$carry[] = $context->instanceid;
|
||||||
|
}
|
||||||
|
return $carry;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (empty($cmids)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $contextlist->get_user();
|
||||||
|
|
||||||
|
// Get all the customcert activities associated with the above course modules.
|
||||||
|
$customcertidstocmids = self::get_customcert_ids_to_cmids_from_cmids($cmids);
|
||||||
|
|
||||||
|
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($customcertidstocmids), SQL_PARAMS_NAMED);
|
||||||
|
$params = array_merge($inparams, ['userid' => $user->id]);
|
||||||
|
$recordset = $DB->get_recordset_select('customcert_issues', "customcertid $insql AND userid = :userid",
|
||||||
|
$params, 'timecreated, id ASC');
|
||||||
|
self::recordset_loop_and_export($recordset, 'customcertid', [], function($carry, $record) {
|
||||||
|
$carry[] = [
|
||||||
|
'code' => $record->code,
|
||||||
|
'emailed' => transform::yesno($record->emailed),
|
||||||
|
'timecreated' => transform::datetime($record->timecreated)
|
||||||
|
];
|
||||||
|
return $carry;
|
||||||
|
}, function($customcertid, $data) use ($user, $customcertidstocmids) {
|
||||||
|
$context = \context_module::instance($customcertidstocmids[$customcertid]);
|
||||||
|
$contextdata = helper::get_context_data($context, $user);
|
||||||
|
$finaldata = (object) array_merge((array) $contextdata, ['issues' => $data]);
|
||||||
|
helper::export_context_files($context, $user);
|
||||||
|
writer::with_context($context)->export_data([], $finaldata);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all data for all users in the specified context.
|
||||||
|
*
|
||||||
|
* @param \context $context the context to delete in.
|
||||||
|
*/
|
||||||
|
public static function delete_data_for_all_users_in_context(\context $context) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (!$context instanceof \context_module) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$cm = get_coursemodule_from_id('customcert', $context->instanceid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$DB->delete_records('customcert_issues', ['customcertid' => $cm->instance]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all user data for the specified user, in the specified contexts.
|
||||||
|
*
|
||||||
|
* @param approved_contextlist $contextlist a list of contexts approved for deletion.
|
||||||
|
*/
|
||||||
|
public static function delete_data_for_user(approved_contextlist $contextlist) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (empty($contextlist->count())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userid = $contextlist->get_user()->id;
|
||||||
|
foreach ($contextlist->get_contexts() as $context) {
|
||||||
|
if (!$context instanceof \context_module) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
|
||||||
|
$DB->delete_records('customcert_issues', ['customcertid' => $instanceid, 'userid' => $userid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete multiple users within a single context.
|
||||||
|
*
|
||||||
|
* @param approved_userlist $userlist The approved context and user information to delete information for.
|
||||||
|
*/
|
||||||
|
public static function delete_data_for_users(approved_userlist $userlist) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$context = $userlist->get_context();
|
||||||
|
if (!$context instanceof \context_module) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cm = get_coursemodule_from_id('customcert', $context->instanceid);
|
||||||
|
if (!$cm) {
|
||||||
|
// Only customcert module will be handled.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userids = $userlist->get_userids();
|
||||||
|
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
|
||||||
|
|
||||||
|
$select = "customcertid = :customcertid AND userid $usersql";
|
||||||
|
$params = ['customcertid' => $cm->instance] + $userparams;
|
||||||
|
$DB->delete_records_select('customcert_issues', $select, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of Customcert IDs mapped to their course module ID.
|
||||||
|
*
|
||||||
|
* @param array $cmids The course module IDs.
|
||||||
|
* @return array In the form of [$customcertid => $cmid].
|
||||||
|
*/
|
||||||
|
protected static function get_customcert_ids_to_cmids_from_cmids(array $cmids) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
|
||||||
|
$sql = "SELECT customcert.id, cm.id AS cmid
|
||||||
|
FROM {customcert} customcert
|
||||||
|
JOIN {modules} m
|
||||||
|
ON m.name = :modulename
|
||||||
|
JOIN {course_modules} cm
|
||||||
|
ON cm.instance = customcert.id
|
||||||
|
AND cm.module = m.id
|
||||||
|
WHERE cm.id $insql";
|
||||||
|
$params = array_merge($inparams, ['modulename' => 'customcert']);
|
||||||
|
|
||||||
|
return $DB->get_records_sql_menu($sql, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loop and export from a recordset.
|
||||||
|
*
|
||||||
|
* @param \moodle_recordset $recordset The recordset.
|
||||||
|
* @param string $splitkey The record key to determine when to export.
|
||||||
|
* @param mixed $initial The initial data to reduce from.
|
||||||
|
* @param callable $reducer The function to return the dataset, receives current dataset, and the current record.
|
||||||
|
* @param callable $export The function to export the dataset, receives the last value from $splitkey and the dataset.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function recordset_loop_and_export(\moodle_recordset $recordset, $splitkey, $initial,
|
||||||
|
callable $reducer, callable $export) {
|
||||||
|
$data = $initial;
|
||||||
|
$lastid = null;
|
||||||
|
|
||||||
|
foreach ($recordset as $record) {
|
||||||
|
if ($lastid && $record->{$splitkey} != $lastid) {
|
||||||
|
$export($lastid, $data);
|
||||||
|
$data = $initial;
|
||||||
|
}
|
||||||
|
$data = $reducer($data, $record);
|
||||||
|
$lastid = $record->{$splitkey};
|
||||||
|
}
|
||||||
|
$recordset->close();
|
||||||
|
|
||||||
|
if (!empty($lastid)) {
|
||||||
|
$export($lastid, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,16 +65,24 @@ class report_table extends \table_sql {
|
||||||
public function __construct($customcertid, $cm, $groupmode, $download = null) {
|
public function __construct($customcertid, $cm, $groupmode, $download = null) {
|
||||||
parent::__construct('mod_customcert_report_table');
|
parent::__construct('mod_customcert_report_table');
|
||||||
|
|
||||||
$columns = array(
|
$context = \context_module::instance($cm->id);
|
||||||
'fullname',
|
$extrafields = \core_user\fields::for_identity($context)->get_required_fields();
|
||||||
'timecreated',
|
|
||||||
'code'
|
$columns = [];
|
||||||
);
|
$columns[] = 'fullname';
|
||||||
$headers = array(
|
foreach ($extrafields as $extrafield) {
|
||||||
get_string('fullname'),
|
$columns[] = $extrafield;
|
||||||
get_string('receiveddate', 'customcert'),
|
}
|
||||||
get_string('code', 'customcert')
|
$columns[] = 'timecreated';
|
||||||
);
|
$columns[] = 'code';
|
||||||
|
|
||||||
|
$headers = [];
|
||||||
|
$headers[] = get_string('fullname');
|
||||||
|
foreach ($extrafields as $extrafield) {
|
||||||
|
$headers[] = \core_user\fields::get_display_name($extrafield);
|
||||||
|
}
|
||||||
|
$headers[] = get_string('receiveddate', 'customcert');
|
||||||
|
$headers[] = get_string('code', 'customcert');
|
||||||
|
|
||||||
// Check if we were passed a filename, which means we want to download it.
|
// Check if we were passed a filename, which means we want to download it.
|
||||||
if ($download) {
|
if ($download) {
|
||||||
|
@ -86,7 +94,7 @@ class report_table extends \table_sql {
|
||||||
$headers[] = get_string('file');
|
$headers[] = get_string('file');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->is_downloading() && has_capability('mod/customcert:manage', \context_module::instance($cm->id))) {
|
if (!$this->is_downloading() && has_capability('mod/customcert:manage', $context)) {
|
||||||
$columns[] = 'actions';
|
$columns[] = 'actions';
|
||||||
$headers[] = '';
|
$headers[] = '';
|
||||||
}
|
}
|
||||||
|
@ -149,11 +157,13 @@ class report_table extends \table_sql {
|
||||||
public function col_download($user) {
|
public function col_download($user) {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
|
|
||||||
$icon = new \pix_icon('i/import', get_string('download'));
|
$icon = new \pix_icon('download', get_string('download'), 'customcert');
|
||||||
$link = new \moodle_url('/mod/customcert/report.php',
|
$link = new \moodle_url('/mod/customcert/view.php',
|
||||||
array('id' => $this->cm->id,
|
[
|
||||||
'downloadcert' => '1',
|
'id' => $this->cm->id,
|
||||||
'userid' => $user->id));
|
'downloadissue' => $user->id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return $OUTPUT->action_link($link, '', null, null, $icon);
|
return $OUTPUT->action_link($link, '', null, null, $icon);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +178,7 @@ class report_table extends \table_sql {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
|
|
||||||
$icon = new \pix_icon('i/delete', get_string('delete'));
|
$icon = new \pix_icon('i/delete', get_string('delete'));
|
||||||
$link = new \moodle_url('/mod/customcert/report.php',
|
$link = new \moodle_url('/mod/customcert/view.php',
|
||||||
[
|
[
|
||||||
'id' => $this->cm->id,
|
'id' => $this->cm->id,
|
||||||
'deleteissue' => $user->issueid,
|
'deleteissue' => $user->issueid,
|
||||||
|
|
|
@ -33,6 +33,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class activity extends \core_search\area\base_activity {
|
class activity extends \core_search\base_activity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
*/
|
*/
|
||||||
namespace mod_customcert\task;
|
namespace mod_customcert\task;
|
||||||
|
|
||||||
|
use mod_customcert\helper;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +52,7 @@ class email_certificate_task extends \core\task\scheduled_task {
|
||||||
global $DB, $PAGE;
|
global $DB, $PAGE;
|
||||||
|
|
||||||
// Get all the certificates that have requested someone get emailed.
|
// Get all the certificates that have requested someone get emailed.
|
||||||
|
$emailotherslengthsql = $DB->sql_length('c.emailothers');
|
||||||
$sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid,
|
$sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid,
|
||||||
co.fullname as coursefullname, co.shortname as courseshortname
|
co.fullname as coursefullname, co.shortname as courseshortname
|
||||||
FROM {customcert} c
|
FROM {customcert} c
|
||||||
|
@ -59,171 +62,197 @@ class email_certificate_task extends \core\task\scheduled_task {
|
||||||
ON c.course = co.id
|
ON c.course = co.id
|
||||||
WHERE (c.emailstudents = :emailstudents
|
WHERE (c.emailstudents = :emailstudents
|
||||||
OR c.emailteachers = :emailteachers
|
OR c.emailteachers = :emailteachers
|
||||||
OR c.emailothers != '')";
|
OR $emailotherslengthsql >= 3)";
|
||||||
if ($customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) {
|
if (!$customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) {
|
||||||
// The renderers used for sending emails.
|
return;
|
||||||
$htmlrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'htmlemail');
|
}
|
||||||
$textrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'textemail');
|
|
||||||
foreach ($customcerts as $customcert) {
|
|
||||||
// Get the context.
|
|
||||||
$context = \context::instance_by_id($customcert->contextid);
|
|
||||||
|
|
||||||
// Get the person we are going to send this email on behalf of.
|
// The renderers used for sending emails.
|
||||||
// Look through the teachers.
|
$htmlrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'htmlemail');
|
||||||
if ($teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
|
$textrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'textemail');
|
||||||
'', '', '', '', false, true)) {
|
foreach ($customcerts as $customcert) {
|
||||||
$teachers = sort_by_roleassignment_authority($teachers, $context);
|
// Do not process an empty certificate.
|
||||||
$userfrom = reset($teachers);
|
$sql = "SELECT ce.*
|
||||||
} else { // Ok, no teachers, use administrator name.
|
FROM {customcert_elements} ce
|
||||||
$userfrom = get_admin();
|
JOIN {customcert_pages} cp
|
||||||
|
ON cp.id = ce.pageid
|
||||||
|
JOIN {customcert_templates} ct
|
||||||
|
ON ct.id = cp.templateid
|
||||||
|
WHERE ct.contextid = :contextid";
|
||||||
|
if (!$DB->record_exists_sql($sql, ['contextid' => $customcert->contextid])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the context.
|
||||||
|
$context = \context::instance_by_id($customcert->contextid);
|
||||||
|
|
||||||
|
// Set the $PAGE context - this ensure settings, such as language, are kept and don't default to the site settings.
|
||||||
|
$PAGE->set_context($context);
|
||||||
|
|
||||||
|
// Get the person we are going to send this email on behalf of.
|
||||||
|
$userfrom = \core_user::get_noreply_user();
|
||||||
|
|
||||||
|
// Store teachers for later.
|
||||||
|
$teachers = get_enrolled_users($context, 'moodle/course:update');
|
||||||
|
|
||||||
|
$courseshortname = format_string($customcert->courseshortname, true, array('context' => $context));
|
||||||
|
$coursefullname = format_string($customcert->coursefullname, true, array('context' => $context));
|
||||||
|
$certificatename = format_string($customcert->name, true, array('context' => $context));
|
||||||
|
|
||||||
|
// Used to create the email subject.
|
||||||
|
$info = new \stdClass;
|
||||||
|
$info->coursename = $courseshortname; // Added for BC, so users who have edited the string don't lose this value.
|
||||||
|
$info->courseshortname = $courseshortname;
|
||||||
|
$info->coursefullname = $coursefullname;
|
||||||
|
$info->certificatename = $certificatename;
|
||||||
|
|
||||||
|
// Get a list of all the issues.
|
||||||
|
$userfields = helper::get_all_user_name_fields('u');
|
||||||
|
$sql = "SELECT u.id, u.username, $userfields, u.email, ci.id as issueid, ci.emailed
|
||||||
|
FROM {customcert_issues} ci
|
||||||
|
JOIN {user} u
|
||||||
|
ON ci.userid = u.id
|
||||||
|
WHERE ci.customcertid = :customcertid";
|
||||||
|
$issuedusers = $DB->get_records_sql($sql, array('customcertid' => $customcert->id));
|
||||||
|
|
||||||
|
// Now, get a list of users who can access the certificate but have not yet.
|
||||||
|
$enrolledusers = get_enrolled_users(\context_course::instance($customcert->courseid), 'mod/customcert:view');
|
||||||
|
foreach ($enrolledusers as $enroluser) {
|
||||||
|
// Check if the user has already been issued.
|
||||||
|
if (in_array($enroluser->id, array_keys((array) $issuedusers))) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$courseshortname = format_string($customcert->courseshortname, true, array('context' => $context));
|
// Now check if the certificate is not visible to the current user.
|
||||||
$coursefullname = format_string($customcert->coursefullname, true, array('context' => $context));
|
$cm = get_fast_modinfo($customcert->courseid, $enroluser->id)->instances['customcert'][$customcert->id];
|
||||||
$certificatename = format_string($customcert->name, true, array('context' => $context));
|
if (!$cm->uservisible) {
|
||||||
|
continue;
|
||||||
// Used to create the email subject.
|
|
||||||
$info = new \stdClass;
|
|
||||||
$info->coursename = $courseshortname; // Added for BC, so users who have edited the string don't lose this value.
|
|
||||||
$info->courseshortname = $courseshortname;
|
|
||||||
$info->coursefullname = $coursefullname;
|
|
||||||
$info->certificatename = $certificatename;
|
|
||||||
|
|
||||||
// Get a list of all the issues.
|
|
||||||
$userfields = get_all_user_name_fields(true, 'u');
|
|
||||||
$sql = "SELECT u.id, u.username, $userfields, u.email, ci.id as issueid, ci.emailed
|
|
||||||
FROM {customcert_issues} ci
|
|
||||||
JOIN {user} u
|
|
||||||
ON ci.userid = u.id
|
|
||||||
WHERE ci.customcertid = :customcertid";
|
|
||||||
$issuedusers = $DB->get_records_sql($sql, array('customcertid' => $customcert->id));
|
|
||||||
|
|
||||||
// Now, get a list of users who can access the certificate but have not yet.
|
|
||||||
$enrolledusers = get_enrolled_users(\context_course::instance($customcert->courseid), 'mod/customcert:view');
|
|
||||||
foreach ($enrolledusers as $enroluser) {
|
|
||||||
// Check if the user has already been issued.
|
|
||||||
if (in_array($enroluser->id, array_keys((array) $issuedusers))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now check if the certificate is not visible to the current user.
|
|
||||||
$cm = get_fast_modinfo($customcert->courseid, $enroluser->id)->instances['customcert'][$customcert->id];
|
|
||||||
if (!$cm->uservisible) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't want to email those with the capability to manage the certificate.
|
|
||||||
if (has_capability('mod/customcert:manage', $context, $enroluser->id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that they have passed the required time.
|
|
||||||
if (!empty($customcert->requiredtime)) {
|
|
||||||
if (\mod_customcert\certificate::get_course_time($customcert->courseid,
|
|
||||||
$enroluser->id) < ($customcert->requiredtime * 60)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the cert hasn't already been issued, e.g via the UI (view.php) - a race condition.
|
|
||||||
$issueid = $DB->get_field('customcert_issues', 'id',
|
|
||||||
array('userid' => $enroluser->id, 'customcertid' => $customcert->id));
|
|
||||||
if (empty($issueid)) {
|
|
||||||
// Ok, issue them the certificate.
|
|
||||||
$issueid = \mod_customcert\certificate::issue_certificate($customcert->id, $enroluser->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add them to the array so we email them.
|
|
||||||
$enroluser->issueid = $issueid;
|
|
||||||
$enroluser->emailed = 0;
|
|
||||||
$issuedusers[] = $enroluser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all the users who have already been emailed.
|
// Don't want to email those with the capability to manage the certificate.
|
||||||
foreach ($issuedusers as $key => $issueduser) {
|
if (has_capability('mod/customcert:manage', $context, $enroluser->id)) {
|
||||||
if ($issueduser->emailed) {
|
continue;
|
||||||
unset($issuedusers[$key]);
|
}
|
||||||
|
|
||||||
|
// Only email those with the capability to receive the certificate.
|
||||||
|
if (!has_capability('mod/customcert:receiveissue', $context, $enroluser->id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that they have passed the required time.
|
||||||
|
if (!empty($customcert->requiredtime)) {
|
||||||
|
if (\mod_customcert\certificate::get_course_time($customcert->courseid,
|
||||||
|
$enroluser->id) < ($customcert->requiredtime * 60)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, email the people we need to.
|
// Ensure the cert hasn't already been issued, e.g via the UI (view.php) - a race condition.
|
||||||
if ($issuedusers) {
|
$issueid = $DB->get_field('customcert_issues', 'id',
|
||||||
foreach ($issuedusers as $user) {
|
array('userid' => $enroluser->id, 'customcertid' => $customcert->id), IGNORE_MULTIPLE);
|
||||||
$userfullname = fullname($user);
|
if (empty($issueid)) {
|
||||||
|
// Ok, issue them the certificate.
|
||||||
|
$issueid = \mod_customcert\certificate::issue_certificate($customcert->id, $enroluser->id);
|
||||||
|
}
|
||||||
|
|
||||||
// Create a directory to store the PDF we will be sending.
|
// Add them to the array so we email them.
|
||||||
$tempdir = make_temp_directory('certificate/attachment');
|
$enroluser->issueid = $issueid;
|
||||||
if (!$tempdir) {
|
$enroluser->emailed = 0;
|
||||||
return false;
|
$issuedusers[] = $enroluser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, get the PDF.
|
// Remove all the users who have already been emailed.
|
||||||
$template = new \stdClass();
|
foreach ($issuedusers as $key => $issueduser) {
|
||||||
$template->id = $customcert->templateid;
|
if ($issueduser->emailed) {
|
||||||
$template->name = $customcert->templatename;
|
unset($issuedusers[$key]);
|
||||||
$template->contextid = $customcert->contextid;
|
}
|
||||||
$template = new \mod_customcert\template($template);
|
}
|
||||||
$filecontents = $template->generate_pdf(false, $user->id, true);
|
|
||||||
|
|
||||||
// Set the name of the file we are going to send.
|
// If there are no users to email we can return early.
|
||||||
$filename = $courseshortname . '_' . $certificatename;
|
if (!$issuedusers) {
|
||||||
$filename = \core_text::entities_to_utf8($filename);
|
continue;
|
||||||
$filename = strip_tags($filename);
|
}
|
||||||
$filename = rtrim($filename, '.');
|
|
||||||
$filename = str_replace('&', '_', $filename) . '.pdf';
|
|
||||||
|
|
||||||
// Create the file we will be sending.
|
// Create a directory to store the PDF we will be sending.
|
||||||
$tempfile = $tempdir . '/' . md5(microtime() . $user->id) . '.pdf';
|
$tempdir = make_temp_directory('certificate/attachment');
|
||||||
file_put_contents($tempfile, $filecontents);
|
if (!$tempdir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($customcert->emailstudents) {
|
// Now, email the people we need to.
|
||||||
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname,
|
foreach ($issuedusers as $user) {
|
||||||
$coursefullname, $certificatename, $customcert->contextid);
|
// Set up the user.
|
||||||
|
cron_setup_user($user);
|
||||||
|
|
||||||
$subject = get_string('emailstudentsubject', 'customcert', $info);
|
$userfullname = fullname($user);
|
||||||
$message = $textrenderer->render($renderable);
|
$info->userfullname = $userfullname;
|
||||||
$messagehtml = $htmlrenderer->render($renderable);
|
|
||||||
email_to_user($user, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, $filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($customcert->emailteachers) {
|
// Now, get the PDF.
|
||||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname,
|
$template = new \stdClass();
|
||||||
$coursefullname, $certificatename, $customcert->contextid);
|
$template->id = $customcert->templateid;
|
||||||
|
$template->name = $customcert->templatename;
|
||||||
|
$template->contextid = $customcert->contextid;
|
||||||
|
$template = new \mod_customcert\template($template);
|
||||||
|
$filecontents = $template->generate_pdf(false, $user->id, true);
|
||||||
|
|
||||||
|
// Set the name of the file we are going to send.
|
||||||
|
$filename = $courseshortname . '_' . $certificatename;
|
||||||
|
$filename = \core_text::entities_to_utf8($filename);
|
||||||
|
$filename = strip_tags($filename);
|
||||||
|
$filename = rtrim($filename, '.');
|
||||||
|
$filename = str_replace('&', '_', $filename) . '.pdf';
|
||||||
|
|
||||||
|
// Create the file we will be sending.
|
||||||
|
$tempfile = $tempdir . '/' . md5(microtime() . $user->id) . '.pdf';
|
||||||
|
file_put_contents($tempfile, $filecontents);
|
||||||
|
|
||||||
|
if ($customcert->emailstudents) {
|
||||||
|
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname,
|
||||||
|
$coursefullname, $certificatename, $customcert->contextid);
|
||||||
|
|
||||||
|
$subject = get_string('emailstudentsubject', 'customcert', $info);
|
||||||
|
$message = $textrenderer->render($renderable);
|
||||||
|
$messagehtml = $htmlrenderer->render($renderable);
|
||||||
|
email_to_user($user, fullname($userfrom), html_entity_decode($subject), $message, $messagehtml,
|
||||||
|
$tempfile, $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($customcert->emailteachers) {
|
||||||
|
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname,
|
||||||
|
$coursefullname, $certificatename, $customcert->contextid);
|
||||||
|
|
||||||
|
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
||||||
|
$message = $textrenderer->render($renderable);
|
||||||
|
$messagehtml = $htmlrenderer->render($renderable);
|
||||||
|
foreach ($teachers as $teacher) {
|
||||||
|
email_to_user($teacher, fullname($userfrom), html_entity_decode($subject), $message, $messagehtml,
|
||||||
|
$tempfile, $filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($customcert->emailothers)) {
|
||||||
|
$others = explode(',', $customcert->emailothers);
|
||||||
|
foreach ($others as $email) {
|
||||||
|
$email = trim($email);
|
||||||
|
if (validate_email($email)) {
|
||||||
|
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname,
|
||||||
|
$courseshortname, $coursefullname, $certificatename, $customcert->contextid);
|
||||||
|
|
||||||
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
||||||
$message = $textrenderer->render($renderable);
|
$message = $textrenderer->render($renderable);
|
||||||
$messagehtml = $htmlrenderer->render($renderable);
|
$messagehtml = $htmlrenderer->render($renderable);
|
||||||
foreach ($teachers as $teacher) {
|
|
||||||
email_to_user($teacher, fullname($userfrom), $subject, $message, $messagehtml, $tempfile,
|
$emailuser = new \stdClass();
|
||||||
$filename);
|
$emailuser->id = -1;
|
||||||
}
|
$emailuser->email = $email;
|
||||||
|
email_to_user($emailuser, fullname($userfrom), html_entity_decode($subject), $message,
|
||||||
|
$messagehtml, $tempfile, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($customcert->emailothers)) {
|
|
||||||
$others = explode(',', $customcert->emailothers);
|
|
||||||
foreach ($others as $email) {
|
|
||||||
$email = trim($email);
|
|
||||||
if (validate_email($email)) {
|
|
||||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname,
|
|
||||||
$courseshortname, $coursefullname, $certificatename, $customcert->contextid);
|
|
||||||
|
|
||||||
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
|
||||||
$message = $textrenderer->render($renderable);
|
|
||||||
$messagehtml = $htmlrenderer->render($renderable);
|
|
||||||
|
|
||||||
$emailuser = new \stdClass();
|
|
||||||
$emailuser->id = -1;
|
|
||||||
$emailuser->email = $email;
|
|
||||||
email_to_user($emailuser, fullname($userfrom), $subject, $message, $messagehtml, $tempfile,
|
|
||||||
$filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the field so that it is emailed.
|
|
||||||
$DB->set_field('customcert_issues', 'emailed', 1, array('id' => $user->issueid));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the field so that it is emailed.
|
||||||
|
$DB->set_field('customcert_issues', 'emailed', 1, array('id' => $user->issueid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,19 @@
|
||||||
* Class represents a customcert template.
|
* Class represents a customcert template.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_customcert
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2022 Kumi Systems e.U. <office@kumi.systems>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace mod_customcert;
|
namespace mod_customcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
error_reporting(E_ALL);
|
||||||
|
require_once(__DIR__ . "/../vendor/autoload.php");
|
||||||
|
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||||
|
|
||||||
|
use mikehaertl\wkhtmlto\Pdf;
|
||||||
|
|
||||||
|
#defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class represents a customcert template.
|
* Class represents a customcert template.
|
||||||
|
@ -50,6 +56,8 @@ class template {
|
||||||
*/
|
*/
|
||||||
protected $contextid;
|
protected $contextid;
|
||||||
|
|
||||||
|
protected $html;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor.
|
* The constructor.
|
||||||
*
|
*
|
||||||
|
@ -59,6 +67,7 @@ class template {
|
||||||
$this->id = $template->id;
|
$this->id = $template->id;
|
||||||
$this->name = $template->name;
|
$this->name = $template->name;
|
||||||
$this->contextid = $template->contextid;
|
$this->contextid = $template->contextid;
|
||||||
|
$this->html = $template->html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,8 +262,8 @@ class template {
|
||||||
* @param bool $return Do we want to return the contents of the PDF?
|
* @param bool $return Do we want to return the contents of the PDF?
|
||||||
* @return string|void Can return the PDF in string format if specified.
|
* @return string|void Can return the PDF in string format if specified.
|
||||||
*/
|
*/
|
||||||
public function generate_pdf($preview = false, $userid = null, $return = false) {
|
public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER, $SITE;
|
||||||
|
|
||||||
if (empty($userid)) {
|
if (empty($userid)) {
|
||||||
$user = $USER;
|
$user = $USER;
|
||||||
|
@ -264,25 +273,44 @@ class template {
|
||||||
|
|
||||||
require_once($CFG->libdir . '/pdflib.php');
|
require_once($CFG->libdir . '/pdflib.php');
|
||||||
|
|
||||||
|
profile_load_data($user);
|
||||||
|
|
||||||
// Get the pages for the template, there should always be at least one page for each template.
|
// Get the pages for the template, there should always be at least one page for each template.
|
||||||
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) {
|
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) {
|
||||||
// Create the pdf object.
|
// Create the pdf object.
|
||||||
$pdf = new \pdf();
|
$pdf = new \pdf();
|
||||||
|
|
||||||
|
$customcert = $DB->get_record('customcert', ['templateid' => $this->id]);
|
||||||
|
|
||||||
// If the template belongs to a certificate then we need to check what permissions we set for it.
|
// If the template belongs to a certificate then we need to check what permissions we set for it.
|
||||||
if ($protection = $DB->get_field('customcert', 'protection', array('templateid' => $this->id))) {
|
if (!empty($customcert->protection)) {
|
||||||
if (!empty($protection)) {
|
$protection = explode(', ', $customcert->protection);
|
||||||
$protection = explode(', ', $protection);
|
$pdf->SetProtection($protection);
|
||||||
$pdf->SetProtection($protection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($customcert->deliveryoption)) {
|
||||||
|
$deliveryoption = certificate::DELIVERY_OPTION_INLINE;
|
||||||
|
} else {
|
||||||
|
$deliveryoption = $customcert->deliveryoption;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename.
|
||||||
|
$filename = rtrim(format_string($this->name, true, ['context' => $this->get_context()]), '.');
|
||||||
|
|
||||||
$pdf->setPrintHeader(false);
|
$pdf->setPrintHeader(false);
|
||||||
$pdf->setPrintFooter(false);
|
$pdf->setPrintFooter(false);
|
||||||
$pdf->SetTitle($this->name);
|
$pdf->SetTitle($filename);
|
||||||
$pdf->SetAutoPageBreak(true, 0);
|
$pdf->SetAutoPageBreak(true, 0);
|
||||||
// Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename.
|
|
||||||
$filename = rtrim($this->name, '.');
|
// This is the logic the TCPDF library uses when processing the name. This makes names
|
||||||
|
// such as 'الشهادة' become empty, so set a default name in these cases.
|
||||||
|
$filename = preg_replace('/[\s]+/', '_', $filename);
|
||||||
|
$filename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $filename);
|
||||||
|
|
||||||
|
if (empty($filename)) {
|
||||||
|
$filename = get_string('certificate', 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
$filename = clean_filename($filename . '.pdf');
|
$filename = clean_filename($filename . '.pdf');
|
||||||
// Loop through the pages and display their content.
|
// Loop through the pages and display their content.
|
||||||
foreach ($pages as $page) {
|
foreach ($pages as $page) {
|
||||||
|
@ -293,22 +321,91 @@ class template {
|
||||||
$orientation = 'P';
|
$orientation = 'P';
|
||||||
}
|
}
|
||||||
$pdf->AddPage($orientation, array($page->width, $page->height));
|
$pdf->AddPage($orientation, array($page->width, $page->height));
|
||||||
$pdf->SetMargins($page->leftmargin, 0, $page->rightmargin);
|
|
||||||
// Get the elements for the page.
|
if ($this->html) {
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
$pdf = new Pdf(array(
|
||||||
// Loop through and display.
|
"disable-smart-shrinking",
|
||||||
foreach ($elements as $element) {
|
"margin-bottom" => "0",
|
||||||
// Get an instance of the element class.
|
"margin-right" => "0",
|
||||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
"margin-left" => "0",
|
||||||
$e->render($pdf, $preview, $user);
|
"margin-top" => "0"
|
||||||
}
|
));
|
||||||
}
|
$html = $this->html;
|
||||||
}
|
|
||||||
|
$context = \context_user::instance($user->id);
|
||||||
|
$fs = get_file_storage();
|
||||||
|
$files = $fs->get_area_files($context->id, 'user', 'icon', 0);
|
||||||
|
|
||||||
|
$file = null;
|
||||||
|
$content = "";
|
||||||
|
foreach ($files as $filefound) {
|
||||||
|
if (!$filefound->is_directory()) {
|
||||||
|
$file = $filefound;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($file) {
|
||||||
|
$location = make_request_directory() . '/target';
|
||||||
|
$content = $file->get_content();
|
||||||
|
} else if ($preview) {
|
||||||
|
}
|
||||||
|
$html = str_replace("__PROFILEPIC__", 'data: ' . mime_content_type($file) . ';base64,' . $content, $html);
|
||||||
|
|
||||||
|
$html = str_replace("__NAME__", $user->firstname . " " . $user->lastname, $html);
|
||||||
|
|
||||||
|
if ($preview) {
|
||||||
|
$code = \mod_customcert\certificate::generate_code();
|
||||||
|
} else {
|
||||||
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
||||||
|
'*', IGNORE_MULTIPLE);
|
||||||
|
$code = $issue->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = str_replace("__CERTNUM__", $code, $html);
|
||||||
|
|
||||||
|
if ($preview) {
|
||||||
|
$courseid = $SITE->id;
|
||||||
|
} else {
|
||||||
|
$courseid = $customcert->course;
|
||||||
|
}
|
||||||
|
|
||||||
|
$course = get_course($courseid);
|
||||||
|
$coursename = $course->fullname;
|
||||||
|
|
||||||
|
$html = str_replace("__COURSE__", $coursename, $html);
|
||||||
|
|
||||||
|
$date = $issue->timecreated;
|
||||||
|
|
||||||
|
$html = str_replace("__DATE__", userdate($date, '%B %d, %Y'), $html);
|
||||||
|
|
||||||
|
$html = str_replace("__PIN__", $user->username, $html);
|
||||||
|
|
||||||
|
$pdf->addPage($html);
|
||||||
|
$pdf->send();
|
||||||
|
die($pdf->getError());
|
||||||
|
} else {
|
||||||
|
$pdf->SetMargins($page->leftmargin, 0, $page->rightmargin);
|
||||||
|
// Get the elements for the page.
|
||||||
|
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
||||||
|
// Loop through and display.
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
// Get an instance of the element class.
|
||||||
|
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||||
|
$e->render($pdf, $preview, $user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($return) {
|
|
||||||
|
if ($return && !$this->html) {
|
||||||
return $pdf->Output('', 'S');
|
return $pdf->Output('', 'S');
|
||||||
}
|
}
|
||||||
$pdf->Output($filename, 'D');
|
|
||||||
|
if (!$this->html) {
|
||||||
|
$pdf->Output($filename, $deliveryoption);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,6 +417,10 @@ class template {
|
||||||
public function copy_to_template($copytotemplateid) {
|
public function copy_to_template($copytotemplateid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
|
$copytotemplate = $DB->get_record('customcert_templates', array('id' => $copytotemplateid));
|
||||||
|
$copytotemplate->html = $this->html;
|
||||||
|
$DB->update_record('customcert_templates', $copytotemplate);
|
||||||
|
|
||||||
// Get the pages for the template, there should always be at least one page for each template.
|
// Get the pages for the template, there should always be at least one page for each template.
|
||||||
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) {
|
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) {
|
||||||
// Loop through the pages.
|
// Loop through the pages.
|
||||||
|
@ -412,6 +513,10 @@ class template {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_html() {
|
||||||
|
return $this->html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the context id.
|
* Returns the context id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "markn86/moodle-mod_customcert",
|
"name": "mdjnelson/moodle-mod_customcert",
|
||||||
"type": "moodle-mod",
|
"type": "moodle-mod",
|
||||||
"require": {
|
"require": {
|
||||||
"composer/installers": "~1.0"
|
"composer/installers": "~1.0",
|
||||||
|
"mikehaertl/phpwkhtmltopdf": "^2.5"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"installer-name": "customcert"
|
"installer-name": "customcert"
|
||||||
|
|
311
composer.lock
generated
Normal file
311
composer.lock
generated
Normal file
|
@ -0,0 +1,311 @@
|
||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "749e39445f7c33f767b710400da4e9c6",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "composer/installers",
|
||||||
|
"version": "v1.12.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/composer/installers.git",
|
||||||
|
"reference": "d20a64ed3c94748397ff5973488761b22f6d3f19"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19",
|
||||||
|
"reference": "d20a64ed3c94748397ff5973488761b22f6d3f19",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"composer-plugin-api": "^1.0 || ^2.0"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"roundcube/plugin-installer": "*",
|
||||||
|
"shama/baton": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"composer/composer": "1.6.* || ^2.0",
|
||||||
|
"composer/semver": "^1 || ^3",
|
||||||
|
"phpstan/phpstan": "^0.12.55",
|
||||||
|
"phpstan/phpstan-phpunit": "^0.12.16",
|
||||||
|
"symfony/phpunit-bridge": "^4.2 || ^5",
|
||||||
|
"symfony/process": "^2.3"
|
||||||
|
},
|
||||||
|
"type": "composer-plugin",
|
||||||
|
"extra": {
|
||||||
|
"class": "Composer\\Installers\\Plugin",
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Composer\\Installers\\": "src/Composer/Installers"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Kyle Robinson Young",
|
||||||
|
"email": "kyle@dontkry.com",
|
||||||
|
"homepage": "https://github.com/shama"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A multi-framework Composer library installer",
|
||||||
|
"homepage": "https://composer.github.io/installers/",
|
||||||
|
"keywords": [
|
||||||
|
"Craft",
|
||||||
|
"Dolibarr",
|
||||||
|
"Eliasis",
|
||||||
|
"Hurad",
|
||||||
|
"ImageCMS",
|
||||||
|
"Kanboard",
|
||||||
|
"Lan Management System",
|
||||||
|
"MODX Evo",
|
||||||
|
"MantisBT",
|
||||||
|
"Mautic",
|
||||||
|
"Maya",
|
||||||
|
"OXID",
|
||||||
|
"Plentymarkets",
|
||||||
|
"Porto",
|
||||||
|
"RadPHP",
|
||||||
|
"SMF",
|
||||||
|
"Starbug",
|
||||||
|
"Thelia",
|
||||||
|
"Whmcs",
|
||||||
|
"WolfCMS",
|
||||||
|
"agl",
|
||||||
|
"aimeos",
|
||||||
|
"annotatecms",
|
||||||
|
"attogram",
|
||||||
|
"bitrix",
|
||||||
|
"cakephp",
|
||||||
|
"chef",
|
||||||
|
"cockpit",
|
||||||
|
"codeigniter",
|
||||||
|
"concrete5",
|
||||||
|
"croogo",
|
||||||
|
"dokuwiki",
|
||||||
|
"drupal",
|
||||||
|
"eZ Platform",
|
||||||
|
"elgg",
|
||||||
|
"expressionengine",
|
||||||
|
"fuelphp",
|
||||||
|
"grav",
|
||||||
|
"installer",
|
||||||
|
"itop",
|
||||||
|
"joomla",
|
||||||
|
"known",
|
||||||
|
"kohana",
|
||||||
|
"laravel",
|
||||||
|
"lavalite",
|
||||||
|
"lithium",
|
||||||
|
"magento",
|
||||||
|
"majima",
|
||||||
|
"mako",
|
||||||
|
"mediawiki",
|
||||||
|
"miaoxing",
|
||||||
|
"modulework",
|
||||||
|
"modx",
|
||||||
|
"moodle",
|
||||||
|
"osclass",
|
||||||
|
"pantheon",
|
||||||
|
"phpbb",
|
||||||
|
"piwik",
|
||||||
|
"ppi",
|
||||||
|
"processwire",
|
||||||
|
"puppet",
|
||||||
|
"pxcms",
|
||||||
|
"reindex",
|
||||||
|
"roundcube",
|
||||||
|
"shopware",
|
||||||
|
"silverstripe",
|
||||||
|
"sydes",
|
||||||
|
"sylius",
|
||||||
|
"symfony",
|
||||||
|
"tastyigniter",
|
||||||
|
"typo3",
|
||||||
|
"wordpress",
|
||||||
|
"yawik",
|
||||||
|
"zend",
|
||||||
|
"zikula"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/composer/installers/issues",
|
||||||
|
"source": "https://github.com/composer/installers/tree/v1.12.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://packagist.com",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/composer",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2021-09-13T08:19:44+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mikehaertl/php-shellcommand",
|
||||||
|
"version": "1.6.4",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mikehaertl/php-shellcommand.git",
|
||||||
|
"reference": "3488d7803df1e8f1a343d3d0ca452d527ad8d5e5"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mikehaertl/php-shellcommand/zipball/3488d7803df1e8f1a343d3d0ca452d527ad8d5e5",
|
||||||
|
"reference": "3488d7803df1e8f1a343d3d0ca452d527ad8d5e5",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">= 5.3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": ">4.0 <=9.4"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"mikehaertl\\shellcommand\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Härtl",
|
||||||
|
"email": "haertl.mike@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "An object oriented interface to shell commands",
|
||||||
|
"keywords": [
|
||||||
|
"shell"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/mikehaertl/php-shellcommand/issues",
|
||||||
|
"source": "https://github.com/mikehaertl/php-shellcommand/tree/1.6.4"
|
||||||
|
},
|
||||||
|
"time": "2021-03-17T06:54:33+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mikehaertl/php-tmpfile",
|
||||||
|
"version": "1.2.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mikehaertl/php-tmpfile.git",
|
||||||
|
"reference": "70a5b70b17bc0d9666388e6a551ecc93d0b40a10"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mikehaertl/php-tmpfile/zipball/70a5b70b17bc0d9666388e6a551ecc93d0b40a10",
|
||||||
|
"reference": "70a5b70b17bc0d9666388e6a551ecc93d0b40a10",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"php": ">=5.3.0",
|
||||||
|
"phpunit/phpunit": ">4.0 <=9.4"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"mikehaertl\\tmp\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Härtl",
|
||||||
|
"email": "haertl.mike@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A convenience class for temporary files",
|
||||||
|
"keywords": [
|
||||||
|
"files"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/mikehaertl/php-tmpfile/issues",
|
||||||
|
"source": "https://github.com/mikehaertl/php-tmpfile/tree/1.2.1"
|
||||||
|
},
|
||||||
|
"time": "2021-03-01T18:26:25+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mikehaertl/phpwkhtmltopdf",
|
||||||
|
"version": "2.5.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mikehaertl/phpwkhtmltopdf.git",
|
||||||
|
"reference": "17ee71341591415d942774eda2c98d8ba7ea9e90"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/zipball/17ee71341591415d942774eda2c98d8ba7ea9e90",
|
||||||
|
"reference": "17ee71341591415d942774eda2c98d8ba7ea9e90",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"mikehaertl/php-shellcommand": "^1.5.0",
|
||||||
|
"mikehaertl/php-tmpfile": "^1.2.1",
|
||||||
|
"php": ">=5.0.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": ">4.0 <9.4"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"mikehaertl\\wkhtmlto\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Haertl",
|
||||||
|
"email": "haertl.mike@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface",
|
||||||
|
"homepage": "http://mikehaertl.github.com/phpwkhtmltopdf/",
|
||||||
|
"keywords": [
|
||||||
|
"pdf",
|
||||||
|
"wkhtmltoimage",
|
||||||
|
"wkhtmltopdf"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/mikehaertl/phpwkhtmltopdf/issues",
|
||||||
|
"source": "https://github.com/mikehaertl/phpwkhtmltopdf/tree/2.5.0"
|
||||||
|
},
|
||||||
|
"time": "2021-03-01T19:41:06+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": [],
|
||||||
|
"plugin-api-version": "2.0.0"
|
||||||
|
}
|
|
@ -60,6 +60,14 @@ $capabilities = array(
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'mod/customcert:receiveissue' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'student' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
'mod/customcert:viewreport' => array(
|
'mod/customcert:viewreport' => array(
|
||||||
|
|
||||||
'captype' => 'read',
|
'captype' => 'read',
|
||||||
|
@ -96,4 +104,64 @@ $capabilities = array(
|
||||||
'manager' => CAP_ALLOW
|
'manager' => CAP_ALLOW
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'mod/customcert:manageemailstudents' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/customcert:manageemailteachers' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/customcert:manageemailothers' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/customcert:manageverifyany' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/customcert:managerequiredtime' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/customcert:manageprotection' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="mod/customcert/db" VERSION="20170530" COMMENT="XMLDB file for Moodle mod/customcert"
|
<XMLDB PATH="mod/customcert/db" VERSION="20211105" COMMENT="XMLDB file for Moodle mod/customcert"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||||
>
|
>
|
||||||
|
@ -10,10 +10,11 @@
|
||||||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="requiredtime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="requiredtime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="verifyany" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="verifyany" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="deliveryoption" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="emailstudents" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="emailstudents" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
@ -23,7 +24,7 @@
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert"/>
|
||||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
|
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
<TABLE NAME="customcert_templates" COMMENT="Stores each customcert template">
|
<TABLE NAME="customcert_templates" COMMENT="Stores each customcert template">
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="References contextid."/>
|
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="References contextid."/>
|
||||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="html" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_template"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_template"/>
|
||||||
|
@ -67,7 +69,7 @@
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_pages"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_pages"/>
|
||||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
|
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_templates" REFFIELDS="id"/>
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
<TABLE NAME="customcert_elements" COMMENT="Stores the elements for a given page">
|
<TABLE NAME="customcert_elements" COMMENT="Stores the elements for a given page">
|
||||||
|
@ -75,8 +77,8 @@
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
<FIELD NAME="element" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="element" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
<FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="data" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="font" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="font" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="fontsize" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="fontsize" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
@ -84,6 +86,7 @@
|
||||||
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="refpoint" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="refpoint" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="alignment" TYPE="char" LENGTH="1" NOTNULL="true" DEFAULT="L" SEQUENCE="false"/>
|
||||||
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="sequence" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
|
55
db/mobile.php
Normal file
55
db/mobile.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines mobile handlers.
|
||||||
|
*
|
||||||
|
* @package mod_customcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
$addons = [
|
||||||
|
'mod_customcert' => [ // Plugin identifier.
|
||||||
|
'handlers' => [ // Different places where the plugin will display content.
|
||||||
|
'issueview' => [ // Handler unique name.
|
||||||
|
'displaydata' => [
|
||||||
|
'icon' => $CFG->wwwroot . '/mod/customcert/pix/icon.png',
|
||||||
|
'class' => 'core-course-module-customcert-handler',
|
||||||
|
],
|
||||||
|
'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin).
|
||||||
|
'method' => 'mobile_view_activity', // Main function in \mod_customcert\output\mobile.
|
||||||
|
'styles' => [
|
||||||
|
'url' => '/mod/customcert/mobile/styles.css',
|
||||||
|
'version' => 1
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'lang' => [ // Language strings that are used in all the handlers.
|
||||||
|
['deleteissueconfirm', 'customcert'],
|
||||||
|
['getcustomcert', 'customcert'],
|
||||||
|
['listofissues', 'customcert'],
|
||||||
|
['nothingtodisplay', 'moodle'],
|
||||||
|
['notissued', 'customcert'],
|
||||||
|
['pluginname', 'customcert'],
|
||||||
|
['receiveddate', 'customcert'],
|
||||||
|
['requiredtimenotmet', 'customcert'],
|
||||||
|
['selectagroup', 'moodle']
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
|
@ -25,6 +25,15 @@
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$functions = array(
|
$functions = array(
|
||||||
|
'mod_customcert_delete_issue' => array(
|
||||||
|
'classname' => 'mod_customcert\external',
|
||||||
|
'methodname' => 'delete_issue',
|
||||||
|
'classpath' => '',
|
||||||
|
'description' => 'Delete an issue for a certificate',
|
||||||
|
'type' => 'write',
|
||||||
|
'ajax' => true,
|
||||||
|
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
|
||||||
|
),
|
||||||
'mod_customcert_save_element' => array(
|
'mod_customcert_save_element' => array(
|
||||||
'classname' => 'mod_customcert\external',
|
'classname' => 'mod_customcert\external',
|
||||||
'methodname' => 'save_element',
|
'methodname' => 'save_element',
|
||||||
|
|
5
db/subplugins.json
Normal file
5
db/subplugins.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"plugintypes": {
|
||||||
|
"customcertelement": "mod\/customcert\/element"
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,17 +35,17 @@ function xmldb_customcert_upgrade($oldversion) {
|
||||||
|
|
||||||
$dbman = $DB->get_manager();
|
$dbman = $DB->get_manager();
|
||||||
|
|
||||||
if ($oldversion < 2016052306) {
|
if ($oldversion < 2016120503) {
|
||||||
|
|
||||||
$table = new xmldb_table('customcert_templates');
|
$table = new xmldb_table('customcert_templates');
|
||||||
$field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id');
|
$field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id');
|
||||||
$dbman->change_field_precision($table, $field);
|
$dbman->change_field_precision($table, $field);
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_mod_savepoint(true, 2016052306, 'customcert');
|
upgrade_mod_savepoint(true, 2016120503, 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oldversion < 2016052308) {
|
if ($oldversion < 2016120505) {
|
||||||
$table = new xmldb_table('customcert');
|
$table = new xmldb_table('customcert');
|
||||||
$field = new xmldb_field('emailstudents', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'requiredtime');
|
$field = new xmldb_field('emailstudents', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'requiredtime');
|
||||||
|
|
||||||
|
@ -77,10 +77,10 @@ function xmldb_customcert_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_mod_savepoint(true, 2016052308, 'customcert');
|
upgrade_mod_savepoint(true, 2016120505, 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oldversion < 2016052310) {
|
if ($oldversion < 2017050501) {
|
||||||
// Remove any duplicate rows from customcert issue table.
|
// Remove any duplicate rows from customcert issue table.
|
||||||
// This SQL fetches the id of those records which have duplicate customcert issues.
|
// This SQL fetches the id of those records which have duplicate customcert issues.
|
||||||
// This doesn't return the first issue.
|
// This doesn't return the first issue.
|
||||||
|
@ -103,10 +103,10 @@ function xmldb_customcert_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_mod_savepoint(true, 2016052310, 'customcert');
|
upgrade_mod_savepoint(true, 2017050501, 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oldversion < 2016052311) {
|
if ($oldversion < 2017050502) {
|
||||||
// Add column for new 'verifycertificateanyone' setting.
|
// Add column for new 'verifycertificateanyone' setting.
|
||||||
$table = new xmldb_table('customcert');
|
$table = new xmldb_table('customcert');
|
||||||
$field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
|
$field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
|
||||||
|
@ -118,10 +118,10 @@ function xmldb_customcert_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_mod_savepoint(true, 2016052311, 'customcert');
|
upgrade_mod_savepoint(true, 2017050502, 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($oldversion < 2016052314) {
|
if ($oldversion < 2017050506) {
|
||||||
$table = new xmldb_table('customcert_elements');
|
$table = new xmldb_table('customcert_elements');
|
||||||
$field = new xmldb_field('size');
|
$field = new xmldb_field('size');
|
||||||
|
|
||||||
|
@ -132,7 +132,71 @@ function xmldb_customcert_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_mod_savepoint(true, 2016052314, 'customcert');
|
upgrade_mod_savepoint(true, 2017050506, 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2018051705) {
|
||||||
|
$table = new xmldb_table('customcert_elements');
|
||||||
|
$field = new xmldb_field('element', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'name');
|
||||||
|
|
||||||
|
// Alter the 'element' column to be characters, rather than text.
|
||||||
|
$dbman->change_field_type($table, $field);
|
||||||
|
|
||||||
|
// Savepoint reached.
|
||||||
|
upgrade_mod_savepoint(true, 2018051705, 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2019111803) {
|
||||||
|
$table = new xmldb_table('customcert');
|
||||||
|
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
|
||||||
|
if ($dbman->index_exists($table, $index)) {
|
||||||
|
$dbman->drop_index($table, $index);
|
||||||
|
}
|
||||||
|
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, ['templateid'], 'customcert_templates', ['id']);
|
||||||
|
$dbman->add_key($table, $key);
|
||||||
|
|
||||||
|
$table = new xmldb_table('customcert_pages');
|
||||||
|
$index = new xmldb_index('templateid', XMLDB_INDEX_UNIQUE, ['templateid']);
|
||||||
|
if ($dbman->index_exists($table, $index)) {
|
||||||
|
$dbman->drop_index($table, $index);
|
||||||
|
}
|
||||||
|
$key = new xmldb_key('templateid', XMLDB_KEY_FOREIGN, ['templateid'], 'customcert_templates', ['id']);
|
||||||
|
$dbman->add_key($table, $key);
|
||||||
|
|
||||||
|
upgrade_mod_savepoint(true, 2019111803, 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2020110901) {
|
||||||
|
$table = new xmldb_table('customcert');
|
||||||
|
$field = new xmldb_field('deliveryoption', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'verifyany');
|
||||||
|
|
||||||
|
// Conditionally launch add field.
|
||||||
|
if (!$dbman->field_exists($table, $field)) {
|
||||||
|
$dbman->add_field($table, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
upgrade_mod_savepoint(true, 2020110901, 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2021051702) {
|
||||||
|
$table = new xmldb_table('customcert_elements');
|
||||||
|
$field = new xmldb_field('alignment', XMLDB_TYPE_CHAR, '1', null, XMLDB_NOTNULL, null, 'L', 'refpoint');
|
||||||
|
|
||||||
|
$dbman->add_field($table, $field);
|
||||||
|
|
||||||
|
upgrade_mod_savepoint(true, 2021051702, 'customcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2021110501) {
|
||||||
|
$table = new xmldb_table('customcert_templates');
|
||||||
|
$field = new xmldb_field('html', XMLDB_TYPE_TEXT, null, null, null, null, null, 'timemodified');
|
||||||
|
|
||||||
|
// Conditionally launch add field html.
|
||||||
|
if (!$dbman->field_exists($table, $field)) {
|
||||||
|
$dbman->add_field($table, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
upgrade_mod_savepoint(true, 2021110501, 'customcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
24
edit.php
24
edit.php
|
@ -51,19 +51,31 @@ $context = context::instance_by_id($contextid);
|
||||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||||
$cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST);
|
$cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST);
|
||||||
require_login($cm->course, false, $cm);
|
require_login($cm->course, false, $cm);
|
||||||
|
|
||||||
|
$customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$title = $customcert->name;
|
||||||
|
$heading = format_string($title);
|
||||||
} else {
|
} else {
|
||||||
require_login();
|
require_login();
|
||||||
|
$title = $SITE->fullname;
|
||||||
|
$heading = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_capability('mod/customcert:manage', $context);
|
require_capability('mod/customcert:manage', $context);
|
||||||
|
|
||||||
// Set up the page.
|
// Set up the page.
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('editcustomcert', 'customcert'));
|
\mod_customcert\page_helper::page_setup($pageurl, $context, $title);
|
||||||
|
|
||||||
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
||||||
// We are managing a template - add some navigation.
|
// We are managing a template - add some navigation.
|
||||||
$PAGE->navbar->add(get_string('managetemplates', 'customcert'),
|
$PAGE->navbar->add(get_string('managetemplates', 'customcert'),
|
||||||
new moodle_url('/mod/customcert/manage_templates.php'));
|
new moodle_url('/mod/customcert/manage_templates.php'));
|
||||||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
|
if (!$tid) {
|
||||||
|
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
|
||||||
|
} else {
|
||||||
|
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'),
|
||||||
|
new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flag to determine if we are deleting anything.
|
// Flag to determine if we are deleting anything.
|
||||||
|
@ -140,11 +152,9 @@ if ($tid) {
|
||||||
// Check if we are deleting either a page or an element.
|
// Check if we are deleting either a page or an element.
|
||||||
if ($deleting) {
|
if ($deleting) {
|
||||||
// Show a confirmation page.
|
// Show a confirmation page.
|
||||||
$strheading = get_string('deleteconfirm', 'customcert');
|
$PAGE->navbar->add(get_string('deleteconfirm', 'customcert'));
|
||||||
$PAGE->navbar->add($strheading);
|
|
||||||
$PAGE->set_title($strheading);
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading($strheading);
|
echo $OUTPUT->heading($heading);
|
||||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
exit();
|
exit();
|
||||||
|
@ -230,7 +240,7 @@ if ($data = $mform->get_data()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
echo $OUTPUT->heading($heading);
|
||||||
$mform->display();
|
$mform->display();
|
||||||
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
|
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
|
||||||
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
|
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
|
||||||
|
|
|
@ -41,6 +41,15 @@ if ($cm = $template->get_cm()) {
|
||||||
// Make sure the user has the required capabilities.
|
// Make sure the user has the required capabilities.
|
||||||
$template->require_manage();
|
$template->require_manage();
|
||||||
|
|
||||||
|
if ($template->get_context()->contextlevel == CONTEXT_MODULE) {
|
||||||
|
$customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$title = $customcert->name;
|
||||||
|
$heading = format_string($title);
|
||||||
|
} else {
|
||||||
|
$title = $SITE->fullname;
|
||||||
|
$heading = $title;
|
||||||
|
}
|
||||||
|
|
||||||
if ($action == 'edit') {
|
if ($action == 'edit') {
|
||||||
// The id of the element must be supplied if we are currently editing one.
|
// The id of the element must be supplied if we are currently editing one.
|
||||||
$id = required_param('id', PARAM_INT);
|
$id = required_param('id', PARAM_INT);
|
||||||
|
@ -56,7 +65,6 @@ if ($action == 'edit') {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the page.
|
// Set up the page.
|
||||||
$title = get_string('editelement', 'customcert');
|
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
||||||
|
|
||||||
// Additional page setup.
|
// Additional page setup.
|
||||||
|
@ -66,7 +74,7 @@ if ($template->get_context()->contextlevel == CONTEXT_SYSTEM) {
|
||||||
}
|
}
|
||||||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php',
|
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php',
|
||||||
array('tid' => $tid)));
|
array('tid' => $tid)));
|
||||||
$PAGE->navbar->add($title);
|
$PAGE->navbar->add(get_string('editelement', 'customcert'));
|
||||||
|
|
||||||
$mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element));
|
$mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element));
|
||||||
|
|
||||||
|
@ -95,6 +103,6 @@ if ($data = $mform->get_data()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('editelement', 'customcert'));
|
echo $OUTPUT->heading($heading);
|
||||||
$mform->display();
|
$mform->display();
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
|
@ -38,7 +38,7 @@ class element extends \customcertelement_image\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
||||||
|
@ -67,12 +67,11 @@ class element extends \customcertelement_image\element {
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If there is no file, we have nothing to display.
|
// If there is no file, we have nothing to display.
|
||||||
if (empty($imageinfo->filename)) {
|
if (empty($imageinfo->filename)) {
|
||||||
|
@ -105,12 +104,11 @@ class element extends \customcertelement_image\element {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If there is no file, we have nothing to display.
|
// If there is no file, we have nothing to display.
|
||||||
if (empty($imageinfo->filename)) {
|
if (empty($imageinfo->filename)) {
|
||||||
|
|
46
element/bgimage/classes/privacy/provider.php
Normal file
46
element/bgimage/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_bgimage.
|
||||||
|
*
|
||||||
|
* @package customcertelement_bgimage
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_bgimage\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_bgimage implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die;
|
||||||
function xmldb_customcertelement_bgimage_upgrade($oldversion) {
|
function xmldb_customcertelement_bgimage_upgrade($oldversion) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if ($oldversion < 2016052303) {
|
if ($oldversion < 2016120501) {
|
||||||
// Go through each 'image' element and update the file stored information.
|
// Go through each 'image' element and update the file stored information.
|
||||||
if ($images = $DB->get_records_select('customcert_elements', $DB->sql_compare_text('element') . ' = \'bgimage\'')) {
|
if ($images = $DB->get_records_select('customcert_elements', $DB->sql_compare_text('element') . ' = \'bgimage\'')) {
|
||||||
// Create a file storage instance we are going to use to create pathname hashes.
|
// Create a file storage instance we are going to use to create pathname hashes.
|
||||||
|
@ -59,7 +59,7 @@ function xmldb_customcertelement_bgimage_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_plugin_savepoint(true, 2016052303, 'customcertelement', 'bgimage');
|
upgrade_plugin_savepoint(true, 2016120501, 'customcertelement', 'bgimage');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -23,3 +23,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['pluginname'] = 'Background image';
|
$string['pluginname'] = 'Background image';
|
||||||
|
$string['privacy:metadata'] = 'The Background image plugin does not store any personal data.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052303; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_bgimage';
|
$plugin->component = 'customcertelement_bgimage';
|
||||||
|
|
|
@ -38,7 +38,7 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
// We want to define the width of the border.
|
// We want to define the width of the border.
|
||||||
|
@ -103,13 +103,12 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
|
||||||
$element = $mform->getElement('width');
|
$element = $mform->getElement('width');
|
||||||
$element->setValue($data);
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
46
element/border/classes/privacy/provider.php
Normal file
46
element/border/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_border.
|
||||||
|
*
|
||||||
|
* @package customcertelement_border
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_border\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_border implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['pluginname'] = 'Border';
|
$string['pluginname'] = 'Border';
|
||||||
|
$string['privacy:metadata'] = 'The Border plugin does not store any personal data.';
|
||||||
$string['invalidwidth'] = 'The width has to be a valid number greater than 0.';
|
$string['invalidwidth'] = 'The width has to be a valid number greater than 0.';
|
||||||
$string['width'] = 'Width';
|
$string['width'] = 'Width';
|
||||||
$string['width_help'] = 'Width of the border in mm.';
|
$string['width_help'] = 'Width of the border in mm.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_border';
|
$plugin->component = 'customcertelement_border';
|
||||||
|
|
|
@ -43,7 +43,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name($this->get_id()));
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_category_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,28 +55,28 @@ class element extends \mod_customcert\element {
|
||||||
* @return string the html
|
* @return string the html
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
global $COURSE;
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_category_name());
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that returns the category name.
|
* Helper function that returns the category name.
|
||||||
*
|
*
|
||||||
* @param int $elementid
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected static function get_category_name($elementid) {
|
protected function get_category_name() : string {
|
||||||
global $DB, $SITE;
|
global $DB, $SITE;
|
||||||
|
|
||||||
$courseid = \mod_customcert\element_helper::get_courseid($elementid);
|
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
||||||
$course = get_course($courseid);
|
$course = get_course($courseid);
|
||||||
|
$context = \mod_customcert\element_helper::get_context($this->get_id());
|
||||||
|
|
||||||
// Check that there is a course category available.
|
// Check that there is a course category available.
|
||||||
if (!empty($course->category)) {
|
if (!empty($course->category)) {
|
||||||
return $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST);
|
$categoryname = $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST);
|
||||||
} else { // Must be in a site template.
|
} else { // Must be in a site template.
|
||||||
return $SITE->fullname;
|
$categoryname = $SITE->fullname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return format_string($categoryname, true, ['context' => $context]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
element/categoryname/classes/privacy/provider.php
Normal file
46
element/categoryname/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_categoryname.
|
||||||
|
*
|
||||||
|
* @package customcertelement_categoryname
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_categoryname\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_categoryname implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,3 +23,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['pluginname'] = 'Category name';
|
$string['pluginname'] = 'Category name';
|
||||||
|
$string['privacy:metadata'] = 'The Category name plugin does not store any personal data.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_categoryname';
|
$plugin->component = 'customcertelement_categoryname';
|
||||||
|
|
|
@ -54,7 +54,7 @@ class element extends \mod_customcert\element {
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
||||||
'*', MUST_EXIST);
|
'*', IGNORE_MULTIPLE);
|
||||||
$code = $issue->code;
|
$code = $issue->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
element/code/classes/privacy/provider.php
Normal file
46
element/code/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_code.
|
||||||
|
*
|
||||||
|
* @package customcertelement_code
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_code\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_code implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,3 +23,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['pluginname'] = 'Code';
|
$string['pluginname'] = 'Code';
|
||||||
|
$string['privacy:metadata'] = 'The Code plugin does not store any personal data.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_code';
|
$plugin->component = 'customcertelement_code';
|
||||||
|
|
154
element/coursefield/classes/element.php
Normal file
154
element/coursefield/classes/element.php
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains the customcert element coursefield's core interaction API.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursefield
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @author Dan Marsden
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_coursefield;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The customcert element coursefield's core interaction API.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursefield
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class element extends \mod_customcert\element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function renders the form elements when adding a customcert element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit form instance
|
||||||
|
*/
|
||||||
|
public function render_form_elements($mform) {
|
||||||
|
// Get the user profile fields.
|
||||||
|
$coursefields = array(
|
||||||
|
'fullname' => get_string('fullnamecourse'),
|
||||||
|
'shortname' => get_string('shortnamecourse'),
|
||||||
|
'idnumber' => get_string('idnumbercourse')
|
||||||
|
);
|
||||||
|
// Get the course custom fields.
|
||||||
|
$arrcustomfields = array();
|
||||||
|
$handler = \core_course\customfield\course_handler::create();
|
||||||
|
$customfields = $handler->get_fields();
|
||||||
|
|
||||||
|
foreach ($customfields as $field) {
|
||||||
|
$arrcustomfields[$field->get('id')] = $field->get_formatted_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the two.
|
||||||
|
$fields = $coursefields + $arrcustomfields;
|
||||||
|
\core_collator::asort($fields);
|
||||||
|
|
||||||
|
// Create the select box where the user field is selected.
|
||||||
|
$mform->addElement('select', 'coursefield', get_string('coursefield', 'customcertelement_coursefield'), $fields);
|
||||||
|
$mform->setType('coursefield', PARAM_ALPHANUM);
|
||||||
|
$mform->addHelpButton('coursefield', 'coursefield', 'customcertelement_coursefield');
|
||||||
|
|
||||||
|
parent::render_form_elements($mform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will handle how form data will be saved into the data column in the
|
||||||
|
* customcert_elements table.
|
||||||
|
*
|
||||||
|
* @param \stdClass $data the form data
|
||||||
|
* @return string the text
|
||||||
|
*/
|
||||||
|
public function save_unique_data($data) {
|
||||||
|
return $data->coursefield;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles rendering the element on the pdf.
|
||||||
|
*
|
||||||
|
* @param \pdf $pdf the pdf object
|
||||||
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
|
*/
|
||||||
|
public function render($pdf, $preview, $user) {
|
||||||
|
|
||||||
|
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
||||||
|
$course = get_course($courseid);
|
||||||
|
|
||||||
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_course_field_value($course, $preview));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the element in html.
|
||||||
|
*
|
||||||
|
* This function is used to render the element when we are using the
|
||||||
|
* drag and drop interface to position it.
|
||||||
|
*/
|
||||||
|
public function render_html() {
|
||||||
|
global $COURSE;
|
||||||
|
|
||||||
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_course_field_value($COURSE, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the data on the form when editing an element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit form instance
|
||||||
|
*/
|
||||||
|
public function definition_after_data($mform) {
|
||||||
|
if (!empty($this->get_data())) {
|
||||||
|
$element = $mform->getElement('coursefield');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
|
}
|
||||||
|
parent::definition_after_data($mform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that returns the field value in a human-readable format.
|
||||||
|
*
|
||||||
|
* @param \stdClass $course the course we are rendering this for
|
||||||
|
* @param bool $preview Is this a preview?
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_course_field_value(\stdClass $course, bool $preview) : string {
|
||||||
|
|
||||||
|
// The user field to display.
|
||||||
|
$field = $this->get_data();
|
||||||
|
// The value to display - we always want to show a value here so it can be repositioned.
|
||||||
|
if ($preview) {
|
||||||
|
$value = $field;
|
||||||
|
} else {
|
||||||
|
$value = '';
|
||||||
|
}
|
||||||
|
if (is_number($field)) { // Must be a custom course profile field.
|
||||||
|
$handler = \core_course\customfield\course_handler::create();
|
||||||
|
$data = $handler->get_instance_data($course->id, true);
|
||||||
|
if (!empty($data[$field])) {
|
||||||
|
$value = $data[$field]->export_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (!empty($course->$field)) { // Field in the course table.
|
||||||
|
$value = $course->$field;
|
||||||
|
}
|
||||||
|
|
||||||
|
$context = \mod_customcert\element_helper::get_context($this->get_id());
|
||||||
|
return format_string($value, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
}
|
47
element/coursefield/classes/privacy/provider.php
Normal file
47
element/coursefield/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_coursefield.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursefield
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @author Dan Marsden
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_coursefield\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_coursefield implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strings for component 'customcertelement_coursefield', language 'en'.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursefield
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @author Dan Marsden
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
$string['pluginname'] = 'Course field';
|
||||||
|
$string['privacy:metadata'] = 'The course field plugin does not store any personal data.';
|
||||||
|
$string['coursefield'] = 'Course field';
|
||||||
|
$string['coursefield_help'] = 'This is the course field that will be displayed on the PDF.';
|
30
element/coursefield/version.php
Normal file
30
element/coursefield/version.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains the version information for the coursefield plugin.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursefield
|
||||||
|
* @copyright 2019 Catalyst IT
|
||||||
|
* @author Dan Marsden
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
|
$plugin->component = 'customcertelement_coursefield';
|
|
@ -35,6 +35,42 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
*/
|
*/
|
||||||
class element extends \mod_customcert\element {
|
class element extends \mod_customcert\element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The course short name.
|
||||||
|
*/
|
||||||
|
const COURSE_SHORT_NAME = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The course fullname.
|
||||||
|
*/
|
||||||
|
const COURSE_FULL_NAME = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function renders the form elements when adding a customcert element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
|
*/
|
||||||
|
public function render_form_elements($mform) {
|
||||||
|
// The course name display options.
|
||||||
|
$mform->addElement('select', 'coursenamedisplay', get_string('coursenamedisplay', 'customcertelement_coursename'),
|
||||||
|
self::get_course_name_display_options());
|
||||||
|
$mform->setType('coursenamedisplay', PARAM_INT);
|
||||||
|
$mform->addHelpButton('coursenamedisplay', 'coursenamedisplay', 'customcertelement_coursename');
|
||||||
|
|
||||||
|
parent::render_form_elements($mform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will handle how form data will be saved into the data column in the
|
||||||
|
* customcert_elements table.
|
||||||
|
*
|
||||||
|
* @param \stdClass $data the form data
|
||||||
|
* @return string the text
|
||||||
|
*/
|
||||||
|
public function save_unique_data($data) {
|
||||||
|
return $data->coursenamedisplay;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
|
@ -43,10 +79,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_course_name_detail());
|
||||||
$course = get_course($courseid);
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $course->fullname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,8 +91,52 @@ class element extends \mod_customcert\element {
|
||||||
* @return string the html
|
* @return string the html
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
global $COURSE;
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_course_name_detail());
|
||||||
|
}
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname);
|
/**
|
||||||
|
* Sets the data on the form when editing an element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
|
*/
|
||||||
|
public function definition_after_data($mform) {
|
||||||
|
if (!empty($this->get_data())) {
|
||||||
|
$element = $mform->getElement('coursenamedisplay');
|
||||||
|
$element->setValue($this->get_data());
|
||||||
|
}
|
||||||
|
parent::definition_after_data($mform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that returns the selected course name detail (i.e. name or short description) for display.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_course_name_detail(): string {
|
||||||
|
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
||||||
|
$course = get_course($courseid);
|
||||||
|
$context = \mod_customcert\element_helper::get_context($this->get_id());
|
||||||
|
|
||||||
|
// The name field to display.
|
||||||
|
$field = $this->get_data();
|
||||||
|
// The name value to display.
|
||||||
|
$value = $course->fullname;
|
||||||
|
if ($field == self::COURSE_SHORT_NAME) {
|
||||||
|
$value = $course->shortname;
|
||||||
|
}
|
||||||
|
|
||||||
|
return format_string($value, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to return all the possible name display options.
|
||||||
|
*
|
||||||
|
* @return array returns an array of name options
|
||||||
|
*/
|
||||||
|
public static function get_course_name_display_options(): array {
|
||||||
|
return [
|
||||||
|
self::COURSE_FULL_NAME => get_string('coursefullname', 'customcertelement_coursename'),
|
||||||
|
self::COURSE_SHORT_NAME => get_string('courseshortname', 'customcertelement_coursename')
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
element/coursename/classes/privacy/provider.php
Normal file
46
element/coursename/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_coursename.
|
||||||
|
*
|
||||||
|
* @package customcertelement_coursename
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_coursename\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_coursename implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,4 +22,10 @@
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$string['coursenamedisplay'] = 'Type';
|
||||||
|
$string['coursenamedisplay_help'] = 'Display the course full name or short name?';
|
||||||
|
$string['coursefullname'] = 'Full name';
|
||||||
|
$string['courseshortname'] = 'Short name';
|
||||||
$string['pluginname'] = 'Course name';
|
$string['pluginname'] = 'Course name';
|
||||||
|
$string['privacy:metadata'] = 'The Course name plugin does not store any personal data.';
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_coursename';
|
$plugin->component = 'customcertelement_coursename';
|
||||||
|
|
|
@ -51,6 +51,21 @@ define('CUSTOMCERT_DATE_COURSE_START', '-3');
|
||||||
*/
|
*/
|
||||||
define('CUSTOMCERT_DATE_COURSE_END', '-4');
|
define('CUSTOMCERT_DATE_COURSE_END', '-4');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Current date
|
||||||
|
*/
|
||||||
|
define('CUSTOMCERT_DATE_CURRENT_DATE', '-5');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Enrollment start
|
||||||
|
*/
|
||||||
|
define('CUSTOMCERT_DATE_ENROLMENT_START', '-6');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Entrollment end
|
||||||
|
*/
|
||||||
|
define('CUSTOMCERT_DATE_ENROLMENT_END', '-7');
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,15 +80,22 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
global $COURSE;
|
global $CFG, $COURSE;
|
||||||
|
|
||||||
// Get the possible date options.
|
// Get the possible date options.
|
||||||
$dateoptions = array();
|
$dateoptions = array();
|
||||||
$dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date');
|
$dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date');
|
||||||
$dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date');
|
$dateoptions[CUSTOMCERT_DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_date');
|
||||||
|
$completionenabled = $CFG->enablecompletion && ($COURSE->id == SITEID || $COURSE->enablecompletion);
|
||||||
|
if ($completionenabled) {
|
||||||
|
$dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date');
|
||||||
|
}
|
||||||
|
$dateoptions[CUSTOMCERT_DATE_ENROLMENT_START] = get_string('enrolmentstartdate', 'customcertelement_date');
|
||||||
|
$dateoptions[CUSTOMCERT_DATE_ENROLMENT_END] = get_string('enrolmentenddate', 'customcertelement_date');
|
||||||
|
|
||||||
$dateoptions[CUSTOMCERT_DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_date');
|
$dateoptions[CUSTOMCERT_DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_date');
|
||||||
$dateoptions[CUSTOMCERT_DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_date');
|
$dateoptions[CUSTOMCERT_DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_date');
|
||||||
$dateoptions[CUSTOMCERT_DATE_COURSE_GRADE] = get_string('coursegradedate', 'customcertelement_date');
|
$dateoptions[CUSTOMCERT_DATE_COURSE_GRADE] = get_string('coursegradedate', 'customcertelement_date');
|
||||||
|
@ -117,15 +139,14 @@ class element extends \mod_customcert\element {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$dateinfo = json_decode($data);
|
$dateinfo = json_decode($this->get_data());
|
||||||
$dateitem = $dateinfo->dateitem;
|
$dateitem = $dateinfo->dateitem;
|
||||||
$dateformat = $dateinfo->dateformat;
|
$dateformat = $dateinfo->dateformat;
|
||||||
|
|
||||||
|
@ -139,10 +160,12 @@ class element extends \mod_customcert\element {
|
||||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
// Now we can get the issue for this user.
|
// Now we can get the issue for this user.
|
||||||
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
||||||
'*', MUST_EXIST);
|
'*', IGNORE_MULTIPLE);
|
||||||
|
|
||||||
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
||||||
$date = $issue->timecreated;
|
$date = $issue->timecreated;
|
||||||
|
} else if ($dateitem == CUSTOMCERT_DATE_CURRENT_DATE) {
|
||||||
|
$date = time();
|
||||||
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
|
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
|
||||||
// Get the last completion date.
|
// Get the last completion date.
|
||||||
$sql = "SELECT MAX(c.timecompleted) as timecompleted
|
$sql = "SELECT MAX(c.timecompleted) as timecompleted
|
||||||
|
@ -154,6 +177,26 @@ class element extends \mod_customcert\element {
|
||||||
$date = $timecompleted->timecompleted;
|
$date = $timecompleted->timecompleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if ($dateitem == CUSTOMCERT_DATE_ENROLMENT_START) {
|
||||||
|
// Get the enrolment start date.
|
||||||
|
$sql = "SELECT ue.timestart FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id
|
||||||
|
WHERE e.courseid = :courseid
|
||||||
|
AND ue.userid = :userid";
|
||||||
|
if ($timestart = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) {
|
||||||
|
if (!empty($timestart->timestart)) {
|
||||||
|
$date = $timestart->timestart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ($dateitem == CUSTOMCERT_DATE_ENROLMENT_END) {
|
||||||
|
// Get the enrolment end date.
|
||||||
|
$sql = "SELECT ue.timeend FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id
|
||||||
|
WHERE e.courseid = :courseid
|
||||||
|
AND ue.userid = :userid";
|
||||||
|
if ($timeend = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) {
|
||||||
|
if (!empty($timeend->timeend)) {
|
||||||
|
$date = $timeend->timeend;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_START) {
|
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_START) {
|
||||||
$date = $DB->get_field('course', 'startdate', array('id' => $courseid));
|
$date = $DB->get_field('course', 'startdate', array('id' => $courseid));
|
||||||
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_END) {
|
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_END) {
|
||||||
|
@ -180,9 +223,8 @@ class element extends \mod_customcert\element {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dategraded = $grade->get_dategraded();
|
if ($grade && !empty($grade->get_dategraded())) {
|
||||||
if ($grade && !empty($dategraded)) {
|
$date = $grade->get_dategraded();
|
||||||
$date = $dategraded;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,13 +245,12 @@ class element extends \mod_customcert\element {
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
return;
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$dateinfo = json_decode($data);
|
$dateinfo = json_decode($this->get_data());
|
||||||
$dateformat = $dateinfo->dateformat;
|
$dateformat = $dateinfo->dateformat;
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
|
||||||
|
@ -218,13 +259,12 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
// Set the item and format for this element.
|
// Set the item and format for this element.
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
$dateinfo = json_decode($this->get_data());
|
||||||
$dateinfo = json_decode($data);
|
|
||||||
|
|
||||||
$element = $mform->getElement('dateitem');
|
$element = $mform->getElement('dateitem');
|
||||||
$element->setValue($dateinfo->dateitem);
|
$element->setValue($dateinfo->dateitem);
|
||||||
|
@ -260,27 +300,44 @@ class element extends \mod_customcert\element {
|
||||||
* @return array the list of date formats
|
* @return array the list of date formats
|
||||||
*/
|
*/
|
||||||
public static function get_date_formats() {
|
public static function get_date_formats() {
|
||||||
$date = time();
|
// Hard-code date so users can see the difference between short dates with and without the leading zero.
|
||||||
|
// Eg. 06/07/18 vs 6/07/18.
|
||||||
|
$date = 1530849658;
|
||||||
|
|
||||||
$suffix = self::get_ordinal_number_suffix(userdate($date, '%d'));
|
$suffix = self::get_ordinal_number_suffix(userdate($date, '%d'));
|
||||||
|
|
||||||
$dateformats = array(
|
$dateformats = [
|
||||||
1 => userdate($date, '%B %d, %Y'),
|
1 => userdate($date, '%B %d, %Y'),
|
||||||
2 => userdate($date, '%B %d' . $suffix . ', %Y'),
|
2 => userdate($date, '%B %d' . $suffix . ', %Y')
|
||||||
'strftimedate' => userdate($date, get_string('strftimedate', 'langconfig')),
|
];
|
||||||
'strftimedatefullshort' => userdate($date, get_string('strftimedatefullshort', 'langconfig')),
|
|
||||||
'strftimedateshort' => userdate($date, get_string('strftimedateshort', 'langconfig')),
|
$strdateformats = [
|
||||||
'strftimedatetime' => userdate($date, get_string('strftimedatetime', 'langconfig')),
|
'strftimedate',
|
||||||
'strftimedatetimeshort' => userdate($date, get_string('strftimedatetimeshort', 'langconfig')),
|
'strftimedatefullshort',
|
||||||
'strftimedaydate' => userdate($date, get_string('strftimedaydate', 'langconfig')),
|
'strftimedatefullshortwleadingzero',
|
||||||
'strftimedaydatetime' => userdate($date, get_string('strftimedaydatetime', 'langconfig')),
|
'strftimedateshort',
|
||||||
'strftimedayshort' => userdate($date, get_string('strftimedayshort', 'langconfig')),
|
'strftimedatetime',
|
||||||
'strftimedaytime' => userdate($date, get_string('strftimedaytime', 'langconfig')),
|
'strftimedatetimeshort',
|
||||||
'strftimemonthyear' => userdate($date, get_string('strftimemonthyear', 'langconfig')),
|
'strftimedatetimeshortwleadingzero',
|
||||||
'strftimerecent' => userdate($date, get_string('strftimerecent', 'langconfig')),
|
'strftimedaydate',
|
||||||
'strftimerecentfull' => userdate($date, get_string('strftimerecentfull', 'langconfig')),
|
'strftimedaydatetime',
|
||||||
'strftimetime' => userdate($date, get_string('strftimetime', 'langconfig'))
|
'strftimedayshort',
|
||||||
);
|
'strftimedaytime',
|
||||||
|
'strftimemonthyear',
|
||||||
|
'strftimerecent',
|
||||||
|
'strftimerecentfull',
|
||||||
|
'strftimetime'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($strdateformats as $strdateformat) {
|
||||||
|
if ($strdateformat == 'strftimedatefullshortwleadingzero') {
|
||||||
|
$dateformats[$strdateformat] = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false);
|
||||||
|
} else if ($strdateformat == 'strftimedatetimeshortwleadingzero') {
|
||||||
|
$dateformats[$strdateformat] = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false);
|
||||||
|
} else {
|
||||||
|
$dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $dateformats;
|
return $dateformats;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +373,13 @@ class element extends \mod_customcert\element {
|
||||||
|
|
||||||
// Ok, so we must have been passed the actual format in the lang file.
|
// Ok, so we must have been passed the actual format in the lang file.
|
||||||
if (!isset($certificatedate)) {
|
if (!isset($certificatedate)) {
|
||||||
$certificatedate = userdate($date, get_string($dateformat, 'langconfig'));
|
if ($dateformat == 'strftimedatefullshortwleadingzero') {
|
||||||
|
$certificatedate = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false);
|
||||||
|
} else if ($dateformat == 'strftimedatetimeshortwleadingzero') {
|
||||||
|
$certificatedate = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false);
|
||||||
|
} else {
|
||||||
|
$certificatedate = userdate($date, get_string($dateformat, 'langconfig'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $certificatedate;
|
return $certificatedate;
|
||||||
|
|
46
element/date/classes/privacy/provider.php
Normal file
46
element/date/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_date.
|
||||||
|
*
|
||||||
|
* @package customcertelement_date
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_date\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_date implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,12 +26,16 @@ $string['completiondate'] = 'Completion date';
|
||||||
$string['courseenddate'] = 'Course end date';
|
$string['courseenddate'] = 'Course end date';
|
||||||
$string['coursegradedate'] = 'Course grade date';
|
$string['coursegradedate'] = 'Course grade date';
|
||||||
$string['coursestartdate'] = 'Course start date';
|
$string['coursestartdate'] = 'Course start date';
|
||||||
|
$string['enrolmentenddate'] = 'Enrolment end date';
|
||||||
|
$string['enrolmentstartdate'] = 'Enrolment start date';
|
||||||
|
$string['currentdate'] = 'Current date';
|
||||||
$string['dateformat'] = 'Date format';
|
$string['dateformat'] = 'Date format';
|
||||||
$string['dateformat_help'] = 'This is the format of the date that will be displayed';
|
$string['dateformat_help'] = 'This is the format of the date that will be displayed';
|
||||||
$string['dateitem'] = 'Date item';
|
$string['dateitem'] = 'Date item';
|
||||||
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
||||||
$string['issueddate'] = 'Issued date';
|
$string['issueddate'] = 'Issued date';
|
||||||
$string['pluginname'] = 'Date';
|
$string['pluginname'] = 'Date';
|
||||||
|
$string['privacy:metadata'] = 'The Date plugin does not store any personal data.';
|
||||||
$string['numbersuffix_nd_as_in_second'] = 'nd';
|
$string['numbersuffix_nd_as_in_second'] = 'nd';
|
||||||
$string['numbersuffix_rd_as_in_third'] = 'rd';
|
$string['numbersuffix_rd_as_in_third'] = 'rd';
|
||||||
$string['numbersuffix_st_as_in_first'] = 'st';
|
$string['numbersuffix_st_as_in_first'] = 'st';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_date';
|
$plugin->component = 'customcertelement_date';
|
||||||
|
|
731
element/daterange/classes/element.php
Normal file
731
element/daterange/classes/element.php
Normal file
|
@ -0,0 +1,731 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains the customcert date range element.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_daterange;
|
||||||
|
|
||||||
|
use \mod_customcert\element_helper;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The customcert date range element.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class element extends \mod_customcert\element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Max recurring period in seconds.
|
||||||
|
*/
|
||||||
|
const MAX_RECURRING_PERIOD = 31556926; // 12 months.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current year placeholder string.
|
||||||
|
*/
|
||||||
|
const CURRENT_YEAR_PLACEHOLDER = '{{current_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First year in a date range placeholder string.
|
||||||
|
*/
|
||||||
|
const RANGE_FIRST_YEAR_PLACEHOLDER = '{{range_first_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last year in a date range placeholder string.
|
||||||
|
*/
|
||||||
|
const RANGE_LAST_YEAR_PLACEHOLDER = '{{range_last_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First year in a date range placeholder string.
|
||||||
|
*/
|
||||||
|
const RECUR_RANGE_FIRST_YEAR_PLACEHOLDER = '{{recurring_range_first_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last year in a date range placeholder string.
|
||||||
|
*/
|
||||||
|
const RECUR_RANGE_LAST_YEAR_PLACEHOLDER = '{{recurring_range_last_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A year in the user's date.
|
||||||
|
*/
|
||||||
|
const DATE_YEAR_PLACEHOLDER = '{{date_year}}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Issue
|
||||||
|
*/
|
||||||
|
const DATE_ISSUE = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Completion
|
||||||
|
*/
|
||||||
|
const DATE_COMPLETION = -2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Course start
|
||||||
|
*/
|
||||||
|
const DATE_COURSE_START = -3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Course end
|
||||||
|
*/
|
||||||
|
const DATE_COURSE_END = -4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Course grade date
|
||||||
|
*/
|
||||||
|
const DATE_COURSE_GRADE = -5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date - Course current date
|
||||||
|
*/
|
||||||
|
const DATE_CURRENT_DATE = -6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function renders the form elements when adding a customcert element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit form instance
|
||||||
|
*/
|
||||||
|
public function render_form_elements($mform) {
|
||||||
|
global $COURSE;
|
||||||
|
|
||||||
|
// Get the possible date options.
|
||||||
|
$dateoptions = array();
|
||||||
|
$dateoptions[self::DATE_ISSUE] = get_string('issueddate', 'customcertelement_daterange');
|
||||||
|
$dateoptions[self::DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_daterange');
|
||||||
|
$dateoptions[self::DATE_COMPLETION] = get_string('completiondate', 'customcertelement_daterange');
|
||||||
|
$dateoptions[self::DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_daterange');
|
||||||
|
$dateoptions[self::DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_daterange');
|
||||||
|
$dateoptions[self::DATE_COURSE_GRADE] = get_string('coursegradedate', 'customcertelement_daterange');
|
||||||
|
|
||||||
|
$dateoptions = $dateoptions + element_helper::get_grade_items($COURSE);
|
||||||
|
|
||||||
|
$mform->addElement('select', 'dateitem', get_string('dateitem', 'customcertelement_daterange'), $dateoptions);
|
||||||
|
$mform->addHelpButton('dateitem', 'dateitem', 'customcertelement_daterange');
|
||||||
|
|
||||||
|
parent::render_form_elements($mform);
|
||||||
|
|
||||||
|
$mform->addElement('header', 'dateranges', get_string('dateranges', 'customcertelement_daterange'));
|
||||||
|
$mform->addElement('static', 'help', '', get_string('help', 'customcertelement_daterange'));
|
||||||
|
$mform->addElement('static', 'placeholders', '', get_string('placeholders', 'customcertelement_daterange'));
|
||||||
|
|
||||||
|
$mform->addElement('text', 'fallbackstring', get_string('fallbackstring', 'customcertelement_daterange'));
|
||||||
|
$mform->addHelpButton('fallbackstring', 'fallbackstring', 'customcertelement_daterange');
|
||||||
|
$mform->setType('fallbackstring', PARAM_NOTAGS);
|
||||||
|
|
||||||
|
if (empty($this->get_decoded_data()->dateranges)) {
|
||||||
|
$repeats = 1;
|
||||||
|
} else {
|
||||||
|
$repeats = count($this->get_decoded_data()->dateranges);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ranges = [];
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement('html', '<hr>');
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement(
|
||||||
|
'date_selector',
|
||||||
|
'startdate',
|
||||||
|
get_string('start', 'customcertelement_daterange')
|
||||||
|
);
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement(
|
||||||
|
'date_selector',
|
||||||
|
'enddate',
|
||||||
|
get_string('end', 'customcertelement_daterange')
|
||||||
|
);
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement(
|
||||||
|
'checkbox',
|
||||||
|
'recurring',
|
||||||
|
get_string('recurring', 'customcertelement_daterange')
|
||||||
|
);
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement(
|
||||||
|
'text',
|
||||||
|
'datestring',
|
||||||
|
get_string('datestring', 'customcertelement_daterange'),
|
||||||
|
['class' => 'datestring']
|
||||||
|
);
|
||||||
|
|
||||||
|
$ranges[] = $mform->createElement(
|
||||||
|
'advcheckbox',
|
||||||
|
'rangedelete',
|
||||||
|
get_string('setdeleted', 'customcertelement_daterange'),
|
||||||
|
'',
|
||||||
|
[],
|
||||||
|
[0, 1]
|
||||||
|
);
|
||||||
|
|
||||||
|
$rangeoptions = array();
|
||||||
|
$rangeoptions['startdate']['type'] = PARAM_INT;
|
||||||
|
$rangeoptions['enddate']['type'] = PARAM_INT;
|
||||||
|
$rangeoptions['recurring']['type'] = PARAM_INT;
|
||||||
|
$rangeoptions['recurring']['helpbutton'] = ['recurring', 'customcertelement_daterange'];
|
||||||
|
$rangeoptions['datestring']['type'] = PARAM_NOTAGS;
|
||||||
|
$rangeoptions['rangedelete']['type'] = PARAM_BOOL;
|
||||||
|
|
||||||
|
$addstring = get_string('addrange', 'customcertelement_daterange');
|
||||||
|
$this->get_edit_element_form()->repeat_elements($ranges, $repeats, $rangeoptions, 'repeats', 'add', 1, $addstring, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function to build consistent form element name.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $num
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function build_element_name($name, $num) {
|
||||||
|
return $name . '[' . $num . ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get decoded data stored in DB.
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
protected function get_decoded_data() {
|
||||||
|
return json_decode($this->get_data());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the data on the form when editing an element.
|
||||||
|
*
|
||||||
|
* @param \MoodleQuickForm $mform the edit form instance
|
||||||
|
*/
|
||||||
|
public function definition_after_data($mform) {
|
||||||
|
if (!empty($this->get_data()) && !$mform->isSubmitted()) {
|
||||||
|
$element = $mform->getElement('dateitem');
|
||||||
|
$element->setValue($this->get_decoded_data()->dateitem);
|
||||||
|
|
||||||
|
$element = $mform->getElement('fallbackstring');
|
||||||
|
$element->setValue($this->get_decoded_data()->fallbackstring);
|
||||||
|
|
||||||
|
foreach ($this->get_decoded_data()->dateranges as $key => $range) {
|
||||||
|
$mform->setDefault($this->build_element_name('startdate', $key), $range->startdate);
|
||||||
|
$mform->setDefault($this->build_element_name('enddate', $key), $range->enddate);
|
||||||
|
$mform->setDefault($this->build_element_name('datestring', $key), $range->datestring);
|
||||||
|
$mform->setDefault($this->build_element_name('recurring', $key), $range->recurring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::definition_after_data($mform);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs validation on the element values.
|
||||||
|
*
|
||||||
|
* @param array $data the submitted data
|
||||||
|
* @param array $files the submitted files
|
||||||
|
* @return array the validation errors
|
||||||
|
*/
|
||||||
|
public function validate_form_elements($data, $files) {
|
||||||
|
$errors = parent::validate_form_elements($data, $files);
|
||||||
|
|
||||||
|
// Check if at least one range is set.
|
||||||
|
$error = get_string('error:atleastone', 'customcertelement_daterange');
|
||||||
|
|
||||||
|
for ($i = 0; $i < $data['repeats']; $i++) {
|
||||||
|
if (empty($data['rangedelete'][$i])) {
|
||||||
|
$error = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($error)) {
|
||||||
|
$errors['help'] = $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that datestring is set dataranges what aren't need to be deleted.
|
||||||
|
for ($i = 0; $i < $data['repeats']; $i++) {
|
||||||
|
// Skip elements that needs to be deleted.
|
||||||
|
if (!empty($data['rangedelete'][$i])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data['datestring'][$i])) {
|
||||||
|
$name = $this->build_element_name('datestring', $i);
|
||||||
|
$errors[$name] = get_string('error:datestring', 'customcertelement_daterange');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that end date is correctly set.
|
||||||
|
if ( $data['startdate'][$i] >= $data['enddate'][$i] ) {
|
||||||
|
$errors[$this->build_element_name('enddate', $i)] = get_string('error:enddate', 'customcertelement_daterange');
|
||||||
|
}
|
||||||
|
|
||||||
|
$rangeperiod = $data['enddate'][$i] - $data['startdate'][$i];
|
||||||
|
|
||||||
|
// Check that recurring dateranges are not longer than 12 months.
|
||||||
|
if (!empty($data['recurring'][$i]) && $rangeperiod >= self::MAX_RECURRING_PERIOD ) {
|
||||||
|
$errors[$this->build_element_name('enddate', $i)] = get_string('error:recurring', 'customcertelement_daterange');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will handle how form data will be saved into the data column in the
|
||||||
|
* customcert_elements table.
|
||||||
|
*
|
||||||
|
* @param \stdClass $data the form data
|
||||||
|
* @return string the json encoded array
|
||||||
|
*/
|
||||||
|
public function save_unique_data($data) {
|
||||||
|
$arrtostore = array(
|
||||||
|
'dateitem' => $data->dateitem,
|
||||||
|
'fallbackstring' => $data->fallbackstring,
|
||||||
|
'dateranges' => [],
|
||||||
|
);
|
||||||
|
|
||||||
|
for ($i = 0; $i < $data->repeats; $i++) {
|
||||||
|
if (empty($data->rangedelete[$i])) {
|
||||||
|
$arrtostore['dateranges'][] = [
|
||||||
|
'startdate' => $data->startdate[$i],
|
||||||
|
'enddate' => $data->enddate[$i],
|
||||||
|
'datestring' => $data->datestring[$i],
|
||||||
|
'recurring' => !empty($data->recurring[$i]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode these variables before saving into the DB.
|
||||||
|
return json_encode($arrtostore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles rendering the element on the pdf.
|
||||||
|
*
|
||||||
|
* @param \pdf $pdf the pdf object
|
||||||
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param \stdClass $user the user we are rendering this for
|
||||||
|
*/
|
||||||
|
public function render($pdf, $preview, $user) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// If there is no element data, we have nothing to display.
|
||||||
|
if (empty($this->get_data())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$courseid = element_helper::get_courseid($this->id);
|
||||||
|
$dateitem = $this->get_decoded_data()->dateitem;
|
||||||
|
|
||||||
|
// If we are previewing this certificate then just show a demonstration date.
|
||||||
|
if ($preview) {
|
||||||
|
$date = time();
|
||||||
|
} else {
|
||||||
|
// Get the page.
|
||||||
|
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||||
|
// Get the customcert this page belongs to.
|
||||||
|
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||||
|
// Now we can get the issue for this user.
|
||||||
|
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id),
|
||||||
|
'*', MUST_EXIST);
|
||||||
|
|
||||||
|
switch ($dateitem) {
|
||||||
|
case self::DATE_ISSUE:
|
||||||
|
$date = $issue->timecreated;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DATE_CURRENT_DATE:
|
||||||
|
$date = time();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DATE_COMPLETION:
|
||||||
|
// Get the last completion date.
|
||||||
|
$sql = "SELECT MAX(c.timecompleted) as timecompleted
|
||||||
|
FROM {course_completions} c
|
||||||
|
WHERE c.userid = :userid
|
||||||
|
AND c.course = :courseid";
|
||||||
|
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) {
|
||||||
|
if (!empty($timecompleted->timecompleted)) {
|
||||||
|
$date = $timecompleted->timecompleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DATE_COURSE_START:
|
||||||
|
$date = $DB->get_field('course', 'startdate', array('id' => $courseid));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DATE_COURSE_END:
|
||||||
|
$date = $DB->get_field('course', 'enddate', array('id' => $courseid));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case self::DATE_COURSE_GRADE:
|
||||||
|
$grade = element_helper::get_course_grade_info(
|
||||||
|
$courseid,
|
||||||
|
GRADE_DISPLAY_TYPE_DEFAULT, $user->id
|
||||||
|
);
|
||||||
|
if ($grade && !empty($grade->get_dategraded())) {
|
||||||
|
$date = $grade->get_dategraded();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (strpos($dateitem, 'gradeitem:') === 0) {
|
||||||
|
$gradeitemid = substr($dateitem, 10);
|
||||||
|
$grade = element_helper::get_grade_item_info(
|
||||||
|
$gradeitemid,
|
||||||
|
$dateitem,
|
||||||
|
$user->id
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$grade = element_helper::get_mod_grade_info(
|
||||||
|
$dateitem,
|
||||||
|
GRADE_DISPLAY_TYPE_DEFAULT,
|
||||||
|
$user->id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($grade && !empty($grade->get_dategraded())) {
|
||||||
|
$date = $grade->get_dategraded();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that a date has been set.
|
||||||
|
if (!empty($date)) {
|
||||||
|
element_helper::render_content($pdf, $this, $this->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get daterange string.
|
||||||
|
*
|
||||||
|
* @param int $date Unix stamp date.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_daterange_string($date) {
|
||||||
|
$matchedrange = null;
|
||||||
|
$outputstring = '';
|
||||||
|
$formatdata = [];
|
||||||
|
$formatdata['date'] = $date;
|
||||||
|
|
||||||
|
foreach ($this->get_decoded_data()->dateranges as $key => $range) {
|
||||||
|
if ($this->is_recurring_range($range)) {
|
||||||
|
if ($matchedrange = $this->get_matched_recurring_range($date, $range)) {
|
||||||
|
$outputstring = $matchedrange->datestring;
|
||||||
|
$formatdata['range'] = $range;
|
||||||
|
$formatdata['recurringrange'] = $matchedrange;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($this->is_date_in_range($date, $range)) {
|
||||||
|
$outputstring = $range->datestring;
|
||||||
|
$formatdata['range'] = $range;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($outputstring) && !empty($this->get_decoded_data()->fallbackstring)) {
|
||||||
|
$outputstring = $this->get_decoded_data()->fallbackstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->format_date_string($outputstring, $formatdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not a range is recurring.
|
||||||
|
*
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function is_recurring_range(\stdClass $range) {
|
||||||
|
return !empty($range->recurring);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the provided date is in the date range.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function is_date_in_range($date, \stdClass $range) {
|
||||||
|
return ($date >= $range->startdate && $date <= $range->enddate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if provided date is in the recurring date range.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function is_date_in_recurring_range($date, \stdClass $range) {
|
||||||
|
$intdate = $this->build_number_from_date($date);
|
||||||
|
$intstart = $this->build_number_from_date($range->startdate);
|
||||||
|
$intend = $this->build_number_from_date($range->enddate);
|
||||||
|
|
||||||
|
if (!$this->has_turn_of_the_year($range)) {
|
||||||
|
if ($intdate >= $intstart && $intdate <= $intend) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($intdate >= $intstart && $intdate >= $intend) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($intdate <= $intstart && $intdate <= $intend) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if provided recurring range has a turn of the year.
|
||||||
|
*
|
||||||
|
* @param \stdClass $reccurringrange Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function has_turn_of_the_year(\stdClass $reccurringrange) {
|
||||||
|
return date('Y', $reccurringrange->startdate) != date('Y', $reccurringrange->enddate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if provided date is in the start year of the recurring range with a turn of the year.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function in_start_year($date, \stdClass $range) {
|
||||||
|
$intdate = $this->build_number_from_date($date);
|
||||||
|
$intstart = $this->build_number_from_date($range->startdate);
|
||||||
|
$intend = $this->build_number_from_date($range->enddate);
|
||||||
|
|
||||||
|
return $intdate >= $intstart && $intdate >= $intend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if provided date is in the end year of the recurring range with a turn of the year.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function in_end_year($date, \stdClass $range) {
|
||||||
|
$intdate = $this->build_number_from_date($date);
|
||||||
|
$intstart = $this->build_number_from_date($range->startdate);
|
||||||
|
$intend = $this->build_number_from_date($range->enddate);
|
||||||
|
|
||||||
|
return $intdate <= $intstart && $intdate <= $intend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return matched recurring date range.
|
||||||
|
*
|
||||||
|
* As recurring date ranges do not depend on the year,
|
||||||
|
* we will use a date's year to build a new matched recurring date range with
|
||||||
|
* start year and end year. This is required to replace placeholders like range_first_year and range_last_year.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
* @param \stdClass $range Range object.
|
||||||
|
*
|
||||||
|
* @return \stdClass || null
|
||||||
|
*/
|
||||||
|
protected function get_matched_recurring_range($date, \stdClass $range) {
|
||||||
|
if (!$this->is_date_in_recurring_range($date, $range)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$matchedrage = clone $range;
|
||||||
|
|
||||||
|
if ($this->has_turn_of_the_year($matchedrage)) {
|
||||||
|
|
||||||
|
if ($this->in_start_year($date, $matchedrage)) {
|
||||||
|
$startyear = date('Y', $date);
|
||||||
|
$endyear = $startyear + 1;
|
||||||
|
$matchedrage->startdate = strtotime(date('d.m.', $matchedrage->startdate) . $startyear);
|
||||||
|
$matchedrage->enddate = strtotime(date('d.m.', $matchedrage->enddate) . $endyear);
|
||||||
|
|
||||||
|
return $matchedrage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->in_end_year($date, $matchedrage)) {
|
||||||
|
$endyear = date('Y', $date);
|
||||||
|
$startyear = $endyear - 1;
|
||||||
|
$matchedrage->startdate = strtotime(date('d.m.', $matchedrage->startdate) . $startyear);
|
||||||
|
$matchedrage->enddate = strtotime(date('d.m.', $matchedrage->enddate) . $endyear);
|
||||||
|
|
||||||
|
return $matchedrage;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$matchedrage->startdate = strtotime(date('d.m.', $matchedrage->startdate) . date('Y', $date));
|
||||||
|
$matchedrage->enddate = strtotime(date('d.m.', $matchedrage->enddate) . date('Y', $date));
|
||||||
|
|
||||||
|
return $matchedrage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build number representation of the provided date.
|
||||||
|
*
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function build_number_from_date($date) {
|
||||||
|
return (int)date('md', $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format date string based on different types of placeholders.
|
||||||
|
*
|
||||||
|
* @param string $datestring The date string
|
||||||
|
* @param array $formatdata A list of format data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function format_date_string($datestring, array $formatdata) {
|
||||||
|
foreach ($this->get_placeholders() as $search => $replace) {
|
||||||
|
$datestring = str_replace($search, $replace, $datestring);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($formatdata['date'])) {
|
||||||
|
foreach ($this->get_date_placeholders($formatdata['date']) as $search => $replace) {
|
||||||
|
$datestring = str_replace($search, $replace, $datestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($formatdata['range'])) {
|
||||||
|
foreach ($this->get_range_placeholders($formatdata['range']) as $search => $replace) {
|
||||||
|
$datestring = str_replace($search, $replace, $datestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($formatdata['recurringrange'])) {
|
||||||
|
foreach ($this->get_recurring_range_placeholders($formatdata['recurringrange']) as $search => $replace) {
|
||||||
|
$datestring = str_replace($search, $replace, $datestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $datestring;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of placeholders to replace in date string as search => $replace pairs.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_placeholders() {
|
||||||
|
return [
|
||||||
|
self::CURRENT_YEAR_PLACEHOLDER => date('Y', time()),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of user's date related placeholders to replace in date string as search => $replace pairs.
|
||||||
|
|
||||||
|
* @param int $date Unix timestamp date to check.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_date_placeholders($date) {
|
||||||
|
return [
|
||||||
|
self::DATE_YEAR_PLACEHOLDER => date('Y', $date),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of range related placeholders to replace in date string as search => $replace pairs.
|
||||||
|
*
|
||||||
|
* @param \stdClass $range
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_range_placeholders(\stdClass $range) {
|
||||||
|
return [
|
||||||
|
self::RANGE_FIRST_YEAR_PLACEHOLDER => date('Y', $range->startdate),
|
||||||
|
self::RANGE_LAST_YEAR_PLACEHOLDER => date('Y', $range->enddate),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of recurring range s placeholders to replace in date string as search => $replace pairs.
|
||||||
|
*
|
||||||
|
* @param \stdClass $range
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_recurring_range_placeholders(\stdClass $range) {
|
||||||
|
return [
|
||||||
|
self::RECUR_RANGE_FIRST_YEAR_PLACEHOLDER => date('Y', $range->startdate),
|
||||||
|
self::RECUR_RANGE_LAST_YEAR_PLACEHOLDER => date('Y', $range->enddate),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the element in html.
|
||||||
|
*
|
||||||
|
* This function is used to render the element when we are using the
|
||||||
|
* drag and drop interface to position it.
|
||||||
|
*
|
||||||
|
* @return string the html
|
||||||
|
*/
|
||||||
|
public function render_html() {
|
||||||
|
// If there is no element data, we have nothing to display.
|
||||||
|
if (empty($this->get_data())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return element_helper::render_html_content($this, get_string('preview', 'customcertelement_daterange', $this->get_name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is responsible for handling the restoration process of the element.
|
||||||
|
*
|
||||||
|
* We will want to update the course module the date element is pointing to as it will
|
||||||
|
* have changed in the course restore.
|
||||||
|
*
|
||||||
|
* @param \restore_customcert_activity_task $restore
|
||||||
|
*/
|
||||||
|
public function after_restore($restore) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = $this->get_decoded_data();
|
||||||
|
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $data->dateitem)) {
|
||||||
|
$data->dateitem = $newitem->newitemid;
|
||||||
|
$DB->set_field('customcert_elements', 'data', $this->save_unique_data($data), array('id' => $this->get_id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
46
element/daterange/classes/privacy/provider.php
Normal file
46
element/daterange/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_daterange.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_daterange\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_daterange implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
53
element/daterange/lang/en/customcertelement_daterange.php
Normal file
53
element/daterange/lang/en/customcertelement_daterange.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strings for component 'customcertelement_daterange', language 'en'.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
$string['addrange'] = 'Add another range';
|
||||||
|
$string['completiondate'] = 'Completion date';
|
||||||
|
$string['courseenddate'] = 'Course end date';
|
||||||
|
$string['coursegradedate'] = 'Course grade date';
|
||||||
|
$string['coursestartdate'] = 'Course start date';
|
||||||
|
$string['currentdate'] = 'Current date';
|
||||||
|
$string['dateitem'] = 'Date item';
|
||||||
|
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
||||||
|
$string['dateranges'] = 'Date ranges';
|
||||||
|
$string['datestring'] = 'String';
|
||||||
|
$string['end'] = 'End';
|
||||||
|
$string['error:atleastone'] = 'You must have at least one date range configured';
|
||||||
|
$string['error:datestring'] = 'You must provide string representation for the date range';
|
||||||
|
$string['error:enddate'] = 'End date must occur after the start date';
|
||||||
|
$string['error:recurring'] = 'Recurring range must not be longer than 12 months';
|
||||||
|
$string['fallbackstring'] = 'Fallback string';
|
||||||
|
$string['fallbackstring_help'] = 'This string will be displayed if no date range applies to a date. If the fallback string is not set, then there will be no output at all.';
|
||||||
|
$string['help'] = 'Configure a string representation for your date ranges.<br /><br />If your ranges overlap the first matched date range will be applied.';
|
||||||
|
$string['issueddate'] = 'Issued date';
|
||||||
|
$string['placeholders'] = 'The following placeholders can be used in the string representation or fallback string. <br/><br /> {{range_first_year}} - first year of the matched range,<br/> {{range_last_year}} - last year of the matched range,<br/> {{recurring_range_first_year}} - first year of the matched recurring period,<br/> {{recurring_range_last_year}} - last year of the matched recurring period,<br/> {{current_year}} - the current year,<br/> {{date_year}} - a year of the users\'s date.';
|
||||||
|
$string['pluginname'] = 'Date range';
|
||||||
|
$string['preview'] = 'Preview {$a}';
|
||||||
|
$string['privacy:metadata'] = 'The Date range plugin does not store any personal data.';
|
||||||
|
$string['recurring'] = 'Recurring';
|
||||||
|
$string['recurring_help'] = 'If you mark a date range as recurring then the configured year will not be considered.';
|
||||||
|
$string['setdeleted'] = 'Delete';
|
||||||
|
$string['start'] = 'Start';
|
248
element/daterange/tests/element_test.php
Normal file
248
element/daterange/tests/element_test.php
Normal file
|
@ -0,0 +1,248 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test datarange element.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
require_once($CFG->dirroot . '/mod/customcert/element/daterange/tests/fixtures/fake_datarange_element.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test datarange element.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class customcertelement_daterange_element_test extends advanced_testcase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to build element data.
|
||||||
|
*
|
||||||
|
* @param stdClass $data Element data.
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
protected function build_element_data(stdClass $data) {
|
||||||
|
return (object) [
|
||||||
|
'id' => 1,
|
||||||
|
'pageid' => 1,
|
||||||
|
'name' => 'Test',
|
||||||
|
'data' => json_encode($data),
|
||||||
|
'font' => 'Font',
|
||||||
|
'fontsize' => 1,
|
||||||
|
'colour' => '#EEE',
|
||||||
|
'posx' => 0,
|
||||||
|
'posy' => 0,
|
||||||
|
'width' => 100,
|
||||||
|
'refpoint' => 1
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to build datarange data.
|
||||||
|
*
|
||||||
|
* @param array $dataranges A list of dataranges.
|
||||||
|
* @param string $fallbackstring Fall back string.
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
protected function build_datarange_data(array $dataranges, $fallbackstring = '') {
|
||||||
|
return (object) [
|
||||||
|
'dateitem' => 1,
|
||||||
|
'fallbackstring' => $fallbackstring,
|
||||||
|
'numranges' => count($dataranges),
|
||||||
|
'dateranges' => $dataranges,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function to get datarange element for testing.
|
||||||
|
*
|
||||||
|
* @param array $dataranges A list of dataranges.
|
||||||
|
* @param string $fallbackstring Fall back strin
|
||||||
|
*
|
||||||
|
* @return \fake_datarange_element
|
||||||
|
*/
|
||||||
|
protected function get_datarange_element(array $dataranges, $fallbackstring = '') {
|
||||||
|
$datarangedata = $this->build_datarange_data($dataranges, $fallbackstring);
|
||||||
|
$elementdata = $this->build_element_data($datarangedata);
|
||||||
|
|
||||||
|
return new fake_datarange_element($elementdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for test_get_daterange_string_for_recurring_ranges.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_test_get_daterange_string_for_recurring_ranges_data_provider() {
|
||||||
|
return [
|
||||||
|
['1.11.2016', 'WS 2016/2017'],
|
||||||
|
['1.11.2017', 'WS 2017/2018'],
|
||||||
|
['1.11.2018', 'WS 2018/2019'],
|
||||||
|
['1.11.2019', 'WS 2019/2020'],
|
||||||
|
['1.02.2017', 'WS 2016/2017'],
|
||||||
|
['1.02.2018', 'WS 2017/2018'],
|
||||||
|
['1.02.2019', 'WS 2018/2019'],
|
||||||
|
['1.02.2020', 'WS 2019/2020'],
|
||||||
|
['1.05.2016', 'SS 2016'],
|
||||||
|
['1.05.2017', 'SS 2017'],
|
||||||
|
['1.05.2018', 'SS 2018'],
|
||||||
|
['1.05.2019', 'SS 2019'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get correct strings for recurring ranges.
|
||||||
|
*
|
||||||
|
* @dataProvider get_test_get_daterange_string_for_recurring_ranges_data_provider
|
||||||
|
*
|
||||||
|
* @param string $date Date to test.
|
||||||
|
* @param string $expected Expected result.
|
||||||
|
*/
|
||||||
|
public function test_get_daterange_string_for_recurring_ranges($date, $expected) {
|
||||||
|
$dateranges = [
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.04.2017'),
|
||||||
|
'enddate' => strtotime('30.09.2017'),
|
||||||
|
'datestring' => 'SS {{date_year}}',
|
||||||
|
'recurring' => true,
|
||||||
|
],
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.10.2017'),
|
||||||
|
'enddate' => strtotime('31.03.2018'),
|
||||||
|
'datestring' => 'WS {{recurring_range_first_year}}/{{recurring_range_last_year}}',
|
||||||
|
'recurring' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$element = $this->get_datarange_element($dateranges);
|
||||||
|
$date = strtotime($date);
|
||||||
|
$this->assertEquals($expected, $element->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that first found element matched.
|
||||||
|
*/
|
||||||
|
public function test_that_first_matched_range_applied_first() {
|
||||||
|
$dateranges = [
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.04.2017'),
|
||||||
|
'enddate' => strtotime('30.09.2017'),
|
||||||
|
'datestring' => 'First range',
|
||||||
|
'recurring' => false,
|
||||||
|
],
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.05.2017'),
|
||||||
|
'enddate' => strtotime('01.07.2018'),
|
||||||
|
'datestring' => 'Second range',
|
||||||
|
'recurring' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$element = $this->get_datarange_element($dateranges);
|
||||||
|
$date = strtotime('1.06.2017');
|
||||||
|
$this->assertEquals('First range', $element->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that placeholders correctly applied to matched range and fall back string.
|
||||||
|
*/
|
||||||
|
public function test_placeholders_and_fall_back_string() {
|
||||||
|
$dateranges = [
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.04.2017'),
|
||||||
|
'enddate' => strtotime('30.09.2018'),
|
||||||
|
'datestring' => '{{current_year}} - {{range_first_year}} - {{range_last_year}} - {{date_year}}',
|
||||||
|
'recurring' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$fallbackstring = '{{current_year}} - {{range_first_year}} - {{range_last_year}} - {{date_year}}';
|
||||||
|
$element = $this->get_datarange_element($dateranges, $fallbackstring);
|
||||||
|
|
||||||
|
$date = strtotime('1.01.2000');
|
||||||
|
$expected = date('Y', time()) . ' - {{range_first_year}} - {{range_last_year}} - 2000';
|
||||||
|
$this->assertEquals($expected, $element->get_daterange_string($date));
|
||||||
|
|
||||||
|
$date = strtotime('1.07.2017');
|
||||||
|
$expected = date('Y', time()) . ' - 2017 - 2018 - 2017';
|
||||||
|
$this->assertEquals($expected, $element->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that nothing will be displayed if not matched and empty fall back string.
|
||||||
|
*/
|
||||||
|
public function test_nothing_will_be_displayed_if_empty_fallback_string() {
|
||||||
|
$dateranges = [
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.04.2017'),
|
||||||
|
'enddate' => strtotime('30.09.2018'),
|
||||||
|
'datestring' => '{{current_year}} - {{range_first_year}} - {{range_last_year}} - {{date_year}}',
|
||||||
|
'recurring' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$fallbackstring = '';
|
||||||
|
$element = $this->get_datarange_element($dateranges, $fallbackstring);
|
||||||
|
|
||||||
|
$date = strtotime('1.07.2011');
|
||||||
|
$this->assertEquals($fallbackstring, $element->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that display recurring_range_first_year and recurring_range_last_year placeholders.
|
||||||
|
*/
|
||||||
|
public function test_recurring_range_first_year_and_recurring_range_last_year_placeholders() {
|
||||||
|
$datestring = '{{range_first_year}}-{{range_last_year}}-{{recurring_range_first_year}}-{{recurring_range_last_year}}';
|
||||||
|
$dateranges = [
|
||||||
|
(object) [
|
||||||
|
'startdate' => strtotime('01.04.2017'),
|
||||||
|
'enddate' => strtotime('30.09.2017'),
|
||||||
|
'datestring' => $datestring,
|
||||||
|
'recurring' => true,
|
||||||
|
],
|
||||||
|
(object)[
|
||||||
|
'startdate' => strtotime('01.10.2017'),
|
||||||
|
'enddate' => strtotime('31.03.2018'),
|
||||||
|
'datestring' => $datestring,
|
||||||
|
'recurring' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$element = $this->get_datarange_element($dateranges);
|
||||||
|
|
||||||
|
$date = strtotime('1.05.2020');
|
||||||
|
$this->assertEquals('2017-2017-2020-2020', $element->get_daterange_string($date));
|
||||||
|
|
||||||
|
$date = strtotime('1.05.2024');
|
||||||
|
$this->assertEquals('2017-2017-2024-2024', $element->get_daterange_string($date));
|
||||||
|
|
||||||
|
$date = strtotime('1.02.2020');
|
||||||
|
$this->assertEquals('2017-2018-2019-2020', $element->get_daterange_string($date));
|
||||||
|
|
||||||
|
$date = strtotime('1.02.2024');
|
||||||
|
$this->assertEquals('2017-2018-2023-2024', $element->get_daterange_string($date));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
element/daterange/tests/fixtures/fake_datarange_element.php
vendored
Normal file
47
element/daterange/tests/fixtures/fake_datarange_element.php
vendored
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake datarange element for testing.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake datarange element for testing.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class fake_datarange_element extends \customcertelement_daterange\element {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override protected method for testing.
|
||||||
|
*
|
||||||
|
* @param int $date
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_daterange_string($date) {
|
||||||
|
$result = parent::get_daterange_string($date);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
29
element/daterange/version.php
Normal file
29
element/daterange/version.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains the version information for the date plugin.
|
||||||
|
*
|
||||||
|
* @package customcertelement_daterange
|
||||||
|
* @copyright 2018 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
|
$plugin->component = 'customcertelement_daterange';
|
|
@ -60,7 +60,7 @@ class element extends \customcertelement_image\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
||||||
|
@ -195,12 +195,11 @@ class element extends \customcertelement_image\element {
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If there is no file, we have nothing to display.
|
// If there is no file, we have nothing to display.
|
||||||
if (empty($imageinfo->filename)) {
|
if (empty($imageinfo->filename)) {
|
||||||
|
@ -241,7 +240,7 @@ class element extends \customcertelement_image\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
global $COURSE, $SITE;
|
global $COURSE, $SITE;
|
||||||
|
@ -253,9 +252,8 @@ class element extends \customcertelement_image\element {
|
||||||
$context = \context_course::instance($COURSE->id);
|
$context = \context_course::instance($COURSE->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
$imageinfo = json_decode($this->get_data());
|
||||||
$imageinfo = json_decode($data);
|
|
||||||
|
|
||||||
$element = $mform->getElement('signaturename');
|
$element = $mform->getElement('signaturename');
|
||||||
$element->setValue($imageinfo->signaturename);
|
$element->setValue($imageinfo->signaturename);
|
||||||
|
|
46
element/digitalsignature/classes/privacy/provider.php
Normal file
46
element/digitalsignature/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_digitalsignature.
|
||||||
|
*
|
||||||
|
* @package customcertelement_digitalsignature
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_digitalsignature\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_digitalsignature implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@
|
||||||
$string['digitalsignature'] = 'Digital signature';
|
$string['digitalsignature'] = 'Digital signature';
|
||||||
$string['nosignature'] = 'No signature';
|
$string['nosignature'] = 'No signature';
|
||||||
$string['pluginname'] = 'Digital signature';
|
$string['pluginname'] = 'Digital signature';
|
||||||
|
$string['privacy:metadata'] = 'The Digital signature plugin does not store any personal data.';
|
||||||
$string['signaturename'] = 'Signature name';
|
$string['signaturename'] = 'Signature name';
|
||||||
$string['signaturepassword'] = 'Signature password';
|
$string['signaturepassword'] = 'Signature password';
|
||||||
$string['signaturelocation'] = 'Signature location';
|
$string['signaturelocation'] = 'Signature location';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052300; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_digitalsignature';
|
$plugin->component = 'customcertelement_digitalsignature';
|
||||||
|
|
|
@ -43,7 +43,7 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
global $COURSE;
|
global $COURSE;
|
||||||
|
@ -93,28 +93,21 @@ class element extends \mod_customcert\element {
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$gradeinfo = json_decode($data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
$gradeitem = $gradeinfo->gradeitem;
|
$gradeitem = $gradeinfo->gradeitem;
|
||||||
$gradeformat = $gradeinfo->gradeformat;
|
$gradeformat = $gradeinfo->gradeformat;
|
||||||
|
|
||||||
// If we are previewing this certificate then just show a demonstration grade.
|
// If we are previewing this certificate then just show a demonstration grade.
|
||||||
if ($preview) {
|
if ($preview) {
|
||||||
// Define how many decimals to display.
|
|
||||||
$decimals = 2;
|
|
||||||
if ($gradeinfo->gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
|
||||||
$decimals = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$courseitem = \grade_item::fetch_course_item($courseid);
|
$courseitem = \grade_item::fetch_course_item($courseid);
|
||||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, $decimals);
|
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat);;
|
||||||
} else {
|
} else {
|
||||||
if ($gradeitem == CUSTOMCERT_GRADE_COURSE) {
|
if ($gradeitem == CUSTOMCERT_GRADE_COURSE) {
|
||||||
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
||||||
|
@ -157,23 +150,16 @@ class element extends \mod_customcert\element {
|
||||||
global $COURSE;
|
global $COURSE;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
return;
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
// Decode the information stored in the database.
|
||||||
$gradeinfo = json_decode($data);
|
$gradeinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
||||||
|
|
||||||
// Define how many decimals to display.
|
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat);
|
||||||
$decimals = 2;
|
|
||||||
if ($gradeinfo->gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
|
||||||
$decimals = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, $decimals);
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $grade);
|
return \mod_customcert\element_helper::render_html_content($this, $grade);
|
||||||
}
|
}
|
||||||
|
@ -181,13 +167,12 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
// Set the item and format for this element.
|
// Set the item and format for this element.
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
$gradeinfo = json_decode($this->get_data());
|
||||||
$gradeinfo = json_decode($data);
|
|
||||||
|
|
||||||
$element = $mform->getElement('gradeitem');
|
$element = $mform->getElement('gradeitem');
|
||||||
$element->setValue($gradeinfo->gradeitem);
|
$element->setValue($gradeinfo->gradeitem);
|
||||||
|
|
46
element/grade/classes/privacy/provider.php
Normal file
46
element/grade/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_grade.
|
||||||
|
*
|
||||||
|
* @package customcertelement_grade
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_grade\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_grade implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,3 +33,4 @@ $string['gradepoints'] = 'Points';
|
||||||
$string['gradeletter'] = 'Letter';
|
$string['gradeletter'] = 'Letter';
|
||||||
$string['pluginname'] = 'Grade';
|
$string['pluginname'] = 'Grade';
|
||||||
$string['previewgrade'] = 'Preview grade';
|
$string['previewgrade'] = 'Preview grade';
|
||||||
|
$string['privacy:metadata'] = 'The Grade plugin does not store any personal data.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_grade';
|
$plugin->component = 'customcertelement_grade';
|
||||||
|
|
|
@ -38,7 +38,7 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
global $COURSE;
|
global $COURSE;
|
||||||
|
@ -73,19 +73,9 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Check that the grade item is not empty.
|
// Check that the grade item is not empty.
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_grade_item_name());
|
||||||
// Get the course module information.
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $data), '*', MUST_EXIST);
|
|
||||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Get the name of the item.
|
|
||||||
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST);
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $itemname);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,19 +88,9 @@ class element extends \mod_customcert\element {
|
||||||
* @return string the html
|
* @return string the html
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Check that the grade item is not empty.
|
// Check that the grade item is not empty.
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
return \mod_customcert\element_helper::render_html_content($this, $this->get_grade_item_name());
|
||||||
// Get the course module information.
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $data), '*', MUST_EXIST);
|
|
||||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Get the name of the item.
|
|
||||||
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST);
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $itemname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
@ -119,14 +99,51 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
|
||||||
$element = $mform->getElement('gradeitem');
|
$element = $mform->getElement('gradeitem');
|
||||||
$element->setValue($data);
|
$element->setValue($this->get_data());
|
||||||
}
|
}
|
||||||
parent::definition_after_data($mform);
|
parent::definition_after_data($mform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that returns the grade item name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_grade_item_name() : string {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$gradeitem = $this->get_data();
|
||||||
|
|
||||||
|
if (strpos($gradeitem, 'gradeitem:') === 0) {
|
||||||
|
$gradeitemid = substr($gradeitem, 10);
|
||||||
|
$gradeitem = \grade_item::fetch(['id' => $gradeitemid]);
|
||||||
|
|
||||||
|
return $gradeitem->get_name();
|
||||||
|
} else {
|
||||||
|
if (!$cm = $DB->get_record('course_modules', array('id' => $gradeitem))) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$module = $DB->get_record('modules', array('id' => $cm->module))) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'itemtype' => 'mod',
|
||||||
|
'itemmodule' => $module->name,
|
||||||
|
'iteminstance' => $cm->instance,
|
||||||
|
'courseid' => $cm->course,
|
||||||
|
'itemnumber' => 0
|
||||||
|
];
|
||||||
|
|
||||||
|
$gradeitem = \grade_item::fetch($params);
|
||||||
|
|
||||||
|
return $gradeitem->get_name();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
46
element/gradeitemname/classes/privacy/provider.php
Normal file
46
element/gradeitemname/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_gradeitemname.
|
||||||
|
*
|
||||||
|
* @package customcertelement_gradeitemname
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_gradeitemname\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_gradeitemname implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,3 +25,4 @@
|
||||||
$string['gradeitem'] = 'Grade item';
|
$string['gradeitem'] = 'Grade item';
|
||||||
$string['gradeitem_help'] = 'The name of the selected item will be displayed on the PDF.';
|
$string['gradeitem_help'] = 'The name of the selected item will be displayed on the PDF.';
|
||||||
$string['pluginname'] = 'Grade item name';
|
$string['pluginname'] = 'Grade item name';
|
||||||
|
$string['privacy:metadata'] = 'The Grade item name plugin does not store any personal data.';
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2016052302; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2021051700; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2016052300; // Requires this Moodle version (3.1).
|
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
|
||||||
$plugin->component = 'customcertelement_gradeitemname';
|
$plugin->component = 'customcertelement_gradeitemname';
|
||||||
|
|
|
@ -60,7 +60,7 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* This function renders the form elements when adding a customcert element.
|
* This function renders the form elements when adding a customcert element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function render_form_elements($mform) {
|
public function render_form_elements($mform) {
|
||||||
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
||||||
|
@ -75,6 +75,24 @@ class element extends \mod_customcert\element {
|
||||||
$mform->setDefault('height', 0);
|
$mform->setDefault('height', 0);
|
||||||
$mform->addHelpButton('height', 'height', 'customcertelement_image');
|
$mform->addHelpButton('height', 'height', 'customcertelement_image');
|
||||||
|
|
||||||
|
$alphachannelvalues = [
|
||||||
|
'0' => 0,
|
||||||
|
'0.1' => 0.1,
|
||||||
|
'0.2' => 0.2,
|
||||||
|
'0.3' => 0.3,
|
||||||
|
'0.4' => 0.4,
|
||||||
|
'0.5' => 0.5,
|
||||||
|
'0.6' => 0.6,
|
||||||
|
'0.7' => 0.7,
|
||||||
|
'0.8' => 0.8,
|
||||||
|
'0.9' => 0.9,
|
||||||
|
'1' => 1
|
||||||
|
];
|
||||||
|
$mform->addElement('select', 'alphachannel', get_string('alphachannel', 'customcertelement_image'), $alphachannelvalues);
|
||||||
|
$mform->setType('alphachannel', PARAM_FLOAT);
|
||||||
|
$mform->setDefault('alphachannel', 1);
|
||||||
|
$mform->addHelpButton('alphachannel', 'alphachannel', 'customcertelement_image');
|
||||||
|
|
||||||
if (get_config('customcert', 'showposxy')) {
|
if (get_config('customcert', 'showposxy')) {
|
||||||
\mod_customcert\element_helper::render_form_element_position($mform);
|
\mod_customcert\element_helper::render_form_element_position($mform);
|
||||||
}
|
}
|
||||||
|
@ -148,6 +166,10 @@ class element extends \mod_customcert\element {
|
||||||
'height' => !empty($data->height) ? (int) $data->height : 0
|
'height' => !empty($data->height) ? (int) $data->height : 0
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isset($data->alphachannel)) {
|
||||||
|
$arrtostore['alphachannel'] = (float) $data->alphachannel;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($data->fileid)) {
|
if (!empty($data->fileid)) {
|
||||||
// Array of data we will be storing in the database.
|
// Array of data we will be storing in the database.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
@ -174,12 +196,11 @@ class element extends \mod_customcert\element {
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If there is no file, we have nothing to display.
|
// If there is no file, we have nothing to display.
|
||||||
if (empty($imageinfo->filename)) {
|
if (empty($imageinfo->filename)) {
|
||||||
|
@ -190,12 +211,20 @@ class element extends \mod_customcert\element {
|
||||||
$location = make_request_directory() . '/target';
|
$location = make_request_directory() . '/target';
|
||||||
$file->copy_content_to($location);
|
$file->copy_content_to($location);
|
||||||
|
|
||||||
|
// Check if the alpha channel is set, if it is, use it.
|
||||||
|
if (isset($imageinfo->alphachannel)) {
|
||||||
|
$pdf->SetAlpha($imageinfo->alphachannel);
|
||||||
|
}
|
||||||
|
|
||||||
$mimetype = $file->get_mimetype();
|
$mimetype = $file->get_mimetype();
|
||||||
if ($mimetype == 'image/svg+xml') {
|
if ($mimetype == 'image/svg+xml') {
|
||||||
$pdf->ImageSVG($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
$pdf->ImageSVG($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||||
} else {
|
} else {
|
||||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore to full opacity.
|
||||||
|
$pdf->SetAlpha(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,12 +238,11 @@ class element extends \mod_customcert\element {
|
||||||
*/
|
*/
|
||||||
public function render_html() {
|
public function render_html() {
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
$data = $this->get_data();
|
if (empty($this->get_data())) {
|
||||||
if (empty($data)) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageinfo = json_decode($data);
|
$imageinfo = json_decode($this->get_data());
|
||||||
|
|
||||||
// If there is no file, we have nothing to display.
|
// If there is no file, we have nothing to display.
|
||||||
if (empty($imageinfo->filename)) {
|
if (empty($imageinfo->filename)) {
|
||||||
|
@ -254,15 +282,14 @@ class element extends \mod_customcert\element {
|
||||||
/**
|
/**
|
||||||
* Sets the data on the form when editing an element.
|
* Sets the data on the form when editing an element.
|
||||||
*
|
*
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \MoodleQuickForm $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
global $COURSE, $SITE;
|
global $COURSE, $SITE;
|
||||||
|
|
||||||
// Set the image, width and height for this element.
|
// Set the image, width, height and alpha channel for this element.
|
||||||
$data = $this->get_data();
|
if (!empty($this->get_data())) {
|
||||||
if (!empty($data)) {
|
$imageinfo = json_decode($this->get_data());
|
||||||
$imageinfo = json_decode($data);
|
|
||||||
if (!empty($imageinfo->filename)) {
|
if (!empty($imageinfo->filename)) {
|
||||||
if ($file = $this->get_file()) {
|
if ($file = $this->get_file()) {
|
||||||
$element = $mform->getElement('fileid');
|
$element = $mform->getElement('fileid');
|
||||||
|
@ -279,6 +306,11 @@ class element extends \mod_customcert\element {
|
||||||
$element = $mform->getElement('height');
|
$element = $mform->getElement('height');
|
||||||
$element->setValue($imageinfo->height);
|
$element->setValue($imageinfo->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($imageinfo->alphachannel) && $mform->elementExists('alphachannel')) {
|
||||||
|
$element = $mform->getElement('alphachannel');
|
||||||
|
$element->setValue($imageinfo->alphachannel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the context.
|
// Set the context.
|
||||||
|
@ -350,14 +382,14 @@ class element extends \mod_customcert\element {
|
||||||
// Loop through the files uploaded in the system context.
|
// Loop through the files uploaded in the system context.
|
||||||
if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) {
|
if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) {
|
||||||
foreach ($files as $hash => $file) {
|
foreach ($files as $hash => $file) {
|
||||||
$arrfiles[$file->get_id()] = $file->get_filename();
|
$arrfiles[$file->get_id()] = get_string('systemimage', 'customcertelement_image', $file->get_filename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Loop through the files uploaded in the course context.
|
// Loop through the files uploaded in the course context.
|
||||||
if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false,
|
if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', false,
|
||||||
'filename', false)) {
|
'filename', false)) {
|
||||||
foreach ($files as $hash => $file) {
|
foreach ($files as $hash => $file) {
|
||||||
$arrfiles[$file->get_id()] = $file->get_filename();
|
$arrfiles[$file->get_id()] = get_string('courseimage', 'customcertelement_image', $file->get_filename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,4 +398,60 @@ class element extends \mod_customcert\element {
|
||||||
|
|
||||||
return $arrfiles;
|
return $arrfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This handles copying data from another element of the same type.
|
||||||
|
*
|
||||||
|
* @param \stdClass $data the form data
|
||||||
|
* @return bool returns true if the data was copied successfully, false otherwise
|
||||||
|
*/
|
||||||
|
public function copy_element($data) {
|
||||||
|
global $COURSE, $DB, $SITE;
|
||||||
|
|
||||||
|
$imagedata = json_decode($data->data);
|
||||||
|
|
||||||
|
// If we are in the site context we don't have to do anything, the image is already there.
|
||||||
|
if ($COURSE->id == $SITE->id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$coursecontext = \context_course::instance($COURSE->id);
|
||||||
|
$systemcontext = \context_system::instance();
|
||||||
|
|
||||||
|
$fs = get_file_storage();
|
||||||
|
|
||||||
|
// Check that a file has been selected.
|
||||||
|
if (isset($imagedata->filearea)) {
|
||||||
|
// If the course file doesn't exist, copy the system file to the course context.
|
||||||
|
if (!$coursefile = $fs->get_file(
|
||||||
|
$coursecontext->id,
|
||||||
|
'mod_customcert',
|
||||||
|
$imagedata->filearea,
|
||||||
|
$imagedata->itemid,
|
||||||
|
$imagedata->filepath,
|
||||||
|
$imagedata->filename
|
||||||
|
)) {
|
||||||
|
$systemfile = $fs->get_file(
|
||||||
|
$systemcontext->id,
|
||||||
|
'mod_customcert',
|
||||||
|
$imagedata->filearea,
|
||||||
|
$imagedata->itemid,
|
||||||
|
$imagedata->filepath,
|
||||||
|
$imagedata->filename
|
||||||
|
);
|
||||||
|
|
||||||
|
// We want to update the context of the file if it doesn't exist in the course context.
|
||||||
|
$fieldupdates = [
|
||||||
|
'contextid' => $coursecontext->id
|
||||||
|
];
|
||||||
|
$coursefile = $fs->create_file_from_storedfile($fieldupdates, $systemfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the image to the copied file in the course.
|
||||||
|
$imagedata->fileid = $coursefile->get_id();
|
||||||
|
$DB->set_field('customcert_elements', 'data', $this->save_unique_data($imagedata), ['id' => $this->get_id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
46
element/image/classes/privacy/provider.php
Normal file
46
element/image/classes/privacy/provider.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem implementation for customcertelement_image.
|
||||||
|
*
|
||||||
|
* @package customcertelement_image
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace customcertelement_image\privacy;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Privacy Subsystem for customcertelement_image implementing null_provider.
|
||||||
|
*
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class provider implements \core_privacy\local\metadata\null_provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the language string identifier with the component's language
|
||||||
|
* file to explain why this plugin stores no data.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_reason() : string {
|
||||||
|
return 'privacy:metadata';
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die;
|
||||||
function xmldb_customcertelement_image_upgrade($oldversion) {
|
function xmldb_customcertelement_image_upgrade($oldversion) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if ($oldversion < 2016052303) {
|
if ($oldversion < 2016120501) {
|
||||||
// Go through each 'image' element and update the file stored information.
|
// Go through each 'image' element and update the file stored information.
|
||||||
if ($images = $DB->get_records_select('customcert_elements', $DB->sql_compare_text('element') . ' = \'image\'')) {
|
if ($images = $DB->get_records_select('customcert_elements', $DB->sql_compare_text('element') . ' = \'image\'')) {
|
||||||
// Create a file storage instance we are going to use to create pathname hashes.
|
// Create a file storage instance we are going to use to create pathname hashes.
|
||||||
|
@ -59,7 +59,7 @@ function xmldb_customcertelement_image_upgrade($oldversion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Savepoint reached.
|
// Savepoint reached.
|
||||||
upgrade_plugin_savepoint(true, 2016052303, 'customcertelement', 'image');
|
upgrade_plugin_savepoint(true, 2016120501, 'customcertelement', 'image');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,11 +22,16 @@
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$string['alphachannel'] = 'Alpha channel';
|
||||||
|
$string['alphachannel_help'] = 'This value determines how transparent the image is. You can set the alpha channel from 0 (fully transparent) to 1 (fully opaque).';
|
||||||
|
$string['courseimage'] = 'Course image: {$a}';
|
||||||
$string['height'] = 'Height';
|
$string['height'] = 'Height';
|
||||||
$string['height_help'] = 'Height of the image in mm. If equal to zero, it is automatically calculated.';
|
$string['height_help'] = 'Height of the image in mm. If equal to zero, it is automatically calculated.';
|
||||||
$string['image'] = 'Image';
|
$string['image'] = 'Image';
|
||||||
$string['invalidheight'] = 'The height has to be a valid number greater than or equal to 0.';
|
$string['invalidheight'] = 'The height has to be a valid number greater than or equal to 0.';
|
||||||
$string['invalidwidth'] = 'The width has to be a valid number greater than or equal to 0.';
|
$string['invalidwidth'] = 'The width has to be a valid number greater than or equal to 0.';
|
||||||
$string['pluginname'] = 'Image';
|
$string['pluginname'] = 'Image';
|
||||||
|
$string['privacy:metadata'] = 'The Image plugin does not store any personal data.';
|
||||||
|
$string['systemimage'] = 'Site image: {$a}';
|
||||||
$string['width'] = 'Width';
|
$string['width'] = 'Width';
|
||||||
$string['width_help'] = 'Width of the image in mm. If equal to zero, it is automatically calculated.';
|
$string['width_help'] = 'Width of the image in mm. If equal to zero, it is automatically calculated.';
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue