Compare commits
420 commits
MOODLE_30_
...
main
Author | SHA1 | Date | |
---|---|---|---|
d406c4ae16 | |||
df7499249e | |||
5ae2fc8acb | |||
0b97efcbd5 | |||
599adda141 | |||
310a6098a0 | |||
ba2a2d9efe | |||
a9a91d8e89 | |||
0a4186a981 | |||
7b03eceec9 | |||
851ce4e77a | |||
85d3a2644e | |||
90ad8d1078 | |||
0a635d65ad | |||
4459df050e | |||
428deb1d08 | |||
9b34c038ec | |||
9bba4828fb | |||
2661b63758 | |||
203f0a0084 | |||
967571cd14 | |||
|
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 | ||
|
2bcc0a6d45 | ||
|
9a6b9bec25 | ||
|
af57d59676 | ||
|
02703e617b | ||
|
1b7a930131 | ||
|
9fd128d5e1 | ||
|
e341d28853 | ||
|
99a4c4578b | ||
|
56c1af1b84 | ||
|
9a42872c22 | ||
|
62715ab073 | ||
|
5f580a9bde | ||
|
317b737e96 | ||
|
cb3f98a3b9 | ||
|
4af6f68e48 | ||
|
f365ff3ada | ||
|
e8db1dba82 | ||
|
761a8f3e57 | ||
|
ff049e2c1b | ||
|
a135007160 | ||
|
0255851a94 | ||
|
166e62a2ee | ||
|
a48ef25d32 | ||
|
58bbf6a8a0 | ||
|
36c55a65ab | ||
|
5f09a9aca0 | ||
|
38103385b4 | ||
|
fa44ed0fa9 | ||
|
555bca9ebb |
150 changed files with 9633 additions and 6209 deletions
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>.
|
41
README.md
41
README.md
|
@ -1,24 +1,39 @@
|
||||||
QUICK INSTALL
|
# The custom certificate activity
|
||||||
=============
|
|
||||||
|
|
||||||
There are two installation methods that are available. Follow one of these, then log into your Moodle site as an administrator and visit the notifications page to complete the install.
|
This activity allows the dynamic generation of PDF certificates with complete customisation via the web browser.
|
||||||
|
|
||||||
==================== MOST RECOMMENDED METHOD - Git ====================
|
## Installation
|
||||||
|
|
||||||
If you do not have git installed, please see the below link. Please note, it is not necessary to set up the SSH Keys. This is only needed if you are going to create a repository of your own on github.com.
|
There are two installation methods that are available.
|
||||||
|
|
||||||
Information on installing git - http://help.github.com/set-up-git-redirect/
|
Follow one of these, then log into your Moodle site as an administrator and visit the notifications page to complete the install.
|
||||||
|
|
||||||
Once you have git installed, simply visit the Moodle mod directory and clone git://github.com/markn86/moodle-mod_customcert.git, remember to rename the folder to customcert if you do not specify this in the clone command
|
### Git
|
||||||
|
|
||||||
Eg. Linux command line would be as follow -
|
This requires Git being installed. If you do not have Git installed, please visit the [Git website](https://git-scm.com/downloads "Git website").
|
||||||
|
|
||||||
git clone git://github.com/markn86/moodle-mod_customcert.git customcert
|
Once you have Git installed, simply visit your Moodle mod directory and clone the repository using the following command.
|
||||||
|
|
||||||
Use git pull to update this repository periodically to ensure you have the latest version.
|
```
|
||||||
|
git clone https://github.com/mdjnelson/moodle-mod_customcert.git customcert
|
||||||
|
```
|
||||||
|
|
||||||
==================== Download the customcert module. ====================
|
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.
|
||||||
|
|
||||||
Visit https://github.com/markn86/moodle-mod_customcert and download the zip, uncompress this zip and extract the folder. The folder will have a name similar to markn86-moodle-mod_customcert-c9fbadb, you MUST rename this to customcert. Place this folder in your mod folder in your Moodle directory.
|
```
|
||||||
|
git checkout MOODLE_32_STABLE
|
||||||
|
```
|
||||||
|
|
||||||
nb. The reason this is not the recommended method is due to the fact you have to over-write the contents of this folder to apply any future updates to the customcert module. In the above method there is a simple command to update the files.
|
Use `git pull` to update this repository periodically to ensure you have the most recent updates.
|
||||||
|
|
||||||
|
### Download the zip
|
||||||
|
|
||||||
|
Visit the [Moodle plugins website](https://moodle.org/plugins/mod_customcert "Moodle plugins website") and download the zip corresponding to the version of Moodle you are using. Extract the zip and place the 'customcert' folder in the mod folder in your Moodle directory.
|
||||||
|
|
||||||
|
## More information
|
||||||
|
|
||||||
|
Visit the [wiki page](https://docs.moodle.org/en/Custom_certificate_module "Wiki page") for more details. Also, it is a wiki, so please feel free to edit it. :)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Licensed under the [GNU GPL License](http://www.gnu.org/copyleft/gpl.html).
|
57
ajax.php
57
ajax.php
|
@ -1,57 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles AJAX requests for the customcert module.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!defined('AJAX_SCRIPT')) {
|
|
||||||
define('AJAX_SCRIPT', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../config.php');
|
|
||||||
|
|
||||||
$tid = required_param('tid', PARAM_INT);
|
|
||||||
$values = required_param('values', PARAM_RAW);
|
|
||||||
$values = json_decode($values);
|
|
||||||
|
|
||||||
// Make sure the template exists.
|
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Set the template.
|
|
||||||
$template = new \mod_customcert\template($template);
|
|
||||||
// Perform checks.
|
|
||||||
if ($cm = $template->get_cm()) {
|
|
||||||
$courseid = $cm->course;
|
|
||||||
require_login($courseid, false, $cm);
|
|
||||||
} else {
|
|
||||||
require_login();
|
|
||||||
}
|
|
||||||
// Make sure the user has the required capabilities.
|
|
||||||
$template->require_manage();
|
|
||||||
|
|
||||||
// Loop through the data.
|
|
||||||
foreach ($values as $value) {
|
|
||||||
$element = new stdClass();
|
|
||||||
$element->id = $value->id;
|
|
||||||
$element->posx = $value->posx;
|
|
||||||
$element->posy = $value->posy;
|
|
||||||
$DB->update_record('customcert_elements', $element);
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define all the backup steps that will be used by the backup_customcert_activity_task.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the complete customcert structure for backup, with file and id annotations.
|
|
||||||
*/
|
|
||||||
class backup_customcert_activity_structure_step extends backup_activity_structure_step {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the structure of the backup file.
|
|
||||||
*
|
|
||||||
* @return backup_nested_element
|
|
||||||
*/
|
|
||||||
protected function define_structure() {
|
|
||||||
|
|
||||||
// The instance.
|
|
||||||
$customcert = new backup_nested_element('customcert', array('id'), array(
|
|
||||||
'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'protection',
|
|
||||||
'timecreated', 'timemodified'));
|
|
||||||
|
|
||||||
// The template.
|
|
||||||
$template = new backup_nested_element('template', array('id'), array(
|
|
||||||
'name', 'contextid', 'timecreated', 'timemodified'));
|
|
||||||
|
|
||||||
// The pages.
|
|
||||||
$pages = new backup_nested_element('pages');
|
|
||||||
$page = new backup_nested_element('page', array('id'), array(
|
|
||||||
'templateid', 'width', 'height', 'leftmargin', 'rightmargin',
|
|
||||||
'sequence', 'timecreated', 'timemodified'));
|
|
||||||
|
|
||||||
// The elements.
|
|
||||||
$element = new backup_nested_element('element', array('id'), array(
|
|
||||||
'pageid', 'name', 'element', 'data', 'font', 'size',
|
|
||||||
'colour', 'posx', 'posy', 'width', 'refpoint', 'sequence',
|
|
||||||
'timecreated', 'timemodified'));
|
|
||||||
|
|
||||||
// The issues.
|
|
||||||
$issues = new backup_nested_element('issues');
|
|
||||||
$issue = new backup_nested_element('issue', array('id'), array(
|
|
||||||
'customcertid', 'userid', 'timecreated', 'code'));
|
|
||||||
|
|
||||||
// Build the tree.
|
|
||||||
$customcert->add_child($issues);
|
|
||||||
$issues->add_child($issue);
|
|
||||||
$customcert->add_child($template);
|
|
||||||
$template->add_child($pages);
|
|
||||||
$pages->add_child($page);
|
|
||||||
$page->add_child($element);
|
|
||||||
|
|
||||||
// Define sources.
|
|
||||||
$customcert->set_source_table('customcert', array('id' => backup::VAR_ACTIVITYID));
|
|
||||||
|
|
||||||
// Define template source.
|
|
||||||
$template->set_source_table('customcert_templates', array('contextid' => backup::VAR_CONTEXTID));
|
|
||||||
|
|
||||||
// Define page source.
|
|
||||||
$page->set_source_table('customcert_pages', array('templateid' => backup::VAR_PARENTID));
|
|
||||||
|
|
||||||
// Define element source, each element belongs to a page.
|
|
||||||
$element->set_source_table('customcert_elements', array('pageid' => backup::VAR_PARENTID));
|
|
||||||
|
|
||||||
// If we are including user info then save the issues.
|
|
||||||
if ($this->get_setting_value('userinfo')) {
|
|
||||||
$issue->set_source_table('customcert_issues', array('customcertid' => backup::VAR_ACTIVITYID));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Annotate the user id's where required.
|
|
||||||
$issue->annotate_ids('user', 'userid');
|
|
||||||
|
|
||||||
// Return the root element (customcert), wrapped into standard activity structure.
|
|
||||||
return $this->prepare_activity_structure($customcert);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,22 +15,25 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file contains the backup tasks that provides all the settings and steps to perform
|
* This file contains the backup tasks that provides all the settings and steps to perform a backup of the activity.
|
||||||
* one complete backup of the activity.
|
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/mod/customcert/backup/moodle2/backup_customcert_stepslib.php');
|
require_once($CFG->dirroot . '/mod/htmlcert/backup/moodle2/backup_htmlcert_stepslib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles creating tasks to peform in order to create the backup.
|
* Handles creating tasks to peform in order to create the backup.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class backup_customcert_activity_task extends backup_activity_task {
|
class backup_htmlcert_activity_task extends backup_activity_task {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define particular settings this activity can have.
|
* Define particular settings this activity can have.
|
||||||
|
@ -43,25 +46,28 @@ class backup_customcert_activity_task extends backup_activity_task {
|
||||||
* Define particular steps this activity can have.
|
* Define particular steps this activity can have.
|
||||||
*/
|
*/
|
||||||
protected function define_my_steps() {
|
protected function define_my_steps() {
|
||||||
// The customcert only has one structure step.
|
// The htmlcert only has one structure step.
|
||||||
$this->add_step(new backup_customcert_activity_structure_step('customcert_structure', 'customcert.xml'));
|
$this->add_step(new backup_htmlcert_activity_structure_step('htmlcert_structure', 'htmlcert.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code the transformations to perform in the activity in order to get transportable (encoded) links.
|
* Code the transformations to perform in the activity in order to get transportable (encoded) links.
|
||||||
|
*
|
||||||
|
* @param string $content
|
||||||
|
* @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, "/");
|
||||||
|
|
||||||
// Link to the list of customcerts.
|
// Link to the list of htmlcerts.
|
||||||
$search ="/(".$base."\/mod\/customcert\/index.php\?id\=)([0-9]+)/";
|
$search = "/(".$base."\/mod\/htmlcert\/index.php\?id\=)([0-9]+)/";
|
||||||
$content = preg_replace($search, '$@customcertINDEX*$2@$', $content);
|
$content = preg_replace($search, '$@HTMLCERTINDEX*$2@$', $content);
|
||||||
|
|
||||||
// Link to customcert view by moduleid.
|
// Link to htmlcert view by moduleid.
|
||||||
$search ="/(".$base."\/mod\/customcert\/view.php\?id\=)([0-9]+)/";
|
$search = "/(".$base."\/mod\/htmlcert\/view.php\?id\=)([0-9]+)/";
|
||||||
$content = preg_replace($search, '$@customcertVIEWBYID*$2@$', $content);
|
$content = preg_replace($search, '$@HTMLCERTVIEWBYID*$2@$', $content);
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
83
backup/moodle2/backup_htmlcert_stepslib.php
Normal file
83
backup/moodle2/backup_htmlcert_stepslib.php
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define all the backup steps that will be used by the backup_htmlcert_activity_task.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the complete htmlcert structure for backup, with file and id annotations.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class backup_htmlcert_activity_structure_step extends backup_activity_structure_step {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the structure of the backup file.
|
||||||
|
*
|
||||||
|
* @return backup_nested_element
|
||||||
|
*/
|
||||||
|
protected function define_structure() {
|
||||||
|
|
||||||
|
// The instance.
|
||||||
|
$htmlcert = new backup_nested_element('htmlcert', array('id'), array(
|
||||||
|
'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'verifyany', 'emailstudents',
|
||||||
|
'emailteachers', 'emailothers', 'protection', 'timecreated', 'timemodified'));
|
||||||
|
|
||||||
|
// The template.
|
||||||
|
$template = new backup_nested_element('template', array('id'), array(
|
||||||
|
'name', 'html', 'contextid', 'timecreated', 'timemodified'));
|
||||||
|
|
||||||
|
// The issues.
|
||||||
|
$issues = new backup_nested_element('issues');
|
||||||
|
$issue = new backup_nested_element('issue', array('id'), array(
|
||||||
|
'htmlcertid', 'userid', 'timecreated', 'emailed', 'code'));
|
||||||
|
|
||||||
|
// Build the tree.
|
||||||
|
$htmlcert->add_child($issues);
|
||||||
|
$issues->add_child($issue);
|
||||||
|
$htmlcert->add_child($template);
|
||||||
|
|
||||||
|
// Define sources.
|
||||||
|
$htmlcert->set_source_table('htmlcert', array('id' => backup::VAR_ACTIVITYID));
|
||||||
|
|
||||||
|
// Define template source.
|
||||||
|
$template->set_source_table('htmlcert_templates', array('contextid' => backup::VAR_CONTEXTID));
|
||||||
|
|
||||||
|
// If we are including user info then save the issues.
|
||||||
|
if ($this->get_setting_value('userinfo')) {
|
||||||
|
$issue->set_source_table('htmlcert_issues', array('htmlcertid' => backup::VAR_ACTIVITYID));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Annotate the user id's where required.
|
||||||
|
$issue->annotate_ids('user', 'userid');
|
||||||
|
|
||||||
|
// Define file annotations.
|
||||||
|
$htmlcert->annotate_files('mod_htmlcert', 'intro', null);
|
||||||
|
$htmlcert->annotate_files('mod_htmlcert', 'image', null, context_course::instance($this->get_courseid())->id);
|
||||||
|
|
||||||
|
// Return the root element (htmlcert), wrapped into standard activity structure.
|
||||||
|
return $this->prepare_activity_structure($htmlcert);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,118 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define all the restore steps that will be used by the restore_customcert_activity_task.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/mod/customcert/backup/moodle2/restore_customcert_stepslib.php');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The class definition for assigning restore tasks that provides all the settings and steps
|
|
||||||
* to perform one complete restore of the activity.
|
|
||||||
*/
|
|
||||||
class restore_customcert_activity_task extends restore_activity_task {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define particular settings this activity can have.
|
|
||||||
*/
|
|
||||||
protected function define_my_settings() {
|
|
||||||
// No particular settings for this activity.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define particular steps this activity can have.
|
|
||||||
*/
|
|
||||||
protected function define_my_steps() {
|
|
||||||
// The customcert only has one structure step.
|
|
||||||
$this->add_step(new restore_customcert_activity_structure_step('customcert_structure', 'customcert.xml'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the contents in the activity that must be processed by the link decoder.
|
|
||||||
*/
|
|
||||||
static public function define_decode_contents() {
|
|
||||||
$contents = array();
|
|
||||||
|
|
||||||
$contents[] = new restore_decode_content('customcert', array('intro'), 'customcert');
|
|
||||||
|
|
||||||
return $contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the decoding rules for links belonging to the activity to be executed by the link decoder.
|
|
||||||
*/
|
|
||||||
static public function define_decode_rules() {
|
|
||||||
$rules = array();
|
|
||||||
|
|
||||||
$rules[] = new restore_decode_rule('CUSTOMCERTVIEWBYID', '/mod/customcert/view.php?id=$1', 'course_module');
|
|
||||||
$rules[] = new restore_decode_rule('CUSTOMCERTINDEX', '/mod/customcert/index.php?id=$1', 'course');
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the restore log rules that will be applied by the {@link restore_logs_processor} when restoring
|
|
||||||
* customcert logs. It must return one array of {@link restore_log_rule} objects.
|
|
||||||
*
|
|
||||||
* @return array the restore log rules
|
|
||||||
*/
|
|
||||||
static public function define_restore_log_rules() {
|
|
||||||
$rules = array();
|
|
||||||
|
|
||||||
$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', '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', 'view report', 'report.php?id={customcert}', '{customcert}');
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is called after all the activities in the backup have been restored. This allows us to get
|
|
||||||
* the new course module ids, as they may have been restored after the customcert module, meaning no id
|
|
||||||
* was available at the time.
|
|
||||||
*/
|
|
||||||
public function after_restore() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Get the customcert elements.
|
|
||||||
$sql = "SELECT e.*
|
|
||||||
FROM {customcert_elements} e
|
|
||||||
INNER JOIN {customcert_pages} p
|
|
||||||
ON e.pageid = p.id
|
|
||||||
INNER JOIN {customcert} c
|
|
||||||
ON p.templateid = c.templateid
|
|
||||||
WHERE c.id = :customcertid";
|
|
||||||
if ($elements = $DB->get_records_sql($sql, array('customcertid' => $this->get_activityid()))) {
|
|
||||||
// Go through the elements for the certificate.
|
|
||||||
foreach ($elements as $e) {
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($e)) {
|
|
||||||
$e->after_restore($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,162 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define all the restore steps that will be used by the restore_customcert_activity_task.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the complete customcert structure for restore, with file and id annotations.
|
|
||||||
*/
|
|
||||||
class restore_customcert_activity_structure_step extends restore_activity_structure_step {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the different items to restore.
|
|
||||||
*
|
|
||||||
* @return array the restore paths
|
|
||||||
*/
|
|
||||||
protected function define_structure() {
|
|
||||||
// The array used to store the path to the items we want to restore.
|
|
||||||
$paths = array();
|
|
||||||
|
|
||||||
// The customcert instance.
|
|
||||||
$paths[] = new restore_path_element('customcert', '/activity/customcert');
|
|
||||||
|
|
||||||
// The templates.
|
|
||||||
$paths[] = new restore_path_element('customcert_template', '/activity/customcert/template');
|
|
||||||
|
|
||||||
// The pages.
|
|
||||||
$paths[] = new restore_path_element('customcert_page', '/activity/customcert/template/pages/page');
|
|
||||||
|
|
||||||
// The elements.
|
|
||||||
$paths[] = new restore_path_element('customcert_element', '/activity/customcert/template/pages/page/element');
|
|
||||||
|
|
||||||
// Check if we want the issues as well.
|
|
||||||
if ($this->get_setting_value('userinfo')) {
|
|
||||||
$paths[] = new restore_path_element('customcert_issue', '/activity/customcert/issues/issue');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the paths wrapped into standard activity structure.
|
|
||||||
return $this->prepare_activity_structure($paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles restoring the customcert activity.
|
|
||||||
*
|
|
||||||
* @param stdClass $data the customcert data
|
|
||||||
*/
|
|
||||||
protected function process_customcert($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$data = (object) $data;
|
|
||||||
$data->course = $this->get_courseid();
|
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
||||||
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
||||||
|
|
||||||
// Insert the customcert record.
|
|
||||||
$newitemid = $DB->insert_record('customcert', $data);
|
|
||||||
|
|
||||||
// Immediately after inserting record call this.
|
|
||||||
$this->apply_activity_instance($newitemid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles restoring a customcert page.
|
|
||||||
*
|
|
||||||
* @param stdClass $data the customcert data
|
|
||||||
*/
|
|
||||||
protected function process_customcert_template($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$data = (object) $data;
|
|
||||||
$oldid = $data->id;
|
|
||||||
|
|
||||||
$data->contextid = $this->task->get_contextid();
|
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
||||||
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
||||||
|
|
||||||
$newitemid = $DB->insert_record('customcert_templates', $data);
|
|
||||||
$this->set_mapping('customcert_template', $oldid, $newitemid);
|
|
||||||
|
|
||||||
// Update the template id for the customcert.
|
|
||||||
$customcert = new stdClass();
|
|
||||||
$customcert->id = $this->get_new_parentid('customcert');
|
|
||||||
$customcert->templateid = $newitemid;
|
|
||||||
$DB->update_record('customcert', $customcert);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles restoring a customcert template.
|
|
||||||
*
|
|
||||||
* @param stdClass $data the customcert data
|
|
||||||
*/
|
|
||||||
protected function process_customcert_page($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$data = (object) $data;
|
|
||||||
$oldid = $data->id;
|
|
||||||
|
|
||||||
$data->templateid = $this->get_new_parentid('customcert_template');
|
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
||||||
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
||||||
|
|
||||||
$newitemid = $DB->insert_record('customcert_pages', $data);
|
|
||||||
$this->set_mapping('customcert_page', $oldid, $newitemid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles restoring a customcert element.
|
|
||||||
*
|
|
||||||
* @param stdclass $data the customcert data
|
|
||||||
*/
|
|
||||||
protected function process_customcert_element($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$data = (object) $data;
|
|
||||||
$oldid = $data->id;
|
|
||||||
|
|
||||||
$data->pageid = $this->get_new_parentid('customcert_page');
|
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
||||||
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
||||||
|
|
||||||
$newitemid = $DB->insert_record('customcert_elements', $data);
|
|
||||||
$this->set_mapping('customcert_element', $oldid, $newitemid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles restoring a customcert issue.
|
|
||||||
*
|
|
||||||
* @param stdClass $data the customcert data
|
|
||||||
*/
|
|
||||||
protected function process_customcert_issue($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$data = (object) $data;
|
|
||||||
$oldid = $data->id;
|
|
||||||
|
|
||||||
$data->customcertid = $this->get_new_parentid('customcert');
|
|
||||||
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
||||||
|
|
||||||
$newitemid = $DB->insert_record('customcert_issues', $data);
|
|
||||||
$this->set_mapping('customcert_issue', $oldid, $newitemid);
|
|
||||||
}
|
|
||||||
}
|
|
103
backup/moodle2/restore_htmlcert_activity_task.class.php
Normal file
103
backup/moodle2/restore_htmlcert_activity_task.class.php
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define all the restore steps that will be used by the restore_htmlcert_activity_task.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
require_once($CFG->dirroot . '/mod/htmlcert/backup/moodle2/restore_htmlcert_stepslib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class definition for assigning tasks that provide the settings and steps to perform a restore of the activity.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class restore_htmlcert_activity_task extends restore_activity_task {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define particular settings this activity can have.
|
||||||
|
*/
|
||||||
|
protected function define_my_settings() {
|
||||||
|
// No particular settings for this activity.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define particular steps this activity can have.
|
||||||
|
*/
|
||||||
|
protected function define_my_steps() {
|
||||||
|
// The htmlcert only has one structure step.
|
||||||
|
$this->add_step(new restore_htmlcert_activity_structure_step('htmlcert_structure', 'htmlcert.xml'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the contents in the activity that must be processed by the link decoder.
|
||||||
|
*/
|
||||||
|
public static function define_decode_contents() {
|
||||||
|
$contents = array();
|
||||||
|
|
||||||
|
$contents[] = new restore_decode_content('htmlcert', array('intro'), 'htmlcert');
|
||||||
|
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the decoding rules for links belonging to the activity to be executed by the link decoder.
|
||||||
|
*/
|
||||||
|
public static function define_decode_rules() {
|
||||||
|
$rules = array();
|
||||||
|
|
||||||
|
$rules[] = new restore_decode_rule('HTMLCERTVIEWBYID', '/mod/htmlcert/view.php?id=$1', 'course_module');
|
||||||
|
$rules[] = new restore_decode_rule('HTMLCERTINDEX', '/mod/htmlcert/index.php?id=$1', 'course');
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the restore log rules that will be applied by the {@see restore_logs_processor} when restoring
|
||||||
|
* htmlcert logs. It must return one array of {@see restore_log_rule} objects.
|
||||||
|
*
|
||||||
|
* @return array the restore log rules
|
||||||
|
*/
|
||||||
|
public static function define_restore_log_rules() {
|
||||||
|
$rules = array();
|
||||||
|
|
||||||
|
$rules[] = new restore_log_rule('htmlcert', 'add', 'view.php?id={course_module}', '{htmlcert}');
|
||||||
|
$rules[] = new restore_log_rule('htmlcert', 'update', 'view.php?id={course_module}', '{htmlcert}');
|
||||||
|
$rules[] = new restore_log_rule('htmlcert', 'view', 'view.php?id={course_module}', '{htmlcert}');
|
||||||
|
$rules[] = new restore_log_rule('htmlcert', 'received', 'view.php?id={course_module}', '{htmlcert}');
|
||||||
|
$rules[] = new restore_log_rule('htmlcert', 'view report', 'view.php?id={course_module}', '{htmlcert}');
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is called after all the activities in the backup have been restored. This allows us to get
|
||||||
|
* the new course module ids, as they may have been restored after the htmlcert module, meaning no id
|
||||||
|
* was available at the time.
|
||||||
|
*/
|
||||||
|
public function after_restore() {
|
||||||
|
global $DB;
|
||||||
|
}
|
||||||
|
}
|
136
backup/moodle2/restore_htmlcert_stepslib.php
Normal file
136
backup/moodle2/restore_htmlcert_stepslib.php
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define all the restore steps that will be used by the restore_htmlcert_activity_task.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the complete htmlcert structure for restore, with file and id annotations.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class restore_htmlcert_activity_structure_step extends restore_activity_structure_step {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the different items to restore.
|
||||||
|
*
|
||||||
|
* @return array the restore paths
|
||||||
|
*/
|
||||||
|
protected function define_structure() {
|
||||||
|
// The array used to store the path to the items we want to restore.
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
// The htmlcert instance.
|
||||||
|
$paths[] = new restore_path_element('htmlcert', '/activity/htmlcert');
|
||||||
|
|
||||||
|
// The templates.
|
||||||
|
$paths[] = new restore_path_element('htmlcert_template', '/activity/htmlcert/template');
|
||||||
|
|
||||||
|
// Check if we want the issues as well.
|
||||||
|
if ($this->get_setting_value('userinfo')) {
|
||||||
|
$paths[] = new restore_path_element('htmlcert_issue', '/activity/htmlcert/issues/issue');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the paths wrapped into standard activity structure.
|
||||||
|
return $this->prepare_activity_structure($paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles restoring the htmlcert activity.
|
||||||
|
*
|
||||||
|
* @param stdClass $data the htmlcert data
|
||||||
|
*/
|
||||||
|
protected function process_htmlcert($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object) $data;
|
||||||
|
$data->course = $this->get_courseid();
|
||||||
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
||||||
|
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
||||||
|
|
||||||
|
// Insert the htmlcert record.
|
||||||
|
$newitemid = $DB->insert_record('htmlcert', $data);
|
||||||
|
|
||||||
|
// Immediately after inserting record call this.
|
||||||
|
$this->apply_activity_instance($newitemid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles restoring a htmlcert templage.
|
||||||
|
*
|
||||||
|
* @param stdClass $data the htmlcert data
|
||||||
|
*/
|
||||||
|
protected function process_htmlcert_template($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object) $data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
|
||||||
|
$data->contextid = $this->task->get_contextid();
|
||||||
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
||||||
|
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
||||||
|
|
||||||
|
$newitemid = $DB->insert_record('htmlcert_templates', $data);
|
||||||
|
$this->set_mapping('htmlcert_template', $oldid, $newitemid);
|
||||||
|
|
||||||
|
// Update the template id for the htmlcert.
|
||||||
|
$htmlcert = new stdClass();
|
||||||
|
$htmlcert->id = $this->get_new_parentid('htmlcert');
|
||||||
|
$htmlcert->templateid = $newitemid;
|
||||||
|
$DB->update_record('htmlcert', $htmlcert);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles restoring a htmlcert issue.
|
||||||
|
*
|
||||||
|
* @param stdClass $data the htmlcert data
|
||||||
|
*/
|
||||||
|
protected function process_htmlcert_issue($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$data = (object) $data;
|
||||||
|
$oldid = $data->id;
|
||||||
|
|
||||||
|
$data->htmlcertid = $this->get_new_parentid('htmlcert');
|
||||||
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
||||||
|
$data->userid = $this->get_mappingid('user', $data->userid);
|
||||||
|
|
||||||
|
$newitemid = $DB->insert_record('htmlcert_issues', $data);
|
||||||
|
$this->set_mapping('htmlcert_issue', $oldid, $newitemid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called immediately after all the other restore functions.
|
||||||
|
*/
|
||||||
|
protected function after_execute() {
|
||||||
|
parent::after_execute();
|
||||||
|
|
||||||
|
// Add the files.
|
||||||
|
$this->add_related_files('mod_htmlcert', 'intro', null);
|
||||||
|
|
||||||
|
// Note - we can't use get_old_contextid() as it refers to the module context.
|
||||||
|
$this->add_related_files('mod_htmlcert', 'image', null, $this->get_task()->get_info()->original_course_contextid);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,19 +14,26 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
namespace mod_customcert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an upload form on the settings page.
|
* Creates an upload form on the settings page.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
require_once($CFG->libdir.'/adminlib.php');
|
require_once($CFG->libdir.'/adminlib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class extends admin setting class to allow/process an uploaded file
|
* Class extends admin setting class to allow/process an uploaded file
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class admin_setting_link extends \admin_setting_configtext {
|
class admin_setting_link extends \admin_setting_configtext {
|
||||||
|
|
||||||
|
@ -40,6 +47,18 @@ class admin_setting_link extends \admin_setting_configtext {
|
||||||
*/
|
*/
|
||||||
protected $linkname;
|
protected $linkname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The admin_setting_link constructor.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $visiblename
|
||||||
|
* @param string $description
|
||||||
|
* @param string $linkname
|
||||||
|
* @param mixed|string $link
|
||||||
|
* @param int|null $defaultsetting
|
||||||
|
* @param string $paramtype
|
||||||
|
* @param null $size
|
||||||
|
*/
|
||||||
public function __construct($name, $visiblename, $description, $linkname, $link, $defaultsetting,
|
public function __construct($name, $visiblename, $description, $linkname, $link, $defaultsetting,
|
||||||
$paramtype = PARAM_RAW, $size=null) {
|
$paramtype = PARAM_RAW, $size=null) {
|
||||||
$this->link = $link;
|
$this->link = $link;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,24 +15,38 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides functionality needed by customcert activities.
|
* Provides functionality needed by htmlcert activities.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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_htmlcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class certificate.
|
* Class certificate.
|
||||||
*
|
*
|
||||||
* Represents a customcert activity instance.
|
* Helper functionality for certificates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
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
|
||||||
*/
|
*/
|
||||||
|
@ -50,17 +64,12 @@ class certificate {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int the number of issues that will be displayed on each page in the report
|
* @var int the number of issues that will be displayed on each page in the report
|
||||||
* If you want to display all customcerts on a page set this to 0.
|
* If you want to display all htmlcerts on a page set this to 0.
|
||||||
*/
|
*/
|
||||||
const CUSTOMCERT_PER_PAGE = '20';
|
const HTMLCERT_PER_PAGE = '50';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int the max number of issues to display
|
* Handles setting the protection field for the htmlcert
|
||||||
*/
|
|
||||||
const CUSTOMCERT_MAX_PER_PAGE = '300';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles setting the protection field for the customcert
|
|
||||||
*
|
*
|
||||||
* @param \stdClass $data
|
* @param \stdClass $data
|
||||||
* @return string the value to insert into the protection field
|
* @return string the value to insert into the protection field
|
||||||
|
@ -83,94 +92,40 @@ class certificate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles uploading an image for the customcert module.
|
* Handles uploading an image for the htmlcert module.
|
||||||
*
|
*
|
||||||
* @param int $draftitemid the draft area containing the files
|
* @param int $draftitemid the draft area containing the files
|
||||||
* @param int $contextid the context we are storing this image in
|
* @param int $contextid the context we are storing this image in
|
||||||
|
* @param string $filearea indentifies the file area.
|
||||||
*/
|
*/
|
||||||
public static function upload_imagefiles($draftitemid, $contextid) {
|
public static function upload_files($draftitemid, $contextid, $filearea = 'image') {
|
||||||
// Save the file if it exists that is currently in the draft area.
|
|
||||||
file_save_draft_area_files($draftitemid, $contextid, 'mod_customcert', 'image', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the list of possible fonts to use.
|
|
||||||
*/
|
|
||||||
public static function get_fonts() {
|
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
// Array to store the available fonts.
|
// Save the file if it exists that is currently in the draft area.
|
||||||
$options = array();
|
require_once($CFG->dirroot . '/lib/filelib.php');
|
||||||
|
file_save_draft_area_files($draftitemid, $contextid, 'mod_htmlcert', $filearea, 0);
|
||||||
// Location of fonts in Moodle.
|
|
||||||
$fontdir = "$CFG->dirroot/lib/tcpdf/fonts";
|
|
||||||
// Check that the directory exists.
|
|
||||||
if (file_exists($fontdir)) {
|
|
||||||
// Get directory contents.
|
|
||||||
$fonts = new \DirectoryIterator($fontdir);
|
|
||||||
// Loop through the font folder.
|
|
||||||
foreach ($fonts as $font) {
|
|
||||||
// If it is not a file, or either '.' or '..', or
|
|
||||||
// the extension is not php, or we can not open file,
|
|
||||||
// skip it.
|
|
||||||
if (!$font->isFile() || $font->isDot() || ($font->getExtension() != 'php')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 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.
|
|
||||||
$name = null;
|
|
||||||
// Some files include a display name, the include next should then set this
|
|
||||||
// value if it is present, if not then $name is used to create the display name.
|
|
||||||
$displayname = null;
|
|
||||||
// Some of the TCPDF files include files that are not present, so we have to
|
|
||||||
// suppress warnings, this is the TCPDF libraries fault, grrr.
|
|
||||||
@include("$fontdir/$font");
|
|
||||||
// If no $name variable in file, skip it.
|
|
||||||
if (is_null($name)) {
|
|
||||||
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.
|
|
||||||
if (is_null($displayname)) {
|
|
||||||
// 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-zA-Z])-([a-zA-Z])/", "$1 - $2", $displayname);
|
|
||||||
}
|
|
||||||
$options[$filename] = $displayname;
|
|
||||||
}
|
|
||||||
ksort($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the list of possible font sizes to use.
|
|
||||||
*/
|
|
||||||
public static function get_font_sizes() {
|
|
||||||
// Array to store the sizes.
|
|
||||||
$sizes = array();
|
|
||||||
|
|
||||||
for ($i = 1; $i <= 60; $i++) {
|
|
||||||
$sizes[$i] = $i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sizes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time the user has spent in the course.
|
* Get the time the user has spent in the course.
|
||||||
*
|
*
|
||||||
* @param int $courseid
|
* @param int $courseid
|
||||||
|
* @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) {
|
public static function get_course_time(int $courseid, int $userid = 0): int {
|
||||||
global $CFG, $DB, $USER;
|
global $CFG, $DB, $USER;
|
||||||
|
|
||||||
|
if (empty($userid)) {
|
||||||
|
$userid = $USER->id;
|
||||||
|
}
|
||||||
|
|
||||||
$logmanager = get_log_manager();
|
$logmanager = get_log_manager();
|
||||||
$readers = $logmanager->get_readers();
|
$readers = $logmanager->get_readers();
|
||||||
$enabledreaders = get_config('tool_log', 'enabled_stores');
|
$enabledreaders = get_config('tool_log', 'enabled_stores');
|
||||||
|
if (empty($enabledreaders)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$enabledreaders = explode(',', $enabledreaders);
|
$enabledreaders = explode(',', $enabledreaders);
|
||||||
|
|
||||||
// Go through all the readers until we find one that we can use.
|
// Go through all the readers until we find one that we can use.
|
||||||
|
@ -199,25 +154,25 @@ class certificate {
|
||||||
WHERE userid = :userid
|
WHERE userid = :userid
|
||||||
AND $coursefield = :courseid
|
AND $coursefield = :courseid
|
||||||
ORDER BY $timefield ASC";
|
ORDER BY $timefield ASC";
|
||||||
$params = array('userid' => $USER->id, 'courseid' => $courseid);
|
$params = array('userid' => $userid, 'courseid' => $courseid);
|
||||||
$totaltime = 0;
|
$totaltime = 0;
|
||||||
if ($logs = $DB->get_recordset_sql($sql, $params)) {
|
if ($logs = $DB->get_recordset_sql($sql, $params)) {
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
if (!isset($login)) {
|
if (!isset($login)) {
|
||||||
// For the first time $login is not set so the first log is also the first login
|
// For the first time $login is not set so the first log is also the first login.
|
||||||
$login = $log->$timefield;
|
$login = $log->$timefield;
|
||||||
$lasthit = $log->$timefield;
|
$lasthit = $log->$timefield;
|
||||||
$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;
|
||||||
} else {
|
} else {
|
||||||
$totaltime += $delay;
|
$totaltime += $delay;
|
||||||
}
|
}
|
||||||
// Now the actual log became the previous log for the next cycle
|
// Now the actual log became the previous log for the next cycle.
|
||||||
$lasthit = $log->$timefield;
|
$lasthit = $log->$timefield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,16 +183,17 @@ class certificate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of issued customcerts.
|
* Returns a list of issued htmlcerts.
|
||||||
*
|
*
|
||||||
* @param int $customcertid
|
* @param int $htmlcertid
|
||||||
* @param bool $groupmode are we in group mode
|
* @param bool $groupmode are we in group mode
|
||||||
* @param \stdClass $cm the course module
|
* @param \stdClass $cm the course module
|
||||||
* @param int $page offset
|
* @param int $limitfrom
|
||||||
* @param int $perpage total per page
|
* @param int $limitnum
|
||||||
* @return \stdClass the users
|
* @param string $sort
|
||||||
|
* @return array the users
|
||||||
*/
|
*/
|
||||||
public static function get_issues($customcertid, $groupmode, $cm, $page, $perpage) {
|
public static function get_issues($htmlcertid, $groupmode, $cm, $limitfrom, $limitnum, $sort = '') {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// Get the conditional SQL.
|
// Get the conditional SQL.
|
||||||
|
@ -248,30 +204,45 @@ class certificate {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the conditional SQL and the customcertid to form all used parameters.
|
// Add the conditional SQL and the htmlcertid to form all used parameters.
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('htmlcertid' => $htmlcertid);
|
||||||
|
|
||||||
// Return the issues.
|
// Return the issues.
|
||||||
$sql = "SELECT u.*, ci.code, ci.timecreated
|
$context = \context_module::instance($cm->id);
|
||||||
|
$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 {htmlcert_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.htmlcertid = :htmlcertid
|
||||||
$conditionssql
|
$conditionssql";
|
||||||
ORDER BY " . $DB->sql_fullname();
|
if ($sort) {
|
||||||
return $DB->get_records_sql($sql, $allparams, $page * $perpage, $perpage);
|
$sql .= "ORDER BY " . $sort;
|
||||||
|
} else {
|
||||||
|
$sql .= "ORDER BY " . $DB->sql_fullname();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $DB->get_records_sql($sql, $allparams, $limitfrom, $limitnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of issues for a given customcert.
|
* Returns the total number of issues for a given htmlcert.
|
||||||
*
|
*
|
||||||
* @param int $customcertid
|
* @param int $htmlcertid
|
||||||
* @param \stdClass $cm the course module
|
* @param \stdClass $cm the course module
|
||||||
* @param bool $groupmode the group mode
|
* @param bool $groupmode the group mode
|
||||||
* @return int the number of issues
|
* @return int the number of issues
|
||||||
*/
|
*/
|
||||||
public static function get_number_of_issues($customcertid, $cm, $groupmode) {
|
public static function get_number_of_issues($htmlcertid, $cm, $groupmode) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// Get the conditional SQL.
|
// Get the conditional SQL.
|
||||||
|
@ -282,16 +253,16 @@ class certificate {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the conditional SQL and the customcertid to form all used parameters.
|
// Add the conditional SQL and the htmlcertid to form all used parameters.
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('htmlcertid' => $htmlcertid);
|
||||||
|
|
||||||
// Return the number of issues.
|
// Return the number of issues.
|
||||||
$sql = "SELECT COUNT(u.id) as count
|
$sql = "SELECT COUNT(u.id) as count
|
||||||
FROM {user} u
|
FROM {user} u
|
||||||
INNER JOIN {customcert_issues} ci
|
INNER JOIN {htmlcert_issues} ci
|
||||||
ON u.id = ci.userid
|
ON u.id = ci.userid
|
||||||
WHERE u.deleted = 0
|
WHERE u.deleted = 0
|
||||||
AND ci.customcertid = :customcertid
|
AND ci.htmlcertid = :htmlcertid
|
||||||
$conditionssql";
|
$conditionssql";
|
||||||
return $DB->count_records_sql($sql, $allparams);
|
return $DB->count_records_sql($sql, $allparams);
|
||||||
}
|
}
|
||||||
|
@ -306,13 +277,13 @@ class certificate {
|
||||||
public static function get_conditional_issues_sql($cm, $groupmode) {
|
public static function get_conditional_issues_sql($cm, $groupmode) {
|
||||||
global $DB, $USER;
|
global $DB, $USER;
|
||||||
|
|
||||||
// Get all users that can manage this customcert to exclude them from the report.
|
// Get all users that can manage this htmlcert to exclude them from the report.
|
||||||
$context = \context_module::instance($cm->id);
|
$context = \context_module::instance($cm->id);
|
||||||
$conditionssql = '';
|
$conditionssql = '';
|
||||||
$conditionsparams = array();
|
$conditionsparams = array();
|
||||||
|
|
||||||
// Get all users that can manage this certificate to exclude them from the report.
|
// Get all users that can manage this certificate to exclude them from the report.
|
||||||
$certmanagers = array_keys(get_users_by_capability($context, 'mod/certificate:manage', 'u.id'));
|
$certmanagers = array_keys(get_users_by_capability($context, 'mod/htmlcert:manage', 'u.id'));
|
||||||
$certmanagers = array_merge($certmanagers, array_keys(get_admins()));
|
$certmanagers = array_merge($certmanagers, array_keys(get_admins()));
|
||||||
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
||||||
$conditionssql .= "AND NOT u.id $sql \n";
|
$conditionssql .= "AND NOT u.id $sql \n";
|
||||||
|
@ -359,6 +330,71 @@ class certificate {
|
||||||
return array($conditionssql, $conditionsparams);
|
return array($conditionssql, $conditionsparams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of certificates for a user.
|
||||||
|
*
|
||||||
|
* @param int $userid
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function get_number_of_certificates_for_user($userid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$sql = "SELECT COUNT(*)
|
||||||
|
FROM {htmlcert} c
|
||||||
|
INNER JOIN {htmlcert_issues} ci
|
||||||
|
ON c.id = ci.htmlcertid
|
||||||
|
WHERE ci.userid = :userid";
|
||||||
|
return $DB->count_records_sql($sql, array('userid' => $userid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the certificates for the user.
|
||||||
|
*
|
||||||
|
* @param int $userid
|
||||||
|
* @param int $limitfrom
|
||||||
|
* @param int $limitnum
|
||||||
|
* @param string $sort
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_certificates_for_user($userid, $limitfrom, $limitnum, $sort = '') {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (empty($sort)) {
|
||||||
|
$sort = 'ci.timecreated DESC';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT c.id, c.name, co.fullname as coursename, ci.code, ci.timecreated
|
||||||
|
FROM {htmlcert} c
|
||||||
|
INNER JOIN {htmlcert_issues} ci
|
||||||
|
ON c.id = ci.htmlcertid
|
||||||
|
INNER JOIN {course} co
|
||||||
|
ON c.course = co.id
|
||||||
|
WHERE ci.userid = :userid
|
||||||
|
ORDER BY $sort";
|
||||||
|
return $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issues a certificate to a user.
|
||||||
|
*
|
||||||
|
* @param int $certificateid The ID of the certificate
|
||||||
|
* @param int $userid The ID of the user to issue the certificate to
|
||||||
|
* @return int The ID of the issue
|
||||||
|
*/
|
||||||
|
public static function issue_certificate($certificateid, $userid) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$issue = new \stdClass();
|
||||||
|
$issue->userid = $userid;
|
||||||
|
$issue->htmlcertid = $certificateid;
|
||||||
|
$issue->code = self::generate_code();
|
||||||
|
$issue->emailed = 0;
|
||||||
|
$issue->timecreated = time();
|
||||||
|
|
||||||
|
// Insert the record into the database.
|
||||||
|
return $DB->insert_record('htmlcert_issues', $issue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a 10-digit code of random letters and numbers.
|
* Generates a 10-digit code of random letters and numbers.
|
||||||
*
|
*
|
||||||
|
@ -370,7 +406,7 @@ class certificate {
|
||||||
$uniquecodefound = false;
|
$uniquecodefound = false;
|
||||||
$code = random_string(10);
|
$code = random_string(10);
|
||||||
while (!$uniquecodefound) {
|
while (!$uniquecodefound) {
|
||||||
if (!$DB->record_exists('customcert_issues', array('code' => $code))) {
|
if (!$DB->record_exists('htmlcert_issues', array('code' => $code))) {
|
||||||
$uniquecodefound = true;
|
$uniquecodefound = true;
|
||||||
} else {
|
} else {
|
||||||
$code = random_string(10);
|
$code = random_string(10);
|
||||||
|
@ -379,62 +415,4 @@ class certificate {
|
||||||
|
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the report.
|
|
||||||
*
|
|
||||||
* @param \stdClass $customcert
|
|
||||||
* @param \stdClass $users the list of users who have had a customcert issued
|
|
||||||
* @param string $type
|
|
||||||
*/
|
|
||||||
public static function generate_report_file($customcert, $users, $type) {
|
|
||||||
global $CFG, $COURSE;
|
|
||||||
|
|
||||||
if ($type == 'ods') {
|
|
||||||
require_once($CFG->libdir . '/odslib.class.php');
|
|
||||||
$workbook = new \MoodleODSWorkbook('-');
|
|
||||||
} else if ($type == 'xls') {
|
|
||||||
require_once($CFG->libdir . '/excellib.class.php');
|
|
||||||
$workbook = new \MoodleExcelWorkbook('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = clean_filename($COURSE->shortname . ' ' . rtrim($customcert->name, '.') . '.' . $type);
|
|
||||||
|
|
||||||
// Send HTTP headers.
|
|
||||||
$workbook->send($filename);
|
|
||||||
|
|
||||||
// Creating the first worksheet.
|
|
||||||
$myxls = $workbook->add_worksheet(get_string('report', 'customcert'));
|
|
||||||
|
|
||||||
// Print names of all the fields.
|
|
||||||
$myxls->write_string(0, 0, get_string('lastname'));
|
|
||||||
$myxls->write_string(0, 1, get_string('firstname'));
|
|
||||||
$myxls->write_string(0, 2, get_string('idnumber'));
|
|
||||||
$myxls->write_string(0, 3, get_string('group'));
|
|
||||||
$myxls->write_string(0, 4, get_string('receiveddate', 'customcert'));
|
|
||||||
$myxls->write_string(0, 5, get_string('code', 'customcert'));
|
|
||||||
|
|
||||||
// Generate the data for the body of the spreadsheet.
|
|
||||||
$row = 1;
|
|
||||||
if ($users) {
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$myxls->write_string($row, 0, $user->lastname);
|
|
||||||
$myxls->write_string($row, 1, $user->firstname);
|
|
||||||
$studentid = (!empty($user->idnumber)) ? $user->idnumber : ' ';
|
|
||||||
$myxls->write_string($row, 2, $studentid);
|
|
||||||
$ug2 = '';
|
|
||||||
if ($usergrps = groups_get_all_groups($COURSE->id, $user->id)) {
|
|
||||||
foreach ($usergrps as $ug) {
|
|
||||||
$ug2 = $ug2 . $ug->name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$myxls->write_string($row, 3, $ug2);
|
|
||||||
$myxls->write_string($row, 4, userdate($user->timecreated));
|
|
||||||
$myxls->write_string($row, 5, $user->code);
|
|
||||||
$row++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Close the workbook.
|
|
||||||
$workbook->close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace mod_customcert;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/course/moodleform_mod.php');
|
|
||||||
require_once($CFG->dirroot . '/mod/customcert/includes/colourpicker.php');
|
|
||||||
|
|
||||||
\MoodleQuickForm::registerElementType('customcert_colourpicker',
|
|
||||||
$CFG->dirroot . '/mod/customcert/includes/colourpicker.php', 'MoodleQuickForm_customcert_colourpicker');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The form for handling editing a customcert element.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class edit_element_form extends \moodleform {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \mod_customcert\element The element object.
|
|
||||||
*/
|
|
||||||
protected $element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form definition.
|
|
||||||
*/
|
|
||||||
public function definition() {
|
|
||||||
$mform =& $this->_form;
|
|
||||||
|
|
||||||
$element = $this->_customdata['element'];
|
|
||||||
|
|
||||||
// Add the field for the name of the element, this is required for all elements.
|
|
||||||
$mform->addElement('text', 'name', get_string('elementname', 'customcert'));
|
|
||||||
$mform->setType('name', PARAM_TEXT);
|
|
||||||
$mform->setDefault('name', get_string('pluginname', 'customcertelement_' . $element->element));
|
|
||||||
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
|
||||||
$mform->addHelpButton('name', 'elementname', 'customcert');
|
|
||||||
|
|
||||||
$this->element = \mod_customcert\element::instance($element);
|
|
||||||
$this->element->render_form_elements($mform);
|
|
||||||
|
|
||||||
$this->add_action_buttons(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fill in the current page data for this customcert.
|
|
||||||
*/
|
|
||||||
public function definition_after_data() {
|
|
||||||
$this->element->definition_after_data($this->_form);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validation.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param array $files
|
|
||||||
* @return array the errors that were found
|
|
||||||
*/
|
|
||||||
public function validation($data, $files) {
|
|
||||||
return $this->element->validate_form_elements($data, $files);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,161 +14,76 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
namespace mod_customcert;
|
/**
|
||||||
|
* This file contains the form for handling the layout of the htmlcert instance.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/course/moodleform_mod.php');
|
require_once($CFG->dirroot . '/course/moodleform_mod.php');
|
||||||
require_once($CFG->dirroot . '/mod/customcert/includes/colourpicker.php');
|
|
||||||
|
|
||||||
\MoodleQuickForm::registerElementType('customcert_colourpicker',
|
|
||||||
$CFG->dirroot . '/mod/customcert/includes/colourpicker.php', 'MoodleQuickForm_customcert_colourpicker');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form for handling the layout of the customcert instance.
|
* The form for handling the layout of the htmlcert instance.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
class edit_form extends \moodleform {
|
class edit_form extends \moodleform {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The id of the template being used.
|
* @var int The id of the template being used.
|
||||||
*/
|
*/
|
||||||
protected $tid = null;
|
protected $tid = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The total number of pages for this cert.
|
|
||||||
*/
|
|
||||||
protected $numpages = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form definition.
|
* Form definition.
|
||||||
*/
|
*/
|
||||||
public function definition() {
|
public function definition() {
|
||||||
global $DB;
|
global $DB, $OUTPUT;
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
|
||||||
$mform->addElement('text', 'name', get_string('name', 'customcert'));
|
$mform->addElement('text', 'name', get_string('name', 'htmlcert'), 'maxlength="255"');
|
||||||
$mform->setType('name', PARAM_TEXT);
|
$mform->setType('name', PARAM_TEXT);
|
||||||
$mform->addRule('name', null, 'required');
|
$mform->addRule('name', null, 'required');
|
||||||
|
|
||||||
// Get the number of pages for this module.
|
$mform->addElement('textarea', 'html', get_string('html', 'htmlcert'));
|
||||||
if (isset($this->_customdata['tid'])) {
|
$mform->setType('html', PARAM_RAW);
|
||||||
$this->tid = $this->_customdata['tid'];
|
|
||||||
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->tid), 'sequence')) {
|
|
||||||
$this->numpages = count($pages);
|
|
||||||
foreach ($pages as $p) {
|
|
||||||
$this->add_customcert_page_elements($p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // Add a new template.
|
|
||||||
// Create a 'fake' page to display the elements on - not yet saved in the DB.
|
|
||||||
$page = new \stdClass();
|
|
||||||
$page->id = 0;
|
|
||||||
$page->sequence = 1;
|
|
||||||
$this->add_customcert_page_elements($page);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->closeHeaderBefore('addcertpage');
|
|
||||||
|
|
||||||
$mform->addElement('submit', 'addcertpage', get_string('addcertpage', 'customcert'));
|
|
||||||
|
|
||||||
$mform->closeHeaderBefore('submitbtn');
|
|
||||||
|
|
||||||
// Add the submit buttons.
|
// Add the submit buttons.
|
||||||
$group = array();
|
$group = array();
|
||||||
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
|
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
|
||||||
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert'));
|
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'htmlcert'), array(), false);
|
||||||
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
|
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
|
||||||
|
|
||||||
$mform->addElement('hidden', 'tid');
|
|
||||||
$mform->setType('tid', PARAM_INT);
|
|
||||||
$mform->setDefault('tid', $this->tid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill in the current page data for this customcert.
|
* Fill in the current page data for this htmlcert.
|
||||||
*/
|
*/
|
||||||
public function definition_after_data() {
|
public function definition_after_data() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$mform = $this->_form;
|
$mform = $this->_form;
|
||||||
|
|
||||||
// Check that we are updating a current customcert.
|
|
||||||
if ($this->tid) {
|
|
||||||
// Get the pages for this customcert.
|
|
||||||
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->tid))) {
|
|
||||||
// Loop through the pages.
|
|
||||||
foreach ($pages as $p) {
|
|
||||||
// Set the width.
|
|
||||||
$element = $mform->getElement('pagewidth_' . $p->id);
|
|
||||||
$element->setValue($p->width);
|
|
||||||
// Set the height.
|
|
||||||
$element = $mform->getElement('pageheight_' . $p->id);
|
|
||||||
$element->setValue($p->height);
|
|
||||||
// Set the left margin.
|
|
||||||
$element = $mform->getElement('pageleftmargin_' . $p->id);
|
|
||||||
$element->setValue($p->leftmargin);
|
|
||||||
// Set the right margin.
|
|
||||||
$element = $mform->getElement('pagerightmargin_' . $p->id);
|
|
||||||
$element->setValue($p->rightmargin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some basic validation.
|
* Some basic validation.
|
||||||
*
|
*
|
||||||
* @param $data
|
* @param array $data
|
||||||
* @param $files
|
* @param array $files
|
||||||
* @return array the errors that were found
|
* @return array the errors that were found
|
||||||
*/
|
*/
|
||||||
public function validation($data, $files) {
|
public function validation($data, $files) {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$errors = parent::validation($data, $files);
|
$errors = parent::validation($data, $files);
|
||||||
|
|
||||||
// Check that the template name does not already exist for another template.
|
if (\core_text::strlen($data['name']) > 255) {
|
||||||
if ($template = $DB->get_record('customcert_templates', array('name' => $data['name']))) {
|
$errors['name'] = get_string('nametoolong', 'htmlcert');
|
||||||
if (empty($data['tid']) || $template->id != $data['tid']) {
|
|
||||||
$errors['name'] = get_string('customcertnameexists', 'customcert');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go through the data and check any width, height or margin values.
|
|
||||||
foreach ($data as $key => $value) {
|
|
||||||
if (strpos($key, 'pagewidth_') !== false) {
|
|
||||||
$page = str_replace('pagewidth_', '', $key);
|
|
||||||
$widthid = 'pagewidth_' . $page;
|
|
||||||
// Validate that the width is a valid value.
|
|
||||||
if ((!isset($data[$widthid])) || (!is_numeric($data[$widthid])) || ($data[$widthid] <= 0)) {
|
|
||||||
$errors[$widthid] = get_string('invalidwidth', 'customcert');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strpos($key, 'pageheight_') !== false) {
|
|
||||||
$page = str_replace('pageheight_', '', $key);
|
|
||||||
$heightid = 'pageheight_' . $page;
|
|
||||||
// Validate that the height is a valid value.
|
|
||||||
if ((!isset($data[$heightid])) || (!is_numeric($data[$heightid])) || ($data[$heightid] <= 0)) {
|
|
||||||
$errors[$heightid] = get_string('invalidheight', 'customcert');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strpos($key, 'pageleftmargin_') !== false) {
|
|
||||||
// Validate that the left margin is a valid value.
|
|
||||||
if (isset($data[$key]) && ($data[$key] < 0)) {
|
|
||||||
$errors[$key] = get_string('invalidmargin', 'customcert');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strpos($key, 'pagerightmargin_') !== false) {
|
|
||||||
// Validate that the right margin is a valid value.
|
|
||||||
if (isset($data[$key]) && ($data[$key] < 0)) {
|
|
||||||
$errors[$key] = get_string('invalidmargin', 'customcert');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
|
@ -177,123 +92,28 @@ class edit_form extends \moodleform {
|
||||||
/**
|
/**
|
||||||
* Adds the page elements to the form.
|
* Adds the page elements to the form.
|
||||||
*
|
*
|
||||||
* @param \stdClass $page the customcert page
|
* @param \stdClass $page the htmlcert page
|
||||||
*/
|
*/
|
||||||
protected function add_customcert_page_elements($page) {
|
protected function add_htmlcert_page_elements($page) {
|
||||||
global $DB, $OUTPUT;
|
global $DB, $OUTPUT;
|
||||||
|
|
||||||
// Create the form object.
|
// Create the form object.
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
|
||||||
if ($this->numpages > 1) {
|
$editlink = '/mod/htmlcert/edit.php';
|
||||||
$mform->addElement('header', 'page_' . $page->id, get_string('page', 'customcert', $page->sequence));
|
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
|
||||||
}
|
|
||||||
|
|
||||||
$editlink = '/mod/customcert/edit.php';
|
$mform->addElement('text', 'pagewidth', get_string('width', 'htmlcert'));
|
||||||
$editlinkparams = array('tid' => $this->tid);
|
$mform->setType('pagewidth', PARAM_INT);
|
||||||
$editelementlink = '/mod/customcert/edit_element.php';
|
$mform->setDefault('pagewidth', '210');
|
||||||
$editelementlinkparams = array('tid' => $this->tid);
|
$mform->addRule('pagewidth', null, 'required', null, 'client');
|
||||||
|
$mform->addHelpButton('pagewidth', 'width', 'htmlcert');
|
||||||
|
|
||||||
// Place the ordering arrows.
|
$mform->addElement('text', 'pageheight', get_string('height', 'htmlcert'));
|
||||||
// Only display the move up arrow if it is not the first.
|
$mform->setType('pageheight', PARAM_INT);
|
||||||
if ($page->sequence > 1) {
|
$mform->setDefault('pageheight', '297');
|
||||||
$url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmoveup', 'aid' => $page->id));
|
$mform->addRule('pageheight', null, 'required', null, 'client');
|
||||||
$mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup'))));
|
$mform->addHelpButton('pageheight', 'height', 'htmlcert');
|
||||||
}
|
|
||||||
// Only display the move down arrow if it is not the last.
|
|
||||||
if ($page->sequence < $this->numpages) {
|
|
||||||
$url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmovedown', 'aid' => $page->id));
|
|
||||||
$mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->addElement('text', 'pagewidth_' . $page->id, get_string('width', 'customcert'));
|
|
||||||
$mform->setType('pagewidth_' . $page->id, PARAM_INT);
|
|
||||||
$mform->setDefault('pagewidth_' . $page->id, '210');
|
|
||||||
$mform->addRule('pagewidth_' . $page->id, null, 'required', null, 'client');
|
|
||||||
$mform->addHelpButton('pagewidth_' . $page->id, 'width', 'customcert');
|
|
||||||
|
|
||||||
$mform->addElement('text', 'pageheight_' . $page->id, get_string('height', 'customcert'));
|
|
||||||
$mform->setType('pageheight_' . $page->id, PARAM_INT);
|
|
||||||
$mform->setDefault('pageheight_' . $page->id, '297');
|
|
||||||
$mform->addRule('pageheight_' . $page->id, null, 'required', null, 'client');
|
|
||||||
$mform->addHelpButton('pageheight_' . $page->id, 'height', 'customcert');
|
|
||||||
|
|
||||||
$mform->addElement('text', 'pageleftmargin_' . $page->id, get_string('leftmargin', 'customcert'));
|
|
||||||
$mform->setType('pageleftmargin_' . $page->id, PARAM_INT);
|
|
||||||
$mform->setDefault('pageleftmargin_' . $page->id, 0);
|
|
||||||
$mform->addHelpButton('pageleftmargin_' . $page->id, 'leftmargin', 'customcert');
|
|
||||||
|
|
||||||
$mform->addElement('text', 'pagerightmargin_' . $page->id, get_string('rightmargin', 'customcert'));
|
|
||||||
$mform->setType('pagerightmargin_' . $page->id, PARAM_INT);
|
|
||||||
$mform->setDefault('pagerightmargin_' . $page->id, 0);
|
|
||||||
$mform->addHelpButton('pagerightmargin_' . $page->id, 'rightmargin', 'customcert');
|
|
||||||
|
|
||||||
$group = array();
|
|
||||||
$group[] = $mform->createElement('select', 'element_' . $page->id, '', element::get_available_types());
|
|
||||||
$group[] = $mform->createElement('submit', 'addelement_' . $page->id, get_string('addelement', 'customcert'));
|
|
||||||
$mform->addElement('group', 'elementgroup', '', $group, '', false);
|
|
||||||
|
|
||||||
// Check if there are elements to add.
|
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
|
||||||
// Get the total number of elements.
|
|
||||||
$numelements = count($elements);
|
|
||||||
// Create a table to display these elements.
|
|
||||||
$table = new \html_table();
|
|
||||||
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
|
||||||
$table->align = array('left', 'left', 'center');
|
|
||||||
// If we have more than one element then we can change the order, so add extra column for the up and down arrow.
|
|
||||||
if ($numelements > 1) {
|
|
||||||
$table->head[] = '';
|
|
||||||
$table->align[] = 'center';
|
|
||||||
}
|
|
||||||
// Loop through and add the elements to the table.
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
$row = new \html_table_row();
|
|
||||||
$row->cells[] = $element->name;
|
|
||||||
$row->cells[] = $element->element;
|
|
||||||
// Link to edit this element.
|
|
||||||
$link = new \moodle_url($editelementlink, $editelementlinkparams + array('id' => $element->id,
|
|
||||||
'action' => 'edit'));
|
|
||||||
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')));
|
|
||||||
// Link to delete the element.
|
|
||||||
$link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement',
|
|
||||||
'aid' => $element->id));
|
|
||||||
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')));
|
|
||||||
// Now display any moving arrows if they are needed.
|
|
||||||
if ($numelements > 1) {
|
|
||||||
// Only display the move up arrow if it is not the first.
|
|
||||||
$moveicons = '';
|
|
||||||
if ($element->sequence > 1) {
|
|
||||||
$url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emoveup',
|
|
||||||
'aid' => $element->id));
|
|
||||||
$moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup')));
|
|
||||||
}
|
|
||||||
// Only display the move down arrow if it is not the last.
|
|
||||||
if ($element->sequence < $numelements) {
|
|
||||||
$url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emovedown',
|
|
||||||
'aid' => $element->id));
|
|
||||||
$moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown')));
|
|
||||||
}
|
|
||||||
$icons .= $moveicons;
|
|
||||||
}
|
|
||||||
$row->cells[] = $icons;
|
|
||||||
$table->data[] = $row;
|
|
||||||
}
|
|
||||||
// Create link to order the elements.
|
|
||||||
$link = \html_writer::link(new \moodle_url('/mod/customcert/rearrange.php', array('pid' => $page->id)),
|
|
||||||
get_string('rearrangeelements', 'customcert'));
|
|
||||||
// Add the table to the form.
|
|
||||||
$mform->addElement('static', 'elements_' . $page->id, get_string('elements', 'customcert'), \html_writer::table($table)
|
|
||||||
. \html_writer::tag( 'div', $link, array('style' => 'text-align:right')));
|
|
||||||
$mform->addHelpButton('elements_' . $page->id, 'elements', 'customcert');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add option to delete this page if there is more than one page.
|
|
||||||
if ($this->numpages > 1) {
|
|
||||||
// Link to delete the element.
|
|
||||||
$deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id));
|
|
||||||
$deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'), array('href' => $deletelink->out(false), 'class' => 'deletebutton'));
|
|
||||||
$mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton')));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,269 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base class for the customcert elements.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace mod_customcert;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class element
|
|
||||||
*
|
|
||||||
* All customercert element plugins are based on this class.
|
|
||||||
*/
|
|
||||||
abstract class element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \stdClass $element The data for the element we are adding.
|
|
||||||
*/
|
|
||||||
public $element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param \stdClass $element the element data
|
|
||||||
*/
|
|
||||||
public function __construct($element) {
|
|
||||||
$this->element = clone($element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function renders the form elements when adding a customcert element.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param edit_element_form $mform the edit_form instance.
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
// Render the common elements.
|
|
||||||
element_helper::render_form_element_font($mform);
|
|
||||||
element_helper::render_form_element_colour($mform);
|
|
||||||
element_helper::render_form_element_position($mform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
// Loop through the properties of the element and set the values
|
|
||||||
// of the corresponding form element, if it exists.
|
|
||||||
foreach ($this->element as $property => $value) {
|
|
||||||
if ($mform->elementExists($property)) {
|
|
||||||
$element = $mform->getElement($property);
|
|
||||||
$element->setValue($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs validation on the element values.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param array $data the submitted data
|
|
||||||
* @param array $files the submitted files
|
|
||||||
* @return array the validation errors
|
|
||||||
*/
|
|
||||||
public function validate_form_elements($data, $files) {
|
|
||||||
// Array to return the errors.
|
|
||||||
$errors = array();
|
|
||||||
|
|
||||||
// Common validation methods.
|
|
||||||
$errors += element_helper::validate_form_element_colour($data);
|
|
||||||
$errors += element_helper::validate_form_element_position($data);
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles saving the form elements created by this element.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param \stdClass $data the form data
|
|
||||||
*/
|
|
||||||
public function save_form_elements($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Get the data from the form.
|
|
||||||
$element = new \stdClass();
|
|
||||||
$element->name = $data->name;
|
|
||||||
$element->data = $this->save_unique_data($data);
|
|
||||||
$element->font = (isset($data->font)) ? $data->font : null;
|
|
||||||
$element->size = (isset($data->size)) ? $data->size : null;
|
|
||||||
$element->colour = (isset($data->colour)) ? $data->colour : null;
|
|
||||||
$element->width = (isset($data->width)) ? $data->width : null;
|
|
||||||
$element->refpoint = (isset($data->refpoint)) ? $data->refpoint : null;
|
|
||||||
$element->timemodified = time();
|
|
||||||
|
|
||||||
// Check if we are updating, or inserting a new element.
|
|
||||||
if (!empty($this->element->id)) { // Must be updating a record in the database.
|
|
||||||
$element->id = $this->element->id;
|
|
||||||
$DB->update_record('customcert_elements', $element);
|
|
||||||
} else { // Must be adding a new one.
|
|
||||||
$element->element = $data->element;
|
|
||||||
$element->pageid = $data->pageid;
|
|
||||||
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
|
|
||||||
$element->timecreated = time();
|
|
||||||
$DB->insert_record('customcert_elements', $element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will handle how form data will be saved into the data column in the
|
|
||||||
* customcert_elements table.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param \stdClass $data the form data
|
|
||||||
* @return string the unique data to save
|
|
||||||
*/
|
|
||||||
public function save_unique_data($data) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This handles copying data from another element of the same type.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param \stdClass $data the form data
|
|
||||||
* @return bool returns true if the data was copied successfully, false otherwise
|
|
||||||
*/
|
|
||||||
public function copy_element($data) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* Must be overridden.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public abstract function render($pdf, $preview);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the element in html.
|
|
||||||
*
|
|
||||||
* Must be overridden.
|
|
||||||
*
|
|
||||||
* 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 abstract function render_html();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles deleting any data this element may have introduced.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @return bool success return true if deletion success, false otherwise
|
|
||||||
*/
|
|
||||||
public function delete() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
return $DB->delete_records('customcert_elements', array('id' => $this->element->id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is responsible for handling the restoration process of the element.
|
|
||||||
*
|
|
||||||
* For example, the function may save data that is related to another course module, this
|
|
||||||
* data will need to be updated if we are restoring the course as the course module id will
|
|
||||||
* be different in the new course.
|
|
||||||
*
|
|
||||||
* @param \restore_customcert_activity_task $restore
|
|
||||||
*/
|
|
||||||
public function after_restore($restore) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic getter for read only access.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*/
|
|
||||||
public function __get($name) {
|
|
||||||
if (property_exists($this->element, $name)) {
|
|
||||||
return $this->element->$name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an instance of the element class.
|
|
||||||
*
|
|
||||||
* @param \stdClass $element the element
|
|
||||||
* @return \mod_customcert\element|bool returns the instance of the element class, or false if element
|
|
||||||
* class does not exists.
|
|
||||||
*/
|
|
||||||
public static function instance($element) {
|
|
||||||
// Get the class name.
|
|
||||||
$classname = '\\customcertelement_' . $element->element . '\\element';
|
|
||||||
|
|
||||||
// Ensure the necessary class exists.
|
|
||||||
if (class_exists($classname)) {
|
|
||||||
return new $classname($element);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the list of possible elements to add.
|
|
||||||
*
|
|
||||||
* @return array the list of element types that can be used.
|
|
||||||
*/
|
|
||||||
public static function get_available_types() {
|
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
// Array to store the element types.
|
|
||||||
$options = array();
|
|
||||||
|
|
||||||
// Check that the directory exists.
|
|
||||||
$elementdir = "$CFG->dirroot/mod/customcert/element";
|
|
||||||
if (file_exists($elementdir)) {
|
|
||||||
// Get directory contents.
|
|
||||||
$elementfolders = new \DirectoryIterator($elementdir);
|
|
||||||
// Loop through the elements folder.
|
|
||||||
foreach ($elementfolders as $elementfolder) {
|
|
||||||
// If it is not a directory or it is '.' or '..', skip it.
|
|
||||||
if (!$elementfolder->isDir() || $elementfolder->isDot()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Check that the standard class exists, if not we do
|
|
||||||
// not want to display it as an option as it will not work.
|
|
||||||
$foldername = $elementfolder->getFilename();
|
|
||||||
// Get the class name.
|
|
||||||
$classname = '\\customcertelement_' . $foldername . '\\element';
|
|
||||||
// Ensure the necessary class exists.
|
|
||||||
if (class_exists($classname)) {
|
|
||||||
$component = "customcertelement_{$foldername}";
|
|
||||||
$options[$foldername] = get_string('pluginname', $component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\core_collator::asort($options);
|
|
||||||
return $options;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,312 +0,0 @@
|
||||||
<?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 useful functions related to elements.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace mod_customcert;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class helper.
|
|
||||||
*
|
|
||||||
* Provides useful functions related to elements.
|
|
||||||
*/
|
|
||||||
class element_helper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int the top-left of element
|
|
||||||
*/
|
|
||||||
const CUSTOMCERT_REF_POINT_TOPLEFT = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int the top-center of element
|
|
||||||
*/
|
|
||||||
const CUSTOMCERT_REF_POINT_TOPCENTER = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int the top-left of element
|
|
||||||
*/
|
|
||||||
const CUSTOMCERT_REF_POINT_TOPRIGHT = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common behaviour for rendering specified content on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param \mod_customcert\element $element the customcert element
|
|
||||||
* @param string $content the content to render
|
|
||||||
*/
|
|
||||||
public static function render_content($pdf, $element, $content) {
|
|
||||||
list($font, $attr) = \mod_customcert\element_helper::get_font($element);
|
|
||||||
$pdf->setFont($font, $attr, $element->size);
|
|
||||||
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->colour, $fontcolour);
|
|
||||||
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
|
|
||||||
|
|
||||||
$x = $element->posx;
|
|
||||||
$y = $element->posy;
|
|
||||||
$w = $element->width;
|
|
||||||
$refpoint = $element->refpoint;
|
|
||||||
$actualwidth = $pdf->GetStringWidth($content);
|
|
||||||
|
|
||||||
if ($w and $w < $actualwidth) {
|
|
||||||
$actualwidth = $w;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($refpoint) {
|
|
||||||
case self::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
|
||||||
$x = $element->posx - $actualwidth;
|
|
||||||
if ($x < 0) {
|
|
||||||
$x = 0;
|
|
||||||
$w = $element->posx;
|
|
||||||
} else {
|
|
||||||
$w = $actualwidth;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case self::CUSTOMCERT_REF_POINT_TOPCENTER:
|
|
||||||
$x = $element->posx - $actualwidth / 2;
|
|
||||||
if ($x < 0) {
|
|
||||||
$x = 0;
|
|
||||||
$w = $element->posx * 2;
|
|
||||||
} else {
|
|
||||||
$w = $actualwidth;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($w) {
|
|
||||||
$w += 0.0001;
|
|
||||||
}
|
|
||||||
$pdf->setCellPaddings(0, 0, 0, 0);
|
|
||||||
$pdf->writeHTMLCell($w, 0, $x, $y, $content, 0, 0, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common behaviour for rendering specified content on the drag and drop page.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\element $element the customcert element
|
|
||||||
* @param string $content the content to render
|
|
||||||
* @return string the html
|
|
||||||
*/
|
|
||||||
public static function render_html_content($element, $content) {
|
|
||||||
list($font, $attr) = \mod_customcert\element_helper::get_font($element);
|
|
||||||
$fontstyle = 'font-family: ' . $font;
|
|
||||||
if (strpos($attr, 'B') !== false) {
|
|
||||||
$fontstyle .= ': font-weight: bold';
|
|
||||||
}
|
|
||||||
if (strpos($attr, 'I') !== false) {
|
|
||||||
$fontstyle .= ': font-style: italic';
|
|
||||||
}
|
|
||||||
|
|
||||||
$style = $fontstyle . '; color: ' . $element->colour . '; font-size: ' . $element->size . 'pt;';
|
|
||||||
if ($element->width) {
|
|
||||||
$style .= ' width: ' . $element->width . 'mm';
|
|
||||||
}
|
|
||||||
return \html_writer::div($content, '', array('style' => $style));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to render the font elements.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
|
||||||
*/
|
|
||||||
public static function render_form_element_font($mform) {
|
|
||||||
$mform->addElement('select', 'font', get_string('font', 'customcert'), \mod_customcert\certificate::get_fonts());
|
|
||||||
$mform->setType('font', PARAM_TEXT);
|
|
||||||
$mform->setDefault('font', 'times');
|
|
||||||
$mform->addHelpButton('font', 'font', 'customcert');
|
|
||||||
$mform->addElement('select', 'size', get_string('fontsize', 'customcert'), \mod_customcert\certificate::get_font_sizes());
|
|
||||||
$mform->setType('size', PARAM_INT);
|
|
||||||
$mform->setDefault('size', 12);
|
|
||||||
$mform->addHelpButton('size', 'fontsize', 'customcert');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to render the colour elements.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
|
||||||
*/
|
|
||||||
public static function render_form_element_colour($mform) {
|
|
||||||
$mform->addElement('customcert_colourpicker', 'colour', get_string('fontcolour', 'customcert'));
|
|
||||||
$mform->setType('colour', PARAM_RAW); // Need to validate that this is a valid colour.
|
|
||||||
$mform->setDefault('colour', '#000000');
|
|
||||||
$mform->addHelpButton('colour', 'fontcolour', 'customcert');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to render the position elements.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance.
|
|
||||||
*/
|
|
||||||
public static function render_form_element_position($mform) {
|
|
||||||
$mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10));
|
|
||||||
$mform->setType('width', PARAM_INT);
|
|
||||||
$mform->setDefault('width', 0);
|
|
||||||
$mform->addHelpButton('width', 'elementwidth', 'customcert');
|
|
||||||
$refpointoptions = array();
|
|
||||||
$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_TOPRIGHT] = get_string('topright', 'customcert');
|
|
||||||
$mform->addElement('select', 'refpoint', get_string('refpoint', 'customcert'), $refpointoptions);
|
|
||||||
$mform->setType('refpoint', PARAM_INT);
|
|
||||||
$mform->setDefault('refpoint', self::CUSTOMCERT_REF_POINT_TOPCENTER);
|
|
||||||
$mform->addHelpButton('refpoint', 'refpoint', 'customcert');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to performs validation on the colour element.
|
|
||||||
*
|
|
||||||
* @param array $data the submitted data
|
|
||||||
* @return array the validation errors
|
|
||||||
*/
|
|
||||||
public static function validate_form_element_colour($data) {
|
|
||||||
$errors = array();
|
|
||||||
// Validate the colour.
|
|
||||||
if (!\mod_customcert\element_helper::validate_colour($data['colour'])) {
|
|
||||||
$errors['colour'] = get_string('invalidcolour', 'customcert');
|
|
||||||
}
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to performs validation on the position elements.
|
|
||||||
*
|
|
||||||
* @param array $data the submitted data
|
|
||||||
* @return array the validation errors
|
|
||||||
*/
|
|
||||||
public static function validate_form_element_position($data) {
|
|
||||||
$errors = array();
|
|
||||||
// Check if width is less than 0.
|
|
||||||
if (isset($data['width']) && $data['width'] < 0) {
|
|
||||||
$errors['width'] = get_string('invalidelementwidth', 'customcert');
|
|
||||||
}
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the font used for this element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\element $element the customcert element
|
|
||||||
* @return array the font and font attributes
|
|
||||||
*/
|
|
||||||
public static function get_font($element) {
|
|
||||||
// Variable for the font.
|
|
||||||
$font = $element->font;
|
|
||||||
// Get the last two characters of the font name.
|
|
||||||
$fontlength = strlen($font);
|
|
||||||
$lastchar = $font[$fontlength - 1];
|
|
||||||
$secondlastchar = $font[$fontlength - 2];
|
|
||||||
// The attributes of the font.
|
|
||||||
$attr = '';
|
|
||||||
// Check if the last character is 'i'.
|
|
||||||
if ($lastchar == 'i') {
|
|
||||||
// Remove the 'i' from the font name.
|
|
||||||
$font = substr($font, 0, -1);
|
|
||||||
// Check if the second last char is b.
|
|
||||||
if ($secondlastchar == 'b') {
|
|
||||||
// Remove the 'b' from the font name.
|
|
||||||
$font = substr($font, 0, -1);
|
|
||||||
$attr .= 'B';
|
|
||||||
}
|
|
||||||
$attr .= 'I';
|
|
||||||
} else if ($lastchar == 'b') {
|
|
||||||
// Remove the 'b' from the font name.
|
|
||||||
$font = substr($font, 0, -1);
|
|
||||||
$attr .= 'B';
|
|
||||||
}
|
|
||||||
return array($font, $attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the colour selected.
|
|
||||||
*
|
|
||||||
* @param string $colour
|
|
||||||
* @return bool returns true if the colour is valid, false otherwise
|
|
||||||
*/
|
|
||||||
public static function validate_colour($colour) {
|
|
||||||
// List of valid HTML colour names.
|
|
||||||
$colournames = array(
|
|
||||||
'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
|
|
||||||
'beige', 'bisque', 'black', 'blanchedalmond', 'blue',
|
|
||||||
'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse',
|
|
||||||
'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson',
|
|
||||||
'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray',
|
|
||||||
'darkgrey', 'darkgreen', 'darkkhaki', 'darkmagenta',
|
|
||||||
'darkolivegreen', 'darkorange', 'darkorchid', 'darkred',
|
|
||||||
'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray',
|
|
||||||
'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink',
|
|
||||||
'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick',
|
|
||||||
'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro',
|
|
||||||
'ghostwhite', 'gold', 'goldenrod', 'gray', 'grey', 'green',
|
|
||||||
'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo',
|
|
||||||
'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen',
|
|
||||||
'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
|
|
||||||
'lightgoldenrodyellow', 'lightgray', 'lightgrey', 'lightgreen',
|
|
||||||
'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue',
|
|
||||||
'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow',
|
|
||||||
'lime', 'limegreen', 'linen', 'magenta', 'maroon',
|
|
||||||
'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple',
|
|
||||||
'mediumseagreen', 'mediumslateblue', 'mediumspringgreen',
|
|
||||||
'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
|
|
||||||
'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive',
|
|
||||||
'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod',
|
|
||||||
'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip',
|
|
||||||
'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red',
|
|
||||||
'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown',
|
|
||||||
'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
|
|
||||||
'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan',
|
|
||||||
'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white',
|
|
||||||
'whitesmoke', 'yellow', 'yellowgreen'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (preg_match('/^#?([[:xdigit:]]{3}){1,2}$/', $colour)) {
|
|
||||||
return true;
|
|
||||||
} else if (in_array(strtolower($colour), $colournames)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function that returns the sequence on a specified customcert page for a
|
|
||||||
* newly created element.
|
|
||||||
*
|
|
||||||
* @param int $pageid the id of the page we are adding this element to
|
|
||||||
* @return int the element number
|
|
||||||
*/
|
|
||||||
public static function get_element_sequence($pageid) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Set the sequence of the element we are creating.
|
|
||||||
$sequence = 1;
|
|
||||||
// Check if there already elements that exist, if so, overwrite value.
|
|
||||||
$sql = "SELECT MAX(sequence) as maxsequence
|
|
||||||
FROM {customcert_elements}
|
|
||||||
WHERE pageid = :id";
|
|
||||||
// Get the current max sequence on this page and add 1 to get the new sequence.
|
|
||||||
if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) {
|
|
||||||
$sequence = $maxseq->maxsequence + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sequence;
|
|
||||||
}
|
|
||||||
}
|
|
37
classes/event/course_module_instance_list_viewed.php
Normal file
37
classes/event/course_module_instance_list_viewed.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?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 course module instance list viewed event class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\event;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The course module instance list viewed event class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
|
||||||
|
}
|
64
classes/event/course_module_viewed.php
Normal file
64
classes/event/course_module_viewed.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?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 course module viewed event class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\event;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The course module viewed event class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class course_module_viewed extends \core\event\course_module_viewed {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises the event.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data['objecttable'] = 'htmlcert';
|
||||||
|
parent::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public static function get_objectid_mapping() {
|
||||||
|
return array('db' => 'htmlcert', 'restore' => 'htmlcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function get_other_mapping() {
|
||||||
|
// No need to map.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
88
classes/external.php
Normal file
88
classes/external.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the external API for this tool.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
require_once("$CFG->libdir/externallib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the external API for this tool.
|
||||||
|
*
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class external extends \external_api {
|
||||||
|
/**
|
||||||
|
* 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 htmlcert 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('htmlcert', ['id' => $certificateid], '*', MUST_EXIST);
|
||||||
|
$issue = $DB->get_record('htmlcert_issues', ['id' => $issueid, 'htmlcertid' => $certificateid], '*', MUST_EXIST);
|
||||||
|
|
||||||
|
$cm = get_coursemodule_from_instance('htmlcert', $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/htmlcert:manage', $context);
|
||||||
|
|
||||||
|
// Delete the issue.
|
||||||
|
return $DB->delete_records('htmlcert_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');
|
||||||
|
}
|
||||||
|
}
|
108
classes/grade_information.php
Normal file
108
classes/grade_information.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the class that provides a grade object to be used by elements for display purposes.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class that provides a grade object to be used by elements for display purposes.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class grade_information {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The grade name.
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var float The raw grade.
|
||||||
|
*/
|
||||||
|
protected $grade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The grade to display
|
||||||
|
*/
|
||||||
|
protected $displaygrade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The date it was graded.
|
||||||
|
*/
|
||||||
|
protected $dategraded;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param float $grade
|
||||||
|
* @param string $displaygrade
|
||||||
|
* @param int $dategraded
|
||||||
|
*/
|
||||||
|
public function __construct($name, $grade, $displaygrade, $dategraded) {
|
||||||
|
$this->name = $name;
|
||||||
|
$this->grade = $grade;
|
||||||
|
$this->displaygrade = $displaygrade;
|
||||||
|
$this->dategraded = $dategraded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_name() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the raw grade.
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function get_grade() {
|
||||||
|
return $this->grade;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the display grade.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_displaygrade() {
|
||||||
|
return $this->displaygrade;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the date it was graded.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function get_dategraded() {
|
||||||
|
return $this->dategraded;
|
||||||
|
}
|
||||||
|
}
|
64
classes/helper.php
Normal file
64
classes/helper.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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_htmlcert
|
||||||
|
* @copyright 2021 Mark Nelson <mdjnelson@gmail.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
use core_user\fields;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class helper.
|
||||||
|
*
|
||||||
|
* Helper functionality for this module.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2021 Mark Nelson <mdjnelson@gmail.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,17 +14,24 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
namespace mod_customcert;
|
/**
|
||||||
|
* This file contains the form for loading htmlcert templates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
require_once($CFG->libdir . '/formslib.php');
|
require_once($CFG->libdir . '/formslib.php');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form for loading customcert templates.
|
* The form for loading htmlcert templates.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 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
|
||||||
*/
|
*/
|
||||||
|
@ -38,15 +45,33 @@ class load_template_form extends \moodleform {
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
|
||||||
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
|
// Get the context.
|
||||||
|
$context = $this->_customdata['context'];
|
||||||
|
$syscontext = \context_system::instance();
|
||||||
|
|
||||||
$templates = $DB->get_records_menu('customcert_templates',
|
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'htmlcert'));
|
||||||
array('contextid' => \CONTEXT_SYSTEM::instance()->id), 'name ASC', 'id, name');
|
|
||||||
|
|
||||||
$group = array();
|
// Display a link to the manage templates page.
|
||||||
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/htmlcert:manage', $syscontext)) {
|
||||||
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
|
$link = \html_writer::link(new \moodle_url('/mod/htmlcert/manage_templates.php'),
|
||||||
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
|
get_string('managetemplates', 'htmlcert'));
|
||||||
$mform->setType('ltid', PARAM_INT);
|
$mform->addElement('static', 'managetemplates', '', $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrtemplates = $DB->get_records_menu('htmlcert_templates', ['contextid' => $syscontext->id], 'name ASC', 'id, name');
|
||||||
|
if ($arrtemplates) {
|
||||||
|
$templates = [];
|
||||||
|
foreach ($arrtemplates as $key => $template) {
|
||||||
|
$templates[$key] = format_string($template, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
$group = array();
|
||||||
|
$group[] = $mform->createElement('select', 'ltid', '', $templates);
|
||||||
|
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'htmlcert'));
|
||||||
|
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
|
||||||
|
$mform->setType('ltid', PARAM_INT);
|
||||||
|
} else {
|
||||||
|
$msg = \html_writer::tag('div', get_string('notemplates', 'htmlcert'), array('class' => 'alert'));
|
||||||
|
$mform->addElement('static', 'notemplates', '', $msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
142
classes/manage_templates_table.php
Normal file
142
classes/manage_templates_table.php
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table that displays the templates in a given context.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die;
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
require_once($CFG->libdir . '/tablelib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for the table that displays the templates in a given context.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class manage_templates_table extends \table_sql {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \context $context
|
||||||
|
*/
|
||||||
|
protected $context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the table.
|
||||||
|
*
|
||||||
|
* @param \context $context
|
||||||
|
*/
|
||||||
|
public function __construct($context) {
|
||||||
|
parent::__construct('mod_htmlcert_manage_templates_table');
|
||||||
|
|
||||||
|
$columns = [
|
||||||
|
'name',
|
||||||
|
'actions'
|
||||||
|
];
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
get_string('name'),
|
||||||
|
''
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->define_columns($columns);
|
||||||
|
$this->define_headers($headers);
|
||||||
|
$this->collapsible(false);
|
||||||
|
$this->sortable(true);
|
||||||
|
|
||||||
|
$this->context = $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the name column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $template
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_name($template) {
|
||||||
|
return format_string($template->name, true, ['context' => $this->context]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the actions column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $template
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_actions($template) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
// Link to edit the template.
|
||||||
|
$editlink = new \moodle_url('/mod/htmlcert/edit.php', array('tid' => $template->id));
|
||||||
|
$editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit')));
|
||||||
|
|
||||||
|
// Link to duplicate the template.
|
||||||
|
$duplicatelink = new \moodle_url('/mod/htmlcert/manage_templates.php',
|
||||||
|
array(
|
||||||
|
'tid' => $template->id,
|
||||||
|
'action' => 'duplicate',
|
||||||
|
'sesskey' => sesskey()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$duplicateicon = $OUTPUT->action_icon($duplicatelink, new \pix_icon('t/copy', get_string('duplicate')), null,
|
||||||
|
array('class' => 'action-icon duplicate-icon'));
|
||||||
|
|
||||||
|
// Link to delete the template.
|
||||||
|
$deletelink = new \moodle_url('/mod/htmlcert/manage_templates.php',
|
||||||
|
array(
|
||||||
|
'tid' => $template->id,
|
||||||
|
'action' => 'delete',
|
||||||
|
'sesskey' => sesskey()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')), null,
|
||||||
|
array('class' => 'action-icon delete-icon'));
|
||||||
|
|
||||||
|
return $editicon . $duplicateicon . $deleteicon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the reader.
|
||||||
|
*
|
||||||
|
* @param int $pagesize size of page for paginated displayed table.
|
||||||
|
* @param bool $useinitialsbar do you want to use the initials bar.
|
||||||
|
*/
|
||||||
|
public function query_db($pagesize, $useinitialsbar = true) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$total = $DB->count_records('htmlcert_templates', array('contextid' => $this->context->id));
|
||||||
|
|
||||||
|
$this->pagesize($pagesize, $total);
|
||||||
|
|
||||||
|
$this->rawdata = $DB->get_records('htmlcert_templates', array('contextid' => $this->context->id),
|
||||||
|
$this->get_sql_sort(), '*', $this->get_page_start(), $this->get_page_size());
|
||||||
|
|
||||||
|
// Set initial bars.
|
||||||
|
if ($useinitialsbar) {
|
||||||
|
$this->initialbars($total > $pagesize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
184
classes/my_certificates_table.php
Normal file
184
classes/my_certificates_table.php
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The report that displays the certificates the user has throughout the site.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die;
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
require_once($CFG->libdir . '/tablelib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for the report that displays the certificates the user has throughout the site.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
class my_certificates_table extends \table_sql {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $userid The user id
|
||||||
|
*/
|
||||||
|
protected $userid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the table.
|
||||||
|
*
|
||||||
|
* @param int $userid
|
||||||
|
* @param string|null $download The file type, null if we are not downloading
|
||||||
|
*/
|
||||||
|
public function __construct($userid, $download = null) {
|
||||||
|
parent::__construct('mod_htmlcert_report_table');
|
||||||
|
|
||||||
|
$columns = array(
|
||||||
|
'name',
|
||||||
|
'coursename',
|
||||||
|
'timecreated',
|
||||||
|
'code'
|
||||||
|
);
|
||||||
|
$headers = array(
|
||||||
|
get_string('name'),
|
||||||
|
get_string('course'),
|
||||||
|
get_string('receiveddate', 'htmlcert'),
|
||||||
|
get_string('code', 'htmlcert')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if we were passed a filename, which means we want to download it.
|
||||||
|
if ($download) {
|
||||||
|
$this->is_downloading($download, 'htmlcert-report');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->is_downloading()) {
|
||||||
|
$columns[] = 'download';
|
||||||
|
$headers[] = get_string('file');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->define_columns($columns);
|
||||||
|
$this->define_headers($headers);
|
||||||
|
$this->collapsible(false);
|
||||||
|
$this->sortable(true);
|
||||||
|
$this->no_sorting('code');
|
||||||
|
$this->no_sorting('download');
|
||||||
|
$this->is_downloadable(true);
|
||||||
|
|
||||||
|
$this->userid = $userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the name column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $certificate
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_name($certificate) {
|
||||||
|
$cm = get_coursemodule_from_instance('htmlcert', $certificate->id);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
return format_string($certificate->name, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the course name column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $certificate
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_coursename($certificate) {
|
||||||
|
$cm = get_coursemodule_from_instance('htmlcert', $certificate->id);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
return format_string($certificate->coursename, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the certificate time created column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $certificate
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_timecreated($certificate) {
|
||||||
|
return userdate($certificate->timecreated);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the code column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $certificate
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_code($certificate) {
|
||||||
|
return $certificate->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the download column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $certificate
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_download($certificate) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$icon = new \pix_icon('download', get_string('download'), 'htmlcert');
|
||||||
|
$link = new \moodle_url('/mod/htmlcert/my_certificates.php',
|
||||||
|
array('userid' => $this->userid,
|
||||||
|
'certificateid' => $certificate->id,
|
||||||
|
'downloadcert' => '1'));
|
||||||
|
|
||||||
|
return $OUTPUT->action_link($link, '', new \popup_action('click', $link), null, $icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the reader.
|
||||||
|
*
|
||||||
|
* @param int $pagesize size of page for paginated displayed table.
|
||||||
|
* @param bool $useinitialsbar do you want to use the initials bar.
|
||||||
|
*/
|
||||||
|
public function query_db($pagesize, $useinitialsbar = true) {
|
||||||
|
$total = certificate::get_number_of_certificates_for_user($this->userid);
|
||||||
|
|
||||||
|
$this->pagesize($pagesize, $total);
|
||||||
|
|
||||||
|
$this->rawdata = certificate::get_certificates_for_user($this->userid, $this->get_page_start(),
|
||||||
|
$this->get_page_size(), $this->get_sql_sort());
|
||||||
|
|
||||||
|
// Set initial bars.
|
||||||
|
if ($useinitialsbar) {
|
||||||
|
$this->initialbars($total > $pagesize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download the data.
|
||||||
|
*/
|
||||||
|
public function download() {
|
||||||
|
\core\session\manager::write_close();
|
||||||
|
$total = certificate::get_number_of_certificates_for_user($this->userid);
|
||||||
|
$this->out($total, false);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,21 +15,32 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customcert module upgrade code.
|
* Email certificate as html renderer.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die;
|
namespace mod_htmlcert\output\email;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customcert module upgrade code.
|
* Email certificate as html renderer.
|
||||||
*
|
*
|
||||||
* @param int $oldversion the version we are upgrading from
|
* @package mod_htmlcert
|
||||||
* @return bool always true
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
function xmldb_customcert_upgrade($oldversion) {
|
class renderer extends \mod_htmlcert\output\renderer {
|
||||||
return true;
|
|
||||||
|
/**
|
||||||
|
* The template name for this renderer.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_template_name() {
|
||||||
|
return 'email_certificate_html';
|
||||||
|
}
|
||||||
}
|
}
|
46
classes/output/email/renderer_textemail.php
Normal file
46
classes/output/email/renderer_textemail.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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email certificate as text renderer.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\output\email;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email certificate as text renderer.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class renderer_textemail extends \mod_htmlcert\output\renderer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The template name for this renderer.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_template_name() {
|
||||||
|
return 'email_certificate_text';
|
||||||
|
}
|
||||||
|
}
|
118
classes/output/email_certificate.php
Normal file
118
classes/output/email_certificate.php
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email certificate renderable.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\output;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email certificate renderable.
|
||||||
|
*
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class email_certificate implements \renderable, \templatable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Are we emailing the student?
|
||||||
|
*/
|
||||||
|
public $isstudent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The name of the user who owns the certificate.
|
||||||
|
*/
|
||||||
|
public $userfullname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The course short name.
|
||||||
|
*/
|
||||||
|
public $courseshortname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The course full name.
|
||||||
|
*/
|
||||||
|
public $coursefullname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The certificate name.
|
||||||
|
*/
|
||||||
|
public $certificatename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int The course module id.
|
||||||
|
*/
|
||||||
|
public $cmid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param bool $isstudent Are we emailing the student?
|
||||||
|
* @param string $userfullname The name of the user who owns the certificate.
|
||||||
|
* @param string $courseshortname The short name of the course.
|
||||||
|
* @param string $coursefullname The full name of the course.
|
||||||
|
* @param string $certificatename The name of the certificate.
|
||||||
|
* @param string $cmid The course module id.
|
||||||
|
*/
|
||||||
|
public function __construct($isstudent, $userfullname, $courseshortname, $coursefullname, $certificatename, $cmid) {
|
||||||
|
$this->isstudent = $isstudent;
|
||||||
|
$this->userfullname = $userfullname;
|
||||||
|
$this->courseshortname = $courseshortname;
|
||||||
|
$this->coursefullname = $coursefullname;
|
||||||
|
$this->certificatename = $certificatename;
|
||||||
|
$this->cmid = $cmid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export this data so it can be used as the context for a mustache template.
|
||||||
|
*
|
||||||
|
* @param \renderer_base $renderer The render to be used for formatting the email
|
||||||
|
* @return \stdClass The data ready for use in a mustache template
|
||||||
|
*/
|
||||||
|
public function export_for_template(\renderer_base $renderer) {
|
||||||
|
$data = new \stdClass();
|
||||||
|
|
||||||
|
// Used for the body text.
|
||||||
|
$info = new \stdClass();
|
||||||
|
$info->userfullname = $this->userfullname;
|
||||||
|
$info->certificatename = $this->certificatename;
|
||||||
|
$info->courseshortname = $this->courseshortname;
|
||||||
|
$info->coursefullname = $this->coursefullname;
|
||||||
|
|
||||||
|
if ($this->isstudent) {
|
||||||
|
$data->emailgreeting = get_string('emailstudentgreeting', 'htmlcert', $this->userfullname);
|
||||||
|
$data->emailbody = get_string('emailstudentbody', 'htmlcert', $info);
|
||||||
|
$data->emailbodyplaintext = get_string('emailstudentbodyplaintext', 'htmlcert', $info);
|
||||||
|
$data->emailcertificatelink = new \moodle_url('/mod/htmlcert/view.php', array('id' => $this->cmid));
|
||||||
|
$data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'htmlcert');
|
||||||
|
} else {
|
||||||
|
$data->emailgreeting = get_string('emailnonstudentgreeting', 'htmlcert');
|
||||||
|
$data->emailbody = get_string('emailnonstudentbody', 'htmlcert', $info);
|
||||||
|
$data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'htmlcert', $info);
|
||||||
|
$data->emailcertificatelink = new \moodle_url('/mod/htmlcert/view.php', array('id' => $this->cmid));
|
||||||
|
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'htmlcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
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_htmlcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\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('htmlcert', $cmid);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
self::require_capability($cm, $context, 'mod/htmlcert:view');
|
||||||
|
|
||||||
|
// Set some variables we are going to be using.
|
||||||
|
$certificate = $DB->get_record('htmlcert', ['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_htmlcert', 'intro');
|
||||||
|
|
||||||
|
// Get any issues this person may have.
|
||||||
|
$issue = false;
|
||||||
|
if ($issues = $DB->get_records('htmlcert_issues', ['userid' => $USER->id, 'htmlcertid' => $certificate->id],
|
||||||
|
'timecreated DESC')) {
|
||||||
|
$issue = reset($issues);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredtimemet = true;
|
||||||
|
$canmanage = has_capability('mod/htmlcert:manage', $context);
|
||||||
|
if ($certificate->requiredtime && !$canmanage) {
|
||||||
|
if (\mod_htmlcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) {
|
||||||
|
$requiredtimemet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileurl = "";
|
||||||
|
if ($requiredtimemet) {
|
||||||
|
$fileurl = new \moodle_url('/mod/htmlcert/mobile/pluginfile.php', ['certificateid' => $certificate->id,
|
||||||
|
'userid' => $USER->id]);
|
||||||
|
$fileurl = $fileurl->out(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$showreport = false;
|
||||||
|
$groups = [];
|
||||||
|
$recipients = [];
|
||||||
|
if (has_capability('mod/htmlcert: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_htmlcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0);
|
||||||
|
foreach ($recipients as $recipient) {
|
||||||
|
$recipient->displayname = fullname($recipient);
|
||||||
|
$recipient->fileurl = new \moodle_url('/mod/htmlcert/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_htmlcert/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);
|
||||||
|
}
|
||||||
|
}
|
63
classes/output/renderer.php
Normal file
63
classes/output/renderer.php
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?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 renderer class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\output;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
use plugin_renderer_base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renderer class.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class renderer extends plugin_renderer_base {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the verify certificate results.
|
||||||
|
*
|
||||||
|
* Defer to template.
|
||||||
|
*
|
||||||
|
* @param \mod_htmlcert\output\verify_certificate_results $page
|
||||||
|
* @return string html for the page
|
||||||
|
*/
|
||||||
|
public function render_verify_certificate_results(verify_certificate_results $page) {
|
||||||
|
$data = $page->export_for_template($this);
|
||||||
|
return parent::render_from_template('mod_htmlcert/verify_certificate_results', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats the email used to send the certificate by the email_certificate_task.
|
||||||
|
*
|
||||||
|
* @param email_certificate $certificate The certificate to email
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function render_email_certificate(email_certificate $certificate) {
|
||||||
|
$data = $certificate->export_for_template($this);
|
||||||
|
return $this->render_from_template('mod_htmlcert/' . $this->get_template_name(), $data);
|
||||||
|
}
|
||||||
|
}
|
99
classes/output/verify_certificate_result.php
Normal file
99
classes/output/verify_certificate_result.php
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?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 class used to prepare a verification result for display.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\output;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
use renderable;
|
||||||
|
use templatable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to prepare a verification result for display.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class verify_certificate_result implements templatable, renderable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The URL to the user's profile.
|
||||||
|
*/
|
||||||
|
public $userprofileurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The user's fullname.
|
||||||
|
*/
|
||||||
|
public $userfullname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The URL to the course page.
|
||||||
|
*/
|
||||||
|
public $courseurl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The course's fullname.
|
||||||
|
*/
|
||||||
|
public $coursefullname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The certificate's name.
|
||||||
|
*/
|
||||||
|
public $certificatename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param \stdClass $result
|
||||||
|
*/
|
||||||
|
public function __construct($result) {
|
||||||
|
$cm = get_coursemodule_from_instance('htmlcert', $result->certificateid);
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
|
||||||
|
$this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid,
|
||||||
|
'course' => $result->courseid));
|
||||||
|
$this->userfullname = fullname($result);
|
||||||
|
$this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid));
|
||||||
|
$this->coursefullname = format_string($result->coursefullname, true, ['context' => $context]);
|
||||||
|
$this->certificatename = format_string($result->certificatename, true, ['context' => $context]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to export the renderer data in a format that is suitable for a mustache template.
|
||||||
|
*
|
||||||
|
* @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
|
||||||
|
* @return \stdClass|array
|
||||||
|
*/
|
||||||
|
public function export_for_template(\renderer_base $output) {
|
||||||
|
$result = new \stdClass();
|
||||||
|
$result->userprofileurl = $this->userprofileurl;
|
||||||
|
$result->userfullname = $this->userfullname;
|
||||||
|
$result->coursefullname = $this->coursefullname;
|
||||||
|
$result->courseurl = $this->courseurl;
|
||||||
|
$result->certificatename = $this->certificatename;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
89
classes/output/verify_certificate_results.php
Normal file
89
classes/output/verify_certificate_results.php
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
<?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 class used to prepare verification results for display.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert\output;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
use renderable;
|
||||||
|
use templatable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to prepare verification results for display.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class verify_certificate_results implements templatable, renderable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Was the code successfully verified?
|
||||||
|
*/
|
||||||
|
public $success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The message to display.
|
||||||
|
*/
|
||||||
|
public $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array The certificates issued with the matching code.
|
||||||
|
*/
|
||||||
|
public $issues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param \stdClass $result
|
||||||
|
*/
|
||||||
|
public function __construct($result) {
|
||||||
|
$this->success = $result->success;
|
||||||
|
if ($this->success) {
|
||||||
|
$this->message = get_string('verified', 'htmlcert');
|
||||||
|
} else {
|
||||||
|
$this->message = get_string('notverified', 'htmlcert');
|
||||||
|
}
|
||||||
|
$this->issues = $result->issues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to export the renderer data in a format that is suitable for a mustache template.
|
||||||
|
*
|
||||||
|
* @param \renderer_base $output Used to do a final render of any components that need to be rendered for export.
|
||||||
|
* @return \stdClass|array
|
||||||
|
*/
|
||||||
|
public function export_for_template(\renderer_base $output) {
|
||||||
|
$result = new \stdClass();
|
||||||
|
$result->success = $this->success;
|
||||||
|
$result->message = $this->message;
|
||||||
|
$result->issues = array();
|
||||||
|
foreach ($this->issues as $issue) {
|
||||||
|
$resultissue = new verify_certificate_result($issue);
|
||||||
|
$result->issues[] = $resultissue->export_for_template($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
/**
|
/**
|
||||||
* Provides useful functions related to setting up the page.
|
* Provides useful functions related to setting up the page.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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_htmlcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
* Class helper.
|
* Class helper.
|
||||||
*
|
*
|
||||||
* Provides useful functions.
|
* Provides useful functions.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class page_helper {
|
class page_helper {
|
||||||
|
|
||||||
|
@ -52,7 +56,7 @@ class page_helper {
|
||||||
$PAGE->set_pagelayout('admin');
|
$PAGE->set_pagelayout('admin');
|
||||||
$PAGE->set_heading($SITE->fullname);
|
$PAGE->set_heading($SITE->fullname);
|
||||||
|
|
||||||
$urloverride = new \moodle_url('/admin/settings.php?section=modsettingcustomcert');
|
$urloverride = new \moodle_url('/admin/settings.php?section=modsettinghtmlcert');
|
||||||
\navigation_node::override_active_url($urloverride);
|
\navigation_node::override_active_url($urloverride);
|
||||||
} else {
|
} else {
|
||||||
$PAGE->set_heading(format_string($COURSE->fullname));
|
$PAGE->set_heading(format_string($COURSE->fullname));
|
||||||
|
|
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_htmlcert.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
namespace mod_htmlcert\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_htmlcert.
|
||||||
|
*
|
||||||
|
* @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(
|
||||||
|
'htmlcert_issues',
|
||||||
|
[
|
||||||
|
'userid' => 'privacy:metadata:htmlcert_issues:userid',
|
||||||
|
'htmlcertid' => 'privacy:metadata:htmlcert_issues:htmlcertid',
|
||||||
|
'code' => 'privacy:metadata:htmlcert_issues:code',
|
||||||
|
'emailed' => 'privacy:metadata:htmlcert_issues:emailed',
|
||||||
|
'timecreated' => 'privacy:metadata:htmlcert_issues:timecreated',
|
||||||
|
],
|
||||||
|
'privacy:metadata:htmlcert_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 {htmlcert} htmlcert
|
||||||
|
ON htmlcert.id = cm.instance
|
||||||
|
INNER JOIN {htmlcert_issues} htmlcertissues
|
||||||
|
ON htmlcertissues.htmlcertid = htmlcert.id
|
||||||
|
WHERE htmlcertissues.userid = :userid";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'modulename' => 'htmlcert',
|
||||||
|
'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 htmlcertissues.userid
|
||||||
|
FROM {course_modules} cm
|
||||||
|
JOIN {modules} m
|
||||||
|
ON m.id = cm.module AND m.name = :modname
|
||||||
|
JOIN {htmlcert} htmlcert
|
||||||
|
ON htmlcert.id = cm.instance
|
||||||
|
JOIN {htmlcert_issues} htmlcertissues
|
||||||
|
ON htmlcertissues.htmlcertid = htmlcert.id
|
||||||
|
WHERE cm.id = :cmid";
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'cmid' => $context->instanceid,
|
||||||
|
'modname' => 'htmlcert',
|
||||||
|
];
|
||||||
|
|
||||||
|
$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 htmlcert activities associated with the above course modules.
|
||||||
|
$htmlcertidstocmids = self::get_htmlcert_ids_to_cmids_from_cmids($cmids);
|
||||||
|
|
||||||
|
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($htmlcertidstocmids), SQL_PARAMS_NAMED);
|
||||||
|
$params = array_merge($inparams, ['userid' => $user->id]);
|
||||||
|
$recordset = $DB->get_recordset_select('htmlcert_issues', "htmlcertid $insql AND userid = :userid",
|
||||||
|
$params, 'timecreated, id ASC');
|
||||||
|
self::recordset_loop_and_export($recordset, 'htmlcertid', [], function($carry, $record) {
|
||||||
|
$carry[] = [
|
||||||
|
'code' => $record->code,
|
||||||
|
'emailed' => transform::yesno($record->emailed),
|
||||||
|
'timecreated' => transform::datetime($record->timecreated)
|
||||||
|
];
|
||||||
|
return $carry;
|
||||||
|
}, function($htmlcertid, $data) use ($user, $htmlcertidstocmids) {
|
||||||
|
$context = \context_module::instance($htmlcertidstocmids[$htmlcertid]);
|
||||||
|
$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('htmlcert', $context->instanceid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$DB->delete_records('htmlcert_issues', ['htmlcertid' => $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('htmlcert_issues', ['htmlcertid' => $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('htmlcert', $context->instanceid);
|
||||||
|
if (!$cm) {
|
||||||
|
// Only htmlcert module will be handled.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userids = $userlist->get_userids();
|
||||||
|
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
|
||||||
|
|
||||||
|
$select = "htmlcertid = :htmlcertid AND userid $usersql";
|
||||||
|
$params = ['htmlcertid' => $cm->instance] + $userparams;
|
||||||
|
$DB->delete_records_select('htmlcert_issues', $select, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of htmlcert IDs mapped to their course module ID.
|
||||||
|
*
|
||||||
|
* @param array $cmids The course module IDs.
|
||||||
|
* @return array In the form of [$htmlcertid => $cmid].
|
||||||
|
*/
|
||||||
|
protected static function get_htmlcert_ids_to_cmids_from_cmids(array $cmids) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
|
||||||
|
$sql = "SELECT htmlcert.id, cm.id AS cmid
|
||||||
|
FROM {htmlcert} htmlcert
|
||||||
|
JOIN {modules} m
|
||||||
|
ON m.name = :modulename
|
||||||
|
JOIN {course_modules} cm
|
||||||
|
ON cm.instance = htmlcert.id
|
||||||
|
AND cm.module = m.id
|
||||||
|
WHERE cm.id $insql";
|
||||||
|
$params = array_merge($inparams, ['modulename' => 'htmlcert']);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
222
classes/report_table.php
Normal file
222
classes/report_table.php
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The report that displays issued certificates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die;
|
||||||
|
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
require_once($CFG->libdir . '/tablelib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for the report that displays issued certificates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class report_table extends \table_sql {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $htmlcertid The custom certificate id
|
||||||
|
*/
|
||||||
|
protected $htmlcertid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \stdClass $cm The course module.
|
||||||
|
*/
|
||||||
|
protected $cm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool $groupmode are we in group mode?
|
||||||
|
*/
|
||||||
|
protected $groupmode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the table.
|
||||||
|
*
|
||||||
|
* @param int $htmlcertid
|
||||||
|
* @param \stdClass $cm the course module
|
||||||
|
* @param bool $groupmode are we in group mode?
|
||||||
|
* @param string|null $download The file type, null if we are not downloading
|
||||||
|
*/
|
||||||
|
public function __construct($htmlcertid, $cm, $groupmode, $download = null) {
|
||||||
|
parent::__construct('mod_htmlcert_report_table');
|
||||||
|
|
||||||
|
$context = \context_module::instance($cm->id);
|
||||||
|
$extrafields = \core_user\fields::for_identity($context)->get_required_fields();
|
||||||
|
|
||||||
|
$columns = [];
|
||||||
|
$columns[] = 'fullname';
|
||||||
|
foreach ($extrafields as $extrafield) {
|
||||||
|
$columns[] = $extrafield;
|
||||||
|
}
|
||||||
|
$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', 'htmlcert');
|
||||||
|
$headers[] = get_string('code', 'htmlcert');
|
||||||
|
|
||||||
|
// Check if we were passed a filename, which means we want to download it.
|
||||||
|
if ($download) {
|
||||||
|
$this->is_downloading($download, 'htmlcert-report');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->is_downloading()) {
|
||||||
|
$columns[] = 'download';
|
||||||
|
$headers[] = get_string('file');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->is_downloading() && has_capability('mod/htmlcert:manage', $context)) {
|
||||||
|
$columns[] = 'actions';
|
||||||
|
$headers[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->define_columns($columns);
|
||||||
|
$this->define_headers($headers);
|
||||||
|
$this->collapsible(false);
|
||||||
|
$this->sortable(true);
|
||||||
|
$this->no_sorting('code');
|
||||||
|
$this->no_sorting('download');
|
||||||
|
$this->is_downloadable(true);
|
||||||
|
|
||||||
|
$this->htmlcertid = $htmlcertid;
|
||||||
|
$this->cm = $cm;
|
||||||
|
$this->groupmode = $groupmode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the fullname column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_fullname($user) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
if (!$this->is_downloading()) {
|
||||||
|
return $OUTPUT->user_picture($user) . ' ' . fullname($user);
|
||||||
|
} else {
|
||||||
|
return fullname($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the certificate time created column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_timecreated($user) {
|
||||||
|
return userdate($user->timecreated);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the code column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_code($user) {
|
||||||
|
return $user->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the download column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_download($user) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$icon = new \pix_icon('download', get_string('download'), 'htmlcert');
|
||||||
|
$link = new \moodle_url('/mod/htmlcert/view.php',
|
||||||
|
[
|
||||||
|
'id' => $this->cm->id,
|
||||||
|
'downloadissue' => $user->id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $OUTPUT->action_link($link, '', null, null, $icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the actions column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_actions($user) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$icon = new \pix_icon('i/delete', get_string('delete'));
|
||||||
|
$link = new \moodle_url('/mod/htmlcert/view.php',
|
||||||
|
[
|
||||||
|
'id' => $this->cm->id,
|
||||||
|
'deleteissue' => $user->issueid,
|
||||||
|
'sesskey' => sesskey()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $OUTPUT->action_icon($link, $icon, null, ['class' => 'action-icon delete-icon']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the reader.
|
||||||
|
*
|
||||||
|
* @param int $pagesize size of page for paginated displayed table.
|
||||||
|
* @param bool $useinitialsbar do you want to use the initials bar.
|
||||||
|
*/
|
||||||
|
public function query_db($pagesize, $useinitialsbar = true) {
|
||||||
|
$total = \mod_htmlcert\certificate::get_number_of_issues($this->htmlcertid, $this->cm, $this->groupmode);
|
||||||
|
|
||||||
|
$this->pagesize($pagesize, $total);
|
||||||
|
|
||||||
|
$this->rawdata = \mod_htmlcert\certificate::get_issues($this->htmlcertid, $this->groupmode, $this->cm,
|
||||||
|
$this->get_page_start(), $this->get_page_size(), $this->get_sql_sort());
|
||||||
|
|
||||||
|
// Set initial bars.
|
||||||
|
if ($useinitialsbar) {
|
||||||
|
$this->initialbars($total > $pagesize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download the data.
|
||||||
|
*/
|
||||||
|
public function download() {
|
||||||
|
\core\session\manager::write_close();
|
||||||
|
$total = \mod_htmlcert\certificate::get_number_of_issues($this->htmlcertid, $this->cm, $this->groupmode);
|
||||||
|
$this->out($total, false);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,13 +15,24 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition of sub-plugins.
|
* Search area for mod_htmlcert activities.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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_htmlcert\search;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$subplugins = array('customcertelement' => 'mod/customcert/element');
|
/**
|
||||||
|
* Search area for mod_htmlcert activities.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class activity extends \core_search\base_activity {
|
||||||
|
|
||||||
|
}
|
250
classes/task/email_certificate_task.php
Normal file
250
classes/task/email_certificate_task.php
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A scheduled task for emailing certificates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Kumi Systems e.U. <office@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
namespace mod_htmlcert\task;
|
||||||
|
|
||||||
|
use mod_htmlcert\helper;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A scheduled task for emailing certificates.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class email_certificate_task extends \core\task\scheduled_task {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a descriptive name for this task (shown to admins).
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_name() {
|
||||||
|
return get_string('taskemailcertificate', 'htmlcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute.
|
||||||
|
*/
|
||||||
|
public function execute() {
|
||||||
|
global $DB, $PAGE;
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
co.fullname as coursefullname, co.shortname as courseshortname
|
||||||
|
FROM {htmlcert} c
|
||||||
|
JOIN {htmlcert_templates} ct
|
||||||
|
ON c.templateid = ct.id
|
||||||
|
JOIN {course} co
|
||||||
|
ON c.course = co.id
|
||||||
|
WHERE (c.emailstudents = :emailstudents
|
||||||
|
OR c.emailteachers = :emailteachers
|
||||||
|
OR $emailotherslengthsql >= 3)";
|
||||||
|
if (!$htmlcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The renderers used for sending emails.
|
||||||
|
$htmlrenderer = $PAGE->get_renderer('mod_htmlcert', 'email', 'htmlemail');
|
||||||
|
$textrenderer = $PAGE->get_renderer('mod_htmlcert', 'email', 'textemail');
|
||||||
|
|
||||||
|
foreach ($customcerts as $customcert) {
|
||||||
|
|
||||||
|
// Get the context.
|
||||||
|
$context = \context::instance_by_id($htmlcert->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($htmlcert->courseshortname, true, array('context' => $context));
|
||||||
|
$coursefullname = format_string($htmlcert->coursefullname, true, array('context' => $context));
|
||||||
|
$certificatename = format_string($htmlcert->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 {htmlcert_issues} ci
|
||||||
|
JOIN {user} u
|
||||||
|
ON ci.userid = u.id
|
||||||
|
WHERE ci.htmlcertid = :htmlcertid";
|
||||||
|
$issuedusers = $DB->get_records_sql($sql, array('htmlcertid' => $htmlcert->id));
|
||||||
|
|
||||||
|
// Now, get a list of users who can access the certificate but have not yet.
|
||||||
|
$enrolledusers = get_enrolled_users(\context_course::instance($htmlcert->courseid), 'mod/htmlcert: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($htmlcert->courseid, $enroluser->id)->instances['htmlcert'][$htmlcert->id];
|
||||||
|
if (!$cm->uservisible) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't want to email those with the capability to manage the certificate.
|
||||||
|
if (has_capability('mod/htmlcert:manage', $context, $enroluser->id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only email those with the capability to receive the certificate.
|
||||||
|
if (!has_capability('mod/htmlcert:receiveissue', $context, $enroluser->id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that they have passed the required time.
|
||||||
|
if (!empty($htmlcert->requiredtime)) {
|
||||||
|
if (\mod_htmlcert\certificate::get_course_time($htmlcert->courseid,
|
||||||
|
$enroluser->id) < ($htmlcert->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('htmlcert_issues', 'id',
|
||||||
|
array('userid' => $enroluser->id, 'htmlcertid' => $htmlcert->id), IGNORE_MULTIPLE);
|
||||||
|
if (empty($issueid)) {
|
||||||
|
// Ok, issue them the certificate.
|
||||||
|
$issueid = \mod_htmlcert\certificate::issue_certificate($htmlcert->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.
|
||||||
|
foreach ($issuedusers as $key => $issueduser) {
|
||||||
|
if ($issueduser->emailed) {
|
||||||
|
unset($issuedusers[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are no users to email we can return early.
|
||||||
|
if (!$issuedusers) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a directory to store the PDF we will be sending.
|
||||||
|
$tempdir = make_temp_directory('certificate/attachment');
|
||||||
|
if (!$tempdir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, email the people we need to.
|
||||||
|
foreach ($issuedusers as $user) {
|
||||||
|
// Set up the user.
|
||||||
|
cron_setup_user($user);
|
||||||
|
|
||||||
|
$userfullname = fullname($user);
|
||||||
|
$info->userfullname = $userfullname;
|
||||||
|
|
||||||
|
// Now, get the PDF.
|
||||||
|
$template = new \stdClass();
|
||||||
|
$template->id = $htmlcert->templateid;
|
||||||
|
$template->name = $htmlcert->templatename;
|
||||||
|
$template->contextid = $htmlcert->contextid;
|
||||||
|
$template = new \mod_htmlcert\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 ($htmlcert->emailstudents) {
|
||||||
|
$renderable = new \mod_htmlcert\output\email_certificate(true, $userfullname, $courseshortname,
|
||||||
|
$coursefullname, $certificatename, $htmlcert->contextid);
|
||||||
|
|
||||||
|
$subject = get_string('emailstudentsubject', 'htmlcert', $info);
|
||||||
|
$message = $textrenderer->render($renderable);
|
||||||
|
$messagehtml = $htmlrenderer->render($renderable);
|
||||||
|
email_to_user($user, fullname($userfrom), html_entity_decode($subject), $message, $messagehtml,
|
||||||
|
$tempfile, $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($htmlcert->emailteachers) {
|
||||||
|
$renderable = new \mod_htmlcert\output\email_certificate(false, $userfullname, $courseshortname,
|
||||||
|
$coursefullname, $certificatename, $htmlcert->contextid);
|
||||||
|
|
||||||
|
$subject = get_string('emailnonstudentsubject', 'htmlcert', $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($htmlcert->emailothers)) {
|
||||||
|
$others = explode(',', $htmlcert->emailothers);
|
||||||
|
foreach ($others as $email) {
|
||||||
|
$email = trim($email);
|
||||||
|
if (validate_email($email)) {
|
||||||
|
$renderable = new \mod_htmlcert\output\email_certificate(false, $userfullname,
|
||||||
|
$courseshortname, $coursefullname, $certificatename, $htmlcert->contextid);
|
||||||
|
|
||||||
|
$subject = get_string('emailnonstudentsubject', 'htmlcert', $info);
|
||||||
|
$message = $textrenderer->render($renderable);
|
||||||
|
$messagehtml = $htmlrenderer->render($renderable);
|
||||||
|
|
||||||
|
$emailuser = new \stdClass();
|
||||||
|
$emailuser->id = -1;
|
||||||
|
$emailuser->email = $email;
|
||||||
|
email_to_user($emailuser, fullname($userfrom), html_entity_decode($subject), $message,
|
||||||
|
$messagehtml, $tempfile, $filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the field so that it is emailed.
|
||||||
|
$DB->set_field('htmlcert_issues', 'emailed', 1, array('id' => $user->issueid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,20 +15,27 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class represents a customcert template.
|
* Class represents a htmlcert template.
|
||||||
*
|
*
|
||||||
* @copyright 2015 Mark Nelson <markn@moodle.com>
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021-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_htmlcert;
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../vendor/autoload.php");
|
||||||
|
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||||
|
|
||||||
|
use mikehaertl\wkhtmlto\Pdf;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class represents a customcert template.
|
* Class represents a htmlcert template.
|
||||||
*
|
*
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021-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
|
||||||
*/
|
*/
|
||||||
class template {
|
class template {
|
||||||
|
@ -48,6 +55,8 @@ class template {
|
||||||
*/
|
*/
|
||||||
protected $contextid;
|
protected $contextid;
|
||||||
|
|
||||||
|
protected $html;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor.
|
* The constructor.
|
||||||
*
|
*
|
||||||
|
@ -57,6 +66,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,74 +80,10 @@ class template {
|
||||||
$savedata = new \stdClass();
|
$savedata = new \stdClass();
|
||||||
$savedata->id = $this->id;
|
$savedata->id = $this->id;
|
||||||
$savedata->name = $data->name;
|
$savedata->name = $data->name;
|
||||||
$savedata->timemodified= time();
|
$savedata->html = $data->html ?: $this->html;
|
||||||
|
$savedata->timemodified = time();
|
||||||
|
|
||||||
$DB->update_record('customcert_templates', $savedata);
|
$DB->update_record('htmlcert_templates', $savedata);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles adding another page to the template.
|
|
||||||
*
|
|
||||||
* @return int the id of the page
|
|
||||||
*/
|
|
||||||
public function add_page() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Set the page number to 1 to begin with.
|
|
||||||
$sequence = 1;
|
|
||||||
// Get the max page number.
|
|
||||||
$sql = "SELECT MAX(sequence) as maxpage
|
|
||||||
FROM {customcert_pages} cp
|
|
||||||
WHERE cp.templateid = :templateid";
|
|
||||||
if ($maxpage = $DB->get_record_sql($sql, array('templateid' => $this->id))) {
|
|
||||||
$sequence = $maxpage->maxpage + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// New page creation.
|
|
||||||
$page = new \stdClass();
|
|
||||||
$page->templateid = $this->id;
|
|
||||||
$page->width = '210';
|
|
||||||
$page->height = '297';
|
|
||||||
$page->sequence = $sequence;
|
|
||||||
$page->timecreated = time();
|
|
||||||
$page->timemodified = $page->timecreated;
|
|
||||||
|
|
||||||
// Insert the page.
|
|
||||||
return $DB->insert_record('customcert_pages', $page);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles saving page data.
|
|
||||||
*
|
|
||||||
* @param \stdClass $data the template data
|
|
||||||
*/
|
|
||||||
public function save_page($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Set the time to a variable.
|
|
||||||
$time = time();
|
|
||||||
|
|
||||||
// Get the existing pages and save the page data.
|
|
||||||
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $data->tid))) {
|
|
||||||
// Loop through existing pages.
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
// Get the name of the fields we want from the form.
|
|
||||||
$width = 'pagewidth_' . $page->id;
|
|
||||||
$height = 'pageheight_' . $page->id;
|
|
||||||
$leftmargin = 'pageleftmargin_' . $page->id;
|
|
||||||
$rightmargin = 'pagerightmargin_' . $page->id;
|
|
||||||
// Create the page data to update the DB with.
|
|
||||||
$p = new \stdClass();
|
|
||||||
$p->id = $page->id;
|
|
||||||
$p->width = $data->$width;
|
|
||||||
$p->height = $data->$height;
|
|
||||||
$p->leftmargin = $data->$leftmargin;
|
|
||||||
$p->rightmargin = $data->$rightmargin;
|
|
||||||
$p->timemodified = $time;
|
|
||||||
// Update the page.
|
|
||||||
$DB->update_record('customcert_pages', $p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,191 +92,113 @@ class template {
|
||||||
* @return bool return true if the deletion was successful, false otherwise
|
* @return bool return true if the deletion was successful, false otherwise
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
global $CFG, $DB;
|
global $DB;
|
||||||
|
|
||||||
// Delete the elements.
|
if (!$DB->delete_records('htmlcert_templates', array('id' => $this->id))) {
|
||||||
$sql = "SELECT e.*
|
|
||||||
FROM {customcert_elements} e
|
|
||||||
INNER JOIN {customcert_pages} p
|
|
||||||
ON e.pageid = p.id
|
|
||||||
WHERE p.templateid = :templateid";
|
|
||||||
if ($elements = $DB->get_records_sql($sql, array('templateid' => $this->id))) {
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
$e->delete();
|
|
||||||
} else {
|
|
||||||
// The plugin files are missing, so just remove the entry from the DB.
|
|
||||||
$DB->delete_records('customcert_elements', array('id' => $element->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the pages.
|
|
||||||
if (!$DB->delete_records('customcert_pages', array('templateid' => $this->id))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, finally delete the actual template.
|
|
||||||
if (!$DB->delete_records('customcert_templates', array('id' => $this->id))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles deleting a page from the template.
|
|
||||||
*
|
|
||||||
* @param int $pageid the template page
|
|
||||||
*/
|
|
||||||
public function delete_page($pageid) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Get the page.
|
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $pageid), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Delete this page.
|
|
||||||
$DB->delete_records('customcert_pages', array('id' => $page->id));
|
|
||||||
|
|
||||||
// The element may have some extra tasks it needs to complete to completely delete itself.
|
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id))) {
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
$e->delete();
|
|
||||||
} else {
|
|
||||||
// The plugin files are missing, so just remove the entry from the DB.
|
|
||||||
$DB->delete_records('customcert_elements', array('id' => $element->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we want to decrease the page number values of
|
|
||||||
// the pages that are greater than the page we deleted.
|
|
||||||
$sql = "UPDATE {customcert_pages}
|
|
||||||
SET sequence = sequence - 1
|
|
||||||
WHERE templateid = :templateid
|
|
||||||
AND sequence > :sequence";
|
|
||||||
$DB->execute($sql, array('templateid' => $this->id, 'sequence' => $page->sequence));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles deleting an element from the template.
|
|
||||||
*
|
|
||||||
* @param int $elementid the template page
|
|
||||||
*/
|
|
||||||
public function delete_element($elementid) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Ensure element exists and delete it.
|
|
||||||
$element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
$e->delete();
|
|
||||||
} else {
|
|
||||||
// The plugin files are missing, so just remove the entry from the DB.
|
|
||||||
$DB->delete_records('customcert_elements', array('id' => $elementid));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we want to decrease the sequence numbers of the elements
|
|
||||||
// that are greater than the element we deleted.
|
|
||||||
$sql = "UPDATE {customcert_elements}
|
|
||||||
SET sequence = sequence - 1
|
|
||||||
WHERE pageid = :pageid
|
|
||||||
AND sequence > :sequence";
|
|
||||||
$DB->execute($sql, array('pageid' => $element->pageid, 'sequence' => $element->sequence));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the PDF for the template.
|
* Generate the PDF for the template.
|
||||||
*
|
*
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
* @param bool $preview true if it is a preview, false otherwise
|
||||||
|
* @param int $userid the id of the user whose certificate we want to view
|
||||||
|
* @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.
|
||||||
*/
|
*/
|
||||||
public function generate_pdf($preview = false) {
|
public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB, $USER, $SITE;
|
||||||
|
|
||||||
require_once($CFG->libdir . '/pdflib.php');
|
if (empty($userid)) {
|
||||||
|
$user = $USER;
|
||||||
|
} else {
|
||||||
|
$user = \core_user::get_user($userid);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the pages for the template, there should always be at least one page for each template.
|
profile_load_data($user);
|
||||||
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) {
|
|
||||||
// Create the pdf object.
|
|
||||||
$pdf = new \pdf();
|
|
||||||
|
|
||||||
// If the template belongs to a certificate then we need to check what permissions we set for it.
|
$htmlcert = $DB->get_record('htmlcert', ['templateid' => $this->id]);
|
||||||
if ($protection = $DB->get_field('customcert', 'protection', array('templateid' => $this->id))) {
|
|
||||||
if (!empty($protection)) {
|
$pdf = new Pdf(array(
|
||||||
$protection = explode(', ', $protection);
|
"disable-smart-shrinking",
|
||||||
$pdf->SetProtection($protection);
|
"margin-bottom" => "0",
|
||||||
}
|
"margin-right" => "0",
|
||||||
|
"margin-left" => "0",
|
||||||
|
"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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$pdf->setPrintHeader(false);
|
if ($file) {
|
||||||
$pdf->setPrintFooter(false);
|
$location = make_request_directory() . '/target';
|
||||||
$pdf->SetTitle($this->name);
|
$content = $file->get_content();
|
||||||
$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, '.');
|
$html = str_replace("__PROFILEPIC__", 'data: ' . mime_content_type($file) . ';base64,' . $content, $html);
|
||||||
$filename = clean_filename($filename . '.pdf');
|
|
||||||
// Loop through the pages and display their content.
|
$html = str_replace("__NAME__", $user->firstname . " " . $user->lastname, $html);
|
||||||
foreach ($pages as $page) {
|
|
||||||
// Add the page to the PDF.
|
if ($preview) {
|
||||||
if ($page->width > $page->height) {
|
$code = \mod_htmlcert\certificate::generate_code();
|
||||||
$orientation = 'L';
|
} else {
|
||||||
} else {
|
$issue = $DB->get_record('htmlcert_issues', array('userid' => $user->id, 'htmlcertid' => $htmlcert->id),
|
||||||
$orientation = 'P';
|
'*', IGNORE_MULTIPLE);
|
||||||
}
|
$code = $issue->code;
|
||||||
$pdf->AddPage($orientation, array($page->width, $page->height));
|
}
|
||||||
$pdf->SetMargins($page->leftmargin, 0, $page->rightmargin);
|
|
||||||
// Get the elements for the page.
|
$html = str_replace("__CERTNUM__", $code, $html);
|
||||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
|
||||||
// Loop through and display.
|
$courseid = $htmlcert->course ?: $SITE->id;
|
||||||
foreach ($elements as $element) {
|
|
||||||
// Get an instance of the element class.
|
$course = get_course($courseid);
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
$coursename = $course->fullname;
|
||||||
$e->render($pdf, $preview);
|
|
||||||
}
|
$html = str_replace("__COURSE__", $coursename, $html);
|
||||||
}
|
|
||||||
}
|
$date = $issue->timecreated;
|
||||||
}
|
|
||||||
$pdf->Output($filename, 'D');
|
$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());
|
||||||
|
|
||||||
|
if ($return) {
|
||||||
|
return $pdf->toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles moving an item on a template.
|
* Handles copying this template into another.
|
||||||
*
|
*
|
||||||
* @param string $itemname the item we are moving
|
* @param int $copytotemplateid The template id to copy to
|
||||||
* @param int $itemid the id of the item
|
|
||||||
* @param string $direction the direction
|
|
||||||
*/
|
*/
|
||||||
public function move_item($itemname, $itemid, $direction) {
|
public function copy_to_template($copytotemplateid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$table = 'customcert_';
|
$copytotemplate = $DB->get_record('htmlcert_templates', array('id' => $copytotemplateid));
|
||||||
if ($itemname == 'page') {
|
$copytotemplate->html = $this->html;
|
||||||
$table .= 'pages';
|
$DB->update_record('htmlcert_templates', $copytotemplate);
|
||||||
} else { // Must be an element.
|
|
||||||
$table .= 'elements';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($moveitem = $DB->get_record($table, array('id' => $itemid))) {
|
|
||||||
// Check which direction we are going.
|
|
||||||
if ($direction == 'up') {
|
|
||||||
$sequence = $moveitem->sequence - 1;
|
|
||||||
} else { // Must be down.
|
|
||||||
$sequence = $moveitem->sequence + 1;
|
|
||||||
}
|
|
||||||
// Get the item we will be swapping with it.
|
|
||||||
$swapitem = $DB->get_record($table, array('sequence' => $sequence));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that there is an item to move, and an item to swap it with.
|
|
||||||
if ($moveitem && !empty($swapitem)) {
|
|
||||||
$DB->set_field($table, 'sequence', $swapitem->sequence, array('id' => $moveitem->id));
|
|
||||||
$DB->set_field($table, 'sequence', $moveitem->sequence, array('id' => $swapitem->id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,6 +219,10 @@ class template {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_html() {
|
||||||
|
return $this->html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the context id.
|
* Returns the context id.
|
||||||
*
|
*
|
||||||
|
@ -377,7 +249,7 @@ class template {
|
||||||
public function get_cm() {
|
public function get_cm() {
|
||||||
$context = $this->get_context();
|
$context = $this->get_context();
|
||||||
if ($context->contextlevel === CONTEXT_MODULE) {
|
if ($context->contextlevel === CONTEXT_MODULE) {
|
||||||
return get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST);
|
return get_coursemodule_from_id('htmlcert', $context->instanceid, 0, false, MUST_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -389,7 +261,7 @@ class template {
|
||||||
* @throws \required_capability_exception if the user does not have the necessary capabilities (ie. Fred)
|
* @throws \required_capability_exception if the user does not have the necessary capabilities (ie. Fred)
|
||||||
*/
|
*/
|
||||||
public function require_manage() {
|
public function require_manage() {
|
||||||
require_capability('mod/customcert:manage', $this->get_context());
|
require_capability('mod/htmlcert:manage', $this->get_context());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -397,7 +269,7 @@ class template {
|
||||||
*
|
*
|
||||||
* @param string $templatename the name of the template
|
* @param string $templatename the name of the template
|
||||||
* @param int $contextid the context id
|
* @param int $contextid the context id
|
||||||
* @return \mod_customcert\template the template object
|
* @return \mod_htmlcert\template the template object
|
||||||
*/
|
*/
|
||||||
public static function create($templatename, $contextid) {
|
public static function create($templatename, $contextid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
@ -407,8 +279,8 @@ class template {
|
||||||
$template->contextid = $contextid;
|
$template->contextid = $contextid;
|
||||||
$template->timecreated = time();
|
$template->timecreated = time();
|
||||||
$template->timemodified = $template->timecreated;
|
$template->timemodified = $template->timecreated;
|
||||||
$template->id = $DB->insert_record('customcert_templates', $template);
|
$template->id = $DB->insert_record('htmlcert_templates', $template);
|
||||||
|
|
||||||
return new \mod_customcert\template($template);
|
return new \mod_htmlcert\template($template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,16 +14,24 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
namespace mod_customcert;
|
/**
|
||||||
|
* This file contains the class that handles uploading files.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
require_once($CFG->libdir.'/formslib.php');
|
require_once($CFG->libdir.'/formslib.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles uploading files
|
* Handles uploading files.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 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
|
||||||
*/
|
*/
|
||||||
|
@ -43,21 +51,23 @@ class upload_image_form extends \moodleform {
|
||||||
'maxbytes' => $CFG->maxbytes,
|
'maxbytes' => $CFG->maxbytes,
|
||||||
'subdirs' => 1,
|
'subdirs' => 1,
|
||||||
'accepted_types' => 'image');
|
'accepted_types' => 'image');
|
||||||
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
|
$mform->addElement('filemanager', 'htmlcertimage', get_string('uploadimage', 'htmlcert'), '',
|
||||||
|
$this->filemanageroptions);
|
||||||
|
|
||||||
$this->add_action_buttons();
|
$this->add_action_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill in the current page data for this customcert.
|
* Fill in the current page data for this htmlcert.
|
||||||
*/
|
*/
|
||||||
public function definition_after_data() {
|
public function definition_after_data() {
|
||||||
$mform = $this->_form;
|
$mform = $this->_form;
|
||||||
|
|
||||||
// Editing existing instance - copy existing files into draft area.
|
// Editing existing instance - copy existing files into draft area.
|
||||||
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
|
$draftitemid = file_get_submitted_draft_itemid('htmlcertimage');
|
||||||
file_prepare_draft_area($draftitemid, \context_system::instance()->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
|
file_prepare_draft_area($draftitemid, \context_system::instance()->id, 'mod_htmlcert', 'image', 0,
|
||||||
$element = $mform->getElement('customcertimage');
|
$this->filemanageroptions);
|
||||||
|
$element = $mform->getElement('htmlcertimage');
|
||||||
$element->setValue($draftitemid);
|
$element->setValue($draftitemid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
68
classes/verify_certificate_form.php
Normal file
68
classes/verify_certificate_form.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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 files contains the form for verifying a certificate.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace mod_htmlcert;
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
|
require_once($CFG->libdir . '/formslib.php');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form for verifying a certificate.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class verify_certificate_form extends \moodleform {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form definition.
|
||||||
|
*/
|
||||||
|
public function definition() {
|
||||||
|
$mform =& $this->_form;
|
||||||
|
|
||||||
|
$mform->addElement('text', 'code', get_string('code', 'htmlcert'));
|
||||||
|
$mform->setType('code', PARAM_ALPHANUM);
|
||||||
|
|
||||||
|
$mform->addElement('submit', 'verify', get_string('verify', 'htmlcert'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validation.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param array $files
|
||||||
|
* @return array the errors that were found
|
||||||
|
*/
|
||||||
|
public function validation($data, $files) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($data['code'] === '') {
|
||||||
|
$errors['code'] = get_string('invalidcode', 'htmlcert');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
}
|
5
composer.json
Normal file
5
composer.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"mikehaertl/phpwkhtmltopdf": "^2.5"
|
||||||
|
}
|
||||||
|
}
|
160
composer.lock
generated
Normal file
160
composer.lock
generated
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
{
|
||||||
|
"_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": "7f2a6587c80faa77c0f646f7f2ea6165",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
121
db/access.php
121
db/access.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customcert module capability definition
|
* htmlcert module capability definition
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$capabilities = array(
|
$capabilities = array(
|
||||||
|
|
||||||
'mod/customcert:addinstance' => array(
|
'mod/htmlcert:addinstance' => array(
|
||||||
'riskbitmask' => RISK_XSS,
|
'riskbitmask' => RISK_XSS,
|
||||||
'captype' => 'write',
|
'captype' => 'write',
|
||||||
'contextlevel' => CONTEXT_COURSE,
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
@ -37,7 +37,7 @@ $capabilities = array(
|
||||||
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
),
|
),
|
||||||
|
|
||||||
'mod/customcert:view' => array(
|
'mod/htmlcert:view' => array(
|
||||||
|
|
||||||
'captype' => 'read',
|
'captype' => 'read',
|
||||||
'contextlevel' => CONTEXT_MODULE,
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
@ -49,14 +49,119 @@ $capabilities = array(
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
'mod/customcert:manage' => array(
|
'mod/htmlcert:manage' => array(
|
||||||
|
|
||||||
'captype' => 'write',
|
'captype' => 'write',
|
||||||
'contextlevel' => CONTEXT_COURSE, CONTEXT_SYSTEM,
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
'archetypes' => array(
|
'archetypes' => array(
|
||||||
'teacher' => CAP_ALLOW,
|
'teacher' => CAP_ALLOW,
|
||||||
'editingteacher' => CAP_ALLOW,
|
'editingteacher' => CAP_ALLOW,
|
||||||
'manager' => CAP_ALLOW
|
'manager' => CAP_ALLOW
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:receiveissue' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'student' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:viewreport' => array(
|
||||||
|
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'teacher' => CAP_ALLOW,
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:viewallcertificates' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_SYSTEM,
|
||||||
|
'archetypes' => array(
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:verifycertificate' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'teacher' => CAP_ALLOW,
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:verifyallcertificates' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_SYSTEM,
|
||||||
|
'archetypes' => array(
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:manageemailstudents' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:manageemailteachers' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:manageemailothers' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:manageverifyany' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:managerequiredtime' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
|
|
||||||
|
'mod/htmlcert:manageprotection' => array(
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="mod/customcert/db" VERSION="20150311" COMMENT="XMLDB file for Moodle mod/customcert"
|
<XMLDB PATH="mod/htmlcert/db" VERSION="20170530" COMMENT="XMLDB file for Moodle mod/htmlcert"
|
||||||
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"
|
||||||
>
|
>
|
||||||
<TABLES>
|
<TABLES>
|
||||||
<TABLE NAME="customcert" COMMENT="Defines customcerts">
|
<TABLE NAME="htmlcert" COMMENT="Defines htmlcerts">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<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"/>
|
||||||
|
@ -13,79 +13,46 @@
|
||||||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="intro" TYPE="text" LENGTH="small" 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="deliveryoption" TYPE="char" LENGTH="255" NOTNULL="false" 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="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="protection" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
<FIELD NAME="protection" TYPE="char" LENGTH="255" NOTNULL="true" 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"/>
|
||||||
</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 htmlcert"/>
|
||||||
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="customcert_template" REFFIELDS="id"/>
|
<KEY NAME="template" TYPE="foreign" FIELDS="templateid" REFTABLE="htmlcert_templates" REFFIELDS="id"/>
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
<TABLE NAME="customcert_templates" COMMENT="Stores each customcert template">
|
<TABLE NAME="htmlcert_templates" COMMENT="Stores each htmlcert template">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<FIELD NAME="name" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="html" TYPE="text" NOTNULL="false"/>
|
||||||
<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"/>
|
||||||
</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 htmlcert_template"/>
|
||||||
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
|
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
<TABLE NAME="customcert_issues" COMMENT="Stores each issue of a customcert">
|
<TABLE NAME="htmlcert_issues" COMMENT="Stores each issue of a htmlcert">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="customcertid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
<FIELD NAME="htmlcertid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
<FIELD NAME="code" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="code" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="emailed" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" 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"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_issues"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for htmlcert_issues"/>
|
||||||
<KEY NAME="customcert" TYPE="foreign" FIELDS="customcertid" REFTABLE="customcert" REFFIELDS="id"/>
|
<KEY NAME="htmlcert" TYPE="foreign" FIELDS="htmlcertid" REFTABLE="htmlcert" REFFIELDS="id"/>
|
||||||
</KEYS>
|
|
||||||
</TABLE>
|
|
||||||
<TABLE NAME="customcert_pages" COMMENT="Stores each page of a custom cert">
|
|
||||||
<FIELDS>
|
|
||||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
|
||||||
<FIELD NAME="templateid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="leftmargin" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="rightmargin" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" 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="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
</FIELDS>
|
|
||||||
<KEYS>
|
|
||||||
<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"/>
|
|
||||||
</KEYS>
|
|
||||||
</TABLE>
|
|
||||||
<TABLE NAME="customcert_elements" COMMENT="Stores the elements for a given page">
|
|
||||||
<FIELDS>
|
|
||||||
<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="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="element" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="font" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="size" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
|
|
||||||
<FIELD NAME="posx" 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="refpoint" TYPE="int" LENGTH="4" 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="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
|
||||||
</FIELDS>
|
|
||||||
<KEYS>
|
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for customcert_elements"/>
|
|
||||||
<KEY NAME="page" TYPE="foreign" FIELDS="pageid" REFTABLE="customcert_pages" REFFIELDS="id"/>
|
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
</TABLES>
|
</TABLES>
|
||||||
|
|
14
db/log.php
14
db/log.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,16 +17,16 @@
|
||||||
/**
|
/**
|
||||||
* Definition of log events
|
* Definition of log events
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$logs = array(
|
$logs = array(
|
||||||
array('module' => 'customcert', 'action' => 'view', 'mtable' => 'customcert', 'field' => 'name'),
|
array('module' => 'htmlcert', 'action' => 'view', 'mtable' => 'htmlcert', 'field' => 'name'),
|
||||||
array('module' => 'customcert', 'action' => 'add', 'mtable' => 'customcert', 'field' => 'name'),
|
array('module' => 'htmlcert', 'action' => 'add', 'mtable' => 'htmlcert', 'field' => 'name'),
|
||||||
array('module' => 'customcert', 'action' => 'update', 'mtable' => 'customcert', 'field' => 'name'),
|
array('module' => 'htmlcert', 'action' => 'update', 'mtable' => 'htmlcert', 'field' => 'name'),
|
||||||
array('module' => 'customcert', 'action' => 'received', 'mtable' => 'customcert', 'field' => 'name'),
|
array('module' => 'htmlcert', 'action' => 'received', 'mtable' => 'htmlcert', 'field' => 'name'),
|
||||||
);
|
);
|
||||||
|
|
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_htmlcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
$addons = [
|
||||||
|
'mod_htmlcert' => [ // Plugin identifier.
|
||||||
|
'handlers' => [ // Different places where the plugin will display content.
|
||||||
|
'issueview' => [ // Handler unique name.
|
||||||
|
'displaydata' => [
|
||||||
|
'icon' => $CFG->wwwroot . '/mod/htmlcert/pix/icon.png',
|
||||||
|
'class' => 'core-course-module-htmlcert-handler',
|
||||||
|
],
|
||||||
|
'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin).
|
||||||
|
'method' => 'mobile_view_activity', // Main function in \mod_htmlcert\output\mobile.
|
||||||
|
'styles' => [
|
||||||
|
'url' => '/mod/htmlcert/mobile/styles.css',
|
||||||
|
'version' => 1
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'lang' => [ // Language strings that are used in all the handlers.
|
||||||
|
['deleteissueconfirm', 'htmlcert'],
|
||||||
|
['gethtmlcert', 'htmlcert'],
|
||||||
|
['listofissues', 'htmlcert'],
|
||||||
|
['nothingtodisplay', 'moodle'],
|
||||||
|
['notissued', 'htmlcert'],
|
||||||
|
['pluginname', 'htmlcert'],
|
||||||
|
['receiveddate', 'htmlcert'],
|
||||||
|
['requiredtimenotmet', 'htmlcert'],
|
||||||
|
['selectagroup', 'moodle']
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
53
db/services.php
Normal file
53
db/services.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web service for mod htmlcert.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
$functions = array(
|
||||||
|
'mod_htmlcert_delete_issue' => array(
|
||||||
|
'classname' => 'mod_htmlcert\external',
|
||||||
|
'methodname' => 'delete_issue',
|
||||||
|
'classpath' => '',
|
||||||
|
'description' => 'Delete an issue for a certificate',
|
||||||
|
'type' => 'write',
|
||||||
|
'ajax' => true,
|
||||||
|
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
|
||||||
|
),
|
||||||
|
'mod_htmlcert_save_element' => array(
|
||||||
|
'classname' => 'mod_htmlcert\external',
|
||||||
|
'methodname' => 'save_element',
|
||||||
|
'classpath' => '',
|
||||||
|
'description' => 'Saves data for an element',
|
||||||
|
'type' => 'write',
|
||||||
|
'ajax' => true
|
||||||
|
),
|
||||||
|
'mod_htmlcert_get_element_html' => array(
|
||||||
|
'classname' => 'mod_htmlcert\external',
|
||||||
|
'methodname' => 'get_element_html',
|
||||||
|
'classpath' => '',
|
||||||
|
'description' => 'Returns the HTML to display for an element',
|
||||||
|
'type' => 'read',
|
||||||
|
'ajax' => true
|
||||||
|
),
|
||||||
|
);
|
|
@ -15,26 +15,24 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subplugin info class.
|
* Definition of htmlcert scheduled tasks.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @category task
|
||||||
|
* @copyright 2017 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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\plugininfo;
|
|
||||||
|
|
||||||
use core\plugininfo\base;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
class customcertelement extends base {
|
$tasks = array(
|
||||||
|
array(
|
||||||
/**
|
'classname' => 'mod_htmlcert\task\email_certificate_task',
|
||||||
* Do not allow users to uninstall these plugins as it could cause customcerts to break.
|
'blocking' => 0,
|
||||||
*
|
'minute' => '*',
|
||||||
* @return bool
|
'hour' => '*',
|
||||||
*/
|
'day' => '*',
|
||||||
public function is_uninstall_allowed() {
|
'month' => '*',
|
||||||
return false;
|
'dayofweek' => '*'
|
||||||
}
|
)
|
||||||
}
|
);
|
185
edit.php
185
edit.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit the customcert settings.
|
* Edit the htmlcert settings.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -34,198 +34,85 @@ $confirm = optional_param('confirm', 0, PARAM_INT);
|
||||||
// Edit an existing template.
|
// Edit an existing template.
|
||||||
if ($tid) {
|
if ($tid) {
|
||||||
// Create the template object.
|
// Create the template object.
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
||||||
$template = new \mod_customcert\template($template);
|
$template = new \mod_htmlcert\template($template);
|
||||||
// Set the context.
|
// Set the context.
|
||||||
$contextid = $template->get_contextid();
|
$contextid = $template->get_contextid();
|
||||||
// Set the page url.
|
// Set the page url.
|
||||||
$pageurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $tid));
|
||||||
} else { // Adding a new template.
|
} else { // Adding a new template.
|
||||||
// Need to supply the contextid.
|
// Need to supply the contextid.
|
||||||
$contextid = required_param('contextid', PARAM_INT);
|
$contextid = required_param('contextid', PARAM_INT);
|
||||||
// Set the page url.
|
// Set the page url.
|
||||||
$pageurl = new moodle_url('/mod/customcert/edit.php', array('contextid' => $contextid));
|
$pageurl = new moodle_url('/mod/htmlcert/edit.php', array('contextid' => $contextid));
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = context::instance_by_id($contextid);
|
$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('htmlcert', $context->instanceid, 0, false, MUST_EXIST);
|
||||||
require_login($cm->course, false, $cm);
|
require_login($cm->course, false, $cm);
|
||||||
|
|
||||||
|
$htmlcert = $DB->get_record('htmlcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$title = $htmlcert->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/htmlcert:manage', $context);
|
||||||
|
|
||||||
// Set up the page.
|
// Set up the page.
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('editcustomcert', 'customcert'));
|
\mod_htmlcert\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', 'htmlcert'),
|
||||||
new moodle_url('/mod/customcert/manage_templates.php'));
|
new moodle_url('/mod/htmlcert/manage_templates.php'));
|
||||||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
|
if (!$tid) {
|
||||||
}
|
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'));
|
||||||
|
} else {
|
||||||
// The form for loading a customcert templates.
|
$PAGE->navbar->add(get_string('edithtmlcert', 'htmlcert'),
|
||||||
if ($tid && $DB->count_records('customcert_templates', array('contextid' => CONTEXT_SYSTEM::instance()->id)) > 0) {
|
new moodle_url('/mod/htmlcert/edit.php', ['tid' => $tid]));
|
||||||
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
|
|
||||||
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flag to determine if we are deleting anything.
|
|
||||||
$deleting = false;
|
|
||||||
|
|
||||||
if ($tid) {
|
|
||||||
switch ($action) {
|
|
||||||
case 'pmoveup' :
|
|
||||||
$template->move_item('page', $actionid, 'up');
|
|
||||||
break;
|
|
||||||
case 'pmovedown' :
|
|
||||||
$template->move_item('page', $actionid, 'down');
|
|
||||||
break;
|
|
||||||
case 'emoveup' :
|
|
||||||
$template->move_item('element', $actionid, 'up');
|
|
||||||
break;
|
|
||||||
case 'emovedown' :
|
|
||||||
$template->move_item('element', $actionid, 'down');
|
|
||||||
break;
|
|
||||||
case 'deletepage' :
|
|
||||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
|
||||||
$template->delete_page($actionid);
|
|
||||||
} else {
|
|
||||||
// Set deletion flag to true.
|
|
||||||
$deleting = true;
|
|
||||||
// Create the message.
|
|
||||||
$message = get_string('deletepageconfirm', 'customcert');
|
|
||||||
// Create the link options.
|
|
||||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
|
||||||
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
|
|
||||||
'action' => 'deletepage',
|
|
||||||
'aid' => $actionid,
|
|
||||||
'confirm' => 1,
|
|
||||||
'sesskey' => sesskey()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'deleteelement' :
|
|
||||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
|
||||||
$template->delete_element($actionid);
|
|
||||||
} else {
|
|
||||||
// Set deletion flag to true.
|
|
||||||
$deleting = true;
|
|
||||||
// Create the message.
|
|
||||||
$message = get_string('deleteelementconfirm', 'customcert');
|
|
||||||
// Create the link options.
|
|
||||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
|
||||||
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
|
|
||||||
'action' => 'deleteelement',
|
|
||||||
'aid' => $actionid,
|
|
||||||
'confirm' => 1,
|
|
||||||
'sesskey' => sesskey()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are deleting either a page or an element.
|
|
||||||
if ($deleting) {
|
|
||||||
// Show a confirmation page.
|
|
||||||
$strheading = get_string('deleteconfirm', 'customcert');
|
|
||||||
$PAGE->navbar->add($strheading);
|
|
||||||
$PAGE->set_title($strheading);
|
|
||||||
echo $OUTPUT->header();
|
|
||||||
echo $OUTPUT->heading($strheading);
|
|
||||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
|
||||||
echo $OUTPUT->footer();
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($tid) {
|
if ($tid) {
|
||||||
$mform = new \mod_customcert\edit_form($pageurl, array('tid' => $tid));
|
$mform = new \mod_htmlcert\edit_form($pageurl, array('tid' => $tid));
|
||||||
// Set the name for the form.
|
// Set the name for the form.
|
||||||
$mform->set_data(array('name' => $template->get_name()));
|
$mform->set_data(array('name' => $template->get_name(), 'html' => ''));
|
||||||
} else {
|
} else {
|
||||||
$mform = new \mod_customcert\edit_form($pageurl);
|
$mform = new \mod_htmlcert\edit_form($pageurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data = $mform->get_data()) {
|
if ($data = $mform->get_data()) {
|
||||||
// If there is no id, then we are creating a template.
|
// If there is no id, then we are creating a template.
|
||||||
if (!$tid) {
|
if (!$tid) {
|
||||||
$template = \mod_customcert\template::create($data->name, $contextid);
|
$template = \mod_htmlcert\template::create($data->name, $contextid);
|
||||||
|
|
||||||
// Create a page for this template.
|
|
||||||
$pageid = $template->add_page();
|
|
||||||
|
|
||||||
// Associate all the data from the form to the newly created page.
|
|
||||||
$width = 'pagewidth_' . $pageid;
|
|
||||||
$height = 'pageheight_' . $pageid;
|
|
||||||
$leftmargin = 'pageleftmargin_' . $pageid;
|
|
||||||
$rightmargin = 'pagerightmargin_' . $pageid;
|
|
||||||
$rightmargin = 'pagerightmargin_' . $pageid;
|
|
||||||
|
|
||||||
$data->$width = $data->pagewidth_0;
|
|
||||||
$data->$height = $data->pageheight_0;
|
|
||||||
$data->$leftmargin = $data->pageleftmargin_0;
|
|
||||||
$data->$rightmargin = $data->pagerightmargin_0;
|
|
||||||
|
|
||||||
// We may also have clicked to add an element, so these need changing as well.
|
|
||||||
if (isset($data->element_0) && isset($data->addelement_0)) {
|
|
||||||
$element = 'element_' . $pageid;
|
|
||||||
$addelement = 'addelement_' . $pageid;
|
|
||||||
$data->$element = $data->element_0;
|
|
||||||
$data->$addelement = $data->addelement_0;
|
|
||||||
|
|
||||||
// Need to remove the temporary element and add element placeholders so we
|
|
||||||
// don't try add an element to the wrong page.
|
|
||||||
unset($data->element_0);
|
|
||||||
unset($data->addelement_0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save any data for the template.
|
// Save any data for the template.
|
||||||
$template->save($data);
|
$template->save($data);
|
||||||
|
|
||||||
// Save any page data.
|
|
||||||
$template->save_page($data);
|
|
||||||
|
|
||||||
// Check if we are adding a page.
|
|
||||||
if (!empty($data->addcertpage)) {
|
|
||||||
$template->add_page();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through the data.
|
|
||||||
foreach ($data as $key => $value) {
|
|
||||||
// Check if they chose to add an element to a page.
|
|
||||||
if (strpos($key, 'addelement_') !== false) {
|
|
||||||
// Get the page id.
|
|
||||||
$pageid = str_replace('addelement_', '', $key);
|
|
||||||
// Get the element.
|
|
||||||
$element = "element_" . $pageid;
|
|
||||||
$element = $data->$element;
|
|
||||||
// Create the URL to redirect to to add this element.
|
|
||||||
$params = array();
|
|
||||||
$params['tid'] = $template->get_id();
|
|
||||||
$params['action'] = 'add';
|
|
||||||
$params['element'] = $element;
|
|
||||||
$params['pageid'] = $pageid;
|
|
||||||
$url = new moodle_url('/mod/customcert/edit_element.php', $params);
|
|
||||||
redirect($url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we want to preview this custom certificate.
|
// Check if we want to preview this custom certificate.
|
||||||
if (!empty($data->previewbtn)) {
|
if (!empty($data->previewbtn)) {
|
||||||
$template->generate_pdf(true);
|
$template->generate_pdf(true);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to the editing page to show form with recent updates.
|
// Redirect to the editing page to show form with recent updates.
|
||||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id()));
|
$url = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $template->get_id()));
|
||||||
redirect($url);
|
redirect($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
echo $OUTPUT->heading($heading);
|
||||||
$mform->display();
|
$mform->display();
|
||||||
if (isset($loadtemplateform)) {
|
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
|
||||||
|
$loadtemplateurl = new moodle_url('/mod/htmlcert/load_template.php', array('tid' => $tid));
|
||||||
|
$loadtemplateform = new \mod_htmlcert\load_template_form($loadtemplateurl, array('context' => $context), 'post',
|
||||||
|
'', array('id' => 'loadtemplateform'));
|
||||||
$loadtemplateform->display();
|
$loadtemplateform->display();
|
||||||
}
|
}
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
100
edit_element.php
100
edit_element.php
|
@ -1,100 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit a customcert element.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once('../../config.php');
|
|
||||||
|
|
||||||
$tid = required_param('tid', PARAM_INT);
|
|
||||||
$action = required_param('action', PARAM_ALPHA);
|
|
||||||
|
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
// Set the template object.
|
|
||||||
$template = new \mod_customcert\template($template);
|
|
||||||
|
|
||||||
// Perform checks.
|
|
||||||
if ($cm = $template->get_cm()) {
|
|
||||||
require_login($cm->course, false, $cm);
|
|
||||||
} else {
|
|
||||||
require_login();
|
|
||||||
}
|
|
||||||
// Make sure the user has the required capabilities.
|
|
||||||
$template->require_manage();
|
|
||||||
|
|
||||||
if ($action == 'edit') {
|
|
||||||
// The id of the element must be supplied if we are currently editing one.
|
|
||||||
$id = required_param('id', PARAM_INT);
|
|
||||||
$element = $DB->get_record('customcert_elements', array('id' => $id), '*', MUST_EXIST);
|
|
||||||
$pageurl = new moodle_url('/mod/customcert/edit_element.php', array('id' => $id, 'tid' => $tid, 'action' => $action));
|
|
||||||
} else { // Must be adding an element.
|
|
||||||
// We need to supply what element we want added to what page.
|
|
||||||
$pageid = required_param('pageid', PARAM_INT);
|
|
||||||
$element = new stdClass();
|
|
||||||
$element->element = required_param('element', PARAM_ALPHA);
|
|
||||||
$pageurl = new moodle_url('/mod/customcert/edit_element.php', array('tid' => $tid, 'element' => $element->element,
|
|
||||||
'pageid' => $pageid, 'action' => $action));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the page.
|
|
||||||
$title = get_string('editelement', 'customcert');
|
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
|
||||||
|
|
||||||
// Additional page setup.
|
|
||||||
if ($template->get_context()->contextlevel == CONTEXT_SYSTEM) {
|
|
||||||
$PAGE->navbar->add(get_string('managetemplates', 'customcert'),
|
|
||||||
new moodle_url('/mod/customcert/manage_templates.php'));
|
|
||||||
}
|
|
||||||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php',
|
|
||||||
array('tid' => $tid)));
|
|
||||||
$PAGE->navbar->add($title);
|
|
||||||
|
|
||||||
$mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element));
|
|
||||||
|
|
||||||
// Check if they cancelled.
|
|
||||||
if ($mform->is_cancelled()) {
|
|
||||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
|
||||||
redirect($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data = $mform->get_data()) {
|
|
||||||
// Set the id, or page id depending on if we are editing an element, or adding a new one.
|
|
||||||
if ($action == 'edit') {
|
|
||||||
$data->id = $id;
|
|
||||||
} else {
|
|
||||||
$data->pageid = $pageid;
|
|
||||||
}
|
|
||||||
// Set the element variable.
|
|
||||||
$data->element = $element->element;
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($data)) {
|
|
||||||
$e->save_form_elements($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
|
||||||
redirect($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
|
||||||
echo $OUTPUT->heading(get_string('editelement', 'customcert'));
|
|
||||||
$mform->display();
|
|
||||||
echo $OUTPUT->footer();
|
|
|
@ -1,116 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_border;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element border's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_border
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
// We want to define the width of the border.
|
|
||||||
$mform->addElement('text', 'width', get_string('width', 'customcertelement_border'), array('size' => 10));
|
|
||||||
$mform->setType('width', PARAM_INT);
|
|
||||||
$mform->addHelpButton('width', 'width', 'customcertelement_border');
|
|
||||||
|
|
||||||
// The only other thing to define is the colour we want the border to be.
|
|
||||||
\mod_customcert\element_helper::render_form_element_colour($mform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
|
|
||||||
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
|
|
||||||
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
|
||||||
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
|
||||||
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
|
|
||||||
$pdf->Line(0, 0, 0, $pdf->getPageHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
// Array to return the errors.
|
|
||||||
$errors = array();
|
|
||||||
|
|
||||||
// Check if width is not set, or not numeric or less than 0.
|
|
||||||
if ((!isset($data['width'])) || (!is_numeric($data['width'])) || ($data['width'] <= 0)) {
|
|
||||||
$errors['width'] = get_string('invalidwidth', 'customcertelement_border');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the colour.
|
|
||||||
$errors += \mod_customcert\element_helper::validate_form_element_colour($data);
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$this->element->width = $this->element->data;
|
|
||||||
}
|
|
||||||
parent::definition_after_data($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 json encoded array
|
|
||||||
*/
|
|
||||||
public function save_unique_data($data) {
|
|
||||||
return $data->width;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?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_border', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_border
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Border';
|
|
||||||
$string['invalidwidth'] = 'The width has to be a valid number greater than 0.';
|
|
||||||
$string['width'] = 'Width';
|
|
||||||
$string['width_help'] = 'Width of the border in mm.';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 border plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_border
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_border';
|
|
|
@ -1,67 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_categoryname;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element categoryname's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_categoryname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class element extends \mod_customcert\element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, self::get_category_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function that returns the category name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function get_category_name() {
|
|
||||||
global $DB, $COURSE;
|
|
||||||
|
|
||||||
// Check that there is a course category available.
|
|
||||||
if (!empty($COURSE->category)) {
|
|
||||||
return $DB->get_field('course_categories', 'name', array('id' => $COURSE->category), MUST_EXIST);
|
|
||||||
} else { // Must be in a site template.
|
|
||||||
return $COURSE->fullname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?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_categoryname', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_categoryname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Category name';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 categoryname plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_categoryname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_categoryname';
|
|
|
@ -1,67 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_code;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element code's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_code
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class element extends \mod_customcert\element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $DB, $USER;
|
|
||||||
|
|
||||||
if ($preview) {
|
|
||||||
$code = \mod_customcert\certificate::generate_code();
|
|
||||||
} else {
|
|
||||||
// Get the page.
|
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->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);
|
|
||||||
$code = $issue->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $code);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
$code = \mod_customcert\certificate::generate_code();
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $code);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?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_code', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_code
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Code';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 code plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_code
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_code';
|
|
|
@ -1,55 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_coursename;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element coursename's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_coursename
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class element extends \mod_customcert\element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?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_coursename', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_coursename
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Course name';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 coursename plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_coursename
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_coursename';
|
|
|
@ -1,263 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_date;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Date - Issue
|
|
||||||
*/
|
|
||||||
define('CUSTOMCERT_DATE_ISSUE', '1');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Date - Completion
|
|
||||||
*/
|
|
||||||
define('CUSTOMCERT_DATE_COMPLETION', '2');
|
|
||||||
|
|
||||||
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element date's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_date
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
// Get the possible date options.
|
|
||||||
$dateoptions = array();
|
|
||||||
$dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date');
|
|
||||||
$dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date');
|
|
||||||
$dateoptions = $dateoptions + \customcertelement_grade\element::get_grade_items();;
|
|
||||||
|
|
||||||
$mform->addElement('select', 'dateitem', get_string('dateitem', 'customcertelement_date'), $dateoptions);
|
|
||||||
$mform->addHelpButton('dateitem', 'dateitem', 'customcertelement_date');
|
|
||||||
|
|
||||||
$mform->addElement('select', 'dateformat', get_string('dateformat', 'customcertelement_date'), self::get_date_formats());
|
|
||||||
$mform->addHelpButton('dateformat', 'dateformat', 'customcertelement_date');
|
|
||||||
|
|
||||||
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 json encoded array
|
|
||||||
*/
|
|
||||||
public function save_unique_data($data) {
|
|
||||||
// Array of data we will be storing in the database.
|
|
||||||
$arrtostore = array(
|
|
||||||
'dateitem' => $data->dateitem,
|
|
||||||
'dateformat' => $data->dateformat
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $COURSE, $DB, $USER;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
|
||||||
if (empty($this->element->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
|
||||||
$dateinfo = json_decode($this->element->data);
|
|
||||||
$dateitem = $dateinfo->dateitem;
|
|
||||||
$dateformat = $dateinfo->dateformat;
|
|
||||||
|
|
||||||
// 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->element->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);
|
|
||||||
|
|
||||||
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
|
||||||
$date = $issue->timecreated;
|
|
||||||
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
|
|
||||||
// Get the enrolment end 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' => $COURSE->id))) {
|
|
||||||
if (!empty($timecompleted->timecompleted)) {
|
|
||||||
$date = $timecompleted->timecompleted;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$gradeitem = new \stdClass();
|
|
||||||
$gradeitem->gradeitem = $dateitem;
|
|
||||||
$gradeitem->gradeformat = GRADE_DISPLAY_TYPE_PERCENTAGE;
|
|
||||||
if ($modinfo = \customcertelement_grade\element::get_grade($gradeitem, $issue->userid)) {
|
|
||||||
if (!empty($modinfo->dategraded)) {
|
|
||||||
$date = $modinfo->dategraded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that a date has been set.
|
|
||||||
if (!empty($date)) {
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_date_format_string($date, $dateformat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->element->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
|
||||||
$dateinfo = json_decode($this->element->data);
|
|
||||||
$dateformat = $dateinfo->dateformat;
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
// Set the item and format for this element.
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$dateinfo = json_decode($this->element->data);
|
|
||||||
$this->element->dateitem = $dateinfo->dateitem;
|
|
||||||
$this->element->dateformat = $dateinfo->dateformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
$dateinfo = json_decode($this->element->data);
|
|
||||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) {
|
|
||||||
$dateinfo->dateitem = $newitem->newitemid;
|
|
||||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($dateinfo), array('id' => $this->element->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return all the date formats.
|
|
||||||
*
|
|
||||||
* @return array the list of date formats
|
|
||||||
*/
|
|
||||||
public static function get_date_formats() {
|
|
||||||
$dateformats = array();
|
|
||||||
$dateformats[1] = 'January 1, 2000';
|
|
||||||
$dateformats[2] = 'January 1st, 2000';
|
|
||||||
$dateformats[3] = '1 January 2000';
|
|
||||||
$dateformats[4] = 'January 2000';
|
|
||||||
$dateformats[5] = get_string('userdateformat', 'customcertelement_date');
|
|
||||||
|
|
||||||
return $dateformats;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the date in a readable format.
|
|
||||||
*
|
|
||||||
* @param int $date
|
|
||||||
* @param string $dateformat
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function get_date_format_string($date, $dateformat) {
|
|
||||||
switch ($dateformat) {
|
|
||||||
case 1:
|
|
||||||
$certificatedate = userdate($date, '%B %d, %Y');
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$suffix = $this->get_ordinal_number_suffix(userdate($date, '%d'));
|
|
||||||
$certificatedate = userdate($date, '%B %d' . $suffix . ', %Y');
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$certificatedate = userdate($date, '%d %B %Y');
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$certificatedate = userdate($date, '%B %Y');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $certificatedate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return the suffix of the day of
|
|
||||||
* the month, eg 'st' if it is the 1st of the month.
|
|
||||||
*
|
|
||||||
* @param int $day the day of the month
|
|
||||||
* @return string the suffix.
|
|
||||||
*/
|
|
||||||
protected function get_ordinal_number_suffix($day) {
|
|
||||||
if (!in_array(($day % 100), array(11, 12, 13))) {
|
|
||||||
switch ($day % 10) {
|
|
||||||
// Handle 1st, 2nd, 3rd.
|
|
||||||
case 1:
|
|
||||||
return get_string('numbersuffix_st', 'customcertelement_date');
|
|
||||||
case 2:
|
|
||||||
return get_string('numbersuffix_nd', 'customcertelement_date');
|
|
||||||
case 3:
|
|
||||||
return get_string('numbersuffix_rd', 'customcertelement_date');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 'th';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?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_date', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_date
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['completiondate'] = 'Completion date';
|
|
||||||
$string['dateformat'] = 'Date format';
|
|
||||||
$string['dateformat_help'] = 'This is the format of the date that will be displayed';
|
|
||||||
$string['dateitem'] = 'Date item';
|
|
||||||
$string['dateitem_help'] = 'This will be the date that is printed on the certificate';
|
|
||||||
$string['issueddate'] = 'Issued date';
|
|
||||||
$string['pluginname'] = 'Date';
|
|
||||||
$string['numbersuffix_nd'] = 'nd';
|
|
||||||
$string['numbersuffix_rd'] = 'rd';
|
|
||||||
$string['numbersuffix_st'] = 'st';
|
|
||||||
$string['userdateformat'] = 'User date format';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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_date
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_date';
|
|
|
@ -1,327 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_grade;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
require_once($CFG->libdir . '/grade/constants.php');
|
|
||||||
require_once($CFG->dirroot . '/grade/lib.php');
|
|
||||||
require_once($CFG->dirroot . '/grade/querylib.php');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grade - Course
|
|
||||||
*/
|
|
||||||
define('CUSTOMCERT_GRADE_COURSE', '0');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element grade's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_grade
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
// Get the grade items we can display.
|
|
||||||
$gradeitems = array();
|
|
||||||
$gradeitems[CUSTOMCERT_GRADE_COURSE] = get_string('coursegrade', 'customcertelement_grade');
|
|
||||||
$gradeitems = $gradeitems + self::get_grade_items();
|
|
||||||
|
|
||||||
// The grade items.
|
|
||||||
$mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_grade'), $gradeitems);
|
|
||||||
$mform->setType('gradeitem', PARAM_INT);
|
|
||||||
$mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_grade');
|
|
||||||
|
|
||||||
// The grade format.
|
|
||||||
$mform->addElement('select', 'gradeformat', get_string('gradeformat', 'customcertelement_grade'), self::get_grade_format_options());
|
|
||||||
$mform->setType('gradeformat', PARAM_INT);
|
|
||||||
$mform->addHelpButton('gradeformat', 'gradeformat', 'customcertelement_grade');
|
|
||||||
|
|
||||||
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 json encoded array
|
|
||||||
*/
|
|
||||||
public function save_unique_data($data) {
|
|
||||||
// Array of data we will be storing in the database.
|
|
||||||
$arrtostore = array(
|
|
||||||
'gradeitem' => $data->gradeitem,
|
|
||||||
'gradeformat' => $data->gradeformat
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $COURSE, $USER;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
|
||||||
if (empty($this->element->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
|
||||||
$gradeinfo = json_decode($this->element->data);
|
|
||||||
|
|
||||||
// If we are previewing this certificate then just show a demonstration grade.
|
|
||||||
if ($preview) {
|
|
||||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
|
||||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, 2);
|
|
||||||
} else {
|
|
||||||
// Get the grade for the grade item.
|
|
||||||
$grade = self::get_grade($gradeinfo, $USER->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $grade);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
|
||||||
if (empty($this->element->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode the information stored in the database.
|
|
||||||
$gradeinfo = json_decode($this->element->data);
|
|
||||||
|
|
||||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
|
||||||
// Define how many decimals to display.
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
// Set the item and format for this element.
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$gradeinfo = json_decode($this->element->data);
|
|
||||||
$this->element->gradeitem = $gradeinfo->gradeitem;
|
|
||||||
$this->element->gradeformat = $gradeinfo->gradeformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is responsible for handling the restoration process of the element.
|
|
||||||
*
|
|
||||||
* We will want to update the course module the grade 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;
|
|
||||||
|
|
||||||
$gradeinfo = json_decode($this->element->data);
|
|
||||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) {
|
|
||||||
$gradeinfo->gradeitem = $newitem->newitemid;
|
|
||||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($gradeinfo), array('id' => $this->element->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return all the grades items for this course.
|
|
||||||
*
|
|
||||||
* @return array the array of gradeable items in the course
|
|
||||||
*/
|
|
||||||
public static function get_grade_items() {
|
|
||||||
global $COURSE, $DB;
|
|
||||||
|
|
||||||
// Array to store the grade items.
|
|
||||||
$modules = 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.
|
|
||||||
switch ($COURSE->format) {
|
|
||||||
case 'topics':
|
|
||||||
$sectionlabel = get_string('topic');
|
|
||||||
break;
|
|
||||||
case 'weeks':
|
|
||||||
$sectionlabel = get_string('week');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$sectionlabel = get_string('section');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return all the possible grade formats.
|
|
||||||
*
|
|
||||||
* @return array returns an array of grade formats
|
|
||||||
*/
|
|
||||||
public static function get_grade_format_options() {
|
|
||||||
$gradeformat = array();
|
|
||||||
$gradeformat[GRADE_DISPLAY_TYPE_REAL] = get_string('gradepoints', 'customcertelement_grade');
|
|
||||||
$gradeformat[GRADE_DISPLAY_TYPE_PERCENTAGE] = get_string('gradepercent', 'customcertelement_grade');
|
|
||||||
$gradeformat[GRADE_DISPLAY_TYPE_LETTER] = get_string('gradeletter', 'customcertelement_grade');
|
|
||||||
|
|
||||||
return $gradeformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return the grade to display.
|
|
||||||
*
|
|
||||||
* @param \stdClass $gradeinfo
|
|
||||||
* @param int $userid
|
|
||||||
* @return string the grade result
|
|
||||||
*/
|
|
||||||
public static function get_grade($gradeinfo, $userid) {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
// Get the grade information.
|
|
||||||
$gradeitem = $gradeinfo->gradeitem;
|
|
||||||
$gradeformat = $gradeinfo->gradeformat;
|
|
||||||
|
|
||||||
// Check if we are displaying the course grade.
|
|
||||||
if ($gradeitem == CUSTOMCERT_GRADE_COURSE) {
|
|
||||||
if ($courseitem = \grade_item::fetch_course_item($COURSE->id)) {
|
|
||||||
// Set the grade type we want.
|
|
||||||
$courseitem->gradetype = GRADE_TYPE_VALUE;
|
|
||||||
$grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid));
|
|
||||||
$coursegrade = grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat, 2);
|
|
||||||
return $coursegrade;
|
|
||||||
}
|
|
||||||
} else { // Get the module grade.
|
|
||||||
if ($modinfo = self::get_mod_grade($gradeitem, $gradeformat, $userid)) {
|
|
||||||
return $modinfo->gradetodisplay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only gets here if no grade was retrieved from the DB.
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return the grade the user achieved for a specified module.
|
|
||||||
*
|
|
||||||
* @param int $moduleid
|
|
||||||
* @param int $gradeformat
|
|
||||||
* @param int $userid
|
|
||||||
* @return \stdClass the grade information
|
|
||||||
*/
|
|
||||||
public static function get_mod_grade($moduleid, $gradeformat, $userid) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $moduleid), '*', MUST_EXIST);
|
|
||||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
|
||||||
|
|
||||||
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
|
||||||
if (!empty($gradeitem)) {
|
|
||||||
$item = new \grade_item();
|
|
||||||
$item->gradetype = GRADE_TYPE_VALUE;
|
|
||||||
$item->courseid = $cm->course;
|
|
||||||
$itemproperties = reset($gradeitem->items);
|
|
||||||
foreach ($itemproperties as $key => $value) {
|
|
||||||
$item->$key = $value;
|
|
||||||
}
|
|
||||||
// Grade for the user.
|
|
||||||
$grade = $item->grades[$userid]->grade;
|
|
||||||
// Define how many decimals to display.
|
|
||||||
$decimals = 2;
|
|
||||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
|
||||||
$decimals = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the object we will be returning.
|
|
||||||
$modinfo = new \stdClass;
|
|
||||||
$modinfo->name = $DB->get_field($module->name, 'name', array('id' => $cm->instance));
|
|
||||||
$modinfo->gradetodisplay = grade_format_gradevalue($grade, $item, true, $gradeformat, $decimals);
|
|
||||||
|
|
||||||
if ($grade) {
|
|
||||||
$modinfo->dategraded = $item->grades[$userid]->dategraded;
|
|
||||||
} else {
|
|
||||||
$modinfo->dategraded = time();
|
|
||||||
}
|
|
||||||
return $modinfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?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_grade', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_grade
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['coursegrade'] = 'Course grade';
|
|
||||||
$string['gradeitem'] = 'Grade item';
|
|
||||||
$string['gradeitem_help'] = 'The grade item you wish to display the grade of.';
|
|
||||||
$string['gradeformat'] = 'Grade format';
|
|
||||||
$string['gradeformat_help'] = 'The format you wish to use when displaying the grade.';
|
|
||||||
$string['gradeitem'] = 'Grade item';
|
|
||||||
$string['gradepercent'] = 'Percentage Grade';
|
|
||||||
$string['gradepoints'] = 'Points Grade';
|
|
||||||
$string['gradeletter'] = 'Letter Grade';
|
|
||||||
$string['pluginname'] = 'Grade';
|
|
||||||
$string['previewgrade'] = 'Preview grade';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 grade plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_grade
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_grade';
|
|
|
@ -1,117 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_gradeitemname;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element gradeitemname's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_gradeitemname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
$mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_gradeitemname'),
|
|
||||||
\customcertelement_grade\element::get_grade_items());
|
|
||||||
$mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_gradeitemname');
|
|
||||||
|
|
||||||
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) {
|
|
||||||
if (!empty($data->gradeitem)) {
|
|
||||||
return $data->gradeitem;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Check that the grade item is not empty.
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
// Get the course module information.
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
// Check that the grade item is not empty.
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
// Get the course module information.
|
|
||||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->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 '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$this->element->gradeitem = $this->element->data;
|
|
||||||
}
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?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_gradeitemname', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_gradeitemname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['gradeitem'] = 'Grade item';
|
|
||||||
$string['gradeitem_help'] = 'The name of the selected item will be displayed on the PDF.';
|
|
||||||
$string['pluginname'] = 'Grade item name';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 gradeitemname plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_gradeitemname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_gradeitemname';
|
|
|
@ -1,258 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_image;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element image's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_image
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class element extends \mod_customcert\element {
|
|
||||||
|
|
||||||
protected $filemanageroptions = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param \stdClass $element the element data
|
|
||||||
*/
|
|
||||||
public function __construct($element) {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
$this->filemanageroptions = array(
|
|
||||||
'maxbytes' => $COURSE->maxbytes,
|
|
||||||
'subdirs' => 1,
|
|
||||||
'accepted_types' => 'image'
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct($element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function renders the form elements when adding a customcert element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
$mform->addElement('select', 'image', get_string('image', 'customcertelement_image'), self::get_images());
|
|
||||||
|
|
||||||
$mform->addElement('text', 'width', get_string('width', 'customcertelement_image'), array('size' => 10));
|
|
||||||
$mform->setType('width', PARAM_INT);
|
|
||||||
$mform->setDefault('width', 0);
|
|
||||||
$mform->addHelpButton('width', 'width', 'customcertelement_image');
|
|
||||||
|
|
||||||
$mform->addElement('text', 'height', get_string('height', 'customcertelement_image'), array('size' => 10));
|
|
||||||
$mform->setType('height', PARAM_INT);
|
|
||||||
$mform->setDefault('height', 0);
|
|
||||||
$mform->addHelpButton('height', 'height', 'customcertelement_image');
|
|
||||||
|
|
||||||
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
// Array to return the errors.
|
|
||||||
$errors = array();
|
|
||||||
|
|
||||||
// Check if width is not set, or not numeric or less than 0.
|
|
||||||
if ((!isset($data['width'])) || (!is_numeric($data['width'])) || ($data['width'] < 0)) {
|
|
||||||
$errors['width'] = get_string('invalidwidth', 'customcertelement_image');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if height is not set, or not numeric or less than 0.
|
|
||||||
if ((!isset($data['height'])) || (!is_numeric($data['height'])) || ($data['height'] < 0)) {
|
|
||||||
$errors['height'] = get_string('invalidheight', 'customcertelement_image');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the position.
|
|
||||||
$errors += \mod_customcert\element_helper::validate_form_element_position($data);
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles saving the form elements created by this element.
|
|
||||||
* Can be overridden if more functionality is needed.
|
|
||||||
*
|
|
||||||
* @param \stdClass $data the form data
|
|
||||||
*/
|
|
||||||
public function save_form_elements($data) {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
// Handle file uploads.
|
|
||||||
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id);
|
|
||||||
|
|
||||||
parent::save_form_elements($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
// Array of data we will be storing in the database.
|
|
||||||
$arrtostore = array(
|
|
||||||
'pathnamehash' => $data->image,
|
|
||||||
'width' => (int) $data->width,
|
|
||||||
'height' => (int) $data->height
|
|
||||||
);
|
|
||||||
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
|
||||||
if (empty($this->element->data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
|
||||||
|
|
||||||
// Get the image.
|
|
||||||
$fs = get_file_storage();
|
|
||||||
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
|
||||||
$contenthash = $file->get_contenthash();
|
|
||||||
$l1 = $contenthash[0] . $contenthash[1];
|
|
||||||
$l2 = $contenthash[2] . $contenthash[3];
|
|
||||||
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
|
|
||||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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->element->data)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
|
||||||
|
|
||||||
// Get the image.
|
|
||||||
$fs = get_file_storage();
|
|
||||||
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
|
||||||
$url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(),
|
|
||||||
$file->get_filepath(), $file->get_filename());
|
|
||||||
$fileimageinfo = $file->get_imageinfo();
|
|
||||||
$whratio = $fileimageinfo['width'] / $fileimageinfo['height'];
|
|
||||||
// The size of the images to use in the CSS style.
|
|
||||||
$style = '';
|
|
||||||
if ($imageinfo->width === 0 && $imageinfo->height === 0) {
|
|
||||||
$style .= 'width: ' . $fileimageinfo['width'] . 'px; ';
|
|
||||||
$style .= 'height: ' . $fileimageinfo['height'] . 'px';
|
|
||||||
} else if ($imageinfo->width === 0) { // Then the height must be set.
|
|
||||||
// We must get the width based on the height to keep the ratio.
|
|
||||||
$style .= 'width: ' . ($imageinfo->height * $whratio) . 'mm; ';
|
|
||||||
$style .= 'height: ' . $imageinfo->height . 'mm';
|
|
||||||
} else if ($imageinfo->height === 0) { // Then the width must be set.
|
|
||||||
$style .= 'width: ' . $imageinfo->width . 'mm; ';
|
|
||||||
// We must get the height based on the width to keep the ratio.
|
|
||||||
$style .= 'height: ' . ($imageinfo->width / $whratio) . 'mm';
|
|
||||||
} else { // Must both be set.
|
|
||||||
$style .= 'width: ' . $imageinfo->width . 'mm; ';
|
|
||||||
$style .= 'height: ' . $imageinfo->height . 'mm';
|
|
||||||
}
|
|
||||||
|
|
||||||
return \html_writer::tag('img', '', array('src' => $url, 'style' => $style));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
// Set the image, width and height for this element.
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$imageinfo = json_decode($this->element->data);
|
|
||||||
$this->element->image = $imageinfo->pathnamehash;
|
|
||||||
$this->element->width = $imageinfo->width;
|
|
||||||
$this->element->height = $imageinfo->height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Editing existing instance - copy existing files into draft area.
|
|
||||||
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
|
|
||||||
file_prepare_draft_area($draftitemid, \context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
|
|
||||||
$element = $mform->getElement('customcertimage');
|
|
||||||
$element->setValue($draftitemid);
|
|
||||||
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the list of possible images to use.
|
|
||||||
*
|
|
||||||
* @return array the list of images that can be used
|
|
||||||
*/
|
|
||||||
public static function get_images() {
|
|
||||||
global $COURSE;
|
|
||||||
|
|
||||||
// Create file storage object.
|
|
||||||
$fs = get_file_storage();
|
|
||||||
|
|
||||||
// The array used to store the images.
|
|
||||||
$arrfiles = array();
|
|
||||||
// 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)) {
|
|
||||||
foreach ($files as $hash => $file) {
|
|
||||||
$arrfiles[$hash] = $file->get_filename();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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, 'filename', false)) {
|
|
||||||
foreach ($files as $hash => $file) {
|
|
||||||
$arrfiles[$hash] = $file->get_filename();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\core_collator::asort($arrfiles);
|
|
||||||
$arrfiles = array_merge(array('0' => get_string('noimage', 'customcert')), $arrfiles);
|
|
||||||
|
|
||||||
return $arrfiles;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?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_image', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_image
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['height'] = 'Height';
|
|
||||||
$string['height_help'] = 'Height of the image in mm. If equal to zero, it is automatically calculated.';
|
|
||||||
$string['image'] = 'Image';
|
|
||||||
$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['pluginname'] = 'Image';
|
|
||||||
$string['width'] = 'Width';
|
|
||||||
$string['width_help'] = 'Width of the image in mm. If equal to zero, it is automatically calculated.';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 image plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_image
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_image';
|
|
|
@ -1,55 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_studentname;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element studentname's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_studentname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class element extends \mod_customcert\element {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $USER;
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, fullname($USER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
global $USER;
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, fullname($USER));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?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_studentname', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_studentname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Student name';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 studentname plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_studentname
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_studentname';
|
|
|
@ -1,120 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_teachername;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element teachername's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_teachername
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
$mform->addElement('select', 'teacher', get_string('teacher', 'customcertelement_teachername'),
|
|
||||||
$this->get_list_of_teachers());
|
|
||||||
$mform->addHelpButton('teacher', 'teacher', 'customcertelement_teachername');
|
|
||||||
|
|
||||||
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) {
|
|
||||||
if (!empty($data->teacher)) {
|
|
||||||
return $data->teacher;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
|
||||||
$teachername = fullname($teacher);
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $teachername);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
|
||||||
$teachername = fullname($teacher);
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $teachername);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to return the teachers for this course.
|
|
||||||
*
|
|
||||||
* @return array the list of teachers
|
|
||||||
*/
|
|
||||||
protected function get_list_of_teachers() {
|
|
||||||
global $PAGE;
|
|
||||||
|
|
||||||
// The list of teachers to return.
|
|
||||||
$teachers = array();
|
|
||||||
|
|
||||||
// Now return all users who can manage the customcert in this context.
|
|
||||||
if ($users = get_users_by_capability($PAGE->context, 'mod/customcert:manage')) {
|
|
||||||
foreach ($users as $user) {
|
|
||||||
$teachers[$user->id] = fullname($user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $teachers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$this->element->teacher = $this->element->data;
|
|
||||||
}
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?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_teachername', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_teachername
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Teacher name';
|
|
||||||
$string['teacher'] = 'Teacher';
|
|
||||||
$string['teacher_help'] = 'This is the teacher name that will be displayed.';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 teachername plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_teachername
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_teachername';
|
|
|
@ -1,87 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_text;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element text's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_text
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
$mform->addElement('textarea', 'text', get_string('text', 'customcertelement_text'));
|
|
||||||
$mform->setType('text', PARAM_RAW);
|
|
||||||
$mform->addHelpButton('text', 'text', 'customcertelement_text');
|
|
||||||
|
|
||||||
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->text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $this->element->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$this->element->text = $this->element->data;
|
|
||||||
}
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?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_text', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_text
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'Text';
|
|
||||||
$string['text'] = 'Text';
|
|
||||||
$string['text_help'] = 'This is the text that will display on the PDF.';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 text plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_text
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_text';
|
|
|
@ -1,144 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
namespace customcertelement_userfield;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The customcert element userfield's core interaction API.
|
|
||||||
*
|
|
||||||
* @package customcertelement_userfield
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function render_form_elements($mform) {
|
|
||||||
// Get the user profile fields.
|
|
||||||
$userfields = array(
|
|
||||||
'firstname' => get_user_field_name('firstname'),
|
|
||||||
'lastname' => get_user_field_name('lastname'),
|
|
||||||
'email' => get_user_field_name('email'),
|
|
||||||
'city' => get_user_field_name('city'),
|
|
||||||
'country' => get_user_field_name('country'),
|
|
||||||
'url' => get_user_field_name('url'),
|
|
||||||
'icq' => get_user_field_name('icq'),
|
|
||||||
'skype' => get_user_field_name('skype'),
|
|
||||||
'aim' => get_user_field_name('aim'),
|
|
||||||
'yahoo' => get_user_field_name('yahoo'),
|
|
||||||
'msn' => get_user_field_name('msn'),
|
|
||||||
'idnumber' => get_user_field_name('idnumber'),
|
|
||||||
'institution' => get_user_field_name('institution'),
|
|
||||||
'department' => get_user_field_name('department'),
|
|
||||||
'phone1' => get_user_field_name('phone1'),
|
|
||||||
'phone2' => get_user_field_name('phone2'),
|
|
||||||
'address' => get_user_field_name('address')
|
|
||||||
);
|
|
||||||
// Get the user custom fields.
|
|
||||||
$arrcustomfields = \availability_profile\condition::get_custom_profile_fields();
|
|
||||||
$customfields = array();
|
|
||||||
foreach ($arrcustomfields as $key => $customfield) {
|
|
||||||
$customfields[$customfield->id] = $key;
|
|
||||||
}
|
|
||||||
// Combine the two.
|
|
||||||
$fields = $userfields + $customfields;
|
|
||||||
\core_collator::asort($fields);
|
|
||||||
|
|
||||||
// Create the select box where the user field is selected.
|
|
||||||
$mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $fields);
|
|
||||||
$mform->setType('userfield', PARAM_ALPHANUM);
|
|
||||||
$mform->addHelpButton('userfield', 'userfield', 'customcertelement_userfield');
|
|
||||||
|
|
||||||
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->userfield;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles rendering the element on the pdf.
|
|
||||||
*
|
|
||||||
* @param \pdf $pdf the pdf object
|
|
||||||
* @param bool $preview true if it is a preview, false otherwise
|
|
||||||
*/
|
|
||||||
public function render($pdf, $preview) {
|
|
||||||
global $DB, $USER;
|
|
||||||
|
|
||||||
// The user field to display.
|
|
||||||
$field = $this->element->data;
|
|
||||||
// The value to display on the PDF.
|
|
||||||
$value = '';
|
|
||||||
if (is_number($field)) { // Must be a custom user profile field.
|
|
||||||
if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
|
|
||||||
$value = $USER->profile[$field->shortname];
|
|
||||||
}
|
|
||||||
} else if (!empty($USER->$field)) { // Field in the user table.
|
|
||||||
$value = $USER->$field;
|
|
||||||
}
|
|
||||||
|
|
||||||
\mod_customcert\element_helper::render_content($pdf, $this, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 $DB, $USER;
|
|
||||||
|
|
||||||
// The user field to display.
|
|
||||||
$field = $this->element->data;
|
|
||||||
// The value to display on the PDF.
|
|
||||||
$value = '';
|
|
||||||
if (is_number($field)) { // Must be a custom user profile field.
|
|
||||||
if ($field = $DB->get_record('user_info_field', array('id' => $field))) {
|
|
||||||
$value = $USER->profile[$field->shortname];
|
|
||||||
}
|
|
||||||
} else if (!empty($USER->$field)) { // Field in the user table.
|
|
||||||
$value = $USER->$field;
|
|
||||||
}
|
|
||||||
|
|
||||||
return \mod_customcert\element_helper::render_html_content($this, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the data on the form when editing an element.
|
|
||||||
*
|
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
|
||||||
*/
|
|
||||||
public function definition_after_data($mform) {
|
|
||||||
if (!empty($this->element->data)) {
|
|
||||||
$this->element->userfield = $this->element->data;
|
|
||||||
}
|
|
||||||
parent::definition_after_data($mform);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?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_userfield', language 'en'.
|
|
||||||
*
|
|
||||||
* @package customcertelement_userfield
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['pluginname'] = 'User field';
|
|
||||||
$string['userfield'] = 'User field';
|
|
||||||
$string['userfield_help'] = 'This is the user field that will be displayed on the PDF.';
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?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 userfield plugin.
|
|
||||||
*
|
|
||||||
* @package customcertelement_userfield
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @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 = 2016021900; // The current module version (Date: YYYYMMDDXX).
|
|
||||||
$plugin->requires = 2015051100; // Requires this Moodle version (2.9).
|
|
||||||
$plugin->component = 'customcertelement_userfield';
|
|
|
@ -1,85 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
||||||
|
|
||||||
require_once("HTML/QuickForm/text.php");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form element for handling the colour picker.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class MoodleQuickForm_customcert_colourpicker extends HTML_QuickForm_text {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The string for the help icon, if empty then no help icon will be displayed.
|
|
||||||
*/
|
|
||||||
public $_helpbutton = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the colour picker.
|
|
||||||
*
|
|
||||||
* @param string $elementName
|
|
||||||
* @param string $elementLabel
|
|
||||||
* @param array $attributes
|
|
||||||
*/
|
|
||||||
function __construct($elementName = null, $elementLabel = null, $attributes = null) {
|
|
||||||
parent::__construct($elementName, $elementLabel, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Old school constructor name to support earlier versions of Moodle.
|
|
||||||
*
|
|
||||||
* @param string $elementName
|
|
||||||
* @param string $elementLabel
|
|
||||||
* @param array $attributes
|
|
||||||
*/
|
|
||||||
function MoodleQuickForm_customcert_colourpicker($elementName = null, $elementLabel = null, $attributes = null) {
|
|
||||||
self::__construct($elementName, $elementLabel, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the html string to display this element.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function toHtml() {
|
|
||||||
global $PAGE, $OUTPUT;
|
|
||||||
|
|
||||||
$PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->getAttribute('id'), null));
|
|
||||||
$content = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>';
|
|
||||||
$content .= html_writer::start_tag('div', array('class' => 'form-colourpicker defaultsnext'));
|
|
||||||
$content .= html_writer::tag('div', $OUTPUT->pix_icon('i/loading', get_string('loading', 'admin'), 'moodle',
|
|
||||||
array('class' => 'loadingicon')), array('class' => 'admin_colourpicker clearfix'));
|
|
||||||
$content .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $this->getAttribute('id'),
|
|
||||||
'name' => $this->getName(), 'value' => $this->getValue(), 'size' => '12'));
|
|
||||||
$content .= html_writer::end_tag('div');
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the html for the help button.
|
|
||||||
*
|
|
||||||
* @return string html for help button
|
|
||||||
*/
|
|
||||||
public function getHelpButton(){
|
|
||||||
return $this->_helpbutton;
|
|
||||||
}
|
|
||||||
}
|
|
57
index.php
57
index.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This page lists all the instances of customcert in a particular course.
|
* This page lists all the instances of htmlcert in a particular course.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -32,18 +32,25 @@ $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
|
||||||
require_login($course);
|
require_login($course);
|
||||||
|
|
||||||
// Set up the page variables.
|
// Set up the page variables.
|
||||||
$pageurl = new moodle_url('/mod/customcert/index.php', array('id' => $course->id));
|
$pageurl = new moodle_url('/mod/htmlcert/index.php', array('id' => $course->id));
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, CONTEXT_COURSE::instance($id),
|
\mod_htmlcert\page_helper::page_setup($pageurl, context_course::instance($id),
|
||||||
get_string('modulenameplural', 'customcert'));
|
get_string('modulenameplural', 'htmlcert'));
|
||||||
|
|
||||||
// Additional page setup needed.
|
// Additional page setup needed.
|
||||||
$PAGE->set_pagelayout('incourse');
|
$PAGE->set_pagelayout('incourse');
|
||||||
$PAGE->navbar->add(get_string('modulenameplural', 'customcert'));
|
$PAGE->navbar->add(get_string('modulenameplural', 'htmlcert'));
|
||||||
|
|
||||||
// Get the customcerts, if there are none display a notice.
|
// Add the page view to the Moodle log.
|
||||||
if (!$customcerts = get_all_instances_in_course('customcert', $course)) {
|
$event = \mod_htmlcert\event\course_module_instance_list_viewed::create(array(
|
||||||
|
'context' => context_course::instance($course->id)
|
||||||
|
));
|
||||||
|
$event->add_record_snapshot('course', $course);
|
||||||
|
$event->trigger();
|
||||||
|
|
||||||
|
// Get the htmlcerts, if there are none display a notice.
|
||||||
|
if (!$htmlcerts = get_all_instances_in_course('htmlcert', $course)) {
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
notice(get_string('nocustomcerts', 'customcert'), new moodle_url('/course/view.php', array('id' => $course->id)));
|
notice(get_string('nohtmlcerts', 'htmlcert'), new moodle_url('/course/view.php', array('id' => $course->id)));
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -53,37 +60,37 @@ $table = new html_table();
|
||||||
|
|
||||||
if ($usesections = course_format_uses_sections($course->format)) {
|
if ($usesections = course_format_uses_sections($course->format)) {
|
||||||
$table->head = array(get_string('sectionname', 'format_'.$course->format), get_string('name'),
|
$table->head = array(get_string('sectionname', 'format_'.$course->format), get_string('name'),
|
||||||
get_string('issued', 'customcert'));
|
get_string('receiveddate', 'htmlcert'));
|
||||||
} else {
|
} else {
|
||||||
$table->head = array(get_string('name'), get_string('issued', 'customcert'));
|
$table->head = array(get_string('name'), get_string('receiveddate', 'htmlcert'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentsection = '';
|
$currentsection = '';
|
||||||
foreach ($customcerts as $customcert) {
|
foreach ($htmlcerts as $htmlcert) {
|
||||||
// Check if the customcert is visible, if so show text as normal, else show it as dimmed.
|
// Check if the htmlcert is visible, if so show text as normal, else show it as dimmed.
|
||||||
if ($customcert->visible) {
|
if ($htmlcert->visible) {
|
||||||
$link = html_writer::tag('a', $customcert->name, array('href' => new moodle_url('/mod/customcert/view.php',
|
$link = html_writer::tag('a', $htmlcert->name, array('href' => new moodle_url('/mod/htmlcert/view.php',
|
||||||
array('id' => $customcert->coursemodule))));
|
array('id' => $htmlcert->coursemodule))));
|
||||||
} else {
|
} else {
|
||||||
$link = html_writer::tag('a', $customcert->name, array('class' => 'dimmed', 'href' =>
|
$link = html_writer::tag('a', $htmlcert->name, array('class' => 'dimmed',
|
||||||
new moodle_url('/mod/customcert/view.php', array('id' => $customcert->coursemodule))));
|
'href' => new moodle_url('/mod/htmlcert/view.php', array('id' => $htmlcert->coursemodule))));
|
||||||
}
|
}
|
||||||
// If we are at a different section then print a horizontal rule.
|
// If we are at a different section then print a horizontal rule.
|
||||||
if ($customcert->section !== $currentsection) {
|
if ($htmlcert->section !== $currentsection) {
|
||||||
if ($currentsection !== '') {
|
if ($currentsection !== '') {
|
||||||
$table->data[] = 'hr';
|
$table->data[] = 'hr';
|
||||||
}
|
}
|
||||||
$currentsection = $customcert->section;
|
$currentsection = $htmlcert->section;
|
||||||
}
|
}
|
||||||
// Check if there is was an issue provided for this user.
|
// Check if there is was an issue provided for this user.
|
||||||
if ($certrecord = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) {
|
if ($certrecord = $DB->get_record('htmlcert_issues', array('userid' => $USER->id, 'htmlcertid' => $htmlcert->id))) {
|
||||||
$issued = userdate($certrecord->timecreated);
|
$issued = userdate($certrecord->timecreated);
|
||||||
} else {
|
} else {
|
||||||
$issued = get_string('notissued', 'customcert');
|
$issued = get_string('notissued', 'htmlcert');
|
||||||
}
|
}
|
||||||
// Only display the section column if the course format uses sections.
|
// Only display the section column if the course format uses sections.
|
||||||
if ($usesections) {
|
if ($usesections) {
|
||||||
$table->data[] = array($customcert->section, $link, $issued);
|
$table->data[] = array($htmlcert->section, $link, $issued);
|
||||||
} else {
|
} else {
|
||||||
$table->data[] = array($link, $issued);
|
$table->data[] = array($link, $issued);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Language strings for the customcert module.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string['addcertpage'] = 'Add another certificate page';
|
|
||||||
$string['addelement'] = 'Add element';
|
|
||||||
$string['awardedto'] = 'Awarded to';
|
|
||||||
$string['code'] = 'Code';
|
|
||||||
$string['copy'] = 'Copy';
|
|
||||||
$string['coursetimereq'] = 'Required minutes in course';
|
|
||||||
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive
|
|
||||||
the certificate.';
|
|
||||||
$string['createtemplate'] = 'Create template';
|
|
||||||
$string['customcertnameexists'] = 'A certificate already exists with this name';
|
|
||||||
$string['customcertreport'] = 'Custom certificate report';
|
|
||||||
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
|
|
||||||
$string['customcert:manage'] = 'Manage a custom certificate';
|
|
||||||
$string['customcert:view'] = 'View a custom certificate';
|
|
||||||
$string['deletecertpage'] = 'Delete certificate page';
|
|
||||||
$string['deleteconfirm'] = 'Delete confirmation';
|
|
||||||
$string['deleteelement'] = 'Delete element';
|
|
||||||
$string['deleteelementconfirm'] = 'Are you sure you want to delete this element?';
|
|
||||||
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
|
|
||||||
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
|
|
||||||
$string['description'] = 'Description';
|
|
||||||
$string['editcustomcert'] = 'Edit custom certificate';
|
|
||||||
$string['editelement'] = 'Edit element';
|
|
||||||
$string['edittemplate'] = 'Edit template';
|
|
||||||
$string['elementname'] = 'Element name';
|
|
||||||
$string['elementname_help'] = 'This will be the name used to identify this element when editing a custom certificate. For example, you may have multiple images on a
|
|
||||||
page and will want to distinguish between them quickly when editing the certificate. Note: this will not displayed on the PDF.';
|
|
||||||
$string['elements'] = 'Elements';
|
|
||||||
$string['elements_help'] = 'These are the list of elements that will be displayed on this PDF page.';
|
|
||||||
$string['elementwidth'] = 'Width';
|
|
||||||
$string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.';
|
|
||||||
$string['font'] = 'Font';
|
|
||||||
$string['font_help'] = 'The font used when generating this element.';
|
|
||||||
$string['fontcolour'] = 'Colour';
|
|
||||||
$string['fontcolour_help'] = 'The colour of the font.';
|
|
||||||
$string['fontsize'] = 'Size';
|
|
||||||
$string['fontsize_help'] = 'The size of the font in points.';
|
|
||||||
$string['getcustomcert'] = 'Get your custom certificate';
|
|
||||||
$string['height'] = 'Height';
|
|
||||||
$string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.';
|
|
||||||
$string['invalidcolour'] = 'Invalid colour chosen, please enter a valid HTML colour name, or a six-digit, or three-digit hexadecimal colour.';
|
|
||||||
$string['invalidelementwidth'] = 'Please enter a positive number.';
|
|
||||||
$string['invalidposition'] = 'Please select a positive number for position {$a}.';
|
|
||||||
$string['invalidheight'] = 'The height has to be a valid number greater than 0.';
|
|
||||||
$string['invalidmargin'] = 'The margin has to be a valid number greater than 0.';
|
|
||||||
$string['invalidwidth'] = 'The width has to be a valid number greater than 0.';
|
|
||||||
$string['issued'] = 'Issued';
|
|
||||||
$string['landscape'] = 'Landscape';
|
|
||||||
$string['leftmargin'] = 'Left margin';
|
|
||||||
$string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.';
|
|
||||||
$string['load'] = 'Load';
|
|
||||||
$string['loadtemplate'] = 'Load template';
|
|
||||||
$string['loadtemplatemsg'] = 'Are you sure you wish to load this template? This will remove any existing pages and elements for this certificate.';
|
|
||||||
$string['managetemplates'] = 'Manage templates';
|
|
||||||
$string['managetemplatesdesc'] = 'This link will take you to a new screen where you will be able to manage templates used by customcert activities in courses.';
|
|
||||||
$string['modify'] = 'Modify';
|
|
||||||
$string['modulename'] = 'Custom certificate';
|
|
||||||
$string['modulenameplural'] = 'Custom certificates';
|
|
||||||
$string['modulename_help'] = 'This module allows for the dynamic generation of PDF certificates.';
|
|
||||||
$string['modulename_link'] = 'Custom_certificate_module';
|
|
||||||
$string['name'] = 'Name';
|
|
||||||
$string['nocustomcerts'] = 'There are no custom certificates for this course';
|
|
||||||
$string['noimage'] = 'No image';
|
|
||||||
$string['notemplates'] = 'No templates';
|
|
||||||
$string['notissued'] = 'Not issued';
|
|
||||||
$string['options'] = 'Options';
|
|
||||||
$string['page'] = 'Page {$a}';
|
|
||||||
$string['pluginadministration'] = 'Custom certificate administration';
|
|
||||||
$string['pluginname'] = 'Custom certificate';
|
|
||||||
$string['print'] = 'Print';
|
|
||||||
$string['portrait'] = 'Portrait';
|
|
||||||
$string['rearrangeelements'] = 'Rearrange elements';
|
|
||||||
$string['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.';
|
|
||||||
$string['receiveddate'] = 'Received date';
|
|
||||||
$string['refpoint'] = 'Reference point location';
|
|
||||||
$string['refpoint_help'] = 'This specifies which location of the element to be located at position X and position Y.';
|
|
||||||
$string['replacetemplate'] = 'Replace';
|
|
||||||
$string['rightmargin'] = 'Right margin';
|
|
||||||
$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.';
|
|
||||||
$string['save'] = 'Save';
|
|
||||||
$string['saveandclose'] = 'Save and close';
|
|
||||||
$string['saveandcontinue'] = 'Save and continue';
|
|
||||||
$string['savechangespreview'] = 'Save changes and preview';
|
|
||||||
$string['savetemplate'] = 'Save template';
|
|
||||||
$string['setprotection'] = 'Set protection';
|
|
||||||
$string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.';
|
|
||||||
$string['summaryofissue'] = 'Summary of issue';
|
|
||||||
$string['templatename'] = 'Template name';
|
|
||||||
$string['templatenameexists'] = 'That template name is currently in use, please choose another.';
|
|
||||||
$string['topcenter'] = 'Center';
|
|
||||||
$string['topleft'] = 'Top left';
|
|
||||||
$string['topright'] = 'Top right';
|
|
||||||
$string['type'] = 'Type';
|
|
||||||
$string['uploadimage'] = 'Upload image';
|
|
||||||
$string['uploadimagedesc'] = 'This link will take you to a new screen where you will be able to upload images. Images uploaded using
|
|
||||||
this method will be available throughout your site to all users who are able to create a custom certificate.';
|
|
||||||
$string['viewcustomcertissues'] = 'View {$a} issued custom certificates';
|
|
||||||
$string['width'] = 'Width';
|
|
||||||
$string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.';
|
|
207
lang/en/htmlcert.php
Normal file
207
lang/en/htmlcert.php
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language strings for the htmlcert module.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
$string['activity'] = 'Activity';
|
||||||
|
$string['addcertpage'] = 'Add page';
|
||||||
|
$string['addelement'] = 'Add element';
|
||||||
|
$string['aligncenter'] = 'Centered';
|
||||||
|
$string['alignleft'] = 'Left alignment';
|
||||||
|
$string['alignment'] = 'Alignment';
|
||||||
|
$string['alignment_help'] = 'This property sets the horizontal alignment of the element. Some elements may not support this, while the behaviour of others may differ.';
|
||||||
|
$string['alignright'] = 'Right alignment';
|
||||||
|
$string['awardedto'] = 'Awarded to';
|
||||||
|
$string['cannotverifyallcertificates'] = 'You do not have the permission to verify all certificates on the site.';
|
||||||
|
$string['certificate'] = 'Certificate';
|
||||||
|
$string['code'] = 'Code';
|
||||||
|
$string['copy'] = 'Copy';
|
||||||
|
$string['coursetimereq'] = 'Required minutes in course';
|
||||||
|
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive
|
||||||
|
the certificate.';
|
||||||
|
$string['createtemplate'] = 'Create template';
|
||||||
|
$string['htmlcert:addinstance'] = 'Add a new HTML certificate instance';
|
||||||
|
$string['htmlcert:manage'] = 'Manage an HTML certificate';
|
||||||
|
$string['htmlcert:manageemailstudents'] = 'Manage email students setting';
|
||||||
|
$string['htmlcert:manageemailteachers'] = 'Manage email teachers setting';
|
||||||
|
$string['htmlcert:manageemailothers'] = 'Manage email others setting';
|
||||||
|
$string['htmlcert:manageverifyany'] = 'Manage verification setting';
|
||||||
|
$string['htmlcert:managerequiredtime'] = 'Manage time required setting';
|
||||||
|
$string['htmlcert:manageprotection'] = 'Manage protection setting';
|
||||||
|
$string['htmlcert:receiveissue'] = 'Receive a certificate';
|
||||||
|
$string['htmlcert:view'] = 'View an HTML certificate';
|
||||||
|
$string['htmlcert:viewreport'] = 'View course report';
|
||||||
|
$string['htmlcert:viewallcertificates'] = 'View all certificates';
|
||||||
|
$string['htmlcert:verifyallcertificates'] = 'Verify all certificates on the site';
|
||||||
|
$string['htmlcert:verifycertificate'] = 'Verify a certificate';
|
||||||
|
$string['htmlcertsettings'] = 'HTML certificate settings';
|
||||||
|
$string['deletecertpage'] = 'Delete page';
|
||||||
|
$string['deleteconfirm'] = 'Delete confirmation';
|
||||||
|
$string['deleteelement'] = 'Delete element';
|
||||||
|
$string['deleteelementconfirm'] = 'Are you sure you want to delete this element?';
|
||||||
|
$string['deleteissueconfirm'] = 'Are you sure you want to delete this certificate issue?';
|
||||||
|
$string['deleteissuedcertificates'] = 'Delete issued certificates';
|
||||||
|
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
|
||||||
|
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
|
||||||
|
$string['deliveryoptiondownload'] = 'Send to the browser and force a file download';
|
||||||
|
$string['deliveryoptioninline'] = 'Send the file inline to the browser';
|
||||||
|
$string['deliveryoptions'] = 'Delivery options';
|
||||||
|
$string['description'] = 'Description';
|
||||||
|
$string['duplicate'] = 'Duplicate';
|
||||||
|
$string['duplicateconfirm'] = 'Duplicate confirmation';
|
||||||
|
$string['duplicatetemplateconfirm'] = 'Are you sure you want to duplicate this certificate template?';
|
||||||
|
$string['edithtmlcert'] = 'Edit certificate';
|
||||||
|
$string['editelement'] = 'Edit element';
|
||||||
|
$string['edittemplate'] = 'Edit template';
|
||||||
|
$string['elementname'] = 'Element name';
|
||||||
|
$string['elementname_help'] = 'This will be the name used to identify this element when editing a certificate. Note: this will not displayed on the PDF.';
|
||||||
|
$string['elementplugins'] = 'Element plugins';
|
||||||
|
$string['elements'] = 'Elements';
|
||||||
|
$string['elements_help'] = 'This is the list of elements that will be displayed on the certificate.
|
||||||
|
|
||||||
|
Please note: The elements are rendered in this order. The order can be changed by using the arrows next to each element.';
|
||||||
|
$string['elementwidth'] = 'Width';
|
||||||
|
$string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.';
|
||||||
|
$string['emailnonstudentbody'] = 'Attached is the certificate \'{$a->certificatename}\' for \'{$a->userfullname}\' for the course \'{$a->coursefullname}\'.';
|
||||||
|
$string['emailnonstudentbodyplaintext'] = 'Attached is the certificate \'{$a->certificatename}\' for \'{$a->userfullname}\' for the course \'{$a->coursefullname}\'.';
|
||||||
|
$string['emailnonstudentcertificatelinktext'] = 'View certificate report';
|
||||||
|
$string['emailnonstudentgreeting'] = 'Hi';
|
||||||
|
$string['emailnonstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
|
||||||
|
$string['emailstudentbody'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
|
||||||
|
$string['emailstudentbodyplaintext'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
|
||||||
|
$string['emailstudentcertificatelinktext'] = 'View certificate';
|
||||||
|
$string['emailstudentgreeting'] = 'Dear {$a}';
|
||||||
|
$string['emailstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
|
||||||
|
$string['emailstudents'] = 'Email students';
|
||||||
|
$string['emailstudents_help'] = 'If set this will email the students a copy of the certificate when it becomes available. <strong>Warning:</strong> Setting this to \'Yes\' before you have finished creating the certificate will email the student an incomplete certificate.';
|
||||||
|
$string['emailteachers'] = 'Email teachers';
|
||||||
|
$string['emailteachers_help'] = 'If set this will email the teachers a copy of the certificate when it becomes available. <strong>Warning:</strong> Setting this to \'Yes\' before you have finished creating the certificate will email the teacher an incomplete certificate.';
|
||||||
|
$string['emailothers'] = 'Email others';
|
||||||
|
$string['emailothers_help'] = 'If set this will email the email addresses listed here (separated by a comma) with a copy of the certificate when it becomes available. <strong>Warning:</strong> Setting this field before you have finished creating the certificate will email the addresses an incomplete certificate.';
|
||||||
|
$string['exampledatawarning'] = 'Some of these values may just be an example to ensure positioning of the elements is possible.';
|
||||||
|
$string['font'] = 'Font';
|
||||||
|
$string['font_help'] = 'The font used when generating this element.';
|
||||||
|
$string['fontcolour'] = 'Colour';
|
||||||
|
$string['fontcolour_help'] = 'The colour of the font.';
|
||||||
|
$string['fontsize'] = 'Size';
|
||||||
|
$string['fontsize_help'] = 'The size of the font in points.';
|
||||||
|
$string['gethtmlcert'] = 'View certificate';
|
||||||
|
$string['gradeoutcome'] = 'Outcome';
|
||||||
|
$string['height'] = 'Height';
|
||||||
|
$string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.';
|
||||||
|
$string['html'] = 'Replace HTML';
|
||||||
|
$string['invalidcode'] = 'Invalid code supplied.';
|
||||||
|
$string['invalidcolour'] = 'Invalid colour chosen, please enter a valid HTML colour name, or a six-digit, or three-digit hexadecimal colour.';
|
||||||
|
$string['invalidelementwidth'] = 'Please enter a positive number.';
|
||||||
|
$string['invalidposition'] = 'Please select a positive number for position {$a}.';
|
||||||
|
$string['invalidheight'] = 'The height has to be a valid number greater than 0.';
|
||||||
|
$string['invalidmargin'] = 'The margin has to be a valid number greater than 0.';
|
||||||
|
$string['invalidwidth'] = 'The width has to be a valid number greater than 0.';
|
||||||
|
$string['landscape'] = 'Landscape';
|
||||||
|
$string['leftmargin'] = 'Left margin';
|
||||||
|
$string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.';
|
||||||
|
$string['listofissues'] = 'Recipients: {$a}';
|
||||||
|
$string['load'] = 'Load';
|
||||||
|
$string['loadtemplate'] = 'Load template';
|
||||||
|
$string['loadtemplatemsg'] = 'Are you sure you wish to load this template? This will remove any existing pages and elements for this certificate.';
|
||||||
|
$string['managetemplates'] = 'Manage templates';
|
||||||
|
$string['managetemplatesdesc'] = 'This link will take you to a new screen where you will be able to manage templates used by HTML certificate activities in courses.';
|
||||||
|
$string['modify'] = 'Modify';
|
||||||
|
$string['modulename'] = 'Certificate';
|
||||||
|
$string['modulenameplural'] = 'Certificates';
|
||||||
|
$string['modulename_help'] = 'This module allows for the dynamic generation of PDF certificates.';
|
||||||
|
$string['modulename_link'] = 'Custom_certificate_module';
|
||||||
|
$string['mycertificates'] = 'My certificates';
|
||||||
|
$string['mycertificatesdescription'] = 'These are the certificates you have been issued by either email or downloading manually.';
|
||||||
|
$string['name'] = 'Name';
|
||||||
|
$string['nametoolong'] = 'You have exceeded the maximum length allowed for the name';
|
||||||
|
$string['nohtmlcerts'] = 'There are no certificates for this course';
|
||||||
|
$string['noimage'] = 'No image';
|
||||||
|
$string['norecipients'] = 'No recipients';
|
||||||
|
$string['notemplates'] = 'No templates';
|
||||||
|
$string['notissued'] = 'Not awarded';
|
||||||
|
$string['notverified'] = 'Not verified';
|
||||||
|
$string['options'] = 'Options';
|
||||||
|
$string['page'] = 'Page {$a}';
|
||||||
|
$string['pluginadministration'] = 'HTML certificate administration';
|
||||||
|
$string['pluginname'] = 'Certificate';
|
||||||
|
$string['portrait'] = 'Portrait';
|
||||||
|
$string['posx'] = 'Position X';
|
||||||
|
$string['posx_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the x direction.';
|
||||||
|
$string['posy'] = 'Position Y';
|
||||||
|
$string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.';
|
||||||
|
$string['preventcopy'] = 'Prevent copy';
|
||||||
|
$string['preventcopy_desc'] = 'Enable protection from copy action.';
|
||||||
|
$string['preventprint'] = 'Prevent print';
|
||||||
|
$string['preventprint_desc'] = 'Enable protection from print action.';
|
||||||
|
$string['preventmodify'] = 'Prevent modify';
|
||||||
|
$string['preventmodify_desc'] = 'Enable protection from modify action.';
|
||||||
|
$string['print'] = 'Print';
|
||||||
|
$string['privacy:metadata:htmlcert_issues'] = 'The list of issued certificates';
|
||||||
|
$string['privacy:metadata:htmlcert_issues:code'] = 'The code that belongs to the certificate';
|
||||||
|
$string['privacy:metadata:htmlcert_issues:htmlcertid'] = 'The ID of the certificate';
|
||||||
|
$string['privacy:metadata:htmlcert_issues:emailed'] = 'Whether or not the certificate was emailed';
|
||||||
|
$string['privacy:metadata:htmlcert_issues:timecreated'] = 'The time the certificate was issued';
|
||||||
|
$string['privacy:metadata:htmlcert_issues:userid'] = 'The ID of the user who was issued the certificate';
|
||||||
|
$string['rearrangeelements'] = 'Reposition elements';
|
||||||
|
$string['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.';
|
||||||
|
$string['receiveddate'] = 'Awarded on';
|
||||||
|
$string['refpoint'] = 'Reference point location';
|
||||||
|
$string['refpoint_help'] = 'The reference point is the location of an element from which its x and y coordinates are determined. It is indicated by the \'+\' that appears in the centre or corners of the element.';
|
||||||
|
$string['replacetemplate'] = 'Replace';
|
||||||
|
$string['requiredtimenotmet'] = 'You must spend at least a minimum of {$a->requiredtime} minutes in the course before you can access this certificate.';
|
||||||
|
$string['rightmargin'] = 'Right margin';
|
||||||
|
$string['rightmargin_help'] = 'This is the right margin of the certificate PDF in mm.';
|
||||||
|
$string['save'] = 'Save';
|
||||||
|
$string['saveandclose'] = 'Save and close';
|
||||||
|
$string['saveandcontinue'] = 'Save and continue';
|
||||||
|
$string['savechangespreview'] = 'Save changes and preview';
|
||||||
|
$string['savetemplate'] = 'Save template';
|
||||||
|
$string['search:activity'] = 'Certificate - activity information';
|
||||||
|
$string['setprotection'] = 'Set protection';
|
||||||
|
$string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.';
|
||||||
|
$string['showposxy'] = 'Show position X and Y';
|
||||||
|
$string['showposxy_desc'] = 'This will show the X and Y position when editing of an element, allowing the user to accurately specify the location.
|
||||||
|
|
||||||
|
This isn\'t required if you plan on solely using the drag and drop interface for this purpose.';
|
||||||
|
$string['taskemailcertificate'] = 'Handles emailing certificates.';
|
||||||
|
$string['templatename'] = 'Template name';
|
||||||
|
$string['templatenameexists'] = 'That template name is currently in use, please choose another.';
|
||||||
|
$string['topcenter'] = 'Center';
|
||||||
|
$string['topleft'] = 'Top left';
|
||||||
|
$string['topright'] = 'Top right';
|
||||||
|
$string['type'] = 'Type';
|
||||||
|
$string['uploadimage'] = 'Upload image';
|
||||||
|
$string['uploadimagedesc'] = 'This link will take you to a new screen where you will be able to upload images. Images uploaded using
|
||||||
|
this method will be available throughout your site to all users who are able to create a certificate.';
|
||||||
|
$string['verified'] = 'Verified';
|
||||||
|
$string['verify'] = 'Verify';
|
||||||
|
$string['verifyallcertificates'] = 'Allow verification of all certificates';
|
||||||
|
$string['verifyallcertificates_desc'] = 'When this setting is enabled any person (including users not logged in) can visit the link \'{$a}\' in order to verify any certificate on the site, rather than having to go to the verification link for each certificate.
|
||||||
|
|
||||||
|
Note - this only applies to certificates where \'Allow anyone to verify a certificate\' has been set to \'Yes\' in the certificate settings.';
|
||||||
|
$string['verifycertificate'] = 'Verify certificate';
|
||||||
|
$string['verifycertificatedesc'] = 'This link will take you to a new screen where you will be able to verify certificates on the site';
|
||||||
|
$string['verifycertificateanyone'] = 'Allow anyone to verify a certificate';
|
||||||
|
$string['verifycertificateanyone_help'] = 'This setting enables anyone with the certificate verification link (including users not logged in) to verify a certificate.';
|
||||||
|
$string['width'] = 'Width';
|
||||||
|
$string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.';
|
195
lib.php
195
lib.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,57 +15,54 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customcert module core interaction API
|
* htmlcert module core interaction API
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add customcert instance.
|
* Add htmlcert instance.
|
||||||
*
|
*
|
||||||
* @param stdClass $data
|
* @param stdClass $data
|
||||||
* @param mod_customcert_mod_form $mform
|
* @param mod_htmlcert_mod_form $mform
|
||||||
* @return int new customcert instance id
|
* @return int new htmlcert instance id
|
||||||
*/
|
*/
|
||||||
function customcert_add_instance($data, $mform) {
|
function htmlcert_add_instance($data, $mform) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// Create a template for this customcert to use.
|
// Create a template for this htmlcert to use.
|
||||||
$context = context_module::instance($data->coursemodule);
|
$context = context_module::instance($data->coursemodule);
|
||||||
$template = \mod_customcert\template::create($data->name, $context->id);
|
$template = \mod_htmlcert\template::create($data->name, $context->id);
|
||||||
|
|
||||||
// Add the data to the DB.
|
// Add the data to the DB.
|
||||||
$data->templateid = $template->get_id();
|
$data->templateid = $template->get_id();
|
||||||
$data->protection = \mod_customcert\certificate::set_protection($data);
|
$data->protection = \mod_htmlcert\certificate::set_protection($data);
|
||||||
$data->timecreated = time();
|
$data->timecreated = time();
|
||||||
$data->timemodified = $data->timecreated;
|
$data->timemodified = $data->timecreated;
|
||||||
$data->id = $DB->insert_record('customcert', $data);
|
$data->id = $DB->insert_record('htmlcert', $data);
|
||||||
|
|
||||||
// Add a page to this customcert.
|
|
||||||
$template->add_page();
|
|
||||||
|
|
||||||
return $data->id;
|
return $data->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update customcert instance.
|
* Update htmlcert instance.
|
||||||
*
|
*
|
||||||
* @param stdClass $data
|
* @param stdClass $data
|
||||||
* @param mod_customcert_mod_form $mform
|
* @param mod_htmlcert_mod_form $mform
|
||||||
* @return bool true
|
* @return bool true
|
||||||
*/
|
*/
|
||||||
function customcert_update_instance($data, $mform) {
|
function htmlcert_update_instance($data, $mform) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$data->protection = \mod_customcert\certificate::set_protection($data);
|
$data->protection = \mod_htmlcert\certificate::set_protection($data);
|
||||||
$data->timemodified = time();
|
$data->timemodified = time();
|
||||||
$data->id = $data->instance;
|
$data->id = $data->instance;
|
||||||
|
|
||||||
return $DB->update_record('customcert', $data);
|
return $DB->update_record('htmlcert', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,36 +73,36 @@ function customcert_update_instance($data, $mform) {
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return bool true if successful
|
* @return bool true if successful
|
||||||
*/
|
*/
|
||||||
function customcert_delete_instance($id) {
|
function htmlcert_delete_instance($id) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// Ensure the customcert exists.
|
// Ensure the htmlcert exists.
|
||||||
if (!$customcert = $DB->get_record('customcert', array('id' => $id))) {
|
if (!$htmlcert = $DB->get_record('htmlcert', array('id' => $id))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the course module as it is used when deleting files.
|
// Get the course module as it is used when deleting files.
|
||||||
if (!$cm = get_coursemodule_from_instance('customcert', $id)) {
|
if (!$cm = get_coursemodule_from_instance('htmlcert', $id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the customcert instance.
|
// Delete the htmlcert instance.
|
||||||
if (!$DB->delete_records('customcert', array('id' => $id))) {
|
if (!$DB->delete_records('htmlcert', array('id' => $id))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, delete the template associated with this certificate.
|
// Now, delete the template associated with this certificate.
|
||||||
if ($template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid))) {
|
if ($template = $DB->get_record('htmlcert_templates', array('id' => $htmlcert->templateid))) {
|
||||||
$template = new \mod_customcert\template($template);
|
$template = new \mod_htmlcert\template($template);
|
||||||
$template->delete();
|
$template->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the customcert issues.
|
// Delete the htmlcert issues.
|
||||||
if (!$DB->delete_records('customcert_issues', array('customcertid' => $id))) {
|
if (!$DB->delete_records('htmlcert_issues', array('htmlcertid' => $id))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete any files associated with the customcert.
|
// Delete any files associated with the htmlcert.
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
$fs->delete_area_files($context->id);
|
$fs->delete_area_files($context->id);
|
||||||
|
@ -115,30 +112,25 @@ function customcert_delete_instance($id) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used by the reset_course_userdata function in moodlelib.
|
* This function is used by the reset_course_userdata function in moodlelib.
|
||||||
* This function will remove all posts from the specified customcert
|
* This function will remove all posts from the specified htmlcert
|
||||||
* and clean up any related data.
|
* and clean up any related data.
|
||||||
*
|
*
|
||||||
* @param stdClass $data the data submitted from the reset course.
|
* @param stdClass $data the data submitted from the reset course.
|
||||||
* @return array status array
|
* @return array status array
|
||||||
*/
|
*/
|
||||||
function customcert_reset_userdata($data) {
|
function htmlcert_reset_userdata($data) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$componentstr = get_string('modulenameplural', 'customcert');
|
$componentstr = get_string('modulenameplural', 'htmlcert');
|
||||||
$status = array();
|
$status = array();
|
||||||
|
|
||||||
if (!empty($data->reset_customcert)) {
|
if (!empty($data->reset_htmlcert)) {
|
||||||
$sql = "SELECT cert.id
|
$sql = "SELECT cert.id
|
||||||
FROM {customcert} cert
|
FROM {htmlcert} cert
|
||||||
WHERE cert.course = :courseid";
|
WHERE cert.course = :courseid";
|
||||||
$DB->delete_records_select('customcert_issues', "customcertid IN ($sql)", array('courseid' => $data->courseid));
|
$DB->delete_records_select('htmlcert_issues', "htmlcertid IN ($sql)", array('courseid' => $data->courseid));
|
||||||
$status[] = array('component' => $componentstr, 'item' => get_string('customcertremoved', 'customcert'), 'error' => false);
|
$status[] = array('component' => $componentstr, 'item' => get_string('deleteissuedcertificates', 'htmlcert'),
|
||||||
}
|
'error' => false);
|
||||||
|
|
||||||
// Updating dates - shift may be negative too.
|
|
||||||
if ($data->timeshift) {
|
|
||||||
shift_course_mod_dates('customcert', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid);
|
|
||||||
$status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -146,13 +138,13 @@ function customcert_reset_userdata($data) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the function for printing the form elements that control
|
* Implementation of the function for printing the form elements that control
|
||||||
* whether the course reset functionality affects the customcert.
|
* whether the course reset functionality affects the htmlcert.
|
||||||
*
|
*
|
||||||
* @param mod_customcert_mod_form $mform form passed by reference
|
* @param mod_htmlcert_mod_form $mform form passed by reference
|
||||||
*/
|
*/
|
||||||
function customcert_reset_course_form_definition(&$mform) {
|
function htmlcert_reset_course_form_definition(&$mform) {
|
||||||
$mform->addElement('header', 'customcertheader', get_string('modulenameplural', 'customcert'));
|
$mform->addElement('header', 'htmlcertheader', get_string('modulenameplural', 'htmlcert'));
|
||||||
$mform->addElement('advcheckbox', 'reset_customcert', get_string('deletissuedcustomcerts', 'customcert'));
|
$mform->addElement('advcheckbox', 'reset_htmlcert', get_string('deleteissuedcertificates', 'htmlcert'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,56 +153,54 @@ function customcert_reset_course_form_definition(&$mform) {
|
||||||
* @param stdClass $course
|
* @param stdClass $course
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function customcert_reset_course_form_defaults($course) {
|
function htmlcert_reset_course_form_defaults($course) {
|
||||||
return array('reset_customcert' => 1);
|
return array('reset_htmlcert' => 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about received customcert.
|
* Returns information about received htmlcert.
|
||||||
* Used for user activity reports.
|
* Used for user activity reports.
|
||||||
*
|
*
|
||||||
* @param stdClass $course
|
* @param stdClass $course
|
||||||
* @param stdClass $user
|
* @param stdClass $user
|
||||||
* @param stdClass $mod
|
* @param stdClass $mod
|
||||||
* @param stdClass $customcert
|
* @param stdClass $htmlcert
|
||||||
* @return stdClass the user outline object
|
* @return stdClass the user outline object
|
||||||
*/
|
*/
|
||||||
function customcert_user_outline($course, $user, $mod, $customcert) {
|
function htmlcert_user_outline($course, $user, $mod, $htmlcert) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$result = new stdClass();
|
$result = new stdClass();
|
||||||
if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) {
|
if ($issue = $DB->get_record('htmlcert_issues', array('htmlcertid' => $htmlcert->id, 'userid' => $user->id))) {
|
||||||
$result->info = get_string('issued', 'customcert');
|
$result->info = get_string('receiveddate', 'htmlcert');
|
||||||
$result->time = $issue->timecreated;
|
$result->time = $issue->timecreated;
|
||||||
} else {
|
} else {
|
||||||
$result->info = get_string('notissued', 'customcert');
|
$result->info = get_string('notissued', 'htmlcert');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about received customcert.
|
* Returns information about received htmlcert.
|
||||||
* Used for user activity reports.
|
* Used for user activity reports.
|
||||||
*
|
*
|
||||||
* @param stdClass $course
|
* @param stdClass $course
|
||||||
* @param stdClass $user
|
* @param stdClass $user
|
||||||
* @param stdClass $mod
|
* @param stdClass $mod
|
||||||
* @param stdClass $customcert
|
* @param stdClass $htmlcert
|
||||||
* @return string the user complete information
|
* @return string the user complete information
|
||||||
*/
|
*/
|
||||||
function customcert_user_complete($course, $user, $mod, $customcert) {
|
function htmlcert_user_complete($course, $user, $mod, $htmlcert) {
|
||||||
global $DB, $OUTPUT;
|
global $DB, $OUTPUT;
|
||||||
|
|
||||||
if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) {
|
if ($issue = $DB->get_record('htmlcert_issues', array('htmlcertid' => $htmlcert->id, 'userid' => $user->id))) {
|
||||||
echo $OUTPUT->box_start();
|
echo $OUTPUT->box_start();
|
||||||
echo get_string('issued', 'customcert') . ": ";
|
echo get_string('receiveddate', 'htmlcert') . ": ";
|
||||||
echo userdate($issue->timecreated);
|
echo userdate($issue->timecreated);
|
||||||
customcert_print_user_files($customcert->id, $user->id);
|
|
||||||
echo '<br />';
|
|
||||||
echo $OUTPUT->box_end();
|
echo $OUTPUT->box_end();
|
||||||
} else {
|
} else {
|
||||||
print_string('notissuedyet', 'customcert');
|
print_string('notissued', 'htmlcert');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +215,7 @@ function customcert_user_complete($course, $user, $mod, $customcert) {
|
||||||
* @param bool $forcedownload
|
* @param bool $forcedownload
|
||||||
* @return bool|null false if file not found, does not return anything if found - just send the file
|
* @return bool|null false if file not found, does not return anything if found - just send the file
|
||||||
*/
|
*/
|
||||||
function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
|
function htmlcert_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
require_once($CFG->libdir . '/filelib.php');
|
require_once($CFG->libdir . '/filelib.php');
|
||||||
|
@ -234,12 +224,12 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
|
||||||
if ($filearea === 'image') {
|
if ($filearea === 'image') {
|
||||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||||
require_login($course, false, $cm);
|
require_login($course, false, $cm);
|
||||||
} else if ($context->contextlevel == CONTEXT_SYSTEM && !has_capability('mod/certificate:manage', $context)) {
|
} else if ($context->contextlevel == CONTEXT_SYSTEM && !has_capability('mod/htmlcert:manage', $context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relativepath = implode('/', $args);
|
$relativepath = implode('/', $args);
|
||||||
$fullpath = '/' . $context->id . '/mod_customcert/image/' . $relativepath;
|
$fullpath = '/' . $context->id . '/mod_htmlcert/image/' . $relativepath;
|
||||||
|
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
||||||
|
@ -251,6 +241,8 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The features this activity supports.
|
||||||
|
*
|
||||||
* @uses FEATURE_GROUPS
|
* @uses FEATURE_GROUPS
|
||||||
* @uses FEATURE_GROUPINGS
|
* @uses FEATURE_GROUPINGS
|
||||||
* @uses FEATURE_GROUPMEMBERSONLY
|
* @uses FEATURE_GROUPMEMBERSONLY
|
||||||
|
@ -261,7 +253,7 @@ function customcert_pluginfile($course, $cm, $context, $filearea, $args, $forced
|
||||||
* @param string $feature FEATURE_xx constant for requested feature
|
* @param string $feature FEATURE_xx constant for requested feature
|
||||||
* @return mixed True if module supports feature, null if doesn't know
|
* @return mixed True if module supports feature, null if doesn't know
|
||||||
*/
|
*/
|
||||||
function customcert_supports($feature) {
|
function htmlcert_supports($feature) {
|
||||||
switch ($feature) {
|
switch ($feature) {
|
||||||
case FEATURE_GROUPS:
|
case FEATURE_GROUPS:
|
||||||
return true;
|
return true;
|
||||||
|
@ -269,6 +261,8 @@ function customcert_supports($feature) {
|
||||||
return true;
|
return true;
|
||||||
case FEATURE_MOD_INTRO:
|
case FEATURE_MOD_INTRO:
|
||||||
return true;
|
return true;
|
||||||
|
case FEATURE_SHOW_DESCRIPTION:
|
||||||
|
return true;
|
||||||
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
||||||
return true;
|
return true;
|
||||||
case FEATURE_BACKUP_MOODLE2:
|
case FEATURE_BACKUP_MOODLE2:
|
||||||
|
@ -279,27 +273,27 @@ function customcert_supports($feature) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for course participation report (in case customcert is added).
|
* Used for course participation report (in case htmlcert is added).
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function customcert_get_view_actions() {
|
function htmlcert_get_view_actions() {
|
||||||
return array('view', 'view all', 'view report');
|
return array('view', 'view all', 'view report');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for course participation report (in case customcert is added).
|
* Used for course participation report (in case htmlcert is added).
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function customcert_get_post_actions() {
|
function htmlcert_get_post_actions() {
|
||||||
return array('received');
|
return array('received');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to be run periodically according to the moodle cron.
|
* Function to be run periodically according to the moodle cron.
|
||||||
*/
|
*/
|
||||||
function customcert_cron() {
|
function htmlcert_cron() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,12 +304,12 @@ function customcert_cron() {
|
||||||
* context when this is called.
|
* context when this is called.
|
||||||
*
|
*
|
||||||
* @param settings_navigation $settings
|
* @param settings_navigation $settings
|
||||||
* @param navigation_node $customcertnode
|
* @param navigation_node $htmlcertnode
|
||||||
*/
|
*/
|
||||||
function customcert_extend_settings_navigation(settings_navigation $settings, navigation_node $customcertnode) {
|
function htmlcert_extend_settings_navigation(settings_navigation $settings, navigation_node $htmlcertnode) {
|
||||||
global $DB, $PAGE;
|
global $DB, $PAGE;
|
||||||
|
|
||||||
$keys = $customcertnode->get_children_key_list();
|
$keys = $htmlcertnode->get_children_key_list();
|
||||||
$beforekey = null;
|
$beforekey = null;
|
||||||
$i = array_search('modedit', $keys);
|
$i = array_search('modedit', $keys);
|
||||||
if ($i === false and array_key_exists(0, $keys)) {
|
if ($i === false and array_key_exists(0, $keys)) {
|
||||||
|
@ -324,15 +318,48 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na
|
||||||
$beforekey = $keys[$i + 1];
|
$beforekey = $keys[$i + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_capability('mod/customcert:manage', $PAGE->cm->context)) {
|
if (has_capability('mod/htmlcert:manage', $PAGE->cm->context)) {
|
||||||
// Get the template id.
|
// Get the template id.
|
||||||
$templateid = $DB->get_field('customcert', 'templateid', array('id' => $PAGE->cm->instance));
|
$templateid = $DB->get_field('htmlcert', 'templateid', array('id' => $PAGE->cm->instance));
|
||||||
$node = navigation_node::create(get_string('editcustomcert', 'customcert'),
|
$node = navigation_node::create(get_string('edithtmlcert', 'htmlcert'),
|
||||||
new moodle_url('/mod/customcert/edit.php', array('tid' => $templateid)),
|
new moodle_url('/mod/htmlcert/edit.php', array('tid' => $templateid)),
|
||||||
navigation_node::TYPE_SETTING, null, 'mod_customcert_edit',
|
navigation_node::TYPE_SETTING, null, 'mod_htmlcert_edit',
|
||||||
new pix_icon('t/edit', ''));
|
new pix_icon('t/edit', ''));
|
||||||
$customcertnode->add_node($node, $beforekey);
|
$htmlcertnode->add_node($node, $beforekey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $customcertnode->trim_if_empty();
|
if (has_capability('mod/htmlcert:verifycertificate', $PAGE->cm->context)) {
|
||||||
|
$node = navigation_node::create(get_string('verifycertificate', 'htmlcert'),
|
||||||
|
new moodle_url('/mod/htmlcert/verify_certificate.php', array('contextid' => $PAGE->cm->context->id)),
|
||||||
|
navigation_node::TYPE_SETTING, null, 'mod_htmlcert_verify_certificate',
|
||||||
|
new pix_icon('t/check', ''));
|
||||||
|
$htmlcertnode->add_node($node, $beforekey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $htmlcertnode->trim_if_empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add nodes to myprofile page.
|
||||||
|
*
|
||||||
|
* @param \core_user\output\myprofile\tree $tree Tree object
|
||||||
|
* @param stdClass $user user object
|
||||||
|
* @param bool $iscurrentuser
|
||||||
|
* @param stdClass $course Course object
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function mod_htmlcert_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
|
||||||
|
$url = new moodle_url('/mod/htmlcert/my_certificates.php', array('userid' => $user->id));
|
||||||
|
$node = new core_user\output\myprofile\node('miscellaneous', 'myhtmlcerts',
|
||||||
|
get_string('mycertificates', 'htmlcert'), null, $url);
|
||||||
|
$tree->add_node($node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get icon mapping for font-awesome.
|
||||||
|
*/
|
||||||
|
function mod_htmlcert_get_fontawesome_icon_map() {
|
||||||
|
return [
|
||||||
|
'mod_htmlcert:download' => 'fa-download'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles loading a customcert template.
|
* Handles loading a htmlcert template.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ $tid = required_param('tid', PARAM_INT);
|
||||||
$ltid = required_param('ltid', PARAM_INT); // The template to load.
|
$ltid = required_param('ltid', PARAM_INT); // The template to load.
|
||||||
$confirm = optional_param('confirm', 0, PARAM_INT);
|
$confirm = optional_param('confirm', 0, PARAM_INT);
|
||||||
|
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
||||||
$template = new \mod_customcert\template($template);
|
$template = new \mod_htmlcert\template($template);
|
||||||
|
|
||||||
$loadtemplate = $DB->get_record('customcert_templates', array('id' => $ltid), '*', MUST_EXIST);
|
$loadtemplate = $DB->get_record('htmlcert_templates', array('id' => $ltid), '*', MUST_EXIST);
|
||||||
$loadtemplate = new \mod_customcert\template($loadtemplate);
|
$loadtemplate = new \mod_htmlcert\template($loadtemplate);
|
||||||
|
|
||||||
if ($cm = $template->get_cm()) {
|
if ($cm = $template->get_cm()) {
|
||||||
require_login($cm->course, false, $cm);
|
require_login($cm->course, false, $cm);
|
||||||
|
@ -41,75 +41,42 @@ if ($cm = $template->get_cm()) {
|
||||||
}
|
}
|
||||||
$template->require_manage();
|
$template->require_manage();
|
||||||
|
|
||||||
|
if ($template->get_context()->contextlevel == CONTEXT_MODULE) {
|
||||||
|
$htmlcert = $DB->get_record('htmlcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$title = $htmlcert->name;
|
||||||
|
$heading = format_string($title);
|
||||||
|
} else {
|
||||||
|
$title = $SITE->fullname;
|
||||||
|
$heading = $title;
|
||||||
|
}
|
||||||
|
|
||||||
// Check that they have confirmed they wish to load the template.
|
// Check that they have confirmed they wish to load the template.
|
||||||
if ($confirm) {
|
if ($confirm && confirm_sesskey()) {
|
||||||
// First, remove all the existing elements and pages.
|
// Copy the items across.
|
||||||
$sql = "SELECT e.*
|
$loadtemplate->copy_to_template($template->get_id());
|
||||||
FROM {customcert_elements} e
|
|
||||||
INNER JOIN {customcert_pages} p
|
|
||||||
ON e.pageid = p.id
|
|
||||||
WHERE p.templateid = :templateid";
|
|
||||||
if ($elements = $DB->get_records_sql($sql, array('templateid' => $template->get_id()))) {
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
$e->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the pages.
|
|
||||||
$DB->delete_records('customcert_pages', array('templateid' => $template->get_id()));
|
|
||||||
|
|
||||||
// Store the current time in a variable.
|
|
||||||
$time = time();
|
|
||||||
|
|
||||||
// Now, get the template data we want to load.
|
|
||||||
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $ltid))) {
|
|
||||||
// Loop through the pages.
|
|
||||||
foreach ($templatepages as $templatepage) {
|
|
||||||
$page = clone($templatepage);
|
|
||||||
$page->templateid = $tid;
|
|
||||||
$page->timecreated = $time;
|
|
||||||
$page->timemodified = $time;
|
|
||||||
// Insert into the database.
|
|
||||||
$page->id = $DB->insert_record('customcert_pages', $page);
|
|
||||||
// Now go through the elements we want to load.
|
|
||||||
if ($templateelements = $DB->get_records('customcert_elements', array('pageid' => $templatepage->id))) {
|
|
||||||
foreach ($templateelements as $templateelement) {
|
|
||||||
$element = clone($templateelement);
|
|
||||||
$element->pageid = $page->id;
|
|
||||||
$element->timecreated = $time;
|
|
||||||
$element->timemodified = $time;
|
|
||||||
// Ok, now we want to insert this into the database.
|
|
||||||
$element->id = $DB->insert_record('customcert_elements', $element);
|
|
||||||
// Load any other information the element may need to for the template.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
if (!$e->copy_element($templateelement)) {
|
|
||||||
// Failed to copy - delete the element.
|
|
||||||
$e->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect.
|
// Redirect.
|
||||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
$url = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $tid));
|
||||||
redirect($url);
|
redirect($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the link options.
|
// Create the link options.
|
||||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
$nourl = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $tid));
|
||||||
$yesurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid,
|
$yesurl = new moodle_url('/mod/htmlcert/load_template.php', array('tid' => $tid,
|
||||||
'ltid' => $ltid,
|
'ltid' => $ltid,
|
||||||
'confirm' => 1));
|
'confirm' => 1,
|
||||||
|
'sesskey' => sesskey()));
|
||||||
|
|
||||||
$pageurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid, 'ltid' => $ltid));
|
$pageurl = new moodle_url('/mod/htmlcert/load_template.php', array('tid' => $tid, 'ltid' => $ltid));
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), get_string('loadtemplate', 'customcert'));
|
\mod_htmlcert\page_helper::page_setup($pageurl, $template->get_context(), $title);
|
||||||
|
|
||||||
|
$str = get_string('edithtmlcert', 'htmlcert');
|
||||||
|
$link = new moodle_url('/mod/htmlcert/edit.php', array('tid' => $template->get_id()));
|
||||||
|
$PAGE->navbar->add($str, new \action_link($link, $str));
|
||||||
|
$PAGE->navbar->add(get_string('loadtemplate', 'htmlcert'));
|
||||||
|
|
||||||
// Show a confirmation page.
|
// Show a confirmation page.
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->confirm(get_string('loadtemplatemsg', 'customcert'), $yesurl, $nourl);
|
echo $OUTPUT->heading($heading);
|
||||||
|
echo $OUTPUT->confirm(get_string('loadtemplatemsg', 'htmlcert'), $yesurl, $nourl);
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
40
load_template_cli.php
Normal file
40
load_template_cli.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
define('CLI_SCRIPT', true);
|
||||||
|
require_once('../../config.php');
|
||||||
|
|
||||||
|
$tid = $argv[1];
|
||||||
|
$ltid = $argv[2];
|
||||||
|
|
||||||
|
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
||||||
|
$template = new \mod_htmlcert\template($template);
|
||||||
|
|
||||||
|
$loadtemplate = $DB->get_record('htmlcert_templates', array('id' => $ltid), '*', MUST_EXIST);
|
||||||
|
$loadtemplate = new \mod_htmlcert\template($loadtemplate);
|
||||||
|
|
||||||
|
$cm = $template->get_cm();
|
||||||
|
|
||||||
|
if ($template->get_context()->contextlevel == CONTEXT_MODULE) {
|
||||||
|
$htmlcert = $DB->get_record('htmlcert', ['id' => $cm->instance], '*', MUST_EXIST);
|
||||||
|
$title = $htmlcert->name;
|
||||||
|
$heading = format_string($title);
|
||||||
|
} else {
|
||||||
|
$title = $SITE->fullname;
|
||||||
|
$heading = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
$loadtemplate->copy_to_template($template->get_id());
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,18 +15,20 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage customcert templates.
|
* Manage htmlcert templates.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('../../config.php');
|
require_once('../../config.php');
|
||||||
|
|
||||||
$contextid = optional_param('contextid', CONTEXT_SYSTEM::instance()->id, PARAM_INT);
|
$contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT);
|
||||||
$action = optional_param('action', '', PARAM_ALPHA);
|
$action = optional_param('action', '', PARAM_ALPHA);
|
||||||
$confirm = optional_param('confirm', 0, PARAM_INT);
|
$confirm = optional_param('confirm', 0, PARAM_INT);
|
||||||
|
$page = optional_param('page', 0, PARAM_INT);
|
||||||
|
$perpage = optional_param('perpage', 10, PARAM_INT);
|
||||||
|
|
||||||
if ($action) {
|
if ($action) {
|
||||||
$tid = required_param('tid', PARAM_INT);
|
$tid = required_param('tid', PARAM_INT);
|
||||||
|
@ -35,81 +37,96 @@ if ($action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tid) {
|
if ($tid) {
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
$template = $DB->get_record('htmlcert_templates', array('id' => $tid), '*', MUST_EXIST);
|
||||||
$template = new \mod_customcert\template($template);
|
$template = new \mod_htmlcert\template($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = context::instance_by_id($contextid);
|
$context = context::instance_by_id($contextid);
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
require_capability('mod/customcert:manage', $context);
|
require_capability('mod/htmlcert:manage', $context);
|
||||||
|
|
||||||
|
$title = $SITE->fullname;
|
||||||
|
|
||||||
// Set up the page.
|
// Set up the page.
|
||||||
$pageurl = new moodle_url('/mod/customcert/manage_templates.php');
|
$pageurl = new moodle_url('/mod/htmlcert/manage_templates.php');
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('managetemplates', 'customcert'));
|
\mod_htmlcert\page_helper::page_setup($pageurl, $context, $title);
|
||||||
|
|
||||||
// Additional page setup.
|
// Additional page setup.
|
||||||
$PAGE->navbar->add(get_string('managetemplates', 'customcert'));
|
if ($tid && $action && confirm_sesskey()) {
|
||||||
|
$PAGE->navbar->add(get_string('managetemplates', 'htmlcert'),
|
||||||
|
new moodle_url('/mod/htmlcert/manage_templates.php'));
|
||||||
|
} else {
|
||||||
|
$PAGE->navbar->add(get_string('managetemplates', 'htmlcert'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$heading = format_string($title, true, ['context' => $context]);
|
||||||
|
|
||||||
// Check if we are deleting a template.
|
|
||||||
if ($tid) {
|
if ($tid) {
|
||||||
if ($action == 'delete') {
|
if ($action && confirm_sesskey()) {
|
||||||
if (!$confirm) {
|
$nourl = new moodle_url('/mod/htmlcert/manage_templates.php');
|
||||||
$nourl = new moodle_url('/mod/customcert/manage_templates.php');
|
$yesurl = new moodle_url('/mod/htmlcert/manage_templates.php',
|
||||||
$yesurl = new moodle_url('/mod/customcert/manage_templates.php', array('tid' => $tid,
|
array(
|
||||||
'action' => 'delete',
|
'tid' => $tid,
|
||||||
|
'action' => $action,
|
||||||
'confirm' => 1,
|
'confirm' => 1,
|
||||||
'sesskey' => sesskey()));
|
'sesskey' => sesskey()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Show a confirmation page.
|
// Check if we are deleting a template.
|
||||||
$strheading = get_string('deleteconfirm', 'customcert');
|
if ($action == 'delete') {
|
||||||
$PAGE->navbar->add($strheading);
|
if (!$confirm) {
|
||||||
$PAGE->set_title($strheading);
|
// Show a confirmation page.
|
||||||
$message = get_string('deletetemplateconfirm', 'customcert');
|
$PAGE->navbar->add(get_string('deleteconfirm', 'htmlcert'));
|
||||||
echo $OUTPUT->header();
|
$message = get_string('deletetemplateconfirm', 'htmlcert');
|
||||||
echo $OUTPUT->heading($strheading);
|
echo $OUTPUT->header();
|
||||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
echo $OUTPUT->heading($heading);
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||||
exit();
|
echo $OUTPUT->footer();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the template.
|
||||||
|
$template->delete();
|
||||||
|
|
||||||
|
// Redirect back to the manage templates page.
|
||||||
|
redirect(new moodle_url('/mod/htmlcert/manage_templates.php'));
|
||||||
|
} else if ($action == 'duplicate') {
|
||||||
|
if (!$confirm) {
|
||||||
|
// Show a confirmation page.
|
||||||
|
$PAGE->navbar->add(get_string('duplicateconfirm', 'htmlcert'));
|
||||||
|
$message = get_string('duplicatetemplateconfirm', 'htmlcert');
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
echo $OUTPUT->heading($heading);
|
||||||
|
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||||
|
echo $OUTPUT->footer();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create another template to copy the data to.
|
||||||
|
$newtemplate = new \stdClass();
|
||||||
|
$newtemplate->name = $template->get_name() . ' (' . strtolower(get_string('duplicate', 'htmlcert')) . ')';
|
||||||
|
$newtemplate->contextid = $template->get_contextid();
|
||||||
|
$newtemplate->timecreated = time();
|
||||||
|
$newtemplate->timemodified = $newtemplate->timecreated;
|
||||||
|
$newtemplateid = $DB->insert_record('htmlcert_templates', $newtemplate);
|
||||||
|
|
||||||
|
// Copy the data to the new template.
|
||||||
|
$template->copy_to_template($newtemplateid);
|
||||||
|
|
||||||
|
// Redirect back to the manage templates page.
|
||||||
|
redirect(new moodle_url('/mod/htmlcert/manage_templates.php'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the template.
|
|
||||||
$template->delete();
|
|
||||||
|
|
||||||
// Redirect back to the manage templates page.
|
|
||||||
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Get all the templates that are available.
|
|
||||||
if ($templates = $DB->get_records('customcert_templates', array('contextid' => $contextid), 'timecreated DESC')) {
|
|
||||||
// Create a table to display these elements.
|
|
||||||
$table = new html_table();
|
|
||||||
$table->head = array(get_string('name', 'customcert'), '');
|
|
||||||
$table->align = array('left', 'center');
|
|
||||||
|
|
||||||
foreach ($templates as $template) {
|
$table = new \mod_htmlcert\manage_templates_table($context);
|
||||||
// Link to edit the element.
|
$table->define_baseurl($pageurl);
|
||||||
$editlink = new \moodle_url('/mod/customcert/edit.php', array('tid' => $template->id));
|
|
||||||
$editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit')));
|
|
||||||
|
|
||||||
// Link to delete the element.
|
|
||||||
$deletelink = new \moodle_url('/mod/customcert/manage_templates.php', array('tid' => $template->id,
|
|
||||||
'action' => 'delete'));
|
|
||||||
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')));
|
|
||||||
|
|
||||||
$row = new html_table_row();
|
|
||||||
$row->cells[] = $template->name;
|
|
||||||
$row->cells[] = $editicon . $deleteicon;
|
|
||||||
$table->data[] = $row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
if (isset($table)) {
|
echo $OUTPUT->heading($heading);
|
||||||
echo html_writer::table($table);
|
$table->out($perpage, false);
|
||||||
} else {
|
$url = new moodle_url('/mod/htmlcert/edit.php?contextid=' . $contextid);
|
||||||
echo html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert'));
|
echo $OUTPUT->single_button($url, get_string('createtemplate', 'htmlcert'), 'get');
|
||||||
}
|
|
||||||
$url = new moodle_url('/mod/customcert/edit.php?contextid=' . $contextid);
|
|
||||||
echo $OUTPUT->single_button($url, get_string('createtemplate', 'customcert'), 'get');
|
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
|
|
94
mobile/pluginfile.php
Normal file
94
mobile/pluginfile.php
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serves files for the mobile app.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2018 Mark Nelson <markn@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AJAX_SCRIPT - exception will be converted into JSON.
|
||||||
|
*/
|
||||||
|
define('AJAX_SCRIPT', true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NO_MOODLE_COOKIES - we don't want any cookie.
|
||||||
|
*/
|
||||||
|
define('NO_MOODLE_COOKIES', true);
|
||||||
|
|
||||||
|
require_once('../../../config.php');
|
||||||
|
require_once($CFG->libdir . '/filelib.php');
|
||||||
|
require_once($CFG->libdir . '/completionlib.php');
|
||||||
|
require_once($CFG->dirroot . '/webservice/lib.php');
|
||||||
|
|
||||||
|
// Allow CORS requests.
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
|
||||||
|
// Authenticate the user.
|
||||||
|
$token = required_param('token', PARAM_ALPHANUM);
|
||||||
|
$certificateid = required_param('certificateid', PARAM_INT);
|
||||||
|
$userid = required_param('userid', PARAM_INT);
|
||||||
|
|
||||||
|
$webservicelib = new webservice();
|
||||||
|
$authenticationinfo = $webservicelib->authenticate_user($token);
|
||||||
|
|
||||||
|
// Check the service allows file download.
|
||||||
|
$enabledfiledownload = (int) ($authenticationinfo['service']->downloadfiles);
|
||||||
|
if (empty($enabledfiledownload)) {
|
||||||
|
throw new webservice_access_exception('Web service file downloading must be enabled in external service settings');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cm = get_coursemodule_from_instance('htmlcert', $certificateid, 0, false, MUST_EXIST);
|
||||||
|
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||||
|
$certificate = $DB->get_record('htmlcert', ['id' => $certificateid], '*', MUST_EXIST);
|
||||||
|
$template = $DB->get_record('htmlcert_templates', ['id' => $certificate->templateid], '*', MUST_EXIST);
|
||||||
|
|
||||||
|
// Capabilities check.
|
||||||
|
require_capability('mod/htmlcert:view', \context_module::instance($cm->id));
|
||||||
|
if ($userid != $USER->id) {
|
||||||
|
require_capability('mod/htmlcert:viewreport', \context_module::instance($cm->id));
|
||||||
|
} else {
|
||||||
|
// Make sure the user has met the required time.
|
||||||
|
if ($certificate->requiredtime) {
|
||||||
|
if (\mod_htmlcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$issue = $DB->get_record('htmlcert_issues', ['htmlcertid' => $certificateid, 'userid' => $userid]);
|
||||||
|
|
||||||
|
// If we are doing it for the logged in user then we want to issue the certificate.
|
||||||
|
if (!$issue) {
|
||||||
|
// If the other user doesn't have an issue, then there is nothing to do.
|
||||||
|
if ($userid != $USER->id) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
\mod_htmlcert\certificate::issue_certificate($certificate->id, $USER->id);
|
||||||
|
|
||||||
|
// Set the custom certificate as viewed.
|
||||||
|
$completion = new completion_info($course);
|
||||||
|
$completion->set_module_viewed($cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we want to generate the PDF.
|
||||||
|
$template = new \mod_htmlcert\template($template);
|
||||||
|
$template->generate_pdf(false, $userid);
|
||||||
|
exit();
|
3
mobile/styles.css
Normal file
3
mobile/styles.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.timerewarded {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
184
mod_form.php
184
mod_form.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,6 +14,16 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file contains the instance add/edit form.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
use mod_htmlcert\certificate;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
||||||
|
@ -21,11 +31,11 @@ require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
||||||
/**
|
/**
|
||||||
* Instance add/edit form.
|
* Instance add/edit form.
|
||||||
*
|
*
|
||||||
* @package mod_customcert
|
* @package mod_htmlcert
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@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
|
||||||
*/
|
*/
|
||||||
class mod_customcert_mod_form extends moodleform_mod {
|
class mod_htmlcert_mod_form extends moodleform_mod {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form definition.
|
* Form definition.
|
||||||
|
@ -37,7 +47,7 @@ class mod_customcert_mod_form extends moodleform_mod {
|
||||||
|
|
||||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||||
|
|
||||||
$mform->addElement('text', 'name', get_string('name', 'customcert'), array('size' => '64'));
|
$mform->addElement('text', 'name', get_string('name', 'htmlcert'), array('size' => '64'));
|
||||||
if (!empty($CFG->formatstringstriptags)) {
|
if (!empty($CFG->formatstringstriptags)) {
|
||||||
$mform->setType('name', PARAM_TEXT);
|
$mform->setType('name', PARAM_TEXT);
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,18 +55,62 @@ class mod_customcert_mod_form extends moodleform_mod {
|
||||||
}
|
}
|
||||||
$mform->addRule('name', null, 'required', null, 'client');
|
$mform->addRule('name', null, 'required', null, 'client');
|
||||||
|
|
||||||
$this->standard_intro_elements(get_string('description', 'customcert'));
|
$this->standard_intro_elements(get_string('description', 'htmlcert'));
|
||||||
|
|
||||||
$mform->addElement('header', 'options', get_string('options', 'customcert'));
|
$mform->addElement('header', 'options', get_string('options', 'htmlcert'));
|
||||||
|
|
||||||
$mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3'));
|
$deliveryoptions = [
|
||||||
$mform->setType('requiredtime', PARAM_INT);
|
certificate::DELIVERY_OPTION_INLINE => get_string('deliveryoptioninline', 'htmlcert'),
|
||||||
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');
|
certificate::DELIVERY_OPTION_DOWNLOAD => get_string('deliveryoptiondownload', 'htmlcert')
|
||||||
|
];
|
||||||
|
$mform->addElement('select', 'deliveryoption', get_string('deliveryoptions', 'htmlcert'), $deliveryoptions);
|
||||||
|
$mform->setDefault('deliveryoption', certificate::DELIVERY_OPTION_INLINE);
|
||||||
|
|
||||||
$mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), get_string('print', 'customcert'));
|
if (has_capability('mod/htmlcert:manageemailstudents', $this->get_context())) {
|
||||||
$mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert'));
|
$mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'htmlcert'));
|
||||||
$mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert'));
|
$mform->setDefault('emailstudents', get_config('htmlcert', 'emailstudents'));
|
||||||
$mform->addHelpButton('protection_print', 'setprotection', 'customcert');
|
$mform->addHelpButton('emailstudents', 'emailstudents', 'htmlcert');
|
||||||
|
$mform->setType('emailstudents', PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/htmlcert:manageemailteachers', $this->get_context())) {
|
||||||
|
$mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'htmlcert'));
|
||||||
|
$mform->setDefault('emailteachers', get_config('htmlcert', 'emailteachers'));
|
||||||
|
$mform->addHelpButton('emailteachers', 'emailteachers', 'htmlcert');
|
||||||
|
$mform->setType('emailteachers', PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/htmlcert:manageemailothers', $this->get_context())) {
|
||||||
|
$mform->addElement('text', 'emailothers', get_string('emailothers', 'htmlcert'), array('size' => '40'));
|
||||||
|
$mform->addHelpButton('emailothers', 'emailothers', 'htmlcert');
|
||||||
|
$mform->setDefault('emailothers', get_config('htmlcert', 'emailothers'));
|
||||||
|
$mform->setType('emailothers', PARAM_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/htmlcert:manageverifyany', $this->get_context())) {
|
||||||
|
$mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'htmlcert'));
|
||||||
|
$mform->addHelpButton('verifyany', 'verifycertificateanyone', 'htmlcert');
|
||||||
|
$mform->setDefault('verifyany', get_config('htmlcert', 'verifyany'));
|
||||||
|
$mform->setType('verifyany', PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/htmlcert:managerequiredtime', $this->get_context())) {
|
||||||
|
$mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'htmlcert'), array('size' => '3'));
|
||||||
|
$mform->addHelpButton('requiredtime', 'coursetimereq', 'htmlcert');
|
||||||
|
$mform->setDefault('requiredtime', get_config('htmlcert', 'requiredtime'));
|
||||||
|
$mform->setType('requiredtime', PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/htmlcert:manageprotection', $this->get_context())) {
|
||||||
|
$mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'htmlcert'),
|
||||||
|
get_string('print', 'htmlcert'));
|
||||||
|
$mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'htmlcert'));
|
||||||
|
$mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'htmlcert'));
|
||||||
|
$mform->addHelpButton('protection_print', 'setprotection', 'htmlcert');
|
||||||
|
$mform->setType('protection_print', PARAM_BOOL);
|
||||||
|
$mform->setType('protection_modify', PARAM_BOOL);
|
||||||
|
$mform->setType('protection_copy', PARAM_BOOL);
|
||||||
|
}
|
||||||
|
|
||||||
$this->standard_coursemodule_elements();
|
$this->standard_coursemodule_elements();
|
||||||
|
|
||||||
|
@ -69,17 +123,51 @@ class mod_customcert_mod_form extends moodleform_mod {
|
||||||
* @param array $defaultvalues
|
* @param array $defaultvalues
|
||||||
*/
|
*/
|
||||||
public function data_preprocessing(&$defaultvalues) {
|
public function data_preprocessing(&$defaultvalues) {
|
||||||
if (!empty($defaultvalues['protection'])) {
|
// Set the values in the form to what has been set in database if updating
|
||||||
$protection = explode(', ', $defaultvalues['protection']);
|
// or set default configured values if creating.
|
||||||
// Set the values in the form to what has been set in database.
|
if (!empty($defaultvalues['update'])) {
|
||||||
if (in_array(\mod_customcert\certificate::PROTECTION_PRINT, $protection)) {
|
if (!empty($defaultvalues['protection'])) {
|
||||||
$defaultvalues['protection_print'] = 1;
|
$protection = $this->build_protection_data($defaultvalues['protection']);
|
||||||
|
|
||||||
|
$defaultvalues['protection_print'] = $protection->protection_print;
|
||||||
|
$defaultvalues['protection_modify'] = $protection->protection_modify;
|
||||||
|
$defaultvalues['protection_copy'] = $protection->protection_copy;
|
||||||
}
|
}
|
||||||
if (in_array(\mod_customcert\certificate::PROTECTION_MODIFY, $protection)) {
|
} else {
|
||||||
$defaultvalues['protection_modify'] = 1;
|
$defaultvalues['protection_print'] = get_config('htmlcert', 'protection_print');
|
||||||
|
$defaultvalues['protection_modify'] = get_config('htmlcert', 'protection_modify');
|
||||||
|
$defaultvalues['protection_copy'] = get_config('htmlcert', 'protection_copy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post process form data.
|
||||||
|
*
|
||||||
|
* @param \stdClass $data
|
||||||
|
*
|
||||||
|
* @throws \dml_exception
|
||||||
|
*/
|
||||||
|
public function data_postprocessing($data) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
parent::data_postprocessing($data);
|
||||||
|
|
||||||
|
// If creating a new activity.
|
||||||
|
if (!empty($data->add)) {
|
||||||
|
foreach ($this->get_options_elements_with_required_caps() as $name => $capability) {
|
||||||
|
if (!isset($data->$name) && !has_capability($capability, $this->get_context())) {
|
||||||
|
$data->$name = get_config('htmlcert', $name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (in_array(\mod_customcert\certificate::PROTECTION_COPY, $protection)) {
|
} else {
|
||||||
$defaultvalues['protection_copy'] = 1;
|
// If updating, but a user can't manage protection, then get data from database.
|
||||||
|
if (!has_capability('mod/htmlcert:manageprotection', $this->get_context())) {
|
||||||
|
$htmlcert = $DB->get_record('htmlcert', array('id' => $data->instance));
|
||||||
|
|
||||||
|
$protection = $this->build_protection_data($htmlcert->protection);
|
||||||
|
$data->protection_print = $protection->protection_print;
|
||||||
|
$data->protection_modify = $protection->protection_modify;
|
||||||
|
$data->protection_copy = $protection->protection_copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,10 +185,58 @@ class mod_customcert_mod_form extends moodleform_mod {
|
||||||
// Check that the required time entered is valid if it was entered at all.
|
// Check that the required time entered is valid if it was entered at all.
|
||||||
if (!empty($data['requiredtime'])) {
|
if (!empty($data['requiredtime'])) {
|
||||||
if ((!is_number($data['requiredtime']) || $data['requiredtime'] < 0)) {
|
if ((!is_number($data['requiredtime']) || $data['requiredtime'] < 0)) {
|
||||||
$errors['requiredtime'] = get_string('requiredtimenotvalid', 'customcert');
|
$errors['requiredtime'] = get_string('requiredtimenotvalid', 'htmlcert');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all options form elements with required capabilities for managing each element.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function get_options_elements_with_required_caps() {
|
||||||
|
return [
|
||||||
|
'emailstudents' => 'mod/htmlcert:manageemailstudents',
|
||||||
|
'emailteachers' => 'mod/htmlcert:manageemailteachers',
|
||||||
|
'emailothers' => 'mod/htmlcert:manageemailothers',
|
||||||
|
'verifyany' => 'mod/htmlcert:manageverifyany',
|
||||||
|
'requiredtime' => 'mod/htmlcert:managerequiredtime',
|
||||||
|
'protection_print' => 'mod/htmlcert:manageprotection',
|
||||||
|
'protection_modify' => 'mod/htmlcert:manageprotection',
|
||||||
|
'protection_copy' => 'mod/htmlcert:manageprotection'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a protection data to be able to set to the form.
|
||||||
|
*
|
||||||
|
* @param string $protection Protection sting from database.
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
protected function build_protection_data($protection) {
|
||||||
|
$data = new stdClass();
|
||||||
|
|
||||||
|
$data->protection_print = 0;
|
||||||
|
$data->protection_modify = 0;
|
||||||
|
$data->protection_copy = 0;
|
||||||
|
|
||||||
|
$protection = explode(', ', $protection);
|
||||||
|
|
||||||
|
if (in_array(certificate::PROTECTION_PRINT, $protection)) {
|
||||||
|
$data->protection_print = 1;
|
||||||
|
}
|
||||||
|
if (in_array(certificate::PROTECTION_MODIFY, $protection)) {
|
||||||
|
$data->protection_modify = 1;
|
||||||
|
}
|
||||||
|
if (in_array(certificate::PROTECTION_COPY, $protection)) {
|
||||||
|
$data->protection_copy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
85
my_certificates.php
Normal file
85
my_certificates.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of the htmlcert 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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles viewing the certificates for a certain user.
|
||||||
|
*
|
||||||
|
* @package mod_htmlcert
|
||||||
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('../../config.php');
|
||||||
|
|
||||||
|
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||||
|
$download = optional_param('download', null, PARAM_ALPHA);
|
||||||
|
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
|
||||||
|
if ($downloadcert) {
|
||||||
|
$certificateid = required_param('certificateid', PARAM_INT);
|
||||||
|
$htmlcert = $DB->get_record('htmlcert', array('id' => $certificateid), '*', MUST_EXIST);
|
||||||
|
|
||||||
|
// Check there exists an issued certificate for this user.
|
||||||
|
if (!$issue = $DB->get_record('htmlcert_issues', ['userid' => $userid, 'htmlcertid' => $htmlcert->id])) {
|
||||||
|
throw new moodle_exception('You have not been issued a certificate');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$page = optional_param('page', 0, PARAM_INT);
|
||||||
|
$perpage = optional_param('perpage', \mod_htmlcert\certificate::HTMLCERT_PER_PAGE, PARAM_INT);
|
||||||
|
$pageurl = $url = new moodle_url('/mod/htmlcert/my_certificates.php', array('userid' => $userid,
|
||||||
|
'page' => $page, 'perpage' => $perpage));
|
||||||
|
|
||||||
|
// Requires a login.
|
||||||
|
require_login();
|
||||||
|
|
||||||
|
// Check that we have a valid user.
|
||||||
|
$user = \core_user::get_user($userid, '*', MUST_EXIST);
|
||||||
|
|
||||||
|
// If we are viewing certificates that are not for the currently logged in user then do a capability check.
|
||||||
|
if (($userid != $USER->id) && !has_capability('mod/htmlcert:viewallcertificates', context_system::instance())) {
|
||||||
|
throw new moodle_exception('You are not allowed to view these certificates');
|
||||||
|
}
|
||||||
|
|
||||||
|
$PAGE->set_url($pageurl);
|
||||||
|
$PAGE->set_context(context_user::instance($userid));
|
||||||
|
$PAGE->set_title(get_string('mycertificates', 'htmlcert'));
|
||||||
|
$PAGE->set_pagelayout('standard');
|
||||||
|
$PAGE->navigation->extend_for_user($user);
|
||||||
|
|
||||||
|
// Check if we requested to download a certificate.
|
||||||
|
if ($downloadcert) {
|
||||||
|
$template = $DB->get_record('htmlcert_templates', array('id' => $htmlcert->templateid), '*', MUST_EXIST);
|
||||||
|
$template = new \mod_htmlcert\template($template);
|
||||||
|
$template->generate_pdf(false, $userid);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = new \mod_htmlcert\my_certificates_table($userid, $download);
|
||||||
|
$table->define_baseurl($pageurl);
|
||||||
|
|
||||||
|
if ($table->is_downloading()) {
|
||||||
|
$table->download();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional page setup.
|
||||||
|
$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $userid)));
|
||||||
|
$PAGE->navbar->add(get_string('mycertificates', 'htmlcert'));
|
||||||
|
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
echo $OUTPUT->heading(get_string('mycertificates', 'htmlcert'));
|
||||||
|
echo html_writer::div(get_string('mycertificatesdescription', 'htmlcert'));
|
||||||
|
$table->out($perpage, false);
|
||||||
|
echo $OUTPUT->footer();
|
BIN
pix/download.png
Normal file
BIN
pix/download.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 207 B |
3
pix/download.svg
Normal file
3
pix/download.svg
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
|
||||||
|
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
|
||||||
|
]><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" preserveAspectRatio="xMinYMid meet" overflow="visible"><path d="M16 9v6c0 .5-.5 1-1 1H1c-.5 0-1-.5-1-1V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1v4h10V9c0-.5.5-1 1-1h1c.5 0 1 .5 1 1zm-3.6-3.9l-.7-.7c-.4-.4-1-.4-1.4 0l-.8.8V1c0-.5-.4-1-1-1h-1c-.5 0-1 .5-1 1v4.2l-.8-.8c-.4-.4-1-.4-1.4 0l-.7.7c-.4.4-.4 1 0 1.4l3.7 3.7c.2.2.5.3.7.3.3 0 .5-.1.7-.3l3.7-3.7c.4-.3.4-1 0-1.4z" fill="#999"/></svg>
|
After Width: | Height: | Size: 618 B |
101
rearrange.php
101
rearrange.php
|
@ -1,101 +0,0 @@
|
||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles position elements on the PDF via drag and drop.
|
|
||||||
*
|
|
||||||
* @package mod_customcert
|
|
||||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once('../../config.php');
|
|
||||||
|
|
||||||
// The page of the customcert we are editing.
|
|
||||||
$pid = required_param('pid', PARAM_INT);
|
|
||||||
|
|
||||||
$page = $DB->get_record('customcert_pages', array('id' => $pid), '*', MUST_EXIST);
|
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $page->templateid), '*', MUST_EXIST);
|
|
||||||
$elements = $DB->get_records('customcert_elements', array('pageid' => $pid), 'sequence');
|
|
||||||
|
|
||||||
// Set the template.
|
|
||||||
$template = new \mod_customcert\template($template);
|
|
||||||
// Perform checks.
|
|
||||||
if ($cm = $template->get_cm()) {
|
|
||||||
require_login($cm->course, false, $cm);
|
|
||||||
} else {
|
|
||||||
require_login();
|
|
||||||
}
|
|
||||||
// Make sure the user has the required capabilities.
|
|
||||||
$template->require_manage();
|
|
||||||
|
|
||||||
// Set the $PAGE settings.
|
|
||||||
$pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid));
|
|
||||||
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), get_string('rearrangeelements', 'customcert'));
|
|
||||||
|
|
||||||
// Include the JS we need.
|
|
||||||
$PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'M.mod_customcert.rearrange.init',
|
|
||||||
array($template->get_id(),
|
|
||||||
$page,
|
|
||||||
$elements));
|
|
||||||
|
|
||||||
// Create the buttons to save the position of the elements.
|
|
||||||
$html = html_writer::start_tag('div', array('class' => 'buttons'));
|
|
||||||
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())),
|
|
||||||
get_string('saveandclose', 'customcert'), 'get', array('class' => 'savepositionsbtn'));
|
|
||||||
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid)),
|
|
||||||
get_string('saveandcontinue', 'customcert'), 'get', array('class' => 'applypositionsbtn'));
|
|
||||||
$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())),
|
|
||||||
get_string('cancel'), 'get', array('class' => 'cancelbtn'));
|
|
||||||
$html .= html_writer::end_tag('div');
|
|
||||||
|
|
||||||
// Create the div that represents the PDF.
|
|
||||||
$style = 'height: ' . $page->height . 'mm; line-height: normal; width: ' . $page->width . 'mm;';
|
|
||||||
$marginstyle = 'height: ' . $page->height . 'mm; width:1px; float:left; position:relative;';
|
|
||||||
$html .= html_writer::start_tag('div', array('id' => 'pdf', 'style' => $style));
|
|
||||||
if ($page->leftmargin) {
|
|
||||||
$position = 'left:' . $page->leftmargin . 'mm;';
|
|
||||||
$html .= "<div id='leftmargin' style='$position $marginstyle'></div>";
|
|
||||||
}
|
|
||||||
if ($elements) {
|
|
||||||
foreach ($elements as $element) {
|
|
||||||
// Get an instance of the element class.
|
|
||||||
if ($e = \mod_customcert\element::instance($element)) {
|
|
||||||
switch ($element->refpoint) {
|
|
||||||
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
|
||||||
$class = 'element refpoint-right';
|
|
||||||
break;
|
|
||||||
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPCENTER:
|
|
||||||
$class = 'element refpoint-center';
|
|
||||||
break;
|
|
||||||
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPLEFT:
|
|
||||||
default:
|
|
||||||
$class = 'element refpoint-left';
|
|
||||||
}
|
|
||||||
$html .= html_writer::tag('div', $e->render_html(), array('class' => $class, 'id' => 'element-' . $element->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($page->rightmargin) {
|
|
||||||
$position = 'left:' . ($page->width - $page->rightmargin) . 'mm;';
|
|
||||||
$html .= "<div id='rightmargin' style='$position $marginstyle'></div>";
|
|
||||||
}
|
|
||||||
$html .= html_writer::end_tag('div');
|
|
||||||
|
|
||||||
echo $OUTPUT->header();
|
|
||||||
echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 4);
|
|
||||||
echo $html;
|
|
||||||
echo $OUTPUT->footer();
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue