commit
ee215165ea
652 changed files with 78337 additions and 0 deletions
@ -0,0 +1,674 @@ |
|||
GNU GENERAL PUBLIC LICENSE |
|||
Version 3, 29 June 2007 |
|||
|
|||
Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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 |
|||
<https://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 |
|||
<https://www.gnu.org/licenses/why-not-lgpl.html>. |
|||
@ -0,0 +1,64 @@ |
|||
# H5P Moodle Plugin |
|||
|
|||
Create and add rich content inside your LMS for free. Some examples of what you |
|||
get with H5P are Interactive Video, Quizzes, Collage and Timeline. |
|||
|
|||
## Usage |
|||
|
|||
If you intend to use the repository directly in production, make sure that you're using the "Stable" branch, as this is the production branch. |
|||
There are no guarantees for the state of the other branches at any given time. |
|||
Also make sure that all submodules are pulled as well using: |
|||
|
|||
``` |
|||
git submodule update --init |
|||
``` |
|||
|
|||
## Description |
|||
|
|||
One of the great benefits with using H5P is that it gives you access to lots of |
|||
different [interactive content types](https://h5p.org/content-types-and-applications). |
|||
|
|||
Another great benefit with H5P is that it allows you to easily share and reuse |
|||
content. To reuse content, you just download the H5P you would like to edit and |
|||
make your changes – e.g. translate to a new language or adjust it to a new |
|||
situation. |
|||
|
|||
H5P is: |
|||
|
|||
* Open Source |
|||
* Free to Use |
|||
* HTML5 |
|||
* Responsive |
|||
|
|||
The H5P community is actively contributing to improve H5P. Updates and new |
|||
features are continuously made available on the community portal |
|||
[H5P.org](https://h5p.org). |
|||
|
|||
View our [setup for Moodle](https://h5p.org/moodle) to get information on how |
|||
to get started with H5P. |
|||
|
|||
### GDPR Compliance |
|||
Information useful to help you achieve GDPR compliance while using this plugin |
|||
can be found at [H5P.org's GDPR Compliance](https://h5p.org/plugin-gdpr-compliance) page. |
|||
|
|||
### Development Version |
|||
Warning! Never use the development version in production, there are no guarantees for which state the development branches are in at a given time. |
|||
|
|||
Inside your `moodle/mod` folder you run the following command: |
|||
``` |
|||
git clone -b master https://github.com/h5p/h5p-moodle-plugin.git hvp && cd hvp && git submodule update --init |
|||
``` |
|||
|
|||
### Enabling The Plugin |
|||
In Moodle, go to administrator -> plugin overview, and press 'Update database'. |
|||
|
|||
## Settings |
|||
Settings can be found at: Site Administration -> Plugins -> Activity Modules -> H5P |
|||
|
|||
## Contributing |
|||
Feel free to contribute by: |
|||
* Submitting translations to the [Moodle AMOS translator](https://lang.moodle.org/local/amos/view.php) |
|||
* Testing and creating issues. But remember to check if the issues is already |
|||
reported before creating a new one. Perhaps you can contribute to an already |
|||
existing issue? |
|||
* Solving issues and submitting code through Pull Requests to the 'master' branch or on a separate feature branch. |
|||
@ -0,0 +1,506 @@ |
|||
<?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/>. |
|||
/** |
|||
* Responsible for handling AJAX requests related to H5P. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
use mod_hvp\framework; |
|||
|
|||
define('AJAX_SCRIPT', true); |
|||
require(__DIR__ . '/../../config.php'); |
|||
require_once($CFG->libdir . '/filelib.php'); |
|||
require_once("locallib.php"); |
|||
|
|||
require_login(); |
|||
|
|||
$action = required_param('action', PARAM_ALPHA); |
|||
switch($action) { |
|||
|
|||
/* |
|||
* Handle user data reporting |
|||
* |
|||
* Type: HTTP POST |
|||
* |
|||
* Parameters: |
|||
* - content_id |
|||
* - data_type |
|||
* - sub_content_id |
|||
*/ |
|||
case 'contentsuserdata': |
|||
\mod_hvp\content_user_data::handle_ajax(); |
|||
break; |
|||
|
|||
/* |
|||
* Handle restricting H5P libraries |
|||
* |
|||
* Type: HTTP GET |
|||
* |
|||
* Parameters: |
|||
* - library_id |
|||
* - restrict (0 or 1) |
|||
* - token |
|||
*/ |
|||
case 'restrictlibrary': |
|||
|
|||
// Check permissions. |
|||
$context = \context_system::instance(); |
|||
if (!has_capability('mod/hvp:restrictlibraries', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontorestrict', 'hvp')); |
|||
http_response_code(403); |
|||
break; |
|||
} |
|||
|
|||
$libraryid = required_param('library_id', PARAM_INT); |
|||
$restrict = required_param('restrict', PARAM_INT); |
|||
|
|||
if (!\H5PCore::validToken('library_' . $libraryid, required_param('token', PARAM_RAW))) { |
|||
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp')); |
|||
exit; |
|||
} |
|||
|
|||
hvp_restrict_library($libraryid, $restrict); |
|||
header('Cache-Control: no-cache'); |
|||
header('Content-Type: application/json'); |
|||
echo json_encode(array( |
|||
'url' => (new moodle_url('/mod/hvp/ajax.php', array( |
|||
'action' => 'restrict_library', |
|||
'token' => \H5PCore::createToken('library_' . $libraryid), |
|||
'restrict' => ($restrict === '1' ? 0 : 1), |
|||
'library_id' => $libraryid |
|||
)))->out(false))); |
|||
break; |
|||
|
|||
/* |
|||
* Collecting data needed by H5P content upgrade |
|||
* |
|||
* Type: HTTP GET |
|||
* |
|||
* Parameters: |
|||
* - library (Format: /<machine-name>/<major-version>/<minor-version>) |
|||
*/ |
|||
case 'getlibrarydataforupgrade': |
|||
|
|||
// Check permissions. |
|||
$context = \context_system::instance(); |
|||
if (!has_capability('mod/hvp:updatelibraries', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontoupgrade', 'hvp')); |
|||
http_response_code(403); |
|||
break; |
|||
} |
|||
|
|||
$library = required_param('library', PARAM_TEXT); |
|||
$library = explode('/', substr($library, 1)); |
|||
|
|||
if (count($library) !== 3) { |
|||
http_response_code(422); |
|||
return; |
|||
} |
|||
|
|||
$library = hvp_get_library_upgrade_info($library[0], $library[1], $library[2]); |
|||
|
|||
header('Cache-Control: no-cache'); |
|||
header('Content-Type: application/json'); |
|||
print json_encode($library); |
|||
|
|||
break; |
|||
|
|||
/* |
|||
* Saving upgraded content, and returning next batch to process |
|||
* |
|||
* Type: HTTP POST |
|||
* |
|||
* Parameters: |
|||
* - library_id |
|||
*/ |
|||
case 'libraryupgradeprogress': |
|||
// Check upgrade permissions. |
|||
$context = \context_system::instance(); |
|||
if (!has_capability('mod/hvp:updatelibraries', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontoupgrade', 'hvp')); |
|||
http_response_code(403); |
|||
break; |
|||
} |
|||
|
|||
// Because of a confirmed bug in PHP, filter_input(INPUT_SERVER, ...) |
|||
// will return null on some versions of FCGI/PHP (5.4 and probably |
|||
// older versions as well), ref. https://bugs.php.net/bug.php?id=49184. |
|||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|||
$libraryid = required_param('library_id', PARAM_INT); |
|||
$out = hvp_content_upgrade_progress($libraryid); |
|||
header('Cache-Control: no-cache'); |
|||
header('Content-Type: application/json'); |
|||
print json_encode($out); |
|||
} else { |
|||
// Only allow POST. |
|||
http_response_code(405); |
|||
} |
|||
break; |
|||
|
|||
/* |
|||
* Handle set finished / storing grades |
|||
* |
|||
* Type: HTTP GET |
|||
* |
|||
* Parameters: |
|||
* - contentId |
|||
* - score |
|||
* - maxScore |
|||
*/ |
|||
case 'setfinished': |
|||
\mod_hvp\user_grades::handle_ajax(); |
|||
break; |
|||
|
|||
/* |
|||
* Saves a dynamically graded grade to the gradebook |
|||
* |
|||
* Type: HTTP POST |
|||
* |
|||
* Parameters: |
|||
* - subcontent_id |
|||
* - score |
|||
*/ |
|||
case 'updatesubcontentscore': |
|||
\mod_hvp\user_grades::handle_dynamic_grading(); |
|||
break; |
|||
|
|||
/* |
|||
* Returns a grade |
|||
* |
|||
* Type: HTTP GET |
|||
* |
|||
* Parameters: |
|||
* - subcontent_id |
|||
*/ |
|||
case 'getsubcontentscore': |
|||
\mod_hvp\user_grades::return_subcontent_grade(); |
|||
break; |
|||
|
|||
/* |
|||
* Provide data for results view |
|||
* |
|||
* Type: HTTP GET |
|||
* |
|||
* Parameters: |
|||
* int content_id |
|||
* int offset |
|||
* int limit |
|||
* int sortBy |
|||
* int sortDir |
|||
* string[] filters |
|||
*/ |
|||
case 'results': |
|||
$results = new \mod_hvp\results(); |
|||
$results->print_results(); |
|||
break; |
|||
|
|||
/* |
|||
* Load list of libraries or details for library. |
|||
* |
|||
* Parameters: |
|||
* string machineName |
|||
* int majorVersion |
|||
* int minorVersion |
|||
*/ |
|||
case 'libraries': |
|||
if (!framework::has_editor_access('nopermissiontoviewcontenttypes')) { |
|||
break; |
|||
} |
|||
|
|||
// Get parameters. |
|||
$name = optional_param('machineName', '', PARAM_TEXT); |
|||
$major = optional_param('majorVersion', 0, PARAM_INT); |
|||
$minor = optional_param('minorVersion', 0, PARAM_INT); |
|||
$editor = framework::instance('editor'); |
|||
$language = optional_param('default-language', null, PARAM_RAW); |
|||
|
|||
if (!empty($name)) { |
|||
$editor->ajax->action(H5PEditorEndpoints::SINGLE_LIBRARY, $name, |
|||
$major, $minor, framework::get_language(), '', '', $language); |
|||
|
|||
new \mod_hvp\event( |
|||
'library', null, |
|||
null, null, |
|||
$name, $major . '.' . $minor |
|||
); |
|||
} else { |
|||
$editor->ajax->action(H5PEditorEndpoints::LIBRARIES); |
|||
} |
|||
|
|||
break; |
|||
|
|||
/* |
|||
* Load content type cache list to display available libraries in hub |
|||
*/ |
|||
case 'contenttypecache': |
|||
if (!framework::has_editor_access('nopermissiontoviewcontenttypes')) { |
|||
break; |
|||
} |
|||
|
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::CONTENT_TYPE_CACHE); |
|||
break; |
|||
|
|||
/* |
|||
* Handle file upload through the editor. |
|||
* |
|||
* Parameters: |
|||
* int contentId |
|||
* int contextId |
|||
*/ |
|||
case 'files': |
|||
$token = required_param('token', PARAM_RAW); |
|||
$contentid = required_param('contentId', PARAM_INT); |
|||
if (!framework::has_editor_access('nopermissiontouploadfiles')) { |
|||
break; |
|||
} |
|||
|
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::FILES, $token, $contentid); |
|||
break; |
|||
|
|||
/* |
|||
* Handle file upload through the editor. |
|||
* |
|||
* Parameters: |
|||
* raw token |
|||
* raw contentTypeUrl |
|||
*/ |
|||
case 'libraryinstall': |
|||
$token = required_param('token', PARAM_RAW); |
|||
$machinename = required_param('id', PARAM_TEXT); |
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::LIBRARY_INSTALL, $token, $machinename); |
|||
break; |
|||
|
|||
/* |
|||
* Install libraries from h5p and retrieve content json |
|||
* |
|||
* Parameters: |
|||
* file h5p |
|||
*/ |
|||
case 'libraryupload': |
|||
$token = required_param('token', PARAM_RAW); |
|||
if (!framework::has_editor_access('nopermissiontouploadcontent')) { |
|||
break; |
|||
} |
|||
|
|||
$editor = framework::instance('editor'); |
|||
$uploadpath = $_FILES['h5p']['tmp_name']; |
|||
$contentid = optional_param('contentId', 0, PARAM_INT); |
|||
$editor->ajax->action(H5PEditorEndpoints::LIBRARY_UPLOAD, $token, $uploadpath, $contentid); |
|||
break; |
|||
|
|||
/* |
|||
* Record xAPI result from view |
|||
*/ |
|||
case 'xapiresult': |
|||
\mod_hvp\xapi_result::handle_ajax(); |
|||
break; |
|||
|
|||
case 'translations': |
|||
if (!framework::has_editor_access('nopermissiontogettranslations')) { |
|||
break; |
|||
} |
|||
$language = required_param('language', PARAM_RAW); |
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::TRANSLATIONS, $language); |
|||
break; |
|||
|
|||
/* |
|||
* Handle filtering of parameters through AJAX. |
|||
*/ |
|||
case 'filter': |
|||
$token = required_param('token', PARAM_RAW); |
|||
$libraryparameters = required_param('libraryParameters', PARAM_RAW); |
|||
|
|||
if (!framework::has_editor_access('nopermissiontouploadfiles')) { |
|||
break; |
|||
} |
|||
|
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::FILTER, $token, $libraryparameters); |
|||
break; |
|||
|
|||
/* |
|||
* Handle filtering of parameters through AJAX. |
|||
*/ |
|||
case 'contenthubmetadatacache': |
|||
if (!framework::has_editor_access('nopermissiontoviewcontenthubcache')) { |
|||
break; |
|||
} |
|||
$editor = framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::CONTENT_HUB_METADATA_CACHE, framework::get_language()); |
|||
break; |
|||
|
|||
case 'contenthubregistration': |
|||
// Check permission. |
|||
$context = \context_system::instance(); |
|||
if (!has_capability('mod/hvp:contenthubregistration', $context)) { |
|||
\H5PCore::ajaxError(get_string('contenthub:nopermissions', 'hvp'), 'NO_PERMISSION', 403); |
|||
return; |
|||
} |
|||
|
|||
$token = required_param('_token', PARAM_RAW); |
|||
|
|||
if (!H5PCore::validToken('contentHubRegistration', $token)) { |
|||
H5PCore::ajaxError('Invalid token', 'INVALID_TOKEN', 401); |
|||
return; |
|||
} |
|||
$logo = isset($_FILES['logo']) ? $_FILES['logo'] : null; |
|||
|
|||
$formdata = [ |
|||
'name' => required_param('name', PARAM_TEXT), |
|||
'email' => required_param('email', PARAM_EMAIL), |
|||
'description' => optional_param('description', '', PARAM_TEXT), |
|||
'contact_person' => optional_param('contact_person', '', PARAM_TEXT), |
|||
'phone' => optional_param('phone', '', PARAM_TEXT), |
|||
'address' => optional_param('address', '', PARAM_TEXT), |
|||
'city' => optional_param('city', '', PARAM_TEXT), |
|||
'zip' => optional_param('zip', '', PARAM_TEXT), |
|||
'country' => optional_param('country', '', PARAM_TEXT), |
|||
'remove_logo' => optional_param('remove_logo', '', PARAM_BOOL), |
|||
]; |
|||
|
|||
$core = framework::instance(); |
|||
$result = $core->hubRegisterAccount($formdata, $logo); |
|||
|
|||
if ($result['success'] === false) { |
|||
$core->h5pF->setErrorMessage($result['message']); |
|||
H5PCore::ajaxError($result['message'], $result['error_code'], $result['status_code']); |
|||
return; |
|||
} |
|||
|
|||
$core->h5pF->setInfoMessage($result['message']); |
|||
H5PCore::ajaxSuccess($result['message']); |
|||
break; |
|||
|
|||
/* |
|||
* Handle filtering of parameters through AJAX. |
|||
*/ |
|||
case 'getcontent': |
|||
$token = required_param('token', PARAM_RAW); |
|||
$hubid = required_param('hubId', PARAM_INT); |
|||
|
|||
$editor = \mod_hvp\framework::instance('editor'); |
|||
$editor->ajax->action(H5PEditorEndpoints::GET_HUB_CONTENT, $token, $hubid, null); |
|||
break; |
|||
|
|||
/* |
|||
* Handle publishing of content to the H5P OER Hub. |
|||
*/ |
|||
case 'share': |
|||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { |
|||
http_response_code(405); |
|||
} |
|||
$token = required_param('_token', PARAM_RAW); |
|||
$id = required_param('id', PARAM_INT); |
|||
|
|||
if (!\H5PCore::validToken('share_' . $id, $token)) { |
|||
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp')); |
|||
break; |
|||
} |
|||
|
|||
$data = array( |
|||
'title' => required_param('title', PARAM_RAW), |
|||
'language' => required_param('language', PARAM_RAW), |
|||
'license' => required_param('license', PARAM_RAW), |
|||
'license_version' => required_param('license_version', PARAM_RAW), |
|||
'level' => optional_param('level', null, PARAM_RAW), |
|||
'disciplines' => optional_param_array('disciplines', null, PARAM_RAW), |
|||
'keywords' => optional_param_array('keywords', null, PARAM_RAW), |
|||
'summary' => optional_param('summary', null, PARAM_RAW), |
|||
'description' => optional_param('description', null, PARAM_RAW), |
|||
'screenshot_alt_texts' => optional_param_array('screenshot_alt_texts', null, PARAM_RAW), |
|||
'remove_screenshots' => optional_param_array('remove_screenshots', null, PARAM_RAW), |
|||
'remove_icon' => optional_param('remove_icon', null, PARAM_RAW), |
|||
'age' => optional_param('age', null, PARAM_RAW), |
|||
); |
|||
|
|||
// Load content. |
|||
$core = \mod_hvp\framework::instance(); |
|||
$cm = get_coursemodule_from_id('hvp', $id); |
|||
$content = $core->loadContent($cm->instance); |
|||
|
|||
// Update Hub status for content before proceeding. |
|||
$newstate = hvp_update_hub_status($content); |
|||
$synced = $newstate !== false ? $newstate : intval($content['synced']); |
|||
|
|||
if ($synced === \H5PContentHubSyncStatus::WAITING) { |
|||
\H5PCore::ajaxError(get_string('contentissyncing', 'hvp')); |
|||
break; |
|||
} |
|||
|
|||
// Create URL. |
|||
$data['download_url'] = hvp_create_hub_export_url($cm->id, $content); |
|||
|
|||
// Get file size. |
|||
$slug = $content['slug'] ? $content['slug'] . '-' : ''; |
|||
$filecontext = context_course::instance($cm->course); |
|||
$file = get_file_storage()->get_file($filecontext->id, 'mod_hvp', 'exports', 0, '/', "{$slug}{$content['id']}.h5p"); |
|||
if (!$file) { |
|||
\H5PCore::ajaxError(get_string('noexport', 'hvp')); |
|||
break; |
|||
} |
|||
$size = $file->get_filesize(); |
|||
$data['size'] = empty($size) ? -1 : $size; |
|||
|
|||
// Add the icon and any screenshots. |
|||
$files = array( |
|||
'icon' => !empty($_FILES['icon']) ? $_FILES['icon'] : null, |
|||
'screenshots' => !empty($_FILES['screenshots']) ? $_FILES['screenshots'] : null, |
|||
); |
|||
|
|||
try { |
|||
$isedit = !empty($content['contentHubId']); |
|||
$updatecontent = $synced === \H5PContentHubSyncStatus::NOT_SYNCED && $isedit; |
|||
if ($updatecontent) { |
|||
// Node has been edited since the last time it was published. |
|||
$data['resync'] = 1; |
|||
} |
|||
$result = $core->hubPublishContent($data, $files, $isedit ? $content['contentHubId'] : null); |
|||
|
|||
$fields = array( |
|||
'shared' => 1, // Content is always shared after sharing or editing. |
|||
); |
|||
if (!$isedit) { |
|||
$fields['hub_id'] = $result->content->id; |
|||
// Sync will not happen on 'edit info', only for 'publish' or 'sync'. |
|||
$fields['synced'] = \H5PContentHubSyncStatus::WAITING; |
|||
} else if ($updatecontent) { |
|||
$fields['synced'] = \H5PContentHubSyncStatus::WAITING; |
|||
} |
|||
|
|||
// Store the content hub id. |
|||
$core->h5pF->updateContentFields($cm->instance, $fields); |
|||
|
|||
H5PCore::ajaxSuccess(); |
|||
} catch (Exception $e) { |
|||
H5PCore::ajaxError(!empty($e->errors) ? $e->errors : $e->getMessage()); |
|||
} |
|||
|
|||
break; |
|||
|
|||
/* |
|||
* Throw error if AJAX isnt handeled |
|||
*/ |
|||
default: |
|||
throw new coding_exception('Unhandled AJAX'); |
|||
break; |
|||
} |
|||
@ -0,0 +1 @@ |
|||
define([],function(){var a=function(){this._actionHandlers={},this.registerEventListeners()};return a.prototype._actionHandlers={},a.prototype.on=function(a,b){this._actionHandlers[a]=b},a.prototype.send=function(a,b){void 0===b&&(b={}),b.context="h5p",b.action=a,window.parent.postMessage(b,"*")},a.prototype.registerEventListeners=function(){var a=this;window.addEventListener("message",function(b){window.parent===b.source&&"h5p"===b.data.context&&void 0!==a._actionHandlers[b.data.action]&&a._actionHandlers[b.data.action](b.data)},!1)},new a}); |
|||
@ -0,0 +1,2 @@ |
|||
define ("mod_hvp/contenthubregistration",[],function(){return{init:function init(){var a=H5PSettings;a.container=document.getElementById("h5p-hub-registration");H5PHub.createRegistrationUI(a)}}}); |
|||
//# sourceMappingURL=contenthubregistration.min.js.map
|
|||
@ -0,0 +1 @@ |
|||
{"version":3,"sources":["../src/contenthubregistration.js"],"names":["define","init","settings","H5PSettings","container","document","getElementById","H5PHub","createRegistrationUI"],"mappings":"AAAAA,OAAM,kCAAC,EAAD,CAAK,UAAY,CACrB,MAAO,CACLC,IAAI,CAAE,eAAY,CAEhB,GAAMC,CAAAA,CAAQ,CAAGC,WAAjB,CACAD,CAAQ,CAACE,SAAT,CAAqBC,QAAQ,CAACC,cAAT,CAAwB,sBAAxB,CAArB,CACAC,MAAM,CAACC,oBAAP,CAA4BN,CAA5B,CACD,CANI,CAQR,CATK,CAAN","sourcesContent":["define([], function () {\n return {\n init: function () {\n // Moodle complains if you pass in settings through init (js_call_amd) since they are too large\n const settings = H5PSettings;\n settings.container = document.getElementById('h5p-hub-registration');\n H5PHub.createRegistrationUI(settings);\n },\n };\n});\n"],"file":"contenthubregistration.min.js"} |
|||
@ -0,0 +1 @@ |
|||
define(["jquery","mod_hvp/communicator"],function(a,b){a(document).ready(function(){a(".h5p-iframe").ready(function(){var a=document.querySelector(".h5p-iframe"),c=a.contentWindow.H5P;if(c&&c.instances&&c.instances[0]){var d,e=c.instances[0],f=!1;b.on("ready",function(){b.send("hello")}),b.on("hello",function(){f=!0,a.contentDocument.body.style.overflow="hidden",document.body.classList.add("h5p-resizing"),c.trigger(e,"resize")}),b.on("resizePrepared",function(){b.send("resize",{scrollHeight:a.contentDocument.body.scrollHeight})}),b.on("resize",function(){c.trigger(e,"resize")}),c.on(e,"resize",function(){c.isFullscreen||(clearTimeout(d),d=setTimeout(function(){f?b.send("prepareResize",{scrollHeight:a.contentDocument.body.scrollHeight,clientHeight:a.contentDocument.body.clientHeight}):b.send("hello")},0))}),c.trigger(e,"resize")}})})}); |
|||
@ -0,0 +1,79 @@ |
|||
// 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/>.
|
|||
|
|||
define([], function() { |
|||
|
|||
/** |
|||
* When embedded the communicator helps talk to the parent page. |
|||
* This is a copy of the H5P.communicator, which we need to communicate in this context |
|||
*/ |
|||
var H5PEmbedCommunicator = function() { |
|||
this._actionHandlers = {}; |
|||
this.registerEventListeners(); |
|||
}; |
|||
|
|||
/** @type {Object} Maps actions to functions. */ |
|||
H5PEmbedCommunicator.prototype._actionHandlers = {}; |
|||
|
|||
/** |
|||
* Register action listener. |
|||
* |
|||
* @param {string} action What you are waiting for |
|||
* @param {function} handler What you want done |
|||
*/ |
|||
H5PEmbedCommunicator.prototype.on = function(action, handler) { |
|||
this._actionHandlers[action] = handler; |
|||
}; |
|||
|
|||
/** |
|||
* Send a message to the all mighty father. |
|||
* |
|||
* @param {string} action |
|||
* @param {Object} [data] payload |
|||
*/ |
|||
H5PEmbedCommunicator.prototype.send = function(action, data) { |
|||
if (data === undefined) { |
|||
data = {}; |
|||
} |
|||
data.context = 'h5p'; |
|||
data.action = action; |
|||
|
|||
// Parent origin can be anything.
|
|||
window.parent.postMessage(data, '*'); |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Register event listeners for the communicator. |
|||
* |
|||
* @method registerEventListeners |
|||
*/ |
|||
H5PEmbedCommunicator.prototype.registerEventListeners = function() { |
|||
var self = this; |
|||
// Register message listener.
|
|||
window.addEventListener('message', function receiveMessage(event) { |
|||
if (window.parent !== event.source || event.data.context !== 'h5p') { |
|||
return; // Only handle messages from parent and in the correct context.
|
|||
} |
|||
|
|||
if (self._actionHandlers[event.data.action] !== undefined) { |
|||
self._actionHandlers[event.data.action](event.data); |
|||
} |
|||
}, false); |
|||
}; |
|||
|
|||
return new H5PEmbedCommunicator(); |
|||
|
|||
}); |
|||
@ -0,0 +1,10 @@ |
|||
define([], function () { |
|||
return { |
|||
init: function () { |
|||
// Moodle complains if you pass in settings through init (js_call_amd) since they are too large
|
|||
const settings = H5PSettings; |
|||
settings.container = document.getElementById('h5p-hub-registration'); |
|||
H5PHub.createRegistrationUI(settings); |
|||
}, |
|||
}; |
|||
}); |
|||
@ -0,0 +1,90 @@ |
|||
// 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/>.
|
|||
|
|||
define(['jquery', 'mod_hvp/communicator'], function($, H5PEmbedCommunicator) { |
|||
|
|||
// Wait for instances to be initialize.
|
|||
$(document).ready(function() { |
|||
$('.h5p-iframe').ready(function() { |
|||
var iFrame = document.querySelector('.h5p-iframe'); |
|||
var H5P = iFrame.contentWindow.H5P; |
|||
|
|||
// Check for H5P instances.
|
|||
if (!H5P || !H5P.instances || !H5P.instances[0]) { |
|||
return; |
|||
} |
|||
|
|||
var resizeDelay; |
|||
var instance = H5P.instances[0]; |
|||
var parentIsFriendly = false; |
|||
|
|||
// Handle that the resizer is loaded after the iframe.
|
|||
H5PEmbedCommunicator.on('ready', function() { |
|||
H5PEmbedCommunicator.send('hello'); |
|||
}); |
|||
|
|||
// Handle hello message from our parent window.
|
|||
H5PEmbedCommunicator.on('hello', function() { |
|||
// Initial setup/handshake is done.
|
|||
parentIsFriendly = true; |
|||
|
|||
// Hide scrollbars for correct size.
|
|||
iFrame.contentDocument.body.style.overflow = 'hidden'; |
|||
|
|||
document.body.classList.add('h5p-resizing'); |
|||
|
|||
// Content need to be resized to fit the new iframe size.
|
|||
H5P.trigger(instance, 'resize'); |
|||
}); |
|||
|
|||
// When resize has been prepared tell parent window to resize.
|
|||
H5PEmbedCommunicator.on('resizePrepared', function() { |
|||
H5PEmbedCommunicator.send('resize', { |
|||
scrollHeight: iFrame.contentDocument.body.scrollHeight |
|||
}); |
|||
}); |
|||
|
|||
H5PEmbedCommunicator.on('resize', function() { |
|||
H5P.trigger(instance, 'resize'); |
|||
}); |
|||
|
|||
H5P.on(instance, 'resize', function() { |
|||
if (H5P.isFullscreen) { |
|||
return; // Skip iframe resize.
|
|||
} |
|||
|
|||
// Use a delay to make sure iframe is resized to the correct size.
|
|||
clearTimeout(resizeDelay); |
|||
resizeDelay = setTimeout(function() { |
|||
// Only resize if the iframe can be resized.
|
|||
if (parentIsFriendly) { |
|||
H5PEmbedCommunicator.send('prepareResize', |
|||
{ |
|||
scrollHeight: iFrame.contentDocument.body.scrollHeight, |
|||
clientHeight: iFrame.contentDocument.body.clientHeight |
|||
} |
|||
); |
|||
} else { |
|||
H5PEmbedCommunicator.send('hello'); |
|||
} |
|||
}, 0); |
|||
}); |
|||
|
|||
// Trigger initial resize for instance.
|
|||
H5P.trigger(instance, 'resize'); |
|||
}); |
|||
}); |
|||
|
|||
}); |
|||
@ -0,0 +1,80 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* References files that should be automatically loaded |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* A simple autoloader which makes it easy to load classes when you need them. |
|||
* |
|||
* @param string $class name |
|||
*/ |
|||
function hvp_autoloader($class) { |
|||
global $CFG; |
|||
static $classmap; |
|||
if (!isset($classmap)) { |
|||
$classmap = array( |
|||
// Core. |
|||
'H5PCore' => 'library/h5p.classes.php', |
|||
'H5PFrameworkInterface' => 'library/h5p.classes.php', |
|||
'H5PContentValidator' => 'library/h5p.classes.php', |
|||
'H5PValidator' => 'library/h5p.classes.php', |
|||
'H5PStorage' => 'library/h5p.classes.php', |
|||
'H5PExport' => 'library/h5p.classes.php', |
|||
'H5PDevelopment' => 'library/h5p-development.class.php', |
|||
'H5PFileStorage' => 'library/h5p-file-storage.interface.php', |
|||
'H5PDefaultStorage' => 'library/h5p-default-storage.class.php', |
|||
'H5PEventBase' => 'library/h5p-event-base.class.php', |
|||
'H5PMetadata' => 'library/h5p-metadata.class.php', |
|||
|
|||
// Editor. |
|||
'H5peditor' => 'editor/h5peditor.class.php', |
|||
'H5PEditorAjax' => 'editor/h5peditor-ajax.class.php', |
|||
'H5PEditorAjaxInterface' => 'editor/h5peditor-ajax.interface.php', |
|||
'H5peditorFile' => 'editor/h5peditor-file.class.php', |
|||
'H5peditorStorage' => 'editor/h5peditor-storage.interface.php', |
|||
|
|||
// Reporting. |
|||
'H5PReport' => 'reporting/h5p-report.class.php', |
|||
'H5PReportXAPIData' => 'reporting/h5p-report-xapi-data.class.php', |
|||
'ChoiceProcessor' => 'reporting/type-processors/choice-processor.class.php', |
|||
'CompoundProcessor' => 'reporting/type-processors/compound-processor.class.php', |
|||
'FillInProcessor' => 'reporting/type-processors/fill-in-processor.class.php', |
|||
'LongChoiceProcessor' => 'reporting/type-processors/long-choice-processor.class.php', |
|||
'MatchingProcessor' => 'reporting/type-processors/matching-processor.class.php', |
|||
'TrueFalseProcessor' => 'reporting/type-processors/true-false-processor.class.php', |
|||
'IVOpenEndedQuestionProcessor' => 'reporting/type-processors/iv-open-ended-question-processor.class.php', |
|||
'TypeProcessor' => 'reporting/type-processors/type-processor.class.php', |
|||
'DocumentationToolProcessor' => 'reporting/type-processors/compound/documentation-tool-processor.class.php', |
|||
'GoalsPageProcessor' => 'reporting/type-processors/compound/goals-page-processor.class.php', |
|||
'GoalsAssessmentPageProcessor' => 'reporting/type-processors/compound/goals-assessment-page-processor.class.php', |
|||
'StandardPageProcessor' => 'reporting/type-processors/compound/standard-page-processor.class.php', |
|||
|
|||
// Plugin specific classes are loaded by Moodle. |
|||
); |
|||
} |
|||
|
|||
if (isset($classmap[$class])) { |
|||
require_once($CFG->dirroot . '/mod/hvp/' . $classmap[$class]); |
|||
} |
|||
} |
|||
spl_autoload_register('hvp_autoloader'); |
|||
@ -0,0 +1,90 @@ |
|||
<?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 backup_hvp_activity_task class |
|||
* |
|||
* @package mod_hvp |
|||
* @category backup |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->dirroot . '/mod/hvp/backup/moodle2/backup_hvp_stepslib.php'); |
|||
|
|||
/** |
|||
* Provides the steps to perform one complete backup of a H5P instance |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class backup_hvp_activity_task extends backup_activity_task { |
|||
|
|||
/** |
|||
* No specific settings for this activity |
|||
*/ |
|||
protected function define_my_settings() { |
|||
} |
|||
|
|||
/** |
|||
* Defines a backup step to store the instance data in the hvp.xml file |
|||
*/ |
|||
protected function define_my_steps() { |
|||
global $CFG; |
|||
|
|||
// Add hvp activity data and content files. |
|||
$this->add_step(new backup_hvp_activity_structure_step('hvp_structure', 'hvp.xml')); |
|||
|
|||
// Allow user to override library backup. |
|||
$backuplibraries = !(isset($CFG->mod_hvp_backup_libraries) && $CFG->mod_hvp_backup_libraries === '0'); |
|||
|
|||
// Exclude hvp libraries step for local 'imports'. |
|||
if ($backuplibraries && backup_controller_dbops::backup_includes_files($this->plan->get_backupid())) { |
|||
|
|||
// Note that this step will only run once per backup as it generates |
|||
// a shared resource. |
|||
$this->add_step(new backup_hvp_libraries_structure_step('hvp_libraries', 'hvp_libraries.xml')); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Encodes URLs to the index.php and view.php scripts |
|||
* |
|||
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts |
|||
* @return string the content with the URLs encoded |
|||
*/ |
|||
static public function encode_content_links($content) { |
|||
global $CFG; |
|||
|
|||
$base = preg_quote($CFG->wwwroot, "/"); |
|||
|
|||
// Link to the list of glossaries. |
|||
$search = "/(".$base."\/mod\/hvp\/index.php\?id\=)([0-9]+)/"; |
|||
$content = preg_replace($search, '$@HVPINDEX*$2@$', $content); |
|||
|
|||
// Link to hvp view by module id. |
|||
$search = "/(".$base."\/mod\/hvp\/view.php\?id\=)([0-9]+)/"; |
|||
$content = preg_replace($search, '$@HVPVIEWBYID*$2@$', $content); |
|||
|
|||
// Link to hvp embed by module id. |
|||
$search = "/(".$base."\/mod\/hvp\/embed.php\?id\=)([0-9]+)/"; |
|||
$content = preg_replace($search, '$@HVPEMBEDBYID*$2@$', $content); |
|||
|
|||
return $content; |
|||
} |
|||
} |
|||
@ -0,0 +1,248 @@ |
|||
<?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 backup structure steps for both hvp content and hvp libraries. |
|||
* |
|||
* @package mod_hvp |
|||
* @category backup |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Define the complete hvp structure for backup, with file and id annotations |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class backup_hvp_activity_structure_step extends backup_activity_structure_step { |
|||
|
|||
/** |
|||
* Defines backup element's structure |
|||
* |
|||
* @return backup_nested_element |
|||
* @throws base_element_struct_exception |
|||
* @throws base_step_exception |
|||
*/ |
|||
protected function define_structure() { |
|||
|
|||
// To know if we are including user info. |
|||
$userinfo = $this->get_setting_value('userinfo'); |
|||
|
|||
// Define each element separated. |
|||
$hvp = new backup_nested_element('hvp', array('id'), array( |
|||
'name', |
|||
'machine_name', |
|||
'major_version', |
|||
'minor_version', |
|||
'intro', |
|||
'introformat', |
|||
'json_content', |
|||
'embed_type', |
|||
'disable', |
|||
'content_type', |
|||
'source', |
|||
'year_from', |
|||
'year_to', |
|||
'license_version', |
|||
'changes', |
|||
'license_extras', |
|||
'author_comments', |
|||
'slug', |
|||
'timecreated', |
|||
'timemodified', |
|||
'authors', |
|||
'license', |
|||
'completionpass' |
|||
)); |
|||
|
|||
// User data. |
|||
$entries = new backup_nested_element('content_user_data'); |
|||
$contentuserdata = new backup_nested_element('entry', array( |
|||
'user_id', // Annotated. |
|||
'sub_content_id' |
|||
), array( |
|||
'data_id', |
|||
'data', |
|||
'preloaded', |
|||
'delete_on_content_change', |
|||
)); |
|||
|
|||
// Build the tree. |
|||
|
|||
$hvp->add_child($entries); |
|||
$entries->add_child($contentuserdata); |
|||
|
|||
// Define sources. |
|||
|
|||
// Uses library name and version instead of main_library_id. |
|||
$hvp->set_source_sql(' |
|||
SELECT h.id, |
|||
hl.machine_name, |
|||
hl.major_version, |
|||
hl.minor_version, |
|||
h.name, |
|||
h.intro, |
|||
h.introformat, |
|||
h.json_content, |
|||
h.embed_type, |
|||
h.disable, |
|||
h.content_type, |
|||
h.slug, |
|||
h.timecreated, |
|||
h.timemodified, |
|||
h.authors, |
|||
h.source, |
|||
h.year_from, |
|||
h.year_to, |
|||
h.license_version, |
|||
h.changes, |
|||
h.license_extras, |
|||
h.author_comments, |
|||
h.license, |
|||
h.completionpass |
|||
FROM {hvp} h |
|||
JOIN {hvp_libraries} hl ON hl.id = h.main_library_id |
|||
WHERE h.id = ?', array(backup::VAR_ACTIVITYID)); |
|||
|
|||
// All the rest of elements only happen if we are including user info. |
|||
if ($userinfo) { |
|||
$contentuserdata->set_source_table('hvp_content_user_data', array('hvp_id' => backup::VAR_PARENTID)); |
|||
} |
|||
|
|||
// Define id annotations. |
|||
$contentuserdata->annotate_ids('user', 'user_id'); |
|||
// In an ideal world we would use the main_library_id and annotate that |
|||
// but since we cannot know the required dependencies of the content |
|||
// without parsing json_content and crawling the libraries_libraries |
|||
// (library dependencies) table it's much easier to just include all |
|||
// installed libraries. |
|||
|
|||
// Define file annotations. |
|||
$hvp->annotate_files('mod_hvp', 'intro', null, null); |
|||
$hvp->annotate_files('mod_hvp', 'content', null, null); |
|||
|
|||
// Return the root element (hvp), wrapped into standard activity structure. |
|||
return $this->prepare_activity_structure($hvp); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Backup h5p libraries. |
|||
* |
|||
* Structure step in charge of constructing the hvp_libraries.xml file for |
|||
* all the H5P libraries. |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class backup_hvp_libraries_structure_step extends backup_structure_step { |
|||
|
|||
/** |
|||
* Determines if backup step should be executed |
|||
* |
|||
* @return bool |
|||
* @throws backup_step_exception |
|||
*/ |
|||
protected function execute_condition() { |
|||
$fullpath = $this->task->get_taskbasepath(); |
|||
if (empty($fullpath)) { |
|||
throw new backup_step_exception('backup_structure_step_undefined_fullpath'); |
|||
} |
|||
|
|||
// Modify filename to use a globally shared file for all libraries. |
|||
$this->filename = "../{$this->filename}"; |
|||
|
|||
// Append the filename to the full path. |
|||
$fullpath = rtrim($fullpath, '/') . '/' . $this->filename; |
|||
|
|||
// Determine if already generated. |
|||
return !file_exists($fullpath); |
|||
} |
|||
|
|||
/** |
|||
* Defines the structure to be executed by this backup step |
|||
* |
|||
* @return backup_nested_element |
|||
* @throws base_element_struct_exception |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function define_structure() { |
|||
// Libraries. |
|||
$libraries = new backup_nested_element('hvp_libraries'); |
|||
$library = new backup_nested_element('library', array('id'), array( |
|||
'title', |
|||
'machine_name', |
|||
'major_version', |
|||
'minor_version', |
|||
'patch_version', |
|||
'runnable', |
|||
'fullscreen', |
|||
'embed_types', |
|||
'preloaded_js', |
|||
'preloaded_css', |
|||
'drop_library_css', |
|||
'semantics', |
|||
'restricted', |
|||
'tutorial_url', |
|||
'add_to', |
|||
'metadata' |
|||
)); |
|||
|
|||
// Library translations. |
|||
$translations = new backup_nested_element('translations'); |
|||
$translation = new backup_nested_element('translation', array( |
|||
'language_code' |
|||
), array( |
|||
'language_json' |
|||
)); |
|||
|
|||
// Library dependencies. |
|||
$dependencies = new backup_nested_element('dependencies'); |
|||
$dependency = new backup_nested_element('dependency', array( |
|||
'required_library_id' |
|||
), array( |
|||
'dependency_type' |
|||
)); |
|||
|
|||
// Build the tree. |
|||
$libraries->add_child($library); |
|||
|
|||
$library->add_child($translations); |
|||
$translations->add_child($translation); |
|||
|
|||
$library->add_child($dependencies); |
|||
$dependencies->add_child($dependency); |
|||
|
|||
// Define sources. |
|||
|
|||
$library->set_source_table('hvp_libraries', array()); |
|||
|
|||
$translation->set_source_table('hvp_libraries_languages', array('library_id' => backup::VAR_PARENTID)); |
|||
|
|||
$dependency->set_source_table('hvp_libraries_libraries', array('library_id' => backup::VAR_PARENTID)); |
|||
|
|||
// Define file annotations. |
|||
$context = \context_system::instance(); |
|||
$library->annotate_files('mod_hvp', 'libraries', null, $context->id); |
|||
|
|||
// Return root element. |
|||
return $libraries; |
|||
} |
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Describe how H5P activites are to be restored from backup |
|||
* |
|||
* @package mod_hvp |
|||
* @category backup |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once($CFG->dirroot . '/mod/hvp/backup/moodle2/restore_hvp_stepslib.php'); // Because it exists (must). |
|||
|
|||
/** |
|||
* Hvp restore task that provides all the settings and steps to perform one complete restore of the activity. |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class restore_hvp_activity_task extends restore_activity_task { |
|||
|
|||
/** |
|||
* Define (add) particular settings this activity can have |
|||
*/ |
|||
protected function define_my_settings() { |
|||
// No particular settings for this activity. |
|||
} |
|||
|
|||
/** |
|||
* Define (add) particular steps this activity can have |
|||
*/ |
|||
protected function define_my_steps() { |
|||
// Add H5P libraries. |
|||
$this->add_step(new restore_hvp_libraries_structure_step('hvp_structure', 'hvp_libraries.xml')); |
|||
|
|||
// Add H5P content. |
|||
$this->add_step(new restore_hvp_activity_structure_step('hvp_structure', 'hvp.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('hvp', array('intro'), 'hvp'); |
|||
|
|||
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('HVPVIEWBYID', '/mod/hvp/view.php?id=$1', 'course_module'); |
|||
$rules[] = new restore_decode_rule('HVPINDEX', '/mod/hvp/index.php?id=$1', 'course'); |
|||
$rules[] = new restore_decode_rule('HVPEMBEDBYID', '/mod/hvp/embed.php?id=$1', 'course_module'); |
|||
|
|||
return $rules; |
|||
} |
|||
|
|||
/** |
|||
* Define the restore log rules that will be applied |
|||
* by the {@link restore_logs_processor} when restoring |
|||
* hvp logs. It must return one array |
|||
* of {@link restore_log_rule} objects |
|||
*/ |
|||
static public function define_restore_log_rules() { |
|||
$rules = array(); |
|||
|
|||
$rules[] = new restore_log_rule('hvp', 'add', 'view.php?id={course_module}', '{hvp}'); |
|||
$rules[] = new restore_log_rule('hvp', 'update', 'view.php?id={course_module}', '{hvp}'); |
|||
$rules[] = new restore_log_rule('hvp', 'view', 'view.php?id={course_module}', '{hvp}'); |
|||
|
|||
return $rules; |
|||
} |
|||
|
|||
/** |
|||
* Define the restore log rules that will be applied |
|||
* by the {@link restore_logs_processor} when restoring |
|||
* course logs. It must return one array |
|||
* of {@link restore_log_rule} objects |
|||
* |
|||
* Note this rules are applied when restoring course logs |
|||
* by the restore final task, but are defined here at |
|||
* activity level. All them are rules not linked to any module instance (cmid = 0) |
|||
*/ |
|||
static public function define_restore_log_rules_for_course() { |
|||
$rules = array(); |
|||
|
|||
$rules[] = new restore_log_rule('hvp', 'view all', 'index.php?id={course}', null); |
|||
|
|||
return $rules; |
|||
} |
|||
} |
|||
@ -0,0 +1,372 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Restore structure step for both hvp content and hvp libraries |
|||
* |
|||
* @package mod_hvp |
|||
* @category backup |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Structure step to restore one H5P activity |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class restore_hvp_activity_structure_step extends restore_activity_structure_step { |
|||
|
|||
/** |
|||
* Defines restore element's structure |
|||
* |
|||
* @return array |
|||
* @throws base_step_exception |
|||
*/ |
|||
protected function define_structure() { |
|||
$paths = array(); |
|||
$userinfo = $this->get_setting_value('userinfo'); |
|||
|
|||
// Restore activities. |
|||
$paths[] = new restore_path_element('hvp', '/activity/hvp'); |
|||
|
|||
if ($userinfo) { |
|||
// Restore content state. |
|||
$paths[] = new restore_path_element('content_user_data', '/activity/hvp/content_user_data/entry'); |
|||
} |
|||
|
|||
// Return the paths wrapped into standard activity structure. |
|||
return $this->prepare_activity_structure($paths); |
|||
} |
|||
|
|||
/** |
|||
* Process H5P, inserting the record into the database. |
|||
* |
|||
* @param $data |
|||
* |
|||
* @throws base_step_exception |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function process_hvp($data) { |
|||
global $DB; |
|||
|
|||
$data = (object) $data; |
|||
$data->course = $this->get_courseid(); |
|||
$data->main_library_id = \restore_hvp_libraries_structure_step::get_library_id($data); |
|||
|
|||
$data->timecreated = $this->apply_date_offset($data->timecreated); |
|||
$data->timemodified = $this->apply_date_offset($data->timemodified); |
|||
|
|||
// Insert the hvp record. |
|||
$newitemid = $DB->insert_record('hvp', $data); |
|||
// Immediately after inserting "activity" record, call this. |
|||
$this->apply_activity_instance($newitemid); |
|||
} |
|||
|
|||
/** |
|||
* Process and inserts content user data. |
|||
* |
|||
* @param $data |
|||
* |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function process_content_user_data($data) { |
|||
global $DB; |
|||
|
|||
$data = (object) $data; |
|||
$data->user_id = $this->get_mappingid('user', $data->user_id); |
|||
$data->hvp_id = $this->get_new_parentid('hvp'); |
|||
|
|||
$DB->insert_record('hvp_content_user_data', $data); |
|||
} |
|||
|
|||
/** |
|||
* Additional work that needs to be done after steps executions. |
|||
*/ |
|||
protected function after_execute() { |
|||
// Add files for intro field. |
|||
$this->add_related_files('mod_hvp', 'intro', null); |
|||
|
|||
// Add hvp related files. |
|||
$this->add_related_files('mod_hvp', 'content', 'hvp'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Structure step to restore H5P libraries |
|||
* |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class restore_hvp_libraries_structure_step extends restore_activity_structure_step { |
|||
|
|||
/** |
|||
* Determines if library should be restored. |
|||
* |
|||
* @return bool |
|||
* @throws backup_step_exception |
|||
*/ |
|||
protected function execute_condition() { |
|||
static $librariesrestored; |
|||
|
|||
// Prevent this step from running more than once |
|||
// since all hvp_libraries.xml files are the same. |
|||
if (!empty($librariesrestored)) { |
|||
return false; |
|||
} |
|||
$librariesrestored = true; |
|||
|
|||
// Get full path to activity backup location. |
|||
$fullpath = $this->task->get_taskbasepath(); |
|||
if (empty($fullpath)) { |
|||
throw new backup_step_exception('backup_structure_step_undefined_fullpath'); |
|||
} |
|||
$fullpath = rtrim($fullpath, '/'); |
|||
|
|||
// Check for the activity's local hvp_libraries.xml file. |
|||
if (file_exists("{$fullpath}/{$this->filename}")) { |
|||
// Use that. |
|||
return true; |
|||
} |
|||
|
|||
// Look for a global hvp_libraries.xml file. |
|||
if (file_exists("{$fullpath}/../{$this->filename}")) { |
|||
// Use it. |
|||
$this->filename = "../{$this->filename}"; |
|||
return true; |
|||
} |
|||
|
|||
// Not able to find a hvp_libraries.xml, skip restore and let the admin |
|||
// be responsible for providing the approperiate libraries. |
|||
// (Could also be using Import which doesn't need libraries). |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Defines how library should be restored. |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function define_structure() { |
|||
$paths = array(); |
|||
|
|||
// Restore libraries first. |
|||
$paths[] = new restore_path_element('hvp_library', '/hvp_libraries/library'); |
|||
|
|||
// Add translations. |
|||
$paths[] = new restore_path_element('hvp_library_translation', '/hvp_libraries/library/translations/translation'); |
|||
|
|||
// ... and dependencies. |
|||
$paths[] = new restore_path_element('hvp_library_dependency', '/hvp_libraries/library/dependencies/dependency'); |
|||
|
|||
// Return the paths wrapped into standard activity structure. |
|||
return $this->prepare_activity_structure($paths); |
|||
} |
|||
|
|||
/** |
|||
* Process and insert library record. |
|||
* |
|||
* @param $data |
|||
* |
|||
* @throws dml_exception |
|||
* @throws restore_step_exception |
|||
*/ |
|||
protected function process_hvp_library($data) { |
|||
global $DB; |
|||
|
|||
$data = (object)$data; |
|||
$oldid = $data->id; |
|||
unset($data->id); |
|||
|
|||
$libraryid = self::get_library_id($data); |
|||
if (!$libraryid) { |
|||
// There is no updating of libraries. If an older patch version exists |
|||
// on the site that one will be used instead of the new one in the backup. |
|||
// This is due to the default behavior when files are restored in Moodle. |
|||
|
|||
// Restore library. |
|||
$libraryid = $DB->insert_record('hvp_libraries', $data); |
|||
|
|||
// Update libraries cache. |
|||
self::get_library_id($data, $libraryid); |
|||
} |
|||
|
|||
// Keep track of libraries for translations and dependencies. |
|||
$this->set_mapping('hvp_library', $oldid, $libraryid); |
|||
|
|||
// Update any dependencies that require this library. |
|||
$this->update_missing_dependencies($oldid, $libraryid); |
|||
} |
|||
|
|||
/** |
|||
* Process and inserts translations for library. |
|||
* |
|||
* @param $data |
|||
* |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function process_hvp_library_translation($data) { |
|||
global $DB; |
|||
|
|||
$data = (object) $data; |
|||
$data->library_id = $this->get_new_parentid('hvp_library'); |
|||
|
|||
// Check that translations doesn't exists. |
|||
$translation = $DB->get_record_sql( |
|||
'SELECT id |
|||
FROM {hvp_libraries_languages} |
|||
WHERE library_id = ? |
|||
AND language_code = ?', |
|||
array($data->library_id, |
|||
$data->language_code) |
|||
); |
|||
|
|||
if (empty($translation)) { |
|||
// Only restore translations if library has been restored. |
|||
$DB->insert_record('hvp_libraries_languages', $data); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Process and inserts library dependencies. |
|||
* |
|||
* @param $data |
|||
* |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function process_hvp_library_dependency($data) { |
|||
global $DB; |
|||
|
|||
$data = (object) $data; |
|||
$data->library_id = $this->get_new_parentid('hvp_library'); |
|||
|
|||
$newlibraryid = $this->get_mappingid('hvp_library', $data->required_library_id); |
|||
if ($newlibraryid) { |
|||
$data->required_library_id = $newlibraryid; |
|||
|
|||
// Check that the dependency doesn't exists. |
|||
$dependency = $DB->get_record_sql( |
|||
'SELECT id |
|||
FROM {hvp_libraries_libraries} |
|||
WHERE library_id = ? |
|||
AND required_library_id = ?', |
|||
[ |
|||
$data->library_id, |
|||
$data->required_library_id, |
|||
] |
|||
); |
|||
if (empty($dependency)) { |
|||
$DB->insert_record('hvp_libraries_libraries', $data); |
|||
} |
|||
} else { |
|||
// The required dependency hasn't been restored yet. We need to add this dependency later. |
|||
$this->update_missing_dependencies($data->required_library_id, null, $data); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Additional work that is executed after library restoration steps. |
|||
* |
|||
* @throws dml_exception |
|||
*/ |
|||
protected function after_execute() { |
|||
// Add files for libraries. |
|||
$context = \context_system::instance(); |
|||
$this->add_related_files('mod_hvp', 'libraries', null, $context->id); |
|||
} |
|||
|
|||
/** |
|||
* Cache to reduce queries. |
|||
* |
|||
* @param $library |
|||
* @param null $set |
|||
* |
|||
* @return mixed |
|||
* @throws dml_exception |
|||
*/ |
|||
public static function get_library_id(&$library, $set = null) { |
|||
static $keytoid; |
|||
global $DB; |
|||
|
|||
$key = $library->machine_name . ' ' . $library->major_version . '.' . $library->minor_version; |
|||
if (is_null($keytoid)) { |
|||
$keytoid = array(); |
|||
} |
|||
if ($set !== null) { |
|||
$keytoid[$key] = $set; |
|||
} else if (!isset($keytoid[$key])) { |
|||
$lib = $DB->get_record_sql( |
|||
'SELECT id |
|||
FROM {hvp_libraries} |
|||
WHERE machine_name = ? |
|||
AND major_version = ? |
|||
AND minor_version = ?', |
|||
array($library->machine_name, |
|||
$library->major_version, |
|||
$library->minor_version) |
|||
); |
|||
|
|||
// Non existing = false. |
|||
$keytoid[$key] = (empty($lib) ? false : $lib->id); |
|||
} |
|||
|
|||
return $keytoid[$key]; |
|||
} |
|||
|
|||
/** |
|||
* Keep track of missing dependencies since libraries aren't inserted |
|||
* in any special order |
|||
* |
|||
* @param $oldid |
|||
* @param $newid |
|||
* @param null $setmissing |
|||
* |
|||
* @throws dml_exception |
|||
*/ |
|||
private function update_missing_dependencies($oldid, $newid, $setmissing = null) { |
|||
static $missingdeps; |
|||
global $DB; |
|||
|
|||
if (is_null($missingdeps)) { |
|||
$missingdeps = array(); |
|||
} |
|||
|
|||
if ($setmissing !== null) { |
|||
$missingdeps[$oldid][] = $setmissing; |
|||
} else if (isset($missingdeps[$oldid])) { |
|||
foreach ($missingdeps[$oldid] as $missingdep) { |
|||
$missingdep->required_library_id = $newid; |
|||
|
|||
// Check that the dependency doesn't exists. |
|||
$dependency = $DB->get_record_sql( |
|||
'SELECT id |
|||
FROM {hvp_libraries_libraries} |
|||
WHERE library_id = ? |
|||
AND required_library_id = ?', |
|||
array($missingdep->library_id, |
|||
$missingdep->required_library_id) |
|||
); |
|||
if (empty($dependency)) { |
|||
$DB->insert_record('hvp_libraries_libraries', $missingdep); |
|||
} |
|||
} |
|||
unset($missingdeps[$oldid]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
<?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/>. |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* No setting - just html |
|||
* Note: since admin_setting is not namespaced, this can not be namespaced and put into a class |
|||
*/ |
|||
class admin_setting_html extends admin_setting { |
|||
|
|||
private $hubinfo; |
|||
|
|||
/** |
|||
* not a setting, just html |
|||
* |
|||
* @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. |
|||
*/ |
|||
public function __construct($name, $translation, $hubinfo) { |
|||
$this->nosave = true; |
|||
$this->hubinfo = $hubinfo; |
|||
parent::__construct($name, $translation, '', ''); |
|||
} |
|||
|
|||
/** |
|||
* Always returns true |
|||
* @return bool Always returns true |
|||
*/ |
|||
public function get_setting() { |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Always returns true |
|||
* @return bool Always returns true |
|||
*/ |
|||
public function get_defaultsetting() { |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Never write settings |
|||
* @return string Always returns an empty string |
|||
*/ |
|||
public function write_setting($data) { |
|||
// Do not write any setting. |
|||
return ''; |
|||
} |
|||
|
|||
/** |
|||
* Returns an HTML string |
|||
* @return string Returns an HTML string |
|||
*/ |
|||
public function output_html($data, $query = '') { |
|||
global $OUTPUT; |
|||
$registrationurl = new moodle_url('/mod/hvp/content_hub_registration.php'); |
|||
if ($this->hubinfo === false) { |
|||
$this->hubinfo = (object) []; |
|||
} |
|||
$this->hubinfo->registrationurl = $registrationurl->out(false); |
|||
return $OUTPUT->render_from_template('mod_hvp/content_hub_registration_box', $this->hubinfo); |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
<?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/>. |
|||
namespace mod_hvp; |
|||
|
|||
use Exception; |
|||
use moodle_url; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Service for communicating with the content hub |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2020 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class content_hub_service { |
|||
|
|||
/** |
|||
* Get settings for content hub registration UI |
|||
* |
|||
* @return array |
|||
* @throws Exception |
|||
*/ |
|||
public static function get_registration_ui_settings() { |
|||
$core = framework::instance(); |
|||
$registrationurl = new moodle_url('/mod/hvp/ajax.php', [ |
|||
'action' => 'contenthubregistration', |
|||
]); |
|||
$accountsettingsurl = new moodle_url('/admin/settings.php?section=modsettinghvp'); |
|||
|
|||
return [ |
|||
'registrationURL' => $registrationurl->out(true), |
|||
'accountSettingsUrl' => $accountsettingsurl->out(true), |
|||
'token' => $core::createToken('contentHubRegistration'), |
|||
'l10n' => $core->getLocalization(), |
|||
'licenseAgreementTitle' => get_string('contenthub:licenseagreementtitle', 'hvp'), |
|||
'licenseAgreementDescription' => get_string('contenthub:licenseagreementdescription', 'hvp'), |
|||
'licenseAgreementMainText' => get_string('contenthub:licenseagreementmaintext', 'hvp'), |
|||
'accountInfo' => $core->hubAccountInfo(), |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
<?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/>. |
|||
/** |
|||
* \mod_hvp\content_type_cache_form class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2017 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
global $CFG; |
|||
require_once($CFG->libdir . '/formslib.php'); |
|||
|
|||
/** |
|||
* Form to update the content type cache that mirrors the available libraries in the H5P hub. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2017 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class content_type_cache_form extends \moodleform { |
|||
|
|||
/** |
|||
* Define form elements |
|||
*/ |
|||
public function definition() { |
|||
// Get form. |
|||
$mform = $this->_form; |
|||
|
|||
// Get and format date. |
|||
$lastupdate = get_config('mod_hvp', 'content_type_cache_updated_at'); |
|||
|
|||
$dateformatted = $lastupdate ? \userdate($lastupdate) : get_string('ctcacheneverupdated', 'hvp'); |
|||
|
|||
// Add last update info. |
|||
$mform->addElement('static', 'lastupdate', |
|||
get_string('ctcachelastupdatelabel', 'hvp'), $dateformatted); |
|||
|
|||
$mform->addElement('static', 'lastupdatedescription', '', |
|||
get_string('ctcachedescription', 'hvp')); |
|||
|
|||
// Update cache button. |
|||
$this->add_action_buttons(false, get_string('ctcachebuttonlabel', 'hvp')); |
|||
} |
|||
} |
|||
@ -0,0 +1,256 @@ |
|||
<?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 mod_hvp content user data. |
|||
* |
|||
* @package mod_hvp |
|||
* @since Moodle 2.7 |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Class content_user_data handles user data and corresponding db operations. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2018 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class content_user_data { |
|||
|
|||
/** |
|||
* Retrieves ajax parameters for content and update or delete |
|||
* user data depending on params. |
|||
* |
|||
* @throws \coding_exception |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function handle_ajax() { |
|||
// Query String Parameters. |
|||
$contentid = required_param('content_id', PARAM_INT); |
|||
$dataid = required_param('data_type', PARAM_RAW); |
|||
$subcontentid = required_param('sub_content_id', PARAM_INT); |
|||
|
|||
// Form Data. |
|||
$data = optional_param('data', null, PARAM_RAW); |
|||
$preload = optional_param('preload', null, PARAM_INT); |
|||
$invalidate = optional_param('invalidate', null, PARAM_INT); |
|||
|
|||
if ($contentid === null || $dataid === null || $subcontentid === null) { |
|||
// Missing parameters. |
|||
\H5PCore::ajaxError(get_string('missingparameters', 'hvp')); |
|||
return; |
|||
} |
|||
|
|||
// Saving data. |
|||
if ($data !== null && $preload !== null && $invalidate !== null) { |
|||
self::store_data($contentid, $subcontentid, $dataid, $data, $preload, $invalidate); |
|||
} else { |
|||
self::fetch_existing_data($contentid, $subcontentid, $dataid); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Stores content user data |
|||
* |
|||
* @param $contentid |
|||
* @param $subcontentid |
|||
* @param $dataid |
|||
* @param $data |
|||
* @param $preload |
|||
* @param $invalidate |
|||
* |
|||
* @throws \coding_exception |
|||
* @throws \dml_exception |
|||
*/ |
|||
private static function store_data($contentid, $subcontentid, $dataid, $data, $preload, $invalidate) { |
|||
// Validate token. |
|||
if (!\H5PCore::validToken('contentuserdata', required_param('token', PARAM_RAW))) { |
|||
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp')); |
|||
return; |
|||
} |
|||
|
|||
if ($contentid === 0) { |
|||
$context = \context::instance_by_id(required_param('contextId', PARAM_RAW)); |
|||
} else { |
|||
// Load course module for content to get context. |
|||
$cm = get_coursemodule_from_instance('hvp', $contentid); |
|||
if (!$cm) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
$context = \context_module::instance($cm->id); |
|||
} |
|||
|
|||
// Check permissions. |
|||
if (!has_capability('mod/hvp:savecontentuserdata', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontosavecontentuserdata', 'hvp')); |
|||
http_response_code(403); |
|||
return; |
|||
} |
|||
|
|||
if ($data === '0') { |
|||
// Delete user data. |
|||
self::delete_user_data($contentid, $subcontentid, $dataid); |
|||
} else { |
|||
// Save user data. |
|||
self::save_user_data($contentid, $subcontentid, $dataid, $preload, $invalidate, $data); |
|||
} |
|||
\H5PCore::ajaxSuccess(); |
|||
} |
|||
|
|||
/** |
|||
* Return existing content user data |
|||
* |
|||
* @param $contentid |
|||
* @param $subcontentid |
|||
* @param $dataid |
|||
* |
|||
* @throws \dml_exception |
|||
*/ |
|||
private static function fetch_existing_data($contentid, $subcontentid, $dataid) { |
|||
// Fetch user data. |
|||
$userdata = self::get_user_data($contentid, $subcontentid, $dataid); |
|||
\H5PCore::ajaxSuccess($userdata ? $userdata->data : null); |
|||
} |
|||
|
|||
/** |
|||
* Get user data for content. |
|||
* |
|||
* @param $contentid |
|||
* @param $subcontentid |
|||
* @param $dataid |
|||
* |
|||
* @return mixed |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function get_user_data($contentid, $subcontentid, $dataid) { |
|||
global $DB, $USER; |
|||
|
|||
$result = $DB->get_record('hvp_content_user_data', array( |
|||
'user_id' => $USER->id, |
|||
'hvp_id' => $contentid, |
|||
'sub_content_id' => $subcontentid, |
|||
'data_id' => $dataid |
|||
) |
|||
); |
|||
|
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* Save user data for specific content in database. |
|||
* |
|||
* @param $contentid |
|||
* @param $subcontentid |
|||
* @param $dataid |
|||
* @param $preload |
|||
* @param $invalidate |
|||
* @param $data |
|||
* |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function save_user_data($contentid, $subcontentid, $dataid, $preload, $invalidate, $data) { |
|||
global $DB, $USER; |
|||
|
|||
// Determine if we should update or insert. |
|||
$update = self::get_user_data($contentid, $subcontentid, $dataid); |
|||
|
|||
// Wash values to ensure 0 or 1. |
|||
$preload = ($preload === '0' || $preload === 0) ? 0 : 1; |
|||
$invalidate = ($invalidate === '0' || $invalidate === 0) ? 0 : 1; |
|||
|
|||
// New data to be inserted. |
|||
$newdata = (object)array( |
|||
'user_id' => $USER->id, |
|||
'hvp_id' => $contentid, |
|||
'sub_content_id' => $subcontentid, |
|||
'data_id' => $dataid, |
|||
'data' => $data, |
|||
'preloaded' => $preload, |
|||
'delete_on_content_change' => $invalidate |
|||
); |
|||
|
|||
// Does not exist. |
|||
if ($update === false) { |
|||
// Insert new data. |
|||
$DB->insert_record('hvp_content_user_data', $newdata); |
|||
} else { |
|||
// Get old data id. |
|||
$newdata->id = $update->id; |
|||
|
|||
// Update old data. |
|||
$DB->update_record('hvp_content_user_data', $newdata); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Delete user data with specific content from database |
|||
* |
|||
* @param $contentid |
|||
* @param $subcontentid |
|||
* @param $dataid |
|||
* |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function delete_user_data($contentid, $subcontentid, $dataid) { |
|||
global $DB, $USER; |
|||
|
|||
$DB->delete_records('hvp_content_user_data', array( |
|||
'user_id' => $USER->id, |
|||
'hvp_id' => $contentid, |
|||
'sub_content_id' => $subcontentid, |
|||
'data_id' => $dataid |
|||
)); |
|||
} |
|||
|
|||
/** |
|||
* Load user data for specific content |
|||
* |
|||
* @param $contentid |
|||
* |
|||
* @return array User data for specific content if found, else null |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function load_pre_loaded_user_data($contentid) { |
|||
global $DB, $USER; |
|||
|
|||
$preloadeduserdata = array( |
|||
'state' => '{}' |
|||
); |
|||
|
|||
$results = $DB->get_records('hvp_content_user_data', array( |
|||
'user_id' => $USER->id, |
|||
'hvp_id' => $contentid, |
|||
'sub_content_id' => 0, |
|||
'preloaded' => 1 |
|||
)); |
|||
|
|||
// Get data for data ids. |
|||
foreach ($results as $contentuserdata) { |
|||
$preloadeduserdata[$contentuserdata->data_id] = $contentuserdata->data; |
|||
} |
|||
|
|||
return $preloadeduserdata; |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
<?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 mod_hvp content user data. |
|||
* |
|||
* @package mod_hvp |
|||
* @since Moodle 3.10 |
|||
* @copyright 2020 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
use curl as moodlecurl; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Override Moodle's curl class to provide proper PUT support. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2020 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class curl extends moodlecurl { |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
public function post($url, $params = '', $options = array()) { |
|||
$options['CURLOPT_POST'] = 1; |
|||
$options['CURLOPT_POSTFIELDS'] = $params; |
|||
return $this->request($url, $options); |
|||
} |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
public function put($url, $params = '', $options = array()) { |
|||
$options['CURLOPT_CUSTOMREQUEST'] = 'PUT'; |
|||
$options['CURLOPT_POSTFIELDS'] = $params; |
|||
return $this->request($url, $options); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,180 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* \mod_hvp\editor_ajax class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once(__DIR__ . '/../autoloader.php'); |
|||
|
|||
/** |
|||
* Moodle's implementation of the H5P Editor Ajax interface. |
|||
* Makes it possible for the editor's core ajax functionality to communicate with the |
|||
* database used by Moodle. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class editor_ajax implements \H5PEditorAjaxInterface { |
|||
|
|||
/** |
|||
* Gets latest library versions that exists locally |
|||
* |
|||
* @return array Latest version of all local libraries |
|||
* @throws \dml_exception |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getLatestLibraryVersions() { |
|||
global $DB; |
|||
|
|||
$maxmajorversionsql = " |
|||
SELECT hl.machine_name, MAX(hl.major_version) AS major_version |
|||
FROM {hvp_libraries} hl |
|||
WHERE hl.runnable = 1 |
|||
GROUP BY hl.machine_name"; |
|||
|
|||
$maxminorversionsql = " |
|||
SELECT hl2.machine_name, hl2.major_version, MAX(hl2.minor_version) AS minor_version |
|||
FROM ({$maxmajorversionsql}) hl1 |
|||
JOIN {hvp_libraries} hl2 |
|||
ON hl1.machine_name = hl2.machine_name |
|||
AND hl1.major_version = hl2.major_version |
|||
GROUP BY hl2.machine_name, hl2.major_version"; |
|||
|
|||
return $DB->get_records_sql(" |
|||
SELECT hl4.id, hl4.machine_name, hl4.title, hl4.major_version, |
|||
hl4.minor_version, hl4.patch_version, hl4.has_icon, hl4.restricted |
|||
FROM {hvp_libraries} hl4 |
|||
JOIN ({$maxminorversionsql}) hl3 |
|||
ON hl4.machine_name = hl3.machine_name |
|||
AND hl4.major_version = hl3.major_version |
|||
AND hl4.minor_version = hl3.minor_version" |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Get locally stored Content Type Cache. If machine name is provided |
|||
* it will only get the given content type from the cache |
|||
* |
|||
* @param null $machinename |
|||
* |
|||
* @return array|mixed|null|object Returns results from querying the database |
|||
* @throws \dml_exception |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getContentTypeCache($machinename = null) { |
|||
global $DB; |
|||
|
|||
if ($machinename) { |
|||
return $DB->get_record_sql( |
|||
"SELECT id, is_recommended |
|||
FROM {hvp_libraries_hub_cache} |
|||
WHERE machine_name = ?", |
|||
array($machinename) |
|||
); |
|||
} |
|||
|
|||
return $DB->get_records("hvp_libraries_hub_cache"); |
|||
} |
|||
|
|||
/** |
|||
* Gets recently used libraries for the current author |
|||
* |
|||
* @return array machine names. The first element in the array is the |
|||
* most recently used. |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getAuthorsRecentlyUsedLibraries() { |
|||
global $DB; |
|||
global $USER; |
|||
$recentlyused = array(); |
|||
|
|||
$results = $DB->get_records_sql( |
|||
"SELECT library_name, max(created_at) AS max_created_at |
|||
FROM {hvp_events} |
|||
WHERE type='content' AND sub_type = 'create' AND user_id = ? |
|||
GROUP BY library_name |
|||
ORDER BY max_created_at DESC", array($USER->id)); |
|||
|
|||
foreach ($results as $row) { |
|||
$recentlyused[] = $row->library_name; |
|||
} |
|||
|
|||
return $recentlyused; |
|||
} |
|||
|
|||
/** |
|||
* Checks if the provided token is valid for this endpoint |
|||
* |
|||
* @param string $token The token that will be validated for. |
|||
* |
|||
* @return bool True if successful validation |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function validateEditorToken($token) { |
|||
return \H5PCore::validToken('editorajax', $token); |
|||
} |
|||
|
|||
/** |
|||
* Get translations for a language for a list of libraries |
|||
* |
|||
* @param array $libraries An array of libraries, in the form "<machineName> <majorVersion>.<minorVersion> |
|||
* @param string $language_code |
|||
* |
|||
* @return array |
|||
* @throws \dml_exception |
|||
*/ |
|||
public function getTranslations($libraries, $language_code) { |
|||
global $DB; |
|||
|
|||
$translations = array(); |
|||
|
|||
foreach ($libraries as $library) { |
|||
$parsedLib = \H5PCore::libraryFromString($library); |
|||
|
|||
$sql = " |
|||
SELECT language_json |
|||
FROM {hvp_libraries} lib |
|||
LEFT JOIN {hvp_libraries_languages} lang |
|||
ON lib.id = lang.library_id |
|||
WHERE lib.machine_name = :machine_name AND |
|||
lib.major_version = :major_version AND |
|||
lib.minor_version = :minor_version AND |
|||
lang.language_code = :language_code"; |
|||
$translation = $DB->get_field_sql($sql, array( |
|||
'machine_name' => $parsedLib['machineName'], |
|||
'major_version' => $parsedLib['majorVersion'], |
|||
'minor_version' => $parsedLib['minorVersion'], |
|||
'language_code' => $language_code, |
|||
)); |
|||
|
|||
if ($translation !== false) { |
|||
$translations[$library] = $translation; |
|||
} |
|||
} |
|||
|
|||
return $translations; |
|||
} |
|||
} |
|||
@ -0,0 +1,355 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* \mod_hvp\framework class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
use H5peditorFile; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require_once(__DIR__ . '/../autoloader.php'); |
|||
|
|||
/** |
|||
* Moodle's implementation of the H5P Editor framework interface. |
|||
* Makes it possible for the editor's core library to communicate with the |
|||
* database used by Moodle. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class editor_framework implements \H5peditorStorage { |
|||
|
|||
/** |
|||
* Load language file(JSON) from database. |
|||
* This is used to translate the editor fields(title, description etc.) |
|||
* |
|||
* @param string $name The machine readable name of the library(content type) |
|||
* @param int $major Major part of version number |
|||
* @param int $minor Minor part of version number |
|||
* @param string $lang Language code |
|||
* @return string Translation in JSON format |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getLanguage($name, $major, $minor, $lang) { |
|||
global $DB; |
|||
|
|||
// Load translation field from DB. |
|||
return $DB->get_field_sql( |
|||
"SELECT hlt.language_json |
|||
FROM {hvp_libraries_languages} hlt |
|||
JOIN {hvp_libraries} hl ON hl.id = hlt.library_id |
|||
WHERE hl.machine_name = ? |
|||
AND hl.major_version = ? |
|||
AND hl.minor_version = ? |
|||
AND hlt.language_code = ? |
|||
", array( |
|||
$name, |
|||
$major, |
|||
$minor, |
|||
$lang |
|||
) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* "Callback" for mark the given file as a permanent file. |
|||
* Used when saving content that has new uploaded files. |
|||
* |
|||
* @param int $fileid |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function keepFile($fileid) { |
|||
global $DB; |
|||
|
|||
// Remove from tmpfiles. |
|||
$DB->delete_records('hvp_tmpfiles', array( |
|||
'id' => $fileid |
|||
)); |
|||
} |
|||
|
|||
/** |
|||
* Decides which content types the editor should have. |
|||
* |
|||
* Two usecases: |
|||
* 1. No input, will list all the available content types. |
|||
* 2. Libraries supported are specified, load additional data and verify |
|||
* that the content types are available. Used by e.g. the Presentation Tool |
|||
* Editor that already knows which content types are supported in its |
|||
* slides. |
|||
* |
|||
* @param array $libraries List of library names + version to load info for |
|||
* @return array List of all libraries loaded |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getLibraries($libraries = null) { |
|||
global $DB; |
|||
|
|||
$contextid = required_param('contextId', PARAM_RAW); |
|||
$superuser = has_capability('mod/hvp:userestrictedlibraries', |
|||
\context::instance_by_id($contextid)); |
|||
|
|||
if ($libraries !== null) { |
|||
// Get details for the specified libraries only. |
|||
$librarieswithdetails = array(); |
|||
foreach ($libraries as $library) { |
|||
// Look for library. |
|||
$details = $DB->get_record_sql( |
|||
"SELECT title, |
|||
runnable, |
|||
restricted, |
|||
tutorial_url, |
|||
metadata_settings |
|||
FROM {hvp_libraries} |
|||
WHERE machine_name = ? |
|||
AND major_version = ? |
|||
AND minor_version = ? |
|||
AND semantics IS NOT NULL |
|||
", array( |
|||
$library->name, |
|||
$library->majorVersion, |
|||
$library->minorVersion |
|||
) |
|||
); |
|||
if ($details) { |
|||
// Library found, add details to list. |
|||
$library->tutorialUrl = $details->tutorial_url; |
|||
$library->title = $details->title; |
|||
$library->runnable = $details->runnable; |
|||
$library->restricted = $superuser ? false : ($details->restricted === '1' ? true : false); |
|||
$library->metadataSettings = json_decode($details->metadata_settings); |
|||
$librarieswithdetails[] = $library; |
|||
} |
|||
} |
|||
|
|||
// Done, return list with library details. |
|||
return $librarieswithdetails; |
|||
} |
|||
|
|||
// Load all libraries. |
|||
$libraries = array(); |
|||
$librariesresult = $DB->get_records_sql( |
|||
"SELECT id, |
|||
machine_name AS name, |
|||
title, |
|||
major_version, |
|||
minor_version, |
|||
tutorial_url, |
|||
restricted, |
|||
metadata_settings |
|||
FROM {hvp_libraries} |
|||
WHERE runnable = 1 |
|||
AND semantics IS NOT NULL |
|||
ORDER BY title" |
|||
); |
|||
foreach ($librariesresult as $library) { |
|||
// Remove unique index. |
|||
unset($library->id); |
|||
|
|||
// Convert snakes to camels. |
|||
$library->majorVersion = (int) $library->major_version; |
|||
unset($library->major_version); |
|||
$library->minorVersion = (int) $library->minor_version; |
|||
unset($library->minor_version); |
|||
if (!empty($library->tutorial_url)) { |
|||
$library->tutorialUrl = $library->tutorial_url; |
|||
} |
|||
unset($library->tutorial_url); |
|||
|
|||
$library->metadataSettings = json_decode($library->metadata_settings); |
|||
unset($library->metadata_settings); |
|||
|
|||
// Make sure we only display the newest version of a library. |
|||
foreach ($libraries as $key => $existinglibrary) { |
|||
if ($library->name === $existinglibrary->name) { |
|||
// Found library with same name, check versions. |
|||
if ( ( $library->majorVersion === $existinglibrary->majorVersion && |
|||
$library->minorVersion > $existinglibrary->minorVersion ) || |
|||
( $library->majorVersion > $existinglibrary->majorVersion ) ) { |
|||
// This is a newer version. |
|||
$existinglibrary->isOld = true; |
|||
} else { |
|||
// This is an older version. |
|||
$library->isOld = true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Check to see if content type should be restricted. |
|||
$library->restricted = $superuser ? false : ($library->restricted === '1' ? true : false); |
|||
|
|||
// Add new library. |
|||
$libraries[] = $library; |
|||
} |
|||
return $libraries; |
|||
} |
|||
|
|||
/** |
|||
* Allow for other plugins to decide which styles and scripts are attached. |
|||
* This is useful for adding and/or modifing the functionality and look of |
|||
* the content types. |
|||
* |
|||
* @param array $files |
|||
* List of files as objects with path and version as properties |
|||
* @param array $libraries |
|||
* List of libraries indexed by machineName with objects as values. The objects |
|||
* have majorVersion and minorVersion as properties. |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function alterLibraryFiles(&$files, $libraries) { |
|||
global $PAGE; |
|||
|
|||
// Refactor dependency list. |
|||
$librarylist = array(); |
|||
foreach ($libraries as $dependency) { |
|||
$librarylist[$dependency['machineName']] = array( |
|||
'majorVersion' => $dependency['majorVersion'], |
|||
'minorVersion' => $dependency['minorVersion'] |
|||
); |
|||
} |
|||
|
|||
$contextid = required_param('contextId', PARAM_INT); |
|||
$context = \context::instance_by_id($contextid); |
|||
|
|||
$PAGE->set_context($context); |
|||
$renderer = $PAGE->get_renderer('mod_hvp'); |
|||
|
|||
$embedtype = 'editor'; |
|||
$renderer->hvp_alter_scripts($files['scripts'], $librarylist, $embedtype); |
|||
$renderer->hvp_alter_styles($files['styles'], $librarylist, $embedtype); |
|||
} |
|||
|
|||
/** |
|||
* Saves a file or moves it temporarily. This is often necessary in order to |
|||
* validate and store uploaded or fetched H5Ps. |
|||
* |
|||
* @param string $data Uri of data that should be saved as a temporary file |
|||
* @param boolean $movefile Can be set to TRUE to move the data instead of saving it |
|||
* |
|||
* @return bool|object Returns false if saving failed or an object with path |
|||
* of the directory and file that is temporarily saved |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public static function saveFileTemporarily($data, $movefile = false) { |
|||
global $CFG; |
|||
|
|||
// Generate local tmp file path. |
|||
$uniqueh5pid = uniqid('hvp-'); |
|||
$filename = $uniqueh5pid . '.h5p'; |
|||
$directory = $CFG->tempdir . DIRECTORY_SEPARATOR . $uniqueh5pid; |
|||
$filepath = $directory . DIRECTORY_SEPARATOR . $filename; |
|||
|
|||
if (!is_dir($directory)) { |
|||
mkdir($directory, 0777, true); |
|||
} |
|||
|
|||
// Move file or save data to new file so core can validate H5P. |
|||
if ($movefile) { |
|||
move_uploaded_file($data, $filepath); |
|||
} else { |
|||
file_put_contents($filepath, $data); |
|||
} |
|||
|
|||
// Add folder and file paths to H5P Core. |
|||
$interface = framework::instance('interface'); |
|||
$interface->getUploadedH5pFolderPath($directory); |
|||
$interface->getUploadedH5pPath($directory . DIRECTORY_SEPARATOR . $filename); |
|||
|
|||
return (object) array( |
|||
'dir' => $directory, |
|||
'fileName' => $filename |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Marks a file for later cleanup, useful when files are not instantly cleaned |
|||
* up. E.g. for files that are uploaded through the editor. |
|||
* |
|||
* @param int $file Id of file that should be cleaned up |
|||
* @param int|null $contentid Content id of file |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public static function markFileForCleanup($file, $contentid = null) { |
|||
global $DB; |
|||
|
|||
// Let H5P Core clean up. |
|||
if ($contentid) { |
|||
return; |
|||
} |
|||
|
|||
// Track temporary files for later cleanup. |
|||
$DB->insert_record_raw('hvp_tmpfiles', array( |
|||
'id' => $file |
|||
), false, false, true); |
|||
} |
|||
|
|||
/** |
|||
* Clean up temporary files |
|||
* |
|||
* @param string $filepath Path to file or directory |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public static function removeTemporarilySavedFiles($filepath) { |
|||
if (is_dir($filepath)) { |
|||
\H5PCore::deleteFileTree($filepath); |
|||
} else { |
|||
@unlink($filepath); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Load a list of available language codes from the database. |
|||
* |
|||
* @param string $machineName The machine readable name of the library(content type) |
|||
* @param int $majorVersion Major part of version number |
|||
* @param int $minorVersion Minor part of version number |
|||
* |
|||
* @return array List of possible language codes |
|||
* @throws \dml_exception |
|||
*/ |
|||
public function getAvailableLanguages($machineName, $majorVersion, $minorVersion) { |
|||
global $DB; |
|||
|
|||
$sql = "SELECT language_code |
|||
FROM {hvp_libraries_languages} hlt |
|||
JOIN {hvp_libraries} hl |
|||
ON hl.id = hlt.library_id |
|||
WHERE hl.machine_name = :machinename |
|||
AND hl.major_version = :major |
|||
AND hl.minor_version = :minor"; |
|||
|
|||
$results = $DB->get_records_sql($sql, array( |
|||
'machinename' => $machineName, |
|||
'major' => $majorVersion, |
|||
'minor' => $minorVersion, |
|||
)); |
|||
|
|||
$codes = array('en'); // Semantics is 'en' by default. |
|||
foreach ($results as $result) { |
|||
$codes[] = $result->language_code; |
|||
} |
|||
|
|||
return $codes; |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
<?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 mod_hvp event logger, makes it easy to track events throughout |
|||
* the H5P system. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class event extends \H5PEventBase { |
|||
private $user; |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
public function __construct($type, $subtype = null, $contentid = null, |
|||
$contenttitle = null, $libraryname = null, $libraryversion = null) { |
|||
global $USER; |
|||
|
|||
// Track the who initiated the event. |
|||
$this->user = $USER->id; |
|||
|
|||
parent::__construct($type, $subtype, $contentid, $contenttitle, $libraryname, $libraryversion); |
|||
} |
|||
|
|||
/** |
|||
* Store the event. |
|||
* |
|||
* @return int Event ID |
|||
*/ |
|||
protected function save() { |
|||
global $DB; |
|||
|
|||
// Get data in array format without null values. |
|||
$data = $this->getDataArray(); |
|||
|
|||
// Add user. |
|||
$data['user_id'] = $this->user; |
|||
|
|||
return $DB->insert_record('hvp_events', $data); |
|||
} |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
protected function saveStats() { |
|||
global $DB; |
|||
$type = $this->type . ' ' . $this->sub_type; |
|||
|
|||
// Grab current counter to check if it exists. |
|||
$id = $DB->get_field_sql( |
|||
"SELECT id |
|||
FROM {hvp_counters} |
|||
WHERE type = ? |
|||
AND library_name = ? |
|||
AND library_version = ?", |
|||
array($type, $this->library_name, $this->library_version) |
|||
); |
|||
|
|||
if ($id === false) { |
|||
// No counter found, insert new one. |
|||
$DB->insert_record('hvp_counters', array( |
|||
'type' => $type, |
|||
'library_name' => $this->library_name, |
|||
'library_version' => $this->library_version, |
|||
'num' => 1 |
|||
)); |
|||
} else { |
|||
// Update num+1. |
|||
$DB->execute( |
|||
"UPDATE {hvp_counters} |
|||
SET num = num + 1 |
|||
WHERE id = ?", |
|||
array($id) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -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/>. |
|||
|
|||
/** |
|||
* Attempt submitted event |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2020 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\event; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp instance list viewed event class. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class attempt_submitted extends \core\event\base |
|||
{ |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
protected function init() { |
|||
$this->data['crud'] = 'u'; |
|||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING; |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
<?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 mod_hvp instance list viewed event. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\event; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp instance list viewed event class. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @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 |
|||
{ |
|||
// No code required here as the parent class handles it all. |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* The mod_hvp course module viewed event. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\event; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp course module viewed event class. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class course_module_viewed extends \core\event\course_module_viewed |
|||
{ |
|||
|
|||
/** |
|||
* Set basic properties for the event. |
|||
*/ |
|||
protected function init() { |
|||
$this->data['objecttable'] = 'hvp'; |
|||
$this->data['crud'] = 'r'; |
|||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING; |
|||
} |
|||
} |
|||
@ -0,0 +1,912 @@ |
|||
<?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 mod_hvp file storage |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
require_once($CFG->dirroot . '/mod/hvp/library/h5p-file-storage.interface.php'); |
|||
|
|||
/** |
|||
* The mod_hvp file storage class. |
|||
* |
|||
* @package mod_hvp |
|||
* @since Moodle 2.7 |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
* |
|||
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
|||
*/ |
|||
class file_storage implements \H5PFileStorage { |
|||
|
|||
/** |
|||
* Store the library folder. |
|||
* |
|||
* @param array $library |
|||
* Library properties |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function saveLibrary($library) { |
|||
// Libraries are stored in a system context. |
|||
$context = \context_system::instance(); |
|||
$options = array( |
|||
'contextid' => $context->id, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'libraries', |
|||
'itemid' => 0, |
|||
'filepath' => '/' . \H5PCore::libraryToFolderName($library) . '/', |
|||
); |
|||
|
|||
// Remove any old existing library files. |
|||
self::deleteFileTree($context->id, $options['filearea'], $options['filepath']); |
|||
|
|||
// Move library folder. |
|||
self::readFileTree($library['uploadDirectory'], $options); |
|||
} |
|||
|
|||
/** |
|||
* Store the content folder. |
|||
* |
|||
* @param string $source |
|||
* Path on file system to content directory. |
|||
* @param array $content |
|||
* Content properties |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function saveContent($source, $content) { |
|||
// Remove any old content. |
|||
$this->deleteContent($content); |
|||
|
|||
// Contents are stored in a course context. |
|||
$context = \context_module::instance($content['coursemodule']); |
|||
$options = array( |
|||
'contextid' => $context->id, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'content', |
|||
'itemid' => $content['id'], |
|||
'filepath' => '/', |
|||
); |
|||
|
|||
// Move content folder. |
|||
self::readFileTree($source, $options); |
|||
} |
|||
|
|||
/** |
|||
* Remove content folder. |
|||
* |
|||
* @param array $content |
|||
* Content properties |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function deleteContent($content) { |
|||
$context = \context_module::instance($content['coursemodule']); |
|||
self::deleteFileTree($context->id, 'content', '/', $content['id']); |
|||
} |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function cloneContent($id, $newid) { |
|||
// Not implemented in Moodle. |
|||
} |
|||
|
|||
/** |
|||
* Get path to a new unique tmp folder. |
|||
* |
|||
* @return string Path |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getTmpPath() { |
|||
global $CFG; |
|||
|
|||
return $CFG->tempdir . uniqid('/hvp-'); |
|||
} |
|||
|
|||
/** |
|||
* Fetch content folder and save in target directory. |
|||
* |
|||
* @param int $id |
|||
* Content identifier |
|||
* @param string $target |
|||
* Where the content folder will be saved |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function exportContent($id, $target) { |
|||
$cm = \get_coursemodule_from_instance('hvp', $id); |
|||
$context = \context_module::instance($cm->id); |
|||
self::exportFileTree($target, $context->id, 'content', '/', $id); |
|||
} |
|||
|
|||
/** |
|||
* Fetch library folder and save in target directory. |
|||
* |
|||
* @param array $library |
|||
* Library properties |
|||
* @param string $target |
|||
* Where the library folder will be saved |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function exportLibrary($library, $target) { |
|||
$folder = \H5PCore::libraryToFolderName($library); |
|||
$context = \context_system::instance(); |
|||
self::exportFileTree("{$target}/{$folder}", $context->id, 'libraries', "/{$folder}/"); |
|||
} |
|||
|
|||
/** |
|||
* Save export in file system |
|||
* |
|||
* @param string $source |
|||
* Path on file system to temporary export file. |
|||
* @param string $filename |
|||
* Name of export file. |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function saveExport($source, $filename) { |
|||
global $COURSE; |
|||
|
|||
// Remove old export. |
|||
$this->deleteExport($filename); |
|||
|
|||
// Create record. |
|||
$context = \context_course::instance($COURSE->id); |
|||
$record = array( |
|||
'contextid' => $context->id, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'exports', |
|||
'itemid' => 0, |
|||
'filepath' => '/', |
|||
'filename' => $filename |
|||
); |
|||
|
|||
// Store new export. |
|||
$fs = get_file_storage(); |
|||
$fs->create_file_from_pathname($record, $source); |
|||
} |
|||
|
|||
/** |
|||
* Get file object for given export file. |
|||
* |
|||
* @param string $filename |
|||
* @return stdClass Moodle file object |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private function getExportFile($filename) { |
|||
global $COURSE; |
|||
$context = \context_course::instance($COURSE->id); |
|||
|
|||
// Check if file exists. |
|||
$fs = get_file_storage(); |
|||
return $fs->get_file($context->id, 'mod_hvp', 'exports', 0, '/', $filename); |
|||
} |
|||
|
|||
/** |
|||
* Removes given export file |
|||
* |
|||
* @param string $filename |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function deleteExport($filename) { |
|||
$file = $this->getExportFile($filename); |
|||
if ($file) { |
|||
// Remove old export. |
|||
$file->delete(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Check if the given export file exists |
|||
* |
|||
* @param string $filename |
|||
* @return boolean |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function hasExport($filename) { |
|||
return !!$this->getExportFile($filename); |
|||
} |
|||
|
|||
/** |
|||
* Will concatenate all JavaScrips and Stylesheets into two files in order |
|||
* to improve page performance. |
|||
* |
|||
* @param array $files |
|||
* A set of all the assets required for content to display |
|||
* @param string $key |
|||
* Hashed key for cached asset |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function cacheAssets(&$files, $key) { |
|||
$context = \context_system::instance(); |
|||
$fs = get_file_storage(); |
|||
|
|||
foreach ($files as $type => $assets) { |
|||
if (empty($assets)) { |
|||
continue; |
|||
} |
|||
|
|||
$content = ''; |
|||
foreach ($assets as $asset) { |
|||
// Find location of asset. |
|||
$location = array(); |
|||
preg_match('/^\/(libraries|development)(.+\/)([^\/]+)$/', $asset->path, $location); |
|||
|
|||
// Locate file. |
|||
$file = $fs->get_file($context->id, 'mod_hvp', $location[1], 0, $location[2], $location[3]); |
|||
|
|||
// Get file content and concatenate. |
|||
if ($type === 'scripts') { |
|||
$content .= $file->get_content() . ";\n"; |
|||
} else { |
|||
// Rewrite relative URLs used inside stylesheets. |
|||
$content .= preg_replace_callback( |
|||
'/url\([\'"]?([^"\')]+)[\'"]?\)/i', |
|||
function ($matches) use ($location) { |
|||
if (preg_match("/^(data:|([a-z0-9]+:)?\/)/i", $matches[1]) === 1) { |
|||
return $matches[0]; // Not relative, skip. |
|||
} |
|||
return 'url("../' . $location[1] . $location[2] . $matches[1] . '")'; |
|||
}, |
|||
$file->get_content()) . "\n"; |
|||
} |
|||
} |
|||
|
|||
// Create new file for cached assets. |
|||
$ext = ($type === 'scripts' ? 'js' : 'css'); |
|||
$fileinfo = array( |
|||
'contextid' => $context->id, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'cachedassets', |
|||
'itemid' => 0, |
|||
'filepath' => '/', |
|||
'filename' => "{$key}.{$ext}" |
|||
); |
|||
|
|||
// Store concatenated content. |
|||
$fs->create_file_from_string($fileinfo, $content); |
|||
$files[$type] = array((object) array( |
|||
'path' => "/cachedassets/{$key}.{$ext}", |
|||
'version' => '' |
|||
)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Will check if there are cache assets available for content. |
|||
* |
|||
* @param string $key |
|||
* Hashed key for cached asset |
|||
* @return array |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getCachedAssets($key) { |
|||
$context = \context_system::instance(); |
|||
$fs = get_file_storage(); |
|||
|
|||
$files = array(); |
|||
|
|||
$js = $fs->get_file($context->id, 'mod_hvp', 'cachedassets', 0, '/', "{$key}.js"); |
|||
if ($js) { |
|||
$files['scripts'] = array((object) array( |
|||
'path' => "/cachedassets/{$key}.js", |
|||
'version' => '' |
|||
)); |
|||
} |
|||
|
|||
$css = $fs->get_file($context->id, 'mod_hvp', 'cachedassets', 0, '/', "{$key}.css"); |
|||
if ($css) { |
|||
$files['styles'] = array((object) array( |
|||
'path' => "/cachedassets/{$key}.css", |
|||
'version' => '' |
|||
)); |
|||
} |
|||
|
|||
return empty($files) ? null : $files; |
|||
} |
|||
|
|||
/** |
|||
* Remove the aggregated cache files. |
|||
* |
|||
* @param array $keys |
|||
* The hash keys of removed files |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function deleteCachedAssets($keys) { |
|||
$context = \context_system::instance(); |
|||
$fs = get_file_storage(); |
|||
|
|||
foreach ($keys as $hash) { |
|||
foreach (array('js', 'css') as $type) { |
|||
$cachedasset = $fs->get_file($context->id, 'mod_hvp', 'cachedassets', 0, '/', "{$hash}.{$type}"); |
|||
if ($cachedasset) { |
|||
$cachedasset->delete(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @inheritdoc |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getContent($filepath) { |
|||
// Grab context and file storage. |
|||
$context = \context_system::instance(); |
|||
$fs = get_file_storage(); |
|||
|
|||
// Find location of file. |
|||
$location = []; |
|||
preg_match('/^\/(libraries|development|cachedassets)(.*\/)([^\/]+)$/', $filepath, $location); |
|||
|
|||
// Locate file. |
|||
$file = $fs->get_file($context->id, 'mod_hvp', $location[1], 0, $location[2], $location[3]); |
|||
if (!$file) { |
|||
throw new \file_serving_exception( |
|||
'Could not retrieve the requested file, check your file permissions.' |
|||
); |
|||
} |
|||
|
|||
// Return content. |
|||
return $file->get_content(); |
|||
} |
|||
|
|||
/** |
|||
* Save files uploaded through the editor. |
|||
* |
|||
* @param \H5peditorFile $file |
|||
* @param int $contentid |
|||
* @param \stdClass $contextid Course Context ID |
|||
* |
|||
* @return int |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function saveFile($file, $contentid, $contextid = null) { |
|||
global $CFG; |
|||
|
|||
if ($contentid !== 0) { |
|||
// Grab cm context. |
|||
$cm = \get_coursemodule_from_instance('hvp', $contentid); |
|||
$context = \context_module::instance($cm->id); |
|||
$contextid = $context->id; |
|||
} else if ($contextid === null) { |
|||
// Check for context id in params. |
|||
$contextid = optional_param('contextId', null, PARAM_INT); |
|||
$context = \context::instance_by_id($contextid); |
|||
} |
|||
|
|||
if (!$context) { |
|||
\H5PCore::ajaxError(get_string('invalidcontext', 'error')); |
|||
return; |
|||
} |
|||
|
|||
$maxsize = get_max_upload_file_size($CFG->maxbytes); |
|||
// Check size of each uploaded file and scan for viruses. |
|||
foreach ($_FILES as $uploadedfile) { |
|||
$filename = clean_param($uploadedfile['name'], PARAM_FILE); |
|||
|
|||
if (!has_capability('moodle/course:ignorefilesizelimits', $context)) { |
|||
if ($uploadedfile['size'] > $maxsize) { |
|||
\H5PCore::ajaxError(get_string('maxbytesfile', 'error', ['file' => $filename, 'size' => display_size($maxsize)])); |
|||
return; |
|||
} |
|||
} |
|||
\core\antivirus\manager::scan_file($uploadedfile['tmp_name'], $filename, true); |
|||
} |
|||
|
|||
// Files not yet related to any activities are stored in a course context |
|||
// These are temporary files and should not be part of backups. |
|||
|
|||
$record = array( |
|||
'contextid' => $contextid, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => $contentid === 0 ? 'editor' : 'content', |
|||
'itemid' => $contentid, |
|||
'filepath' => '/' . $file->getType() . 's/', |
|||
'filename' => $file->getName() |
|||
); |
|||
$fs = get_file_storage(); |
|||
$storedfile = $fs->create_file_from_pathname($record, $_FILES['file']['tmp_name']); |
|||
|
|||
return $storedfile->get_id(); |
|||
} |
|||
|
|||
/** |
|||
* Copy a file from another content or editor tmp dir. |
|||
* Used when copy pasting content in H5P. |
|||
* |
|||
* @param string $file path + name |
|||
* @param string|int $fromid Content ID or 'editor' string |
|||
* @param stdClass $tocontent Target Content |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function cloneContentFile($file, $fromid, $tocontent) { |
|||
|
|||
// Determine source file area and item id. |
|||
if ($fromid === 'editor') { |
|||
$sourcefilearea = 'editor'; |
|||
if (empty($tocontent->instance)) { |
|||
$sourceitemid = \context_course::instance($tocontent->course); |
|||
} else { |
|||
$sourceitemid = \context_module::instance($tocontent->coursemodule); |
|||
} |
|||
} else { |
|||
$sourcefilearea = 'content'; |
|||
$sourceitemid = $fromid; |
|||
}; |
|||
|
|||
// Check to see if source exist. |
|||
$sourcefile = $this->getFile($sourcefilearea, $sourceitemid, $file); |
|||
if ($sourcefile === false) { |
|||
return; // Nothing to copy from. |
|||
} |
|||
|
|||
// Check to make sure source doesn't exist already. |
|||
if ($this->getFile('content', $tocontent, $file) !== false) { |
|||
return; // File exists, no need to copy. |
|||
} |
|||
|
|||
// Grab context for CM. |
|||
$context = \context_module::instance($tocontent->coursemodule); |
|||
|
|||
// Create new file record. |
|||
$record = [ |
|||
'contextid' => $context->id, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'content', |
|||
'itemid' => $tocontent->id, |
|||
'filepath' => $this->getFilepath($file), |
|||
'filename' => $this->getFilename($file), |
|||
]; |
|||
$fs = get_file_storage(); |
|||
$fs->create_file_from_storedfile($record, $sourcefile); |
|||
} |
|||
|
|||
/** |
|||
* Checks to see if content has the given file. |
|||
* Used when saving content. |
|||
* |
|||
* @param string $file path + name |
|||
* @param stdClass $content |
|||
* @return string|int File ID or null if not found |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getContentFile($file, $content) { |
|||
$file = $this->getFile('content', $content, $file); |
|||
return ($file === false ? null : $file->get_id()); |
|||
} |
|||
|
|||
/** |
|||
* Remove content files that are no longer used. |
|||
* Used when saving content. |
|||
* |
|||
* @param string $file path + name |
|||
* @param stdClass $content |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function removeContentFile($file, $content) { |
|||
$file = $this->getFile('content', $content, $file); |
|||
if ($file !== false) { |
|||
$file->delete(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Copies files from tmp folder to Moodle storage. |
|||
* |
|||
* @param string $source |
|||
* Path to source directory |
|||
* @param array $options |
|||
* For Moodle's file record |
|||
* @throws \Exception Unable to copy |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private static function readFileTree($source, $options) { |
|||
$dir = opendir($source); |
|||
if ($dir === false) { |
|||
trigger_error('Unable to open directory ' . $source, E_USER_WARNING); |
|||
throw new \Exception('unabletocopy'); |
|||
} |
|||
|
|||
while (false !== ($file = readdir($dir))) { |
|||
if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') { |
|||
if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { |
|||
$suboptions = $options; |
|||
$suboptions['filepath'] .= $file . '/'; |
|||
self::readFileTree($source . '/' . $file, $suboptions); |
|||
} else { |
|||
$record = $options; |
|||
$record['filename'] = $file; |
|||
$fs = get_file_storage(); |
|||
$fs->create_file_from_pathname($record, $source . '/' . $file); |
|||
} |
|||
} |
|||
} |
|||
closedir($dir); |
|||
} |
|||
|
|||
/** |
|||
* Copies files from Moodle storage to temporary folder. |
|||
* |
|||
* @param string $target |
|||
* Path to temporary folder |
|||
* @param int $contextid |
|||
* Moodle context where the files are found |
|||
* @param string $filearea |
|||
* Moodle file area |
|||
* @param string $filepath |
|||
* Moodle file path |
|||
* @param int $itemid |
|||
* Optional Moodle item ID |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private static function exportFileTree($target, $contextid, $filearea, $filepath, $itemid = 0) { |
|||
// Make sure target folder exists. |
|||
if (!file_exists($target)) { |
|||
mkdir($target, 0777, true); |
|||
} |
|||
|
|||
// Read source files. |
|||
$fs = get_file_storage(); |
|||
$files = $fs->get_directory_files($contextid, 'mod_hvp', $filearea, $itemid, $filepath, true); |
|||
|
|||
foreach ($files as $file) { |
|||
// Correct target path for file. |
|||
$path = $target . str_replace($filepath, '/', $file->get_filepath()); |
|||
|
|||
if ($file->is_directory()) { |
|||
// Create directory. |
|||
$path = rtrim($path, '/'); |
|||
if (!file_exists($path)) { |
|||
mkdir($path, 0777, true); |
|||
} |
|||
} else { |
|||
// Copy file. |
|||
$file->copy_content_to($path . $file->get_filename()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Recursive removal of given filepath. |
|||
* |
|||
* @param int $contextid |
|||
* @param string $filearea |
|||
* @param string $filepath |
|||
* @param int $itemid |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private static function deleteFileTree($contextid, $filearea, $filepath, $itemid = 0) { |
|||
$fs = get_file_storage(); |
|||
if ($filepath === '/') { |
|||
// Remove complete file area. |
|||
$fs->delete_area_files($contextid, 'mod_hvp', $filearea, $itemid); |
|||
return; |
|||
} |
|||
|
|||
// Look up files and remove. |
|||
$files = $fs->get_directory_files($contextid, 'mod_hvp', $filearea, $itemid, $filepath, true); |
|||
foreach ($files as $file) { |
|||
$file->delete(); |
|||
} |
|||
|
|||
// Remove root dir. |
|||
$file = $fs->get_file($contextid, 'mod_hvp', $filearea, $itemid, $filepath, '.'); |
|||
if ($file) { |
|||
$file->delete(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Help make it easy to load content files. |
|||
* |
|||
* @param string $filearea |
|||
* @param int|object $itemid |
|||
* @param string $file path + name |
|||
* |
|||
* @return \stored_file|bool |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private function getFile($filearea, $itemid, $file) { |
|||
if ($filearea === 'editor') { |
|||
// Itemid is actually cm or course context. |
|||
$context = $itemid; |
|||
$itemid = 0; |
|||
} else if (is_object($itemid)) { |
|||
// Grab CM context from item. |
|||
$context = \context_module::instance($itemid->coursemodule); |
|||
$itemid = $itemid->id; |
|||
} else { |
|||
// Use item ID to find CM context. |
|||
$cm = \get_coursemodule_from_instance('hvp', $itemid); |
|||
$context = \context_module::instance($cm->id); |
|||
} |
|||
|
|||
// Load file. |
|||
$fs = get_file_storage(); |
|||
return $fs->get_file($context->id, 'mod_hvp', $filearea, $itemid, $this->getFilepath($file), $this->getFilename($file)); |
|||
} |
|||
|
|||
/** |
|||
* Extract Moodle compatible filepath |
|||
* |
|||
* @param string $file |
|||
* @return string With slashes |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private function getFilepath($file) { |
|||
return '/' . dirname($file) . '/'; |
|||
} |
|||
|
|||
/** |
|||
* Extract filename from filepath string |
|||
* |
|||
* @param string $file |
|||
* @return string Without slashes |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private function getFilename($file) { |
|||
return basename($file); |
|||
} |
|||
|
|||
/** |
|||
* Checks if a file exists |
|||
* |
|||
* @method fileExists |
|||
* @param string $filearea [description] |
|||
* @param string $filepath [description] |
|||
* @param string $filename [description] |
|||
* @return boolean |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public static function fileExists($contextid, $filearea, $filepath, $filename) { |
|||
// Check if file exists. |
|||
$fs = get_file_storage(); |
|||
return ($fs->get_file($contextid, 'mod_hvp', $filearea, 0, $filepath, $filename) !== false); |
|||
} |
|||
|
|||
/** |
|||
* Check if server setup has write permission to |
|||
* the required folders |
|||
* |
|||
* @return bool true if server has the proper write access |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function hasWriteAccess() { |
|||
global $CFG; |
|||
|
|||
if (!is_dir($CFG->dataroot)) { |
|||
trigger_error('Path is not a directory ' . $CFG->dataroot, E_USER_WARNING); |
|||
return false; |
|||
} |
|||
|
|||
if (!is_writable($CFG->dataroot)) { |
|||
trigger_error('Unable to write to ' . $CFG->dataroot . ' – check directory permissions –', E_USER_WARNING); |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Copy a content from one directory to another. Defaults to cloning |
|||
* content from the current temporary upload folder to the editor path. |
|||
* |
|||
* @param string $source path to source directory |
|||
* @param string $contentid path of target directory. Defaults to editor path |
|||
* |
|||
* @return object|null Object containing h5p json and content json data |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function moveContentDirectory($source, $contentid = null) { |
|||
if ($source === null) { |
|||
return null; |
|||
} |
|||
|
|||
// Default to 0 (editor). |
|||
if (!isset($contentid)) { |
|||
$contentid = 0; |
|||
} |
|||
|
|||
// Find content context. |
|||
if ($contentid > 0) { |
|||
// Grab cm context. |
|||
$cm = \get_coursemodule_from_instance('hvp', $contentid); |
|||
$context = \context_module::instance($cm->id); |
|||
$contextid = $context->id; |
|||
} |
|||
|
|||
// Get context from parameters. |
|||
if (!isset($contextid)) { |
|||
$contextid = required_param('contextId', PARAM_INT); |
|||
} |
|||
|
|||
// Get h5p and content json. |
|||
$contentsource = $source . DIRECTORY_SEPARATOR . 'content'; |
|||
|
|||
// Move all temporary content files to editor. |
|||
$contentfiles = array_diff(scandir($contentsource), array('.', '..', 'content.json')); |
|||
foreach ($contentfiles as $file) { |
|||
if (is_dir("{$contentsource}/{$file}")) { |
|||
self::moveFileTree("{$contentsource}/{$file}", $contextid, $contentid); |
|||
} else { |
|||
self::moveFile("{$contentsource}/{$file}", $contextid, $contentid); |
|||
} |
|||
} |
|||
|
|||
// TODO: Return list of all files so they can be marked as temporary. JI-366. |
|||
} |
|||
|
|||
/** |
|||
* Move a single file to editor |
|||
* |
|||
* @param string $sourcefile Path to source fil |
|||
* @param int $contextid Id of context |
|||
* @param int $contentid Id of content, 0 if editor |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private static function moveFile($sourcefile, $contextid, $contentid) { |
|||
$fs = get_file_storage(); |
|||
|
|||
$pathparts = pathinfo($sourcefile); |
|||
$filename = $pathparts['basename']; |
|||
$filepath = $pathparts['dirname']; |
|||
$foldername = basename($filepath); |
|||
|
|||
if ($contentid > 0) { |
|||
// Create file record for content. |
|||
$record = array( |
|||
'contextid' => $contextid, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => $contentid > 0 ? 'content' : 'editor', |
|||
'itemid' => $contentid, |
|||
'filepath' => '/' . $foldername . '/', |
|||
'filename' => $filename |
|||
); |
|||
} else { |
|||
// Create file record for editor. |
|||
$record = array( |
|||
'contextid' => $contextid, |
|||
'component' => 'mod_hvp', |
|||
'filearea' => 'editor', |
|||
'itemid' => 0, |
|||
'filepath' => '/' . $foldername . '/', |
|||
'filename' => $filename |
|||
); |
|||
} |
|||
|
|||
$sourcedata = file_get_contents($sourcefile); |
|||
|
|||
// Check if file already exists. |
|||
$fileexists = $fs->file_exists($record['contextid'], 'mod_hvp', |
|||
$record['filearea'], $record['itemid'], $record['filepath'], |
|||
$record['filename'] |
|||
); |
|||
|
|||
if ($fileexists) { |
|||
// Delete it to make sure that it is replaced with correct content. |
|||
$file = $fs->get_file($record['contextid'], 'mod_hvp', |
|||
$record['filearea'], $record['itemid'], $record['filepath'], |
|||
$record['filename'] |
|||
); |
|||
if ($file) { |
|||
$file->delete(); |
|||
} |
|||
} |
|||
|
|||
$fs->create_file_from_string($record, $sourcedata); |
|||
} |
|||
|
|||
/** |
|||
* Move a complete file tree to the editor |
|||
* |
|||
* @param string $sourcefiletree Path of file tree that should be moved |
|||
* @param int $contextid Id of context |
|||
* @param int $contentid Id of content, 0 for editor |
|||
* |
|||
* @throws \Exception |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
private static function moveFileTree($sourcefiletree, $contextid, $contentid) { |
|||
$dir = opendir($sourcefiletree); |
|||
if ($dir === false) { |
|||
trigger_error('Unable to open directory ' . $sourcefiletree, E_USER_WARNING); |
|||
throw new \Exception('unabletocopy'); |
|||
} |
|||
|
|||
while (false !== ($file = readdir($dir))) { |
|||
if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') { |
|||
if (is_dir("{$sourcefiletree}/{$file}")) { |
|||
self::moveFileTree("{$sourcefiletree}/{$file}", $contextid, $contentid); |
|||
} else { |
|||
self::moveFile("{$sourcefiletree}/{$file}", $contextid, $contentid); |
|||
} |
|||
} |
|||
} |
|||
closedir($dir); |
|||
} |
|||
|
|||
/** |
|||
* Check if the library has a presave.js in the root folder |
|||
* |
|||
* @param string $libraryname |
|||
* @param string $developmentpath |
|||
* |
|||
* @return bool |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function hasPresave($libraryname, $developmentpath = null) { |
|||
// TODO: Implement. |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Check if upgrades script exist for library. |
|||
* |
|||
* @param string $machineName |
|||
* @param int $majorVersion |
|||
* @param int $minorVersion |
|||
* @return string Relative path |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function getUpgradeScript($machinename, $majorversion, $minorversion) { |
|||
$context = \context_system::instance(); |
|||
$fs = get_file_storage(); |
|||
$area = 'libraries'; |
|||
$path = "/{$machinename}-{$majorversion}.{$minorversion}/"; |
|||
$file = 'upgrades.js'; |
|||
if ($fs->get_file($context->id, 'mod_hvp', $area, 0, $path, $file)) { |
|||
return "/{$area}{$path}{$file}"; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Store the given stream into the given file. |
|||
* |
|||
* @param string $path |
|||
* @param string $file |
|||
* @param resource $stream |
|||
* |
|||
* @return bool |
|||
*/ |
|||
// @codingStandardsIgnoreLine |
|||
public function saveFileFromZip($path, $file, $stream) { |
|||
$filepath = $path . '/' . $file; |
|||
|
|||
// Make sure the directory exists first. |
|||
$matches = array(); |
|||
preg_match('/(.+)\/[^\/]*$/', $filepath, $matches); |
|||
// Recursively make directories. |
|||
if (!file_exists($matches[1])) { |
|||
mkdir($matches[1], 0777, true); |
|||
} |
|||
|
|||
// Store in local storage folder. |
|||
return file_put_contents($filepath, $stream); |
|||
} |
|||
|
|||
// @codingStandardIgnoreLine |
|||
public function deleteLibrary($library) { |
|||
// TODO: Implement deleteLibrary() method. |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,123 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Helpers for authenticating mobile users through tokens |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2019 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
class mobile_auth { |
|||
|
|||
const VALID_TIME = 60; |
|||
|
|||
/** |
|||
* Generate embed auth token |
|||
* |
|||
* @param string $secret Secret phrase added to the hash |
|||
* @param int $validfor Time factor that determines how long the token is valid |
|||
* |
|||
* @return array Login token and secret |
|||
* @throws \Exception |
|||
*/ |
|||
public static function create_embed_auth_token($secret = null, $validfor = null) { |
|||
if (!$validfor) { |
|||
$validfor = self::get_time_factor(); |
|||
} |
|||
|
|||
if (empty($secret)) { |
|||
if (function_exists('random_bytes')) { |
|||
$secret = base64_encode(random_bytes(15)); |
|||
} else if (function_exists('openssl_random_pseudo_bytes')) { |
|||
$secret = base64_encode(openssl_random_pseudo_bytes(15)); |
|||
} else { |
|||
$secret = uniqid('', true); |
|||
} |
|||
} |
|||
|
|||
return [ |
|||
hash('md5', 'embed_auth' . $validfor . $secret), |
|||
$secret |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* Validate embed auth token |
|||
* |
|||
* @param string $token |
|||
* @param string $secret |
|||
* |
|||
* @return bool True if valid token was supplied |
|||
* @throws \Exception |
|||
*/ |
|||
public static function validate_embed_auth_token($token, $secret) { |
|||
$timefactor = self::get_time_factor(); |
|||
// Splitting into two halves and allowing both allows for fractions roundup in the time factor. |
|||
list($generatedtoken) = self::create_embed_auth_token($secret, $timefactor); |
|||
list($generatedtoken2) = self::create_embed_auth_token($secret, $timefactor - 1); |
|||
return $token === $generatedtoken || $token === $generatedtoken2; |
|||
} |
|||
|
|||
/** |
|||
* Check if provided user_id and token are valid for authenticating the user |
|||
* |
|||
* @param string $userid |
|||
* @param string $token |
|||
* |
|||
* @return bool True if token and user_id is valid |
|||
* @throws \dml_exception |
|||
*/ |
|||
public static function has_valid_token($userid, $secret) { |
|||
global $DB; |
|||
|
|||
if (!$userid || !$secret) { |
|||
return false; |
|||
} |
|||
|
|||
$auth = $DB->get_record('hvp_auth', array( |
|||
'user_id' => $userid, |
|||
)); |
|||
if (!$auth) { |
|||
return false; |
|||
} |
|||
|
|||
$isvalid = self::validate_embed_auth_token($auth->secret, $secret); |
|||
|
|||
// Cleanup user's token when used. |
|||
if ($isvalid) { |
|||
$DB->delete_records('hvp_auth', array( |
|||
'user_id' => $userid |
|||
)); |
|||
} |
|||
|
|||
return $isvalid; |
|||
} |
|||
|
|||
/** |
|||
* Get time factor for how long the token is valid |
|||
* |
|||
* @return float |
|||
*/ |
|||
public static function get_time_factor() { |
|||
return ceil(time() / self::VALID_TIME); |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
<?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/>. |
|||
|
|||
namespace mod_hvp\output; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
use context_module; |
|||
use mod_hvp; |
|||
|
|||
class mobile { |
|||
|
|||
public static function mobile_course_view($args) { |
|||
global $DB, $CFG, $OUTPUT, $USER; |
|||
|
|||
$cmid = $args['cmid']; |
|||
if (!$CFG->allowframembedding) { |
|||
$context = \context_system::instance(); |
|||
if (has_capability('moodle/site:config', $context)) { |
|||
$template = 'mod_hvp/iframe_embedding_disabled'; |
|||
} else { |
|||
$template = 'mod_hvp/contact_site_administrator'; |
|||
} |
|||
return array( |
|||
'templates' => array( |
|||
array( |
|||
'id' => 'noiframeembedding', |
|||
'html' => $OUTPUT->render_from_template($template, []) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
// Verify course context. |
|||
$cm = get_coursemodule_from_id('hvp', $cmid); |
|||
if (!$cm) { |
|||
print_error('invalidcoursemodule'); |
|||
} |
|||
$course = $DB->get_record('course', array('id' => $cm->course)); |
|||
if (!$course) { |
|||
print_error('coursemisconf'); |
|||
} |
|||
require_course_login($course, false, $cm, true, true); |
|||
$context = context_module::instance($cm->id); |
|||
require_capability('mod/hvp:view', $context); |
|||
|
|||
list($token, $secret) = mod_hvp\mobile_auth::create_embed_auth_token(); |
|||
|
|||
// Store secret in database. |
|||
$auth = $DB->get_record('hvp_auth', array( |
|||
'user_id' => $USER->id, |
|||
)); |
|||
$currenttimestamp = time(); |
|||
if ($auth) { |
|||
$DB->update_record('hvp_auth', array( |
|||
'id' => $auth->id, |
|||
'secret' => $token, |
|||
'created_at' => $currenttimestamp, |
|||
)); |
|||
} else { |
|||
$DB->insert_record('hvp_auth', array( |
|||
'user_id' => $USER->id, |
|||
'secret' => $token, |
|||
'created_at' => $currenttimestamp |
|||
)); |
|||
} |
|||
|
|||
$data = [ |
|||
'cmid' => $cmid, |
|||
'wwwroot' => $CFG->wwwroot, |
|||
'user_id' => $USER->id, |
|||
'secret' => urlencode($secret) |
|||
]; |
|||
|
|||
return array( |
|||
'templates' => array( |
|||
array( |
|||
'id' => 'main', |
|||
'html' => $OUTPUT->render_from_template('mod_hvp/mobile_view_page', $data), |
|||
), |
|||
), |
|||
'javascript' => file_get_contents($CFG->dirroot . '/mod/hvp/library/js/h5p-resizer.js'), |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,519 @@ |
|||
<?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 H5P. |
|||
*/ |
|||
|
|||
namespace mod_hvp\privacy; |
|||
|
|||
use \core_privacy\local\request\writer; |
|||
use \core_privacy\local\request\contextlist; |
|||
use \core_privacy\local\request\approved_contextlist; |
|||
use \core_privacy\local\request\deletion_criteria; |
|||
use \core_privacy\local\request\approved_userlist; |
|||
use \core_privacy\local\request\userlist; |
|||
use \core_privacy\local\metadata\collection; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Privacy Subsystem implementation for H5P. |
|||
*/ |
|||
class provider implements |
|||
// This plugin has data. |
|||
\core_privacy\local\metadata\provider, |
|||
\core_privacy\local\request\core_userlist_provider, |
|||
// This plugin currently implements the original plugin_provider interface. |
|||
\core_privacy\local\request\plugin\provider { |
|||
|
|||
use \core_privacy\local\legacy_polyfill; |
|||
|
|||
/** |
|||
* Get the list of contexts that contain user information for the specified user. |
|||
* |
|||
* @param collection $items The collection to add metadata to. |
|||
* |
|||
* @return collection The array of metadata |
|||
*/ |
|||
public static function _get_metadata(collection $items) { |
|||
// Stores files using the Moodle file api. |
|||
$items->add_subsystem_link( |
|||
'core_files', |
|||
[], |
|||
'privacy:metadata:core_files' |
|||
); |
|||
|
|||
// Stores grades using the Moodle gradebook api. |
|||
$items->add_subsystem_link( |
|||
'core_grades', |
|||
[], |
|||
'privacy:metadata:core_grades' |
|||
); |
|||
|
|||
// Content user data table. |
|||
$items->add_database_table('hvp_content_user_data', [ |
|||
'id' => 'privacy:metadata:hvp_content_user_data:id', |
|||
'user_id' => 'privacy:metadata:hvp_content_user_data:user_id', |
|||
'hvp_id' => 'privacy:metadata:hvp_content_user_data:hvp_id', |
|||
'sub_content_id' => 'privacy:metadata:hvp_content_user_data:sub_content_id', |
|||
'data_id' => 'privacy:metadata:hvp_content_user_data:data_id', |
|||
'data' => 'privacy:metadata:hvp_content_user_data:data', |
|||
'preloaded' => 'privacy:metadata:hvp_content_user_data:preloaded', |
|||
'delete_on_content_change' => 'privacy:metadata:hvp_content_user_data:delete_on_content_change', |
|||
], |
|||
'privacy:metadata:hvp_content_user_data' |
|||
); |
|||
|
|||
// Events table. |
|||
$items->add_database_table('hvp_events', [ |
|||
'id' => 'privacy:metadata:hvp_events:id', |
|||
'user_id' => 'privacy:metadata:hvp_events:user_id', |
|||
'created_at' => 'privacy:metadata:hvp_events:created_at', |
|||
'type' => 'privacy:metadata:hvp_events:type', |
|||
'sub_type' => 'privacy:metadata:hvp_events:sub_type', |
|||
'content_id' => 'privacy:metadata:hvp_events:content_id', |
|||
'content_title' => 'privacy:metadata:hvp_events:content_title', |
|||
'library_name' => 'privacy:metadata:hvp_events:library_name', |
|||
'library_version' => 'privacy:metadata:hvp_events:library_version', |
|||
], 'privacy:metadata:hvp_events'); |
|||
|
|||
// Xapi results table. |
|||
$items->add_database_table('hvp_xapi_results', [ |
|||
'id' => 'privacy:metadata:hvp_xapi_results:id', |
|||
'content_id' => 'privacy:metadata:hvp_xapi_results:content_id', |
|||
'user_id' => 'privacy:metadata:hvp_xapi_results:user_id', |
|||
'parent_id' => 'privacy:metadata:hvp_xapi_results:parent_id', |
|||
'interaction_type' => 'privacy:metadata:hvp_xapi_results:interaction_type', |
|||
'description' => 'privacy:metadata:hvp_xapi_results:description', |
|||
'correct_responses_pattern' => 'privacy:metadata:hvp_xapi_results:correct_responses_pattern', |
|||
'response' => 'privacy:metadata:hvp_xapi_results:response', |
|||
'additionals' => 'privacy:metadata:hvp_xapi_results:additionals', |
|||
'raw_score' => 'privacy:metadata:hvp_xapi_results:raw_score', |
|||
'max_score' => 'privacy:metadata:hvp_xapi_results:max_score', |
|||
], 'privacy:metadata:hvp_xapi_results'); |
|||
|
|||
return $items; |
|||
} |
|||
|
|||
/** |
|||
* Get the list of contexts where the specified user has attempted a quiz, or been involved with manual marking |
|||
* and/or grading of a quiz. |
|||
* |
|||
* @param int $userid The user to search. |
|||
* |
|||
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin. |
|||
*/ |
|||
public static function _get_contexts_for_userid($userid) { |
|||
$contextlist = new contextlist(); |
|||
|
|||
// Context for content_user_data. |
|||
$cudsql = " |
|||
SELECT |
|||
c.id |
|||
FROM {course_modules} cm |
|||
INNER JOIN {modules} m ON m.id = cm.module |
|||
INNER JOIN {context} c ON c.instanceid = cm.id |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_content_user_data} d ON h.id = d.hvp_id |
|||
WHERE m.name = 'hvp' |
|||
AND c.contextlevel = :contextlevel |
|||
AND d.user_id = :userid |
|||
"; |
|||
|
|||
$cudparams = array( |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'userid' => $userid, |
|||
); |
|||
|
|||
$contextlist->add_from_sql($cudsql, $cudparams); |
|||
|
|||
// Context for xapi results. |
|||
$xapisql = " |
|||
SELECT |
|||
c.id |
|||
FROM {course_modules} cm |
|||
INNER JOIN {modules} m ON m.id = cm.module |
|||
INNER JOIN {context} c ON c.instanceid = cm.id |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_xapi_results} x ON x.content_id = h.id |
|||
WHERE m.name = 'hvp' |
|||
AND c.contextlevel = :contextlevel |
|||
AND x.user_id = :userid |
|||
"; |
|||
|
|||
$xapiparams = array( |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'userid' => $userid, |
|||
); |
|||
|
|||
$contextlist->add_from_sql($xapisql, $xapiparams); |
|||
|
|||
// Table hvp_events note: |
|||
// H5P events are not tied to instance ids, thus we cannot determine |
|||
// their context ids, they are considered to be user level context |
|||
// actions. |
|||
|
|||
return $contextlist; |
|||
} |
|||
|
|||
/** |
|||
* Export all user data for the specified user, in the specified contexts, using the supplied |
|||
* exporter instance. |
|||
* |
|||
* @param approved_contextlist $contextlist The approved contexts to export information for. |
|||
*/ |
|||
public static function _export_user_data(approved_contextlist $contextlist) { |
|||
global $DB; |
|||
|
|||
if (!count($contextlist)) { |
|||
return; |
|||
} |
|||
|
|||
$user = $contextlist->get_user(); |
|||
$userid = $user->id; |
|||
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED); |
|||
|
|||
$cud = self::get_exportable_content_user_data($contextsql, $contextparams, $userid); |
|||
$xapi = self::get_exportable_xapi_results($contextsql, $contextparams, $userid); |
|||
|
|||
// Export data with context. |
|||
foreach ($contextlist->get_contexts() as $context) { |
|||
$h5pdata = \core_privacy\local\request\helper::get_context_data($context, $contextlist->get_user()); |
|||
\core_privacy\local\request\helper::export_context_files($context, $contextlist->get_user()); |
|||
|
|||
// Add content user data. |
|||
if (!empty($cud[$context->id]) && !empty($cud[$context->id]->data)) { |
|||
$h5pdata->contentuserdata = $cud[$context->id]->data; |
|||
} |
|||
|
|||
// Add xAPI data. |
|||
if (!empty($xapi[$context->id])) { |
|||
$h5pdata->xapiresults = $xapi[$context->id]; |
|||
} |
|||
|
|||
writer::with_context($context)->export_data([], $h5pdata); |
|||
} |
|||
|
|||
// Write H5PEvents to subcontext of the user context. |
|||
$usercontext = \context_user::instance($userid); |
|||
$h5pevents = self::get_exportable_events($userid); |
|||
writer::with_context($usercontext)->export_data(['H5PEvents'], $h5pevents); |
|||
} |
|||
|
|||
/** |
|||
* Get exportable content user data for a given context and user |
|||
* |
|||
* @param $contextsql |
|||
* @param $contextparams |
|||
* @param $userid |
|||
* |
|||
* @return array Exportable and writable content user data |
|||
* @throws \dml_exception |
|||
*/ |
|||
protected static function get_exportable_content_user_data($contextsql, $contextparams, $userid) { |
|||
global $DB; |
|||
|
|||
$cudsql = " |
|||
SELECT |
|||
c.id as contextid, |
|||
cm.id as cmid, |
|||
h.id, |
|||
h.name, |
|||
cud.data |
|||
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 = :modname |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_content_user_data} cud ON cud.hvp_id = h.id |
|||
WHERE cud.user_id = :userid |
|||
AND c.id {$contextsql} |
|||
"; |
|||
|
|||
$cudparams = [ |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'modname' => 'hvp', |
|||
'userid' => $userid, |
|||
]; |
|||
$cudparams += $contextparams; |
|||
|
|||
$cudresult = $DB->get_recordset_sql($cudsql, $cudparams); |
|||
$cud = []; |
|||
foreach ($cudresult as $record) { |
|||
$cud[$record->contextid] = $record; |
|||
} |
|||
$cudresult->close(); |
|||
|
|||
return $cud; |
|||
} |
|||
|
|||
/** |
|||
* Get exportable xapi results from context and user id |
|||
* |
|||
* @param $contextsql |
|||
* @param $contextparams |
|||
* @param $userid |
|||
* |
|||
* @return array Exportable and writable xapi results |
|||
* @throws \dml_exception |
|||
*/ |
|||
protected static function get_exportable_xapi_results($contextsql, $contextparams, $userid) { |
|||
global $DB; |
|||
|
|||
$xapisql = " |
|||
SELECT |
|||
c.id as contextid, |
|||
cm.id as cmid, |
|||
h.id, |
|||
h.name, |
|||
x.content_id, |
|||
x.parent_id, |
|||
x.description, |
|||
x.response, |
|||
x.additionals, |
|||
x.raw_score, |
|||
x.max_score |
|||
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 = :modname |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_xapi_results} x ON x.content_id = h.id |
|||
WHERE x.user_id = :userid |
|||
AND c.id {$contextsql} |
|||
"; |
|||
|
|||
$xapiparams = [ |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'modname' => 'hvp', |
|||
'userid' => $userid, |
|||
]; |
|||
$xapiparams += $contextparams; |
|||
|
|||
$xapiresult = $DB->get_recordset_sql($xapisql, $xapiparams); |
|||
$xapi = []; |
|||
foreach ($xapiresult as $record) { |
|||
$h5pxapi = (object) array(); |
|||
if (!empty($record->content_id)) { |
|||
$h5pxapi->content_id = $record->content_id; |
|||
} |
|||
|
|||
if (!empty($record->parent_id)) { |
|||
$h5pxapi->parent_id = $record->parent_id; |
|||
} |
|||
|
|||
if (!empty($record->description)) { |
|||
$h5pxapi->description = $record->description; |
|||
} |
|||
|
|||
if (!empty($record->response)) { |
|||
$h5pxapi->response = $record->response; |
|||
} |
|||
|
|||
if (!empty($record->additionals)) { |
|||
$h5pxapi->additionals = $record->additionals; |
|||
} |
|||
|
|||
if (!empty($record->raw_score)) { |
|||
$h5pxapi->raw_score = $record->raw_score; |
|||
} |
|||
|
|||
if (!empty($record->max_score)) { |
|||
$h5pxapi->max_score = $record->max_score; |
|||
} |
|||
|
|||
$xapi[$record->contextid][] = $h5pxapi; |
|||
} |
|||
$xapiresult->close(); |
|||
|
|||
return $xapi; |
|||
} |
|||
|
|||
/** |
|||
* Get exportable H5P events from user id |
|||
* |
|||
* @param $userid |
|||
* |
|||
* @return object Exportable and writable H5P events |
|||
* @throws \dml_exception |
|||
*/ |
|||
protected static function get_exportable_events($userid) { |
|||
global $DB; |
|||
|
|||
$eventssql = " |
|||
SELECT * |
|||
FROM {hvp_events} |
|||
WHERE user_id = :userid |
|||
"; |
|||
|
|||
$eventsparams = [ |
|||
'userid' => $userid, |
|||
]; |
|||
|
|||
$h5peventsresults = $DB->get_recordset_sql($eventssql, $eventsparams); |
|||
$h5pevents = (object) [ |
|||
'events' => [], |
|||
]; |
|||
foreach ($h5peventsresults as $event) { |
|||
$h5pevents->events[] = $event; |
|||
} |
|||
$h5peventsresults->close(); |
|||
|
|||
return $h5pevents; |
|||
} |
|||
|
|||
/** |
|||
* Delete all data for all users in the specified context. |
|||
* |
|||
* @param \context $context The specific context to delete data for. |
|||
*/ |
|||
public static function _delete_data_for_all_users_in_context(\context $context) { |
|||
global $DB; |
|||
|
|||
if ($context->contextlevel == CONTEXT_USER) { |
|||
// Delete all H5P events. |
|||
$DB->delete_records('hvp_events'); |
|||
return; |
|||
} else if ($context->contextlevel != CONTEXT_MODULE) { |
|||
return; |
|||
} |
|||
|
|||
$cm = get_coursemodule_from_id('hvp', $context->instanceid); |
|||
if (!$cm) { |
|||
return; |
|||
} |
|||
|
|||
// Delete content user data. |
|||
$DB->delete_records('hvp_content_user_data', [ |
|||
'hvp_id' => $cm->instance, |
|||
]); |
|||
|
|||
// Delete xAPI results. |
|||
$DB->delete_records('hvp_xapi_results', [ |
|||
'content_id' => $cm->instance, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Delete all user data for the specified user, in the specified contexts. |
|||
* |
|||
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for. |
|||
*/ |
|||
public static function _delete_data_for_user(approved_contextlist $contextlist) { |
|||
global $DB; |
|||
|
|||
$count = $contextlist->count(); |
|||
if (empty($count)) { |
|||
return; |
|||
} |
|||
|
|||
$userid = $contextlist->get_user()->id; |
|||
foreach ($contextlist->get_contexts() as $context) { |
|||
$cm = get_coursemodule_from_id('hvp', $context->instanceid); |
|||
|
|||
if (!$cm) { |
|||
continue; |
|||
} |
|||
|
|||
// Delete content user data. |
|||
$DB->delete_records('hvp_content_user_data', [ |
|||
'hvp_id' => $cm->instance, |
|||
'user_id' => $userid, |
|||
]); |
|||
|
|||
// Delete xAPI results. |
|||
$DB->delete_records('hvp_xapi_results', [ |
|||
'content_id' => $cm->instance, |
|||
'user_id' => $userid, |
|||
]); |
|||
} |
|||
|
|||
// Delete H5P events. |
|||
$DB->delete_records('hvp_events', [ |
|||
'user_id' => $userid, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 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 (!is_a($context, \context_module::class)) { |
|||
return; |
|||
} |
|||
|
|||
$sql = " |
|||
SELECT d.user_id |
|||
FROM {course_modules} cm |
|||
INNER JOIN {modules} m ON m.id = cm.module AND m.name = 'hvp' |
|||
INNER JOIN {context} c ON c.instanceid = cm.id |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_content_user_data} d ON h.id = d.hvp_id |
|||
WHERE c.contextlevel = :contextlevel AND c.id = :contextid"; |
|||
|
|||
$params = [ |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'contextid' => $context->id, |
|||
]; |
|||
$userlist->add_from_sql('user_id', $sql, $params); |
|||
|
|||
$sql = " |
|||
SELECT |
|||
x.user_id |
|||
FROM {course_modules} cm |
|||
INNER JOIN {modules} m ON m.id = cm.module AND m.name = 'hvp' |
|||
INNER JOIN {context} c ON c.instanceid = cm.id |
|||
INNER JOIN {hvp} h ON h.id = cm.instance |
|||
INNER JOIN {hvp_xapi_results} x ON x.content_id = h.id |
|||
WHERE c.contextlevel = :contextlevel AND c.id = :contextid"; |
|||
$userlist->add_from_sql('user_id', $sql, $params); |
|||
} |
|||
|
|||
/** |
|||
* 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 (!is_a($context, \context_module::class)) { |
|||
return; |
|||
} |
|||
$cm = get_coursemodule_from_id('hvp', $context->instanceid); |
|||
|
|||
// Prepare SQL to gather all completed IDs. |
|||
$userids = $userlist->get_userids(); |
|||
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); |
|||
|
|||
$inparams['hvpid'] = $cm->instance; |
|||
|
|||
$DB->delete_records_select( |
|||
'hvp_content_user_data', |
|||
"hvp_id = :hvpid AND user_id $insql", |
|||
$inparams |
|||
); |
|||
|
|||
$DB->delete_records_select( |
|||
'hvp_xapi_results', |
|||
"hvp_id = :hvpid AND user_id $insql", |
|||
$inparams |
|||
); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,379 @@ |
|||
<?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 mod_hvp file storage |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp file storage class. |
|||
* |
|||
* @package mod_hvp |
|||
* @since Moodle 2.7 |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class results { |
|||
|
|||
// Type specific inputs. |
|||
protected $contentid; |
|||
|
|||
// Generic result inputs. |
|||
protected $offset, $limit, $orderby, $orderdir, $filters; |
|||
|
|||
/** |
|||
* Start handling results by filtering input parameters. |
|||
*/ |
|||
public function __construct() { |
|||
$this->filter_input(); |
|||
} |
|||
|
|||
/** |
|||
* Filter and load input parameters |
|||
* |
|||
* @throws \coding_exception |
|||
*/ |
|||
protected function filter_input() { |
|||
// Type specifc. |
|||
$this->contentid = optional_param('content_id', 0, PARAM_INT); |
|||
|
|||
// Used to handle pagination. |
|||
$this->offset = optional_param('offset', 0, PARAM_INT); |
|||
|
|||
// Max number of items to display on one page. |
|||
$this->limit = optional_param('limit', 20, PARAM_INT); |
|||
if ($this->limit > 100) { |
|||
// Avoid wrong usage. |
|||
throw new \coding_exception('limit to high'); |
|||
} |
|||
|
|||
// Field to order by. |
|||
$this->orderby = optional_param('sortBy', 0, PARAM_INT); |
|||
|
|||
// Direction to order in. |
|||
$this->orderdir = optional_param('sortDir', 0, PARAM_INT); |
|||
|
|||
// List of fields to filter results on. |
|||
$this->filters = optional_param_array('filters', array(), PARAM_RAW_TRIMMED); |
|||
} |
|||
|
|||
/** |
|||
* Print results data |
|||
*/ |
|||
public function print_results() { |
|||
global $USER; |
|||
|
|||
$cm = get_coursemodule_from_instance('hvp', $this->contentid); |
|||
if (!$cm) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
// Check permission. |
|||
$context = \context_module::instance($cm->id); |
|||
$viewownresults = has_capability('mod/hvp:viewresults', $context); |
|||
$viewallresults = has_capability('mod/hvp:viewallresults', $context); |
|||
if (!$viewownresults && !$viewallresults) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontoviewresult', 'hvp')); |
|||
http_response_code(403); |
|||
return; |
|||
} |
|||
|
|||
// Only get own results if can't view all. |
|||
$uid = $viewallresults ? null : (int)$USER->id; |
|||
$results = $this->get_results($uid); |
|||
$rows = $this->get_human_readable_results($results, $cm->course); |
|||
|
|||
header('Cache-Control: no-cache'); |
|||
header('Content-type: application/json'); |
|||
print json_encode(array( |
|||
'num' => $this->get_results_num(), |
|||
'rows' => $rows |
|||
)); |
|||
} |
|||
|
|||
/** |
|||
* Constructs human readable results |
|||
* |
|||
* @param $results |
|||
* @param $course |
|||
* |
|||
* @return array |
|||
*/ |
|||
private function get_human_readable_results($results, $course) { |
|||
// Make data readable for humans. |
|||
$rows = array(); |
|||
foreach ($results as $result) { |
|||
$userlink = \html_writer::link( |
|||
new \moodle_url('/user/view.php', array( |
|||
'id' => $result->id, |
|||
'course' => $course |
|||
)), |
|||
\fullname($result) |
|||
); |
|||
|
|||
$reviewlink = '—'; |
|||
|
|||
// Check if result has xAPI data. |
|||
if ($result->xapiid) { |
|||
$reviewlink = \html_writer::link( |
|||
new \moodle_url('/mod/hvp/review.php', |
|||
array( |
|||
'id' => $this->contentid, |
|||
'course' => $course, |
|||
'user' => $result->id |
|||
) |
|||
), |
|||
get_string('viewreportlabel', 'hvp') |
|||
); |
|||
} else if ($result->rawgrade !== null) { |
|||
$reviewlink = get_string('reportnotsupported', 'hvp'); |
|||
} |
|||
|
|||
$rows[] = array( |
|||
$userlink, |
|||
$result->rawgrade === null ? '—' : (int) $result->rawgrade, |
|||
$result->rawgrade === null ? '—' : (int) $result->rawgrademax, |
|||
empty($result->timemodified) ? '—' : date('Y/m/d – H:i', $result->timemodified), |
|||
$reviewlink |
|||
); |
|||
} |
|||
|
|||
return $rows; |
|||
} |
|||
|
|||
/** |
|||
* Builds the SQL query required to retrieve results for the given |
|||
* interactive content. |
|||
* |
|||
* @param int $uid Only get results for uid |
|||
* |
|||
* @throws \coding_exception |
|||
* @return array |
|||
*/ |
|||
protected function get_results($uid=null) { |
|||
// Add extra fields, joins and where for the different result lists. |
|||
if ($this->contentid !== 0) { |
|||
list($fields, $join, $where, $order, $args) = $this->get_content_sql($uid); |
|||
} else { |
|||
throw new \coding_exception('missing content_id'); |
|||
} |
|||
|
|||
// Xapi join. |
|||
$where[] = "x.content_id = ?"; |
|||
$args[] = $this->contentid; |
|||
|
|||
// Build where statement. |
|||
$where[] = "i.itemtype = 'mod'"; |
|||
$where[] = "i.itemmodule = 'hvp'"; |
|||
$where[] = "x.parent_id IS NULL"; |
|||
$where = 'WHERE ' . implode(' AND ', $where); |
|||
|
|||
// Order results by the select column and direction. |
|||
$order[] = 'g.rawgrade'; |
|||
$order[] = 'g.rawgrademax'; |
|||
$order[] = 'g.timemodified'; |
|||
$orderby = $this->get_order_sql($order); |
|||
|
|||
// Join on xAPI results. |
|||
$join .= ' LEFT JOIN {hvp_xapi_results} x ON g.userid = x.user_id'; |
|||
$groupby = ' GROUP BY i.id, g.id, u.id, i.iteminstance, x.id'; |
|||
|
|||
// Get from statement. |
|||
$from = $this->get_from_sql(); |
|||
|
|||
// Execute query and get results. |
|||
return $this->get_sql_results(" |
|||
SELECT u.id, |
|||
i.id AS gradeitemid, |
|||
g.id AS gradeid, |
|||
{$fields} |
|||
g.rawgrade, |
|||
g.rawgrademax, |
|||
g.timemodified, |
|||
x.id as xapiid |
|||
{$from} |
|||
{$join} |
|||
{$where} |
|||
{$groupby} |
|||
{$orderby} |
|||
", $args, |
|||
$this->offset, |
|||
$this->limit); |
|||
} |
|||
|
|||
/** |
|||
* Build and execute the query needed to tell the number of total results. |
|||
* This is used to create pagination. |
|||
* |
|||
* @return int |
|||
*/ |
|||
protected function get_results_num() { |
|||
global $DB; |
|||
|
|||
list(, $join, $where, , $args) = $this->get_content_sql(); |
|||
$where[] = "i.itemtype = 'mod'"; |
|||
$where[] = "i.itemmodule = 'hvp'"; |
|||
$where = 'WHERE ' . implode(' AND ', $where); |
|||
$from = $this->get_from_sql(); |
|||
|
|||
return (int) $DB->get_field_sql("SELECT COUNT(i.id) {$from} {$join} {$where}", $args); |
|||
} |
|||
|
|||
/** |
|||
* Builds the order part of the SQL query. |
|||
* |
|||
* @param array $fields Fields allowed to order by |
|||
* @throws \coding_exception |
|||
* @return string |
|||
*/ |
|||
protected function get_order_sql($fields) { |
|||
// Make sure selected order field is valid. |
|||
if (!isset($fields[$this->orderby])) { |
|||
throw new \coding_exception('invalid order field'); |
|||
} |
|||
|
|||
// Find selected sortable field. |
|||
$field = $fields[$this->orderby]; |
|||
|
|||
if (is_object($field)) { |
|||
// Some fields are reverse sorted by default, e.g. text fields. |
|||
// This feels more natural for the humans. |
|||
if (!empty($field->reverse)) { |
|||
$this->orderdir = !$this->orderdir; |
|||
} |
|||
|
|||
$field = $field->name; |
|||
} |
|||
|
|||
$dir = ($this->orderdir ? 'ASC' : 'DESC'); |
|||
if ($field === 'u.firstname') { |
|||
// Order by all user name fields. |
|||
$field = implode(" {$dir}, ", self::get_ordered_user_name_fields()); |
|||
} |
|||
|
|||
return "ORDER BY {$field} {$dir}"; |
|||
} |
|||
|
|||
/** |
|||
* Get from part of the SQL query. |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function get_from_sql() { |
|||
return " FROM {grade_items} i LEFT JOIN {grade_grades} g ON i.id = g.itemid LEFT JOIN {user} u ON u.id = g.userid"; |
|||
} |
|||
|
|||
/** |
|||
* Get all user name fields in display order. |
|||
* |
|||
* @param string $prefix Optional table prefix to prepend to all fields |
|||
* @return array |
|||
*/ |
|||
public static function get_ordered_user_name_fields($prefix = 'u.') { |
|||
static $ordered; |
|||
|
|||
if (empty($ordered)) { |
|||
$available = \get_all_user_name_fields(); |
|||
$displayname = \fullname((object)$available); |
|||
if (empty($displayname)) { |
|||
$ordered = array("{$prefix}firstname", "{$prefix}lastname"); |
|||
} else { |
|||
// Find fields in order. |
|||
foreach ($available as $key => $value) { |
|||
$ordered[] = $prefix . $available[$key]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return $ordered; |
|||
} |
|||
|
|||
/** |
|||
* Get the different parts needed to create the SQL for getting results |
|||
* belonging to a specifc content. |
|||
* (An alternative to this could be getting all the results for a |
|||
* specified user.) |
|||
* |
|||
* @param int $uid Only get users with this id |
|||
* @return array $fields, $join, $where, $order, $args |
|||
*/ |
|||
protected function get_content_sql($uid=null) { |
|||
global $DB; |
|||
|
|||
$usernamefields = implode(', ', self::get_ordered_user_name_fields()); |
|||
$fields = " {$usernamefields}, "; |
|||
$join = ""; |
|||
$where = array("i.iteminstance = ?"); |
|||
$args = array($this->contentid); |
|||
|
|||
// Only get entries with own user id. |
|||
if (isset($uid)) { |
|||
array_push($where, "u.id = ?"); |
|||
array_push($args, $uid); |
|||
} |
|||
|
|||
if (isset($this->filters[0])) { |
|||
$keywordswhere = array(); |
|||
|
|||
// Split up keywords using whitespace and comma. |
|||
foreach (preg_split("/[\s,]+/", $this->filters[0]) as $keyword) { |
|||
// Search all user name fields. |
|||
$usernamewhere = array(); |
|||
foreach (self::get_ordered_user_name_fields() as $usernamefield) { |
|||
$usernamewhere[] = $DB->sql_like($usernamefield, '?', false); |
|||
$args[] = '%' . $keyword . '%'; |
|||
} |
|||
|
|||
// Add user name fields where to keywords where. |
|||
if (!empty($usernamewhere)) { |
|||
$keywordswhere[] = '(' . implode(' OR ', $usernamewhere) . ')'; |
|||
} |
|||
} |
|||
|
|||
// Add keywords where to SQL where. |
|||
if (!empty($keywordswhere)) { |
|||
$where[] = '(' . implode(' AND ', $keywordswhere) . ')'; |
|||
} |
|||
} |
|||
$order = array((object) array( |
|||
'name' => 'u.firstname', |
|||
'reverse' => true |
|||
)); |
|||
|
|||
return array($fields, $join, $where, $order, $args); |
|||
} |
|||
|
|||
/** |
|||
* Execute given query and return any results |
|||
* |
|||
* @param string $query |
|||
* @param array $args Used for placeholders |
|||
* @return array |
|||
*/ |
|||
protected function get_sql_results($query, $args, $limitfrom = 0, $limitnum = 0) { |
|||
global $DB; |
|||
return $DB->get_records_sql($query, $args, $limitfrom, $limitnum); |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
/** |
|||
* Defines the task which looks for H5P updates. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\task; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp look for updates task class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class look_for_updates extends \core\task\scheduled_task { |
|||
public function get_name() { |
|||
return get_string('lookforupdates', 'mod_hvp'); |
|||
} |
|||
|
|||
public function execute() { |
|||
// Check to make sure external communications hasn't been disabled. |
|||
if (get_config('mod_hvp', 'hub_is_enabled') || get_config('mod_hvp', 'send_usage_statistics')) { |
|||
$core = \mod_hvp\framework::instance(); |
|||
$core->fetchLibrariesMetadata(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
<?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 the task which removes old mobile auth tokens from the hvp_auth table. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2019 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\task; |
|||
|
|||
use mod_hvp\mobile_auth; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp remove old auth tokens class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2019 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class remove_old_auth_tokens extends \core\task\scheduled_task { |
|||
public function get_name() { |
|||
return get_string('removeoldmobileauthentries', 'mod_hvp'); |
|||
} |
|||
|
|||
public function execute() { |
|||
global $DB; |
|||
|
|||
require_once(__DIR__ . '/../../autoloader.php'); |
|||
$deletethreshold = time() - mobile_auth::VALID_TIME; |
|||
$DB->delete_records_select('hvp_auth', 'created_at < :threshold', array( |
|||
'threshold' => $deletethreshold, |
|||
)); |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?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 the task which looks for H5P updates. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\task; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp look for updates task class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class remove_old_log_entries extends \core\task\scheduled_task { |
|||
public function get_name() { |
|||
return get_string('removeoldlogentries', 'mod_hvp'); |
|||
} |
|||
|
|||
public function execute() { |
|||
global $DB; |
|||
|
|||
require_once(__DIR__ . '/../../autoloader.php'); |
|||
// @codingStandardsIgnoreLine |
|||
$olderthan = (time() - \H5PEventBase::$log_time); |
|||
$DB->execute("DELETE FROM {hvp_events} WHERE created_at < {$olderthan}"); |
|||
} |
|||
} |
|||
@ -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/>. |
|||
/** |
|||
* Defines the task which removes old tmp files |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp\task; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* The mod_hvp look for updates task class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class remove_tmpfiles extends \core\task\scheduled_task { |
|||
public function get_name() { |
|||
return get_string('removetmpfiles', 'mod_hvp'); |
|||
} |
|||
|
|||
public function execute() { |
|||
global $DB; |
|||
$tmpfiles = $DB->get_records_sql( |
|||
"SELECT f.id |
|||
FROM {hvp_tmpfiles} tf |
|||
JOIN {files} f ON f.id = tf.id |
|||
WHERE f.timecreated < ?", |
|||
array(time() - 86400) |
|||
); |
|||
if (empty($tmpfiles)) { |
|||
return; // Nothing to clean up. |
|||
} |
|||
|
|||
$fs = get_file_storage(); |
|||
foreach ($tmpfiles as $tmpfile) { |
|||
// Delete file. |
|||
$file = $fs->get_file_by_id($tmpfile->id); |
|||
$file->delete(); |
|||
|
|||
// Remove tmpfile entry. |
|||
$DB->delete_records('hvp_tmpfiles', array('id' => $tmpfile->id)); |
|||
} |
|||
} |
|||
} |
|||
@ -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/>. |
|||
|
|||
/** |
|||
* \mod_hvp\upload_libraries_form class |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
// Load moodleform class. |
|||
require_once("$CFG->libdir/formslib.php"); |
|||
|
|||
/** |
|||
* Form to upload new H5P libraries and upgrade existing once |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class upload_libraries_form extends \moodleform { |
|||
|
|||
/** |
|||
* Define form elements |
|||
*/ |
|||
public function definition() { |
|||
global $CFG, $OUTPUT; |
|||
|
|||
// Get form. |
|||
$mform = $this->_form; |
|||
|
|||
// Add File Picker. |
|||
$mform->addElement('filepicker', 'h5pfile', get_string('h5pfile', 'hvp'), null, |
|||
array('maxbytes' => $CFG->maxbytes, 'accepted_types' => '*.h5p')); |
|||
|
|||
// Add options. |
|||
$mform->addElement('checkbox', |
|||
'onlyupdate', |
|||
get_string('options', 'hvp'), |
|||
get_string('onlyupdate', 'hvp'), |
|||
array('group' => 1) |
|||
); |
|||
$mform->setType('onlyupdate', PARAM_BOOL); |
|||
$mform->setDefault('onlyupdate', false); |
|||
|
|||
$mform->addElement('checkbox', |
|||
'disablefileextensioncheck', |
|||
'', |
|||
get_string('disablefileextensioncheck', 'hvp'), |
|||
array('group' => 1) |
|||
); |
|||
$mform->setType('disablefileextensioncheck', PARAM_BOOL); |
|||
$mform->setDefault('disablefileextensioncheck', false); |
|||
|
|||
$notification = $OUTPUT->notification( |
|||
get_string('disablefileextensioncheckwarning', 'hvp'), |
|||
'notifymessage' |
|||
); |
|||
$mform->addElement('static', '', '', $notification); |
|||
|
|||
// Upload button. |
|||
$this->add_action_buttons(false, get_string('upload', 'hvp')); |
|||
} |
|||
|
|||
/** |
|||
* Preprocess incoming data |
|||
* |
|||
* @param array $defaultvalues default values for form |
|||
*/ |
|||
public function data_preprocessing(&$defaultvalues) { |
|||
// Aaah.. we meet again h5pfile!. |
|||
$draftitemid = file_get_submitted_draft_itemid('h5pfile'); |
|||
file_prepare_draft_area($draftitemid, $this->context->id, 'mod_hvp', 'package', 0); |
|||
$defaultvalues['h5pfile'] = $draftitemid; |
|||
} |
|||
|
|||
/** |
|||
* Validate incoming data |
|||
* |
|||
* @param array $data array of ("fieldname"=>value) of submitted data |
|||
* @param array $files array of uploaded files "element_name"=>tmp_file_path |
|||
* @return array of "element_name"=>"error_description" if there are errors, |
|||
* or an empty array if everything is OK (true allowed for backwards compatibility too). |
|||
*/ |
|||
public function validation($data, $files) { |
|||
global $CFG; |
|||
$errors = array(); |
|||
|
|||
// Check for file. |
|||
if (empty($data['h5pfile'])) { |
|||
$errors['h5pfile'] = get_string('required'); |
|||
return $errors; |
|||
} |
|||
|
|||
$files = $this->get_draft_files('h5pfile'); |
|||
if (count($files) < 1) { |
|||
$errors['h5pfile'] = get_string('required'); |
|||
return $errors; |
|||
} |
|||
|
|||
// Add file so that core framework can find it. |
|||
$file = reset($files); |
|||
$interface = \mod_hvp\framework::instance('interface'); |
|||
|
|||
$path = $CFG->tempdir . uniqid('/hvp-'); |
|||
$interface->getUploadedH5pFolderPath($path); |
|||
$path .= '.h5p'; |
|||
$interface->getUploadedH5pPath($path); |
|||
$file->copy_content_to($path); |
|||
|
|||
// Validate package. |
|||
$h5pvalidator = \mod_hvp\framework::instance('validator'); |
|||
if (!$h5pvalidator->isValidPackage(true, isset($data['onlyupdate']))) { |
|||
// Errors while validating the package. |
|||
$errors = array_map(function ($message) { |
|||
return $message->message; |
|||
}, framework::messages('error')); |
|||
|
|||
$messages = array_merge(framework::messages('info'), $errors); |
|||
$errors['h5pfile'] = implode('<br/>', $messages); |
|||
} |
|||
return $errors; |
|||
} |
|||
} |
|||
@ -0,0 +1,226 @@ |
|||
<?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 mod_hvp user grades |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
require(__DIR__ . '/../lib.php'); |
|||
|
|||
/** |
|||
* Handles grade storage for users |
|||
* @package mod_hvp |
|||
*/ |
|||
class user_grades { |
|||
|
|||
public static function handle_ajax() { |
|||
global $DB, $USER, $CFG; |
|||
|
|||
if (!\H5PCore::validToken('result', required_param('token', PARAM_RAW))) { |
|||
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp')); |
|||
return; |
|||
} |
|||
|
|||
$cm = get_coursemodule_from_id('hvp', required_param('contextId', PARAM_INT)); |
|||
if (!$cm) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
// Content parameters. |
|||
$score = required_param('score', PARAM_INT); |
|||
$maxscore = required_param('maxScore', PARAM_INT); |
|||
|
|||
// Check permission. |
|||
$context = \context_module::instance($cm->id); |
|||
if (!has_capability('mod/hvp:saveresults', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontosaveresult', 'hvp')); |
|||
http_response_code(403); |
|||
return; |
|||
} |
|||
|
|||
// Get hvp data from content. |
|||
$hvp = $DB->get_record('hvp', array('id' => $cm->instance)); |
|||
if (!$hvp) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
// Create grade object and set grades. |
|||
$grade = (object) array( |
|||
'userid' => $USER->id |
|||
); |
|||
|
|||
// Set grade using Gradebook API. |
|||
$hvp->cmidnumber = $cm->idnumber; |
|||
$hvp->name = $cm->name; |
|||
$hvp->rawgrade = $score; |
|||
$hvp->rawgrademax = $maxscore; |
|||
hvp_grade_item_update($hvp, $grade); |
|||
|
|||
// Get content info for log. |
|||
$content = $DB->get_record_sql( |
|||
"SELECT c.name AS title, l.machine_name AS name, l.major_version, l.minor_version |
|||
FROM {hvp} c |
|||
JOIN {hvp_libraries} l ON l.id = c.main_library_id |
|||
WHERE c.id = ?", |
|||
array($hvp->id) |
|||
); |
|||
|
|||
require_once($CFG->libdir.'/completionlib.php'); |
|||
|
|||
// Load Course. |
|||
$course = $DB->get_record('course', array('id' => $cm->course)); |
|||
$completion = new \completion_info( $course ); |
|||
|
|||
if ( $completion->is_enabled( $cm) ) { |
|||
$completion->update_state($cm, COMPLETION_COMPLETE); |
|||
} |
|||
|
|||
// Log results set event. |
|||
new \mod_hvp\event( |
|||
'results', 'set', |
|||
$hvp->id, $content->title, |
|||
$content->name, $content->major_version . '.' . $content->minor_version |
|||
); |
|||
|
|||
// Trigger Moodle event for async notification messages. |
|||
$event = \mod_hvp\event\attempt_submitted::create([ |
|||
'context' => $context, |
|||
]); |
|||
$event->trigger(); |
|||
|
|||
\H5PCore::ajaxSuccess(); |
|||
} |
|||
|
|||
/** |
|||
* Since the subcontent types do not have their own row in the table, |
|||
* we use the hvp_results_table as a 'staging area' to set and get |
|||
* dynamically graded scores. |
|||
*/ |
|||
public static function handle_dynamic_grading() { |
|||
global $DB; |
|||
|
|||
if (!\H5PCore::validToken('result', required_param('token', PARAM_RAW))) { |
|||
\H5PCore::ajaxError(get_string('invalidtoken', 'hvp')); |
|||
return; |
|||
} |
|||
|
|||
$cm = get_coursemodule_from_id('hvp', required_param('contextId', PARAM_INT)); |
|||
if (!$cm) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
// Content parameters. |
|||
$subcontentid = required_param('subcontent_id', PARAM_INT); |
|||
$score = required_param('score', PARAM_INT); |
|||
|
|||
// Update the answer's score. |
|||
$data = (object) [ |
|||
'id' => $subcontentid, |
|||
'raw_score' => $score |
|||
]; |
|||
$DB->update_record('hvp_xapi_results', $data, false); |
|||
|
|||
// Load freshly updated record. |
|||
$answer = $DB->get_record('hvp_xapi_results', array('id' => $subcontentid)); |
|||
|
|||
// Get the sum of all the OEQ scores with the same parent. |
|||
$totalgradablesscore = intval($DB->get_field_sql( |
|||
"SELECT SUM(raw_score) |
|||
FROM {hvp_xapi_results} |
|||
WHERE parent_id = ? |
|||
AND additionals = ?", array($answer->parent_id, |
|||
'{"extensions":{"https:\/\/h5p.org\/x-api\/h5p-machine-name":"H5P.FreeTextQuestion"}}') |
|||
)); |
|||
|
|||
// Get the original raw score from the main content type. |
|||
$baseanswer = $DB->get_record('hvp_xapi_results', array( |
|||
'id' => $answer->parent_id |
|||
)); |
|||
|
|||
// Get hvp data from content. |
|||
$hvp = $DB->get_record('hvp', array('id' => $cm->instance)); |
|||
if (!$hvp) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
// Set grade using Gradebook API. |
|||
$hvp->rawgrade = $baseanswer->raw_score + $totalgradablesscore; |
|||
$hvp->rawgrademax = $baseanswer->max_score; |
|||
hvp_grade_item_update($hvp, (object) array( |
|||
'userid' => $answer->user_id |
|||
)); |
|||
|
|||
// Get the num of ungraded OEQ answers. |
|||
$numungraded = intval($DB->get_field_sql( |
|||
"SELECT COUNT(*) |
|||
FROM {hvp_xapi_results} |
|||
WHERE parent_id = ? |
|||
AND raw_score IS NULL |
|||
AND additionals = ?", array($answer->parent_id, |
|||
'{"extensions":{"https:\/\/h5p.org\/x-api\/h5p-machine-name":"H5P.FreeTextQuestion"}}') |
|||
)); |
|||
|
|||
$response = [ |
|||
'score' => $answer->raw_score, |
|||
'maxScore' => $answer->max_score, |
|||
'totalUngraded' => $numungraded, |
|||
]; |
|||
\H5PCore::ajaxSuccess($response); |
|||
} |
|||
|
|||
/** |
|||
* Fetch score/maxScore for ungraded item + number of ungraded items. |
|||
*/ |
|||
public static function return_subcontent_grade() { |
|||
global $DB; |
|||
|
|||
// Content parameters. |
|||
$subcontentid = required_param('subcontent_id', PARAM_INT); |
|||
$answer = $DB->get_record('hvp_xapi_results', array('id' => $subcontentid)); |
|||
|
|||
// Get the num of ungraded OEQ answers. |
|||
$numungraded = intval($DB->get_field_sql( |
|||
"SELECT COUNT(*) |
|||
FROM {hvp_xapi_results} |
|||
WHERE parent_id = ? |
|||
AND raw_score IS NULL |
|||
AND additionals = ?", array($answer->parent_id, |
|||
'{"extensions":{"https:\/\/h5p.org\/x-api\/h5p-machine-name":"H5P.FreeTextQuestion"}}') |
|||
)); |
|||
|
|||
$response = [ |
|||
'score' => $answer->raw_score, |
|||
'maxScore' => $answer->max_score, |
|||
'totalUngraded' => $numungraded, |
|||
]; |
|||
\H5PCore::ajaxSuccess($response); |
|||
} |
|||
} |
|||
@ -0,0 +1,363 @@ |
|||
<?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 mod_hvp view assets convenience class for viewing and embedding H5Ps |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2017 Joubel |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
use moodle_url; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Handles finding and attaching assets for view |
|||
* @package mod_hvp |
|||
*/ |
|||
class view_assets { |
|||
|
|||
private $cm; |
|||
private $course; |
|||
private $core; |
|||
private $content; |
|||
private $jsrequires; |
|||
private $cssrequires; |
|||
|
|||
protected $settings; |
|||
protected $embedtype; |
|||
protected $files; |
|||
|
|||
public function __construct($cm, $course, $options = []) { |
|||
$this->cm = $cm; |
|||
$this->course = $course; |
|||
$this->core = framework::instance(); |
|||
$this->content = $this->core->loadContent($cm->instance); |
|||
$this->settings = hvp_get_core_assets(\context_module::instance($cm->id)); |
|||
$this->jsrequires = []; |
|||
$this->cssrequires = []; |
|||
|
|||
$context = \context_module::instance($this->cm->id); |
|||
$displayoptions = $this->core->getDisplayOptionsForView($this->content['disable'], $context->instanceid); |
|||
if (isset($options['disabledownload']) && $options['disabledownload']) { |
|||
$displayoptions[\H5PCore::DISPLAY_OPTION_DOWNLOAD] = false; |
|||
} |
|||
if (isset($options['disablefullscreen']) && $options['disablefullscreen']) { |
|||
$this->settings['fullscreenDisabled'] = true; |
|||
} |
|||
|
|||
// Add JavaScript settings for this content. |
|||
$cid = 'cid-' . $this->content['id']; |
|||
$root = self::getsiteroot(); |
|||
$this->settings['contents'][ $cid ] = array( |
|||
'library' => \H5PCore::libraryToString($this->content['library']), |
|||
'jsonContent' => $this->getfilteredparameters(), |
|||
'fullScreen' => $this->content['library']['fullscreen'], |
|||
'exportUrl' => $this->getexportsettings($displayoptions[ \H5PCore::DISPLAY_OPTION_DOWNLOAD ]), |
|||
'embedCode' => $this->getembedcode($displayoptions[ \H5PCore::DISPLAY_OPTION_EMBED ]), |
|||
'resizeCode' => $this->getresizecode($displayoptions[ \H5PCore::DISPLAY_OPTION_EMBED ]), |
|||
'title' => $this->content['title'], |
|||
'displayOptions' => $displayoptions, |
|||
'url' => "{$root}/mod/hvp/view.php?id={$this->cm->id}", |
|||
'contentUrl' => "{$root}/pluginfile.php/{$context->id}/mod_hvp/content/{$this->content['id']}", |
|||
'metadata' => $this->content['metadata'], |
|||
'contentUserData' => array( |
|||
0 => content_user_data::load_pre_loaded_user_data($this->content['id']) |
|||
) |
|||
); |
|||
|
|||
$this->embedtype = isset($options->forceembedtype) ? $options->forceembedtype : \H5PCore::determineEmbedType( |
|||
$this->content['embedType'], $this->content['library']['embedTypes'] |
|||
); |
|||
|
|||
$this->files = $this->getdependencyfiles(); |
|||
$this->generateassets(); |
|||
} |
|||
|
|||
/** |
|||
* Filtered and potentially altered parameters |
|||
* |
|||
* @return Object|string |
|||
*/ |
|||
private function getfilteredparameters() { |
|||
global $PAGE; |
|||
|
|||
$safeparameters = $this->core->filterParameters($this->content); |
|||
$decodedparams = json_decode($safeparameters); |
|||
$hvpoutput = $PAGE->get_renderer('mod_hvp'); |
|||
$hvpoutput->hvp_alter_filtered_parameters( |
|||
$decodedparams, |
|||
$this->content['library']['name'], |
|||
$this->content['library']['majorVersion'], |
|||
$this->content['library']['minorVersion'] |
|||
); |
|||
$safeparameters = json_encode($decodedparams); |
|||
|
|||
return $safeparameters; |
|||
} |
|||
|
|||
/** |
|||
* Export path for settings |
|||
* |
|||
* @param $downloadenabled |
|||
* |
|||
* @return string |
|||
*/ |
|||
private function getexportsettings($downloadenabled) { |
|||
global $CFG; |
|||
|
|||
if ( ! $downloadenabled || (isset($CFG->mod_hvp_export) && $CFG->mod_hvp_export === false)) { |
|||
return ''; |
|||
} |
|||
|
|||
$modulecontext = \context_module::instance($this->cm->id); |
|||
$slug = $this->content['slug'] ? $this->content['slug'] . '-' : ''; |
|||
$url = \moodle_url::make_pluginfile_url($modulecontext->id, |
|||
'mod_hvp', |
|||
'exports', |
|||
'', |
|||
'', |
|||
"{$slug}{$this->content['id']}.h5p" |
|||
); |
|||
|
|||
return $url->out(); |
|||
} |
|||
|
|||
/** |
|||
* Embed code for settings |
|||
* |
|||
* @param $embedenabled |
|||
* |
|||
* @return string |
|||
*/ |
|||
private function getembedcode($embedenabled) { |
|||
if ( ! $embedenabled) { |
|||
return ''; |
|||
} |
|||
|
|||
$root = self::getsiteroot(); |
|||
$embedurl = new \moodle_url("{$root}/mod/hvp/embed.php?id={$this->cm->id}"); |
|||
$title = isset($this->content['metadata']['a11yTitle']) |
|||
? $this->content['metadata']['a11yTitle'] |
|||
: (isset($this->content['metadata']['title']) |
|||
? $this->content['metadata']['title'] |
|||
: '' |
|||
); |
|||
|
|||
return "<iframe src=\"{$embedurl->out()}\" width=\":w\" height=\":h\" frameborder=\"0\" " . |
|||
"allowfullscreen=\"allowfullscreen\" title=\"{$title}\"></iframe>"; |
|||
} |
|||
|
|||
/** |
|||
* Resizing script for settings |
|||
* |
|||
* @param $embedenabled |
|||
* |
|||
* @return string |
|||
*/ |
|||
private function getresizecode($embedenabled) { |
|||
if ( ! $embedenabled) { |
|||
return ''; |
|||
} |
|||
|
|||
$resizeurl = new \moodle_url(self::getsiteroot() . '/mod/hvp/library/js/h5p-resizer.js'); |
|||
|
|||
return "<script src=\"{$resizeurl->out()}\" charset=\"UTF-8\"></script>"; |
|||
} |
|||
|
|||
/** |
|||
* Finds library dependencies of view |
|||
* |
|||
* @return array Files that the view has dependencies to |
|||
*/ |
|||
private function getdependencyfiles() { |
|||
global $PAGE; |
|||
|
|||
$preloadeddeps = $this->core->loadContentDependencies($this->content['id'], 'preloaded'); |
|||
$files = $this->core->getDependenciesFiles($preloadeddeps); |
|||
|
|||
// Add additional asset files if required. |
|||
$hvpoutput = $PAGE->get_renderer('mod_hvp'); |
|||
$hvpoutput->hvp_alter_scripts($files['scripts'], $preloadeddeps, $this->embedtype); |
|||
$hvpoutput->hvp_alter_styles($files['styles'], $preloadeddeps, $this->embedtype); |
|||
|
|||
return $files; |
|||
} |
|||
|
|||
/** |
|||
* Generates assets depending on embed type |
|||
*/ |
|||
private function generateassets() { |
|||
if ($this->embedtype === 'div') { |
|||
$context = \context_system::instance(); |
|||
$hvppath = "/pluginfile.php/{$context->id}/mod_hvp"; |
|||
|
|||
// Schedule JavaScripts for loading through Moodle. |
|||
foreach ($this->files['scripts'] as $script) { |
|||
$url = $script->path . $script->version; |
|||
|
|||
// Add URL prefix if not external. |
|||
$isexternal = strpos($script->path, '://'); |
|||
if ($isexternal === false) { |
|||
$url = $hvppath . $url; |
|||
} |
|||
$this->settings['loadedJs'][] = $url; |
|||
$this->jsrequires[] = new \moodle_url($isexternal ? $url : self::getsiteroot() . $url); |
|||
} |
|||
|
|||
// Schedule stylesheets for loading through Moodle. |
|||
foreach ($this->files['styles'] as $style) { |
|||
$url = $style->path . $style->version; |
|||
|
|||
// Add URL prefix if not external. |
|||
$isexternal = strpos($style->path, '://'); |
|||
if ($isexternal === false) { |
|||
$url = $hvppath . $url; |
|||
} |
|||
$this->settings['loadedCss'][] = $url; |
|||
$this->cssrequires[] = new \moodle_url($isexternal ? $url : self::getsiteroot() . $url); |
|||
} |
|||
} else { |
|||
// JavaScripts and stylesheets will be loaded through h5p.js. |
|||
$cid = 'cid-' . $this->content['id']; |
|||
$this->settings['contents'][ $cid ]['scripts'] = $this->core->getAssetsUrls($this->files['scripts']); |
|||
$this->settings['contents'][ $cid ]['styles'] = $this->core->getAssetsUrls($this->files['styles']); |
|||
} |
|||
} |
|||
|
|||
public function getcontent() { |
|||
return $this->content; |
|||
} |
|||
|
|||
/** |
|||
* Logs viewed to all handlers |
|||
*/ |
|||
public function logviewed() { |
|||
$this->logh5pviewedevent(); |
|||
$this->logcompletioncriteriaviewed(); |
|||
$this->triggermoduleviewedevent(); |
|||
} |
|||
|
|||
/** |
|||
* Logs content viewed to H5P core |
|||
*/ |
|||
public function logh5pviewedevent() { |
|||
new event( |
|||
'content', null, |
|||
$this->content['id'], $this->content['title'], |
|||
$this->content['library']['name'], |
|||
$this->content['library']['majorVersion'] . '.' . $this->content['library']['minorVersion'] |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Logs activity viewed to completion criterias |
|||
*/ |
|||
public function logcompletioncriteriaviewed() { |
|||
$completion = new \completion_info($this->course); |
|||
$completion->set_module_viewed($this->cm); |
|||
} |
|||
|
|||
/** |
|||
* Allows observers to act on viewed event |
|||
*/ |
|||
public function triggermoduleviewedevent() { |
|||
$event = event\course_module_viewed::create(array( |
|||
'objectid' => $this->cm->instance, |
|||
'context' => \context_module::instance($this->cm->id) |
|||
)); |
|||
$event->add_record_snapshot('course_modules', $this->cm); |
|||
$event->trigger(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Adds js assets to current page |
|||
*/ |
|||
public function addassetstopage() { |
|||
global $PAGE; |
|||
|
|||
foreach ($this->jsrequires as $script) { |
|||
$PAGE->requires->js($script, true); |
|||
} |
|||
|
|||
foreach ($this->cssrequires as $css) { |
|||
$PAGE->requires->css($css); |
|||
} |
|||
|
|||
// Print JavaScript settings to page. |
|||
$PAGE->requires->data_for_js('H5PIntegration', $this->settings, true); |
|||
|
|||
// Add xAPI collector script. |
|||
$PAGE->requires->js(new \moodle_url(self::getsiteroot() . '/mod/hvp/xapi-collector.js'), true); |
|||
} |
|||
|
|||
/** |
|||
* Outputs h5p view |
|||
*/ |
|||
public function outputview() { |
|||
if ($this->embedtype === 'div') { |
|||
echo "<div class=\"h5p-content\" data-content-id=\"{$this->content['id']}\"></div>"; |
|||
} else { |
|||
$title = isset($this->content['metadata']['a11yTitle']) |
|||
? $this->content['metadata']['a11yTitle'] |
|||
: (isset($this->content['metadata']['title']) |
|||
? $this->content['metadata']['title'] |
|||
: '' |
|||
); |
|||
|
|||
echo "<div class=\"h5p-iframe-wrapper\">" . |
|||
"<iframe id=\"h5p-iframe-{$this->content['id']}\"" . |
|||
" class=\"h5p-iframe\"" . |
|||
" data-content-id=\"{$this->content['id']}\"" . |
|||
" style=\"height:1px\"" . |
|||
" src=\"about:blank\"" . |
|||
" frameBorder=\"0\"" . |
|||
" scrolling=\"no\"" . |
|||
" title=\"{$title}\">" . |
|||
"</iframe>" . |
|||
"</div>"; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Checks if content is valid, prints an error if not |
|||
*/ |
|||
public function validatecontent() { |
|||
if ($this->content === null) { |
|||
print_error('invalidhvp', 'mod_hvp'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Gets the site root absolute address |
|||
* |
|||
* @return string Root address for the site |
|||
*/ |
|||
public static function getsiteroot() { |
|||
global $CFG; |
|||
// In Moodle 3.4 version wwwroot is always the same as httpswwwroot. |
|||
if ($CFG->version < 2017111300) { |
|||
return $CFG->httpswwwroot; |
|||
} |
|||
|
|||
return $CFG->wwwroot; |
|||
} |
|||
} |
|||
@ -0,0 +1,154 @@ |
|||
<?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 mod_hvp content user data. |
|||
* |
|||
* @package mod_hvp |
|||
* @since Moodle 2.7 |
|||
* @copyright 2017 Joubel AS |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
namespace mod_hvp; |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Class xapi_result handles xapi results and corresponding db operations. |
|||
* |
|||
* @package mod_hvp |
|||
*/ |
|||
class xapi_result { |
|||
|
|||
/** |
|||
* Handle xapi results endpoint |
|||
*/ |
|||
public static function handle_ajax() { |
|||
// Validate token. |
|||
if (!self::validate_token()) { |
|||
$core = framework::instance(); |
|||
\H5PCore::ajaxError($core->h5pF->t('Invalid security token.'), |
|||
'INVALID_TOKEN'); |
|||
return; |
|||
} |
|||
|
|||
$cm = get_coursemodule_from_id('hvp', required_param('contextId', PARAM_INT)); |
|||
if (!$cm) { |
|||
\H5PCore::ajaxError('No such content'); |
|||
http_response_code(404); |
|||
return; |
|||
} |
|||
|
|||
$xapiresult = required_param('xAPIResult', PARAM_RAW); |
|||
|
|||
// Validate. |
|||
$context = \context_module::instance($cm->id); |
|||
if (!has_capability('mod/hvp:saveresults', $context)) { |
|||
\H5PCore::ajaxError(get_string('nopermissiontosaveresult', 'hvp')); |
|||
return; |
|||
} |
|||
|
|||
$xapijson = json_decode($xapiresult); |
|||
if (!$xapijson) { |
|||
\H5PCore::ajaxError('Invalid json in xAPI data.'); |
|||
return; |
|||
} |
|||
|
|||
if (!self::validate_xapi_data($xapijson)) { |
|||
\H5PCore::ajaxError('Invalid xAPI data.'); |
|||
return; |
|||
} |
|||
|
|||
// Delete any old results. |
|||
self::remove_xapi_data($cm->instance); |
|||
|
|||
// Store results. |
|||
self::store_xapi_data($cm->instance, $xapijson); |
|||
|
|||
// Successfully inserted xAPI result. |
|||
\H5PCore::ajaxSuccess(); |
|||
} |
|||
|
|||
/** |
|||
* Validate xAPI results token |
|||
* |
|||
* @return bool True if token was valid |
|||
*/ |
|||
private static function validate_token() { |
|||
$token = required_param('token', PARAM_ALPHANUM); |
|||
return \H5PCore::validToken('xapiresult', $token); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* Validate xAPI data |
|||
* |
|||
* @param object $xapidata xAPI data |
|||
* |
|||
* @return bool True if valid data |
|||
*/ |
|||
private static function validate_xapi_data($xapidata) { |
|||
$xapidata = new \H5PReportXAPIData($xapidata); |
|||
return $xapidata->validateData(); |
|||
} |
|||
|
|||
/** |
|||
* Store xAPI result(s) |
|||
* |
|||
* @param int $contentid Content id |
|||
* @param object $xapidata xAPI data |
|||
* @param int $parentid Parent id |
|||
*/ |
|||
private static function store_xapi_data($contentid, $xapidata, $parentid = null) { |
|||
global $DB, $USER; |
|||
|
|||
$xapidata = new \H5PReportXAPIData($xapidata, $parentid); |
|||
$insertedid = $DB->insert_record('hvp_xapi_results', (object) array( |
|||
'content_id' => $contentid, |
|||
'user_id' => $USER->id, |
|||
'parent_id' => $xapidata->getParentID(), |
|||
'interaction_type' => $xapidata->getInteractionType(), |
|||
'description' => $xapidata->getDescription(), |
|||
'correct_responses_pattern' => $xapidata->getCorrectResponsesPattern(), |
|||
'response' => $xapidata->getResponse(), |
|||
'additionals' => $xapidata->getAdditionals(), |
|||
'raw_score' => $xapidata->getScoreRaw(), |
|||
'max_score' => $xapidata->getScoreMax(), |
|||
)); |
|||
|
|||
// Save sub content statements data. |
|||
if ($xapidata->isCompound()) { |
|||
foreach ($xapidata->getChildren($contentid) as $child) { |
|||
self::store_xapi_data($contentid, $child, $insertedid); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Remove xAPI result(s) |
|||
* |
|||
* @param int $contentid Content id |
|||
*/ |
|||
private static function remove_xapi_data($contentid) { |
|||
global $DB, $USER; |
|||
|
|||
$DB->delete_records('hvp_xapi_results', array( |
|||
'content_id' => $contentid, |
|||
'user_id' => $USER->id |
|||
)); |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?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/>. |
|||
/** |
|||
* Responsible for displaying the content upgrade page |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2020 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
use mod_hvp\content_hub_service; |
|||
|
|||
require_once("../../config.php"); |
|||
require_once($CFG->libdir.'/adminlib.php'); |
|||
require_once("locallib.php"); |
|||
|
|||
global $PAGE, $SITE, $OUTPUT, $CFG; |
|||
|
|||
// No guest autologin. |
|||
require_login(0, false); |
|||
|
|||
$context = \context_system::instance(); |
|||
require_capability('mod/hvp:contenthubregistration', $context); |
|||
|
|||
$pageurl = new moodle_url('/mod/hvp/content_hub_registration.php'); |
|||
$PAGE->set_context(context_system::instance()); |
|||
$PAGE->set_url($pageurl); |
|||
$PAGE->set_title("{$SITE->shortname}: " . get_string('upgrade', 'hvp')); |
|||
$PAGE->set_heading(get_string('contenthub:settings:heading', 'mod_hvp')); |
|||
|
|||
$settings = content_hub_service::get_registration_ui_settings(); |
|||
$PAGE->requires->data_for_js('H5PSettings', $settings, true); |
|||
$PAGE->requires->js(new moodle_url('library/js/h5p-hub-registration.js'), true); |
|||
$PAGE->requires->css(new moodle_url('library/styles/h5p.css')); |
|||
$PAGE->requires->css(new moodle_url('library/styles/h5p-hub-registration.css')); |
|||
|
|||
echo $OUTPUT->header(); |
|||
|
|||
echo $OUTPUT->render_from_template('mod_hvp/content_hub_registration', []); |
|||
$PAGE->requires->js_call_amd('mod_hvp/contenthubregistration', 'init'); |
|||
|
|||
echo $OUTPUT->footer(); |
|||
@ -0,0 +1,43 @@ |
|||
/* global H5PDataView */ |
|||
(function($) { |
|||
|
|||
/** |
|||
* Creates a new dataview. |
|||
* |
|||
* @private |
|||
* @param {object} dataView Structure |
|||
* @param {string} dataView.source AJAX URL for data view |
|||
* @param {object[]} dataView.headers Header text and props |
|||
* @param {boolean[]} dataView.filters Which fields to allow filtering for |
|||
* @param {object} dataView.order Default order by and direction |
|||
* @param {object} dataView.l10n Translations |
|||
* @param {Element} wrapper Where in the DOM should the dataview be appended |
|||
* @param {function} loaded Callback for when the dataview is ready |
|||
*/ |
|||
var createDataView = function(dataView, wrapper, loaded) { |
|||
new H5PDataView( |
|||
wrapper, |
|||
dataView.source, |
|||
dataView.headers, |
|||
dataView.l10n, |
|||
undefined, |
|||
dataView.filters, |
|||
loaded, |
|||
dataView.order |
|||
); |
|||
}; |
|||
|
|||
// Create data views when page is done loading.
|
|||
$(document).ready(function() { |
|||
for (var id in H5PIntegration.dataViews) { |
|||
if (!H5PIntegration.dataViews.hasOwnProperty(id)) { |
|||
continue; |
|||
} |
|||
|
|||
var wrapper = $('#' + id).get(0); |
|||
if (wrapper !== undefined) { |
|||
createDataView(H5PIntegration.dataViews[id], wrapper); |
|||
} |
|||
} |
|||
}); |
|||
})(H5P.jQuery); |
|||
@ -0,0 +1,207 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Capability definitions for the hvp module. |
|||
* |
|||
* Available archetypes: |
|||
* manager |
|||
* coursecreator |
|||
* editingteacher |
|||
* teacher |
|||
* student |
|||
* guest |
|||
* user |
|||
* frontpage |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$capabilities = array( |
|||
|
|||
'mod/hvp:view' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW, |
|||
'student' => CAP_ALLOW, |
|||
'guest' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:addinstance' => array( |
|||
'riskbitmask' => RISK_SPAM | RISK_XSS, |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW |
|||
), |
|||
'clonepermissionsfrom' => 'moodle/course:manageactivities' |
|||
), |
|||
|
|||
'mod/hvp:manage' => array( |
|||
'riskbitmask' => RISK_SPAM | RISK_XSS, |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW |
|||
), |
|||
'clonepermissionsfrom' => 'mod/hvp:addinstance' |
|||
), |
|||
|
|||
'mod/hvp:share' => array( |
|||
'riskbitmask' => RISK_SPAM, |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'editingteacher' => CAP_ALLOW, |
|||
'manager' => CAP_ALLOW |
|||
), |
|||
'clonepermissionsfrom' => 'mod/hvp:addinstance' |
|||
), |
|||
|
|||
'mod/hvp:getexport' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:getembedcode' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:saveresults' => array( |
|||
'riskbitmask' => RISK_SPAM, |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'student' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:savecontentuserdata' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW, |
|||
'student' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:viewresults' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'student' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:viewallresults' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:restrictlibraries' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_SYSTEM, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:userestrictedlibraries' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:updatelibraries' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_SYSTEM, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:getcachedassets' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_SYSTEM, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW, |
|||
'editingteacher' => CAP_ALLOW, |
|||
'teacher' => CAP_ALLOW, |
|||
'student' => CAP_ALLOW, |
|||
'user' => CAP_ALLOW, |
|||
'guest' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
'mod/hvp:installrecommendedh5plibraries' => array( |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_COURSE, |
|||
'archetypes' => array( |
|||
'manager' => CAP_ALLOW |
|||
) |
|||
), |
|||
|
|||
// Receive a confirmation message of own h5p submission. |
|||
'mod/hvp:emailconfirmsubmission' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array() |
|||
), |
|||
|
|||
// Receive a notification message of other peoples' h5p submissions. |
|||
'mod/hvp:emailnotifysubmission' => array( |
|||
'captype' => 'read', |
|||
'contextlevel' => CONTEXT_MODULE, |
|||
'archetypes' => array() |
|||
), |
|||
|
|||
'mod/hvp:contenthubregistration' => [ |
|||
'captype' => 'write', |
|||
'contextlevel' => CONTEXT_SYSTEM, |
|||
'archetypes' => [], // Only admins by default. |
|||
], |
|||
|
|||
); |
|||
@ -0,0 +1,38 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Add event handlers for H5P |
|||
* |
|||
* @package mod_hvp |
|||
* @category event |
|||
* @copyright 2020 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$observers = array( |
|||
|
|||
// Handle attempt submitted event, as a way to send confirmation messages asynchronously. |
|||
array( |
|||
'eventname' => '\mod_hvp\event\attempt_submitted', |
|||
'includefile' => '/mod/hvp/locallib.php', |
|||
'callback' => 'hvp_attempt_submitted_handler', |
|||
'internal' => false |
|||
), |
|||
); |
|||
@ -0,0 +1,54 @@ |
|||
<?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/>. |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
function xmldb_hvp_install() { |
|||
|
|||
// Try to install all the default content types. |
|||
require_once(__DIR__ . '/../autoloader.php'); |
|||
|
|||
// Fetch info about library updates. |
|||
$core = \mod_hvp\framework::instance('core'); |
|||
$core->fetchLibrariesMetadata(); |
|||
|
|||
// Check that plugin is set up correctly. |
|||
$core->checkSetupForRequirements(); |
|||
|
|||
// Print any messages. |
|||
echo '<h3>' . get_string('welcomeheader', 'hvp') . '</h3>' . |
|||
'<p>' . |
|||
get_string('welcomegettingstarted', 'hvp', array( |
|||
'moodle_tutorial' => 'href="https://h5p.org/moodle" target="_blank"', |
|||
'example_content' => 'href="https://h5p.org/content-types-and-applications" target="_blank"' |
|||
)) . |
|||
'</p>' . |
|||
'<p>' . |
|||
get_string('welcomecommunity', 'hvp', array( |
|||
'forums' => 'href="https://h5p.org/forum" target="_blank"' |
|||
)) . |
|||
'</p>' . |
|||
'<p>' . get_string('welcomecontactus', 'hvp', |
|||
'href="https://h5p.org/contact" target="_blank"') . |
|||
'</p>'; |
|||
|
|||
// Notify of communication with H5P Hub. |
|||
// @codingStandardsIgnoreLine |
|||
echo "<p>H5P fetches content types directly from the H5P Hub. In order to do this the H5P plugin will communicate with the Hub once a day to fetch information about new and updated content types. It will send in anonymous data to the Hub about H5P usage. Read more at <a href=\"https://h5p.org/tracking-the-usage-of-h5p\">the plugin communication page at H5P.org</a>.</p>"; |
|||
|
|||
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info')); |
|||
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error')); |
|||
} |
|||
@ -0,0 +1,255 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<XMLDB PATH="mod/hvp/db" VERSION="20190731" COMMENT="XMLDB file for Moodle mod/hvp" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" |
|||
> |
|||
<TABLES> |
|||
<TABLE NAME="hvp" COMMENT="Activity data"> |
|||
<FIELDS> |
|||
<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="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="json_content" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The content in json format"/> |
|||
<FIELD NAME="embed_type" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="disable" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="main_library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The library we first instanciate for this node"/> |
|||
<FIELD NAME="content_type" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="Content type as defined in h5p.json"/> |
|||
<FIELD NAME="authors" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of authors in json format"/> |
|||
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Link to the source, could also be citation"/> |
|||
<FIELD NAME="year_from" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="Start year for copyright"/> |
|||
<FIELD NAME="year_to" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="End year for copyright"/> |
|||
<FIELD NAME="license" TYPE="char" LENGTH="63" NOTNULL="false" SEQUENCE="false" COMMENT="License name of the content"/> |
|||
<FIELD NAME="license_version" TYPE="char" LENGTH="15" NOTNULL="false" SEQUENCE="false" COMMENT="Version of the license used for the content"/> |
|||
<FIELD NAME="changes" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of changes in json format"/> |
|||
<FIELD NAME="license_extras" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Extra licensing terms"/> |
|||
<FIELD NAME="author_comments" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Comments for the editor"/> |
|||
<FIELD NAME="default_language" TYPE="char" LENGTH="32" NOTNULL="false" SEQUENCE="false" COMMENT="Default language for common fields"/> |
|||
<FIELD NAME="filtered" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Filtered version of json_content"/> |
|||
<FIELD NAME="slug" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Human readable content identifier that is unique"/> |
|||
<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="completionpass" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="shared" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> |
|||
<FIELD NAME="synced" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="hub_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="a11y_title" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_xapi_results" COMMENT="Stored xAPI events"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="content_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="parent_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="interaction_type" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="correct_responses_pattern" TYPE="text" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="response" TYPE="text" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="additionals" TYPE="text" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="raw_score" TYPE="int" LENGTH="6" NOTNULL="false" SEQUENCE="false"/> |
|||
<FIELD NAME="max_score" TYPE="int" LENGTH="6" NOTNULL="false" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="results" UNIQUE="false" FIELDS="content_id, user_id"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_content_user_data" COMMENT="Stores user data about the content"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Id for the user answering this H5P"/> |
|||
<FIELD NAME="hvp_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Id of hvp content in the 'hvp' table"/> |
|||
<FIELD NAME="sub_content_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Subcontent id of hvp content, 0 if this is not subcontent"/> |
|||
<FIELD NAME="data_id" TYPE="char" LENGTH="127" NOTNULL="false" SEQUENCE="false" COMMENT="The data type identifier"/> |
|||
<FIELD NAME="data" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The actual user data that was stored."/> |
|||
<FIELD NAME="preloaded" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="delete_on_content_change" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_libraries" COMMENT="Stores information about libraries."> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key: The id of the library"/> |
|||
<FIELD NAME="machine_name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The library machine name"/> |
|||
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The human readable name of this library"/> |
|||
<FIELD NAME="major_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="minor_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="patch_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="runnable" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Can this library be started by the module? i.e. not a dependency."/> |
|||
<FIELD NAME="fullscreen" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display fullscreen button"/> |
|||
<FIELD NAME="embed_types" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="preloaded_js" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Comma separated list of scripts to load."/> |
|||
<FIELD NAME="preloaded_css" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Comma separated list of stylesheets to load."/> |
|||
<FIELD NAME="drop_library_css" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of libraries that should not have CSS included if this library is used. Comma separated list."/> |
|||
<FIELD NAME="semantics" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The semantics definition in json format"/> |
|||
<FIELD NAME="restricted" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Restricts the ability to create new content using this library"/> |
|||
<FIELD NAME="tutorial_url" TYPE="char" LENGTH="1000" NOTNULL="false" SEQUENCE="false" COMMENT="URL to a tutorial for this library"/> |
|||
<FIELD NAME="has_icon" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether or not this library contains an icon.svg"/> |
|||
<FIELD NAME="add_to" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Plugin configuration data"/> |
|||
<FIELD NAME="metadata_settings" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Metadata settings"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="meta" UNIQUE="false" FIELDS="machine_name, major_version, minor_version, patch_version, runnable"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_libraries_hub_cache" COMMENT="Caches content types from the H5P hub."> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key: The id of the library"/> |
|||
<FIELD NAME="machine_name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The library machine name"/> |
|||
<FIELD NAME="major_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="minor_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="patch_version" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="h5p_major_version" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="The major version required of H5P core"/> |
|||
<FIELD NAME="h5p_minor_version" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="The minor version required of H5P core"/> |
|||
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The human readable name of this library"/> |
|||
<FIELD NAME="summary" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Short description of library"/> |
|||
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Long description of library"/> |
|||
<FIELD NAME="icon" TYPE="char" LENGTH="511" NOTNULL="true" SEQUENCE="false" COMMENT="URL to icon"/> |
|||
<FIELD NAME="created_at" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="Time that the library was uploaded"/> |
|||
<FIELD NAME="updated_at" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="Time that the library has its latest update"/> |
|||
<FIELD NAME="is_recommended" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Whether the library is recommended by the HUB moderators"/> |
|||
<FIELD NAME="popularity" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="How many times the library has been downloaded"/> |
|||
<FIELD NAME="screenshots" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Screenshot URLs json encoded"/> |
|||
<FIELD NAME="license" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Library license(s) json encoded"/> |
|||
<FIELD NAME="example" TYPE="char" LENGTH="511" NOTNULL="true" SEQUENCE="false" COMMENT="URL to example content for this library"/> |
|||
<FIELD NAME="tutorial" TYPE="char" LENGTH="511" NOTNULL="false" SEQUENCE="false" COMMENT="Tutorial URL"/> |
|||
<FIELD NAME="keywords" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Keywords for library json encoded"/> |
|||
<FIELD NAME="categories" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Categories for library json encoded"/> |
|||
<FIELD NAME="owner" TYPE="char" LENGTH="511" NOTNULL="false" SEQUENCE="false" COMMENT="Owner of the library"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_content_hub_cache" COMMENT="Caches content metadata options from the H5P OER Hub."> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="language" TYPE="char" LENGTH="31" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="json" TYPE="text" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="last_checked" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="language" UNIQUE="true" FIELDS="language"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_libraries_libraries" COMMENT="Library dependencies"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Primary Key: The id of a H5P library."/> |
|||
<FIELD NAME="required_library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The dependency to load"/> |
|||
<FIELD NAME="dependency_type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="'preloaded, dynamic, or editor'"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_libraries_languages" COMMENT="Translations for libraries"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="language_code" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="language_json" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The translations defined in json format"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_libraries_cachedassets" COMMENT="Use to know which caches to clear when a library is updated"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="hash" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="relation" UNIQUE="true" FIELDS="library_id, hash"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_contents_libraries" COMMENT="Store which library is used in which content."> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="hvp_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Identifier for a content found from the 'hvp' table"/> |
|||
<FIELD NAME="library_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The identifier of a H5P library this content uses"/> |
|||
<FIELD NAME="dependency_type" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="dynamic, preloaded or editor"/> |
|||
<FIELD NAME="drop_css" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="1 if the preloaded css from the dependency is to be excluded"/> |
|||
<FIELD NAME="weight" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Determines the order in which the preloaded libraries will be loaded"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="meta" UNIQUE="false" FIELDS="drop_css"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_events" COMMENT="Keep track of logged H5P events"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="created_at" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="type" TYPE="char" LENGTH="63" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="sub_type" TYPE="char" LENGTH="63" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="content_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="content_title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="library_name" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="library_version" TYPE="char" LENGTH="31" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_tmpfiles" COMMENT="Keep track of files uploaded before content is saved"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_counters" COMMENT="A set of global counters to keep track of H5P usage"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="type" TYPE="char" LENGTH="63" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="library_name" TYPE="char" LENGTH="127" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="library_version" TYPE="char" LENGTH="31" NOTNULL="true" SEQUENCE="false"/> |
|||
<FIELD NAME="num" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="realkey" UNIQUE="false" FIELDS="type, library_name, library_version"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
<TABLE NAME="hvp_auth" COMMENT="Stores tokens for authenticating users for different actions"> |
|||
<FIELDS> |
|||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> |
|||
<FIELD NAME="user_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Id of the user that created the token"/> |
|||
<FIELD NAME="created_at" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="Timestamp for when token was created"/> |
|||
<FIELD NAME="secret" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="Secret used to generate the authentication token"/> |
|||
</FIELDS> |
|||
<KEYS> |
|||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> |
|||
</KEYS> |
|||
<INDEXES> |
|||
<INDEX NAME="user_id" UNIQUE="true" FIELDS="user_id"/> |
|||
</INDEXES> |
|||
</TABLE> |
|||
</TABLES> |
|||
</XMLDB> |
|||
@ -0,0 +1,40 @@ |
|||
<?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 message providers (types of message sent) for the hvp module. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2020 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$messageproviders = array( |
|||
// Notify teacher that a student has submitted an attempt. |
|||
'submission' => array( |
|||
'capability' => 'mod/hvp:emailnotifysubmission' |
|||
), |
|||
|
|||
// Confirm a student's quiz attempt. |
|||
'confirmation' => array( |
|||
'capability' => 'mod/hvp:emailconfirmsubmission', |
|||
'defaults' => array( |
|||
'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF, |
|||
), |
|||
), |
|||
); |
|||
@ -0,0 +1,32 @@ |
|||
<?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/>. |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$addons = array( |
|||
"mod_hvp" => array( // Plugin identifier. |
|||
'handlers' => array( // Different places where the plugin will display content. |
|||
'coursehvp' => array( // Handler unique name (alphanumeric). |
|||
'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin). |
|||
'method' => 'mobile_course_view', // Main function in \mod_certificate\output\mobile. |
|||
'displaydata' => array( |
|||
'icon' => $CFG->wwwroot . '/mod/hvp/pix/icon.svg', |
|||
'class' => '', |
|||
), |
|||
) |
|||
) |
|||
) |
|||
); |
|||
@ -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/>. |
|||
/** |
|||
* Defines the task which looks for H5P updates. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
$tasks = array( |
|||
array( |
|||
'classname' => 'mod_hvp\task\look_for_updates', |
|||
'blocking' => 0, |
|||
'minute' => 'R', |
|||
'hour' => 'R', |
|||
'day' => '*', |
|||
'dayofweek' => '*', |
|||
'month' => '*' |
|||
), |
|||
array( |
|||
'classname' => 'mod_hvp\task\remove_tmpfiles', |
|||
'blocking' => 0, |
|||
'minute' => 'R', |
|||
'hour' => 'R', |
|||
'day' => '*', |
|||
'dayofweek' => '*', |
|||
'month' => '*' |
|||
), |
|||
array( |
|||
'classname' => 'mod_hvp\task\remove_old_log_entries', |
|||
'blocking' => 0, |
|||
'minute' => 'R', |
|||
'hour' => 'R', |
|||
'day' => '*', |
|||
'dayofweek' => '*', |
|||
'month' => '*' |
|||
), |
|||
array( |
|||
'classname' => 'mod_hvp\task\remove_old_auth_tokens', |
|||
'blocking' => 0, |
|||
'minute' => 'R', |
|||
'hour' => '*', |
|||
'day' => '*', |
|||
'dayofweek' => '*', |
|||
'month' => '*' |
|||
) |
|||
); |
|||
@ -0,0 +1,606 @@ |
|||
<?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/>. |
|||
|
|||
/** |
|||
* Upgrade definitions for the hvp module. |
|||
* |
|||
* @package mod_hvp |
|||
* @copyright 2016 Joubel AS <contact@joubel.com> |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
/** |
|||
* Adds data for tracking when content was created and last modified. |
|||
*/ |
|||
function hvp_upgrade_2016011300() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
$table = new xmldb_table('hvp'); |
|||
|
|||
// Define field timecreated to be added to hvp. |
|||
$timecreated = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'slug'); |
|||
|
|||
// Conditionally launch add field timecreated. |
|||
if (!$dbman->field_exists($table, $timecreated)) { |
|||
$dbman->add_field($table, $timecreated); |
|||
} |
|||
|
|||
// Define field timemodified to be added to hvp. |
|||
$timemodified = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timecreated'); |
|||
|
|||
// Conditionally launch add field timemodified. |
|||
if (!$dbman->field_exists($table, $timemodified)) { |
|||
$dbman->add_field($table, $timemodified); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Adds table for keeping track of, and cleaning up temporary files |
|||
*/ |
|||
function hvp_upgrade_2016042500() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Define table hvp_tmpfiles to be created. |
|||
$table = new xmldb_table('hvp_tmpfiles'); |
|||
|
|||
// Adding fields to table hvp_tmpfiles. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
|
|||
// Adding keys to table hvp_tmpfiles. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
|
|||
// Conditionally launch create table for hvp_tmpfiles. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Adds events table |
|||
*/ |
|||
function hvp_upgrade_2016050600() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Define table hvp_events to be created. |
|||
$table = new xmldb_table('hvp_events'); |
|||
|
|||
// Adding fields to table hvp_events. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('user_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('created_at', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('type', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('sub_type', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('content_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('content_title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('library_name', XMLDB_TYPE_CHAR, '127', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('library_version', XMLDB_TYPE_CHAR, '31', null, XMLDB_NOTNULL, null, null); |
|||
|
|||
// Adding keys to table hvp_events. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
|
|||
// Conditionally launch create table for hvp_events. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
|
|||
// Define table hvp_counters to be created. |
|||
$table = new xmldb_table('hvp_counters'); |
|||
|
|||
// Adding fields to table hvp_counters. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('type', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('library_name', XMLDB_TYPE_CHAR, '127', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('library_version', XMLDB_TYPE_CHAR, '31', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('num', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
|
|||
// Adding keys to table hvp_counters. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
|
|||
// Adding indexes to table hvp_counters. |
|||
$table->add_index('realkey', XMLDB_INDEX_NOTUNIQUE, [ |
|||
'type', |
|||
'library_name', |
|||
'library_version', |
|||
]); |
|||
|
|||
// Conditionally launch create table for hvp_counters. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Adds intro and introformat to hvp table |
|||
*/ |
|||
function hvp_upgrade_2016051000() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
$table = new xmldb_table('hvp'); |
|||
|
|||
// Define field intro to be added to hvp. |
|||
$intro = new xmldb_field('intro', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); |
|||
|
|||
// Add field intro if not defined already. |
|||
if (!$dbman->field_exists($table, $intro)) { |
|||
$dbman->add_field($table, $intro); |
|||
} |
|||
|
|||
// Define field introformat to be added to hvp. |
|||
$introformat = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro'); |
|||
|
|||
// Add field introformat if not defined already. |
|||
if (!$dbman->field_exists($table, $introformat)) { |
|||
$dbman->add_field($table, $introformat); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Changes context of activity files to enable backup an restore. |
|||
*/ |
|||
function hvp_upgrade_2016110100() { |
|||
global $DB; |
|||
|
|||
// Change context of activity files from COURSE to MODULE. |
|||
$filearea = 'content'; |
|||
$component = 'mod_hvp'; |
|||
|
|||
// Find activity ID and correct context ID. |
|||
$hvpsresult = $DB->get_records_sql( |
|||
"SELECT f.id AS fileid, f.itemid, c.id, f.filepath, f.filename, f.pathnamehash |
|||
FROM {files} f |
|||
JOIN {course_modules} cm ON f.itemid = cm.instance |
|||
JOIN {modules} md ON md.id = cm.module |
|||
JOIN {context} c ON c.instanceid = cm.id |
|||
WHERE md.name = 'hvp' |
|||
AND f.filearea = 'content' |
|||
AND c.contextlevel = " . CONTEXT_MODULE |
|||
); |
|||
|
|||
foreach ($hvpsresult as $hvp) { |
|||
// Need to re-hash pathname after changing context. |
|||
$pathnamehash = file_storage::get_pathname_hash($hvp->id, |
|||
$component, |
|||
$filearea, |
|||
$hvp->itemid, |
|||
$hvp->filepath, |
|||
$hvp->filename |
|||
); |
|||
|
|||
// Double check that hash doesn't exist (avoid duplicate entries). |
|||
if (!$DB->get_field_sql("SELECT contextid FROM {files} WHERE pathnamehash = '{$pathnamehash}'")) { |
|||
// Update context ID and pathname hash for files. |
|||
$DB->execute(" |
|||
UPDATE {files} |
|||
SET contextid = {$hvp->id}, |
|||
pathnamehash = '{$pathnamehash}' |
|||
WHERE pathnamehash = '{$hvp->pathnamehash}'" |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Notifies about breaking changes to H5P content type styling |
|||
*/ |
|||
function hvp_upgrade_2016122800() { |
|||
// @codingStandardsIgnoreLine |
|||
\mod_hvp\framework::messages('info', '<span style="font-weight: bold;">Upgrade your H5P content types!</span> Old content types will still work, but the authoring tool will look and feel much better if you <a href="https://h5p.org/update-all-content-types">upgrade the content types</a>.'); |
|||
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info')); |
|||
} |
|||
|
|||
/** |
|||
* Adds content type cache to enable the content type hub |
|||
*/ |
|||
function hvp_upgrade_2017040500() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Add content type cache database. |
|||
$table = new xmldb_table('hvp_libraries_hub_cache'); |
|||
|
|||
// Adding fields to table hvp_libraries_hub_cache. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('machine_name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('major_version', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('minor_version', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('patch_version', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('h5p_major_version', XMLDB_TYPE_INTEGER, '4', null, null, null, null); |
|||
$table->add_field('h5p_minor_version', XMLDB_TYPE_INTEGER, '4', null, null, null, null); |
|||
$table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('summary', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('description', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('icon', XMLDB_TYPE_CHAR, '511', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('created_at', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('updated_at', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('is_recommended', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('popularity', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('screenshots', XMLDB_TYPE_TEXT, null, null, null, null, null); |
|||
$table->add_field('license', XMLDB_TYPE_TEXT, null, null, null, null, null); |
|||
$table->add_field('example', XMLDB_TYPE_CHAR, '511', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('tutorial', XMLDB_TYPE_CHAR, '511', null, null, null, null); |
|||
$table->add_field('keywords', XMLDB_TYPE_TEXT, null, null, null, null, null); |
|||
$table->add_field('categories', XMLDB_TYPE_TEXT, null, null, null, null, null); |
|||
$table->add_field('owner', XMLDB_TYPE_CHAR, '511', null, null, null, null); |
|||
|
|||
// Adding keys to table hvp_libraries_hub_cache. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
|
|||
// Conditionally create table for hvp_libraries_hub_cache. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
|
|||
// Update the content type cache. |
|||
$core = \mod_hvp\framework::instance(); |
|||
$core->updateContentTypeCache(); |
|||
|
|||
// Print messages. |
|||
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info')); |
|||
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error')); |
|||
|
|||
// Add has_icon to libraries folder. |
|||
$table = new xmldb_table('hvp_libraries'); |
|||
|
|||
// Define field has_icon to be added to hvp_libraries. |
|||
$hasicon = new xmldb_field('has_icon', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
|||
|
|||
// Add field has_icon if it does not exist. |
|||
if (!$dbman->field_exists($table, $hasicon)) { |
|||
$dbman->add_field($table, $hasicon); |
|||
} |
|||
|
|||
// Display hub communication info. |
|||
if (!get_config('mod_hvp', 'external_communication')) { |
|||
// @codingStandardsIgnoreLine |
|||
\mod_hvp\framework::messages('info', 'H5P now fetches content types directly from the H5P Hub. In order to do this, the H5P plugin will communicate with H5P.org once per day to fetch information about new and updated content types. It will send in anonymous data to the hub about H5P usage. You may disable the data contribution and/or the H5P Hub in the H5P settings.'); |
|||
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info')); |
|||
} |
|||
|
|||
// Enable hub and delete old communication variable. |
|||
set_config('hub_is_enabled', true, 'mod_hvp'); |
|||
unset_config('hub_is_enabled', 'mod_hvp'); |
|||
} |
|||
|
|||
/** |
|||
* Adds xAPI results table to enable reporting |
|||
*/ |
|||
function hvp_upgrade_2017050900() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Add report rendering. |
|||
$table = new xmldb_table('hvp_xapi_results'); |
|||
|
|||
// Add fields. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('content_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('user_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('parent_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null); |
|||
$table->add_field('interaction_type', XMLDB_TYPE_CHAR, '127', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('description', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('correct_responses_pattern', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('response', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('additionals', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
|
|||
// Add keys and index. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
$table->add_index('result', XMLDB_INDEX_UNIQUE, [ |
|||
'id', |
|||
'content_id', |
|||
'user_id', |
|||
]); |
|||
|
|||
// Create table if it does not exist. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Adds raw score and max score to xapi results table |
|||
*/ |
|||
function hvp_upgrade_2017060900() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Add score to report rendering. |
|||
$table = new xmldb_table('hvp_xapi_results'); |
|||
|
|||
if ($dbman->table_exists($table)) { |
|||
// Raw score field. |
|||
$scorefield = new xmldb_field('raw_score', XMLDB_TYPE_INTEGER, '6'); |
|||
if (!$dbman->field_exists($table, $scorefield)) { |
|||
$dbman->add_field($table, $scorefield); |
|||
} |
|||
|
|||
// Max score field. |
|||
$maxscorefield = new xmldb_field('max_score', XMLDB_TYPE_INTEGER, '6'); |
|||
if (!$dbman->field_exists($table, $maxscorefield)) { |
|||
$dbman->add_field($table, $maxscorefield); |
|||
} |
|||
} |
|||
} |
|||
|
|||
function hvp_upgrade_2018090300() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
$table = new xmldb_table('hvp'); |
|||
|
|||
// Remove old, unused metadata fields. |
|||
if ($dbman->field_exists($table, 'author')) { |
|||
$dbman->drop_field($table, new xmldb_field('author')); |
|||
} |
|||
|
|||
if ($dbman->field_exists($table, 'license')) { |
|||
$dbman->drop_field($table, new xmldb_field('license')); |
|||
} |
|||
|
|||
if ($dbman->field_exists($table, 'meta_keywords')) { |
|||
$dbman->drop_field($table, new xmldb_field('meta_keywords')); |
|||
} |
|||
|
|||
if ($dbman->field_exists($table, 'meta_description')) { |
|||
$dbman->drop_field($table, new xmldb_field('meta_description')); |
|||
} |
|||
|
|||
// Create new metadata fields. |
|||
if (!$dbman->field_exists($table, 'authors')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('authors', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'source')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'year_from')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('year_from', XMLDB_TYPE_INTEGER, '4', null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'year_to')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('year_to', XMLDB_TYPE_INTEGER, '4', null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'license')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('license', XMLDB_TYPE_CHAR, '63', null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'license_version')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('license_version', XMLDB_TYPE_CHAR, '15', null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'changes')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('changes', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'license_extras')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('license_extras', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'author_comments')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('author_comments', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
// Add new libraries fields. |
|||
$table = new xmldb_table('hvp_libraries'); |
|||
if (!$dbman->field_exists($table, 'add_to')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('add_to', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
|
|||
if (!$dbman->field_exists($table, 'metadata_settings')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('metadata_settings', XMLDB_TYPE_TEXT, null, null, null, null, null) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Adds authentication table |
|||
* |
|||
* @throws ddl_exception |
|||
*/ |
|||
function hvp_upgrade_2019022600() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Add auth table. |
|||
$table = new xmldb_table('hvp_auth'); |
|||
|
|||
// Add fields. |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('user_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('created_at', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('secret', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null); |
|||
|
|||
// Add keys and index. |
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
$table->add_index('user_id', XMLDB_INDEX_UNIQUE, ['user_id']); |
|||
|
|||
// Create table if it does not exist. |
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Add default language to content |
|||
* |
|||
* @throws ddl_exception |
|||
* @throws ddl_table_missing_exception |
|||
*/ |
|||
function hvp_upgrade_2019030700() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
$table = new xmldb_table('hvp'); |
|||
|
|||
if (!$dbman->field_exists($table, 'default_language')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('default_language', XMLDB_TYPE_CHAR, '32', null, null, null, null) |
|||
); |
|||
} |
|||
} |
|||
|
|||
function hvp_upgrade_2020080400() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
// Define field completionscorerequired to be added to hvp. |
|||
$table = new xmldb_table('hvp'); |
|||
// Conditionally launch add field completionscorerequired. |
|||
if (!$dbman->field_exists($table, 'completionpass')) { |
|||
$dbman->add_field( |
|||
$table, |
|||
new xmldb_field('completionpass', XMLDB_TYPE_INTEGER, '1', null, null, null, 0, 'timemodified') |
|||
); |
|||
} |
|||
} |
|||
|
|||
function hvp_upgrade_2020080401() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Changing nullability of field completionpass on table hvp to not null. |
|||
$table = new xmldb_table('hvp'); |
|||
$field = new xmldb_field('completionpass', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified'); |
|||
|
|||
// Launch change of nullability for field completionpass. |
|||
$dbman->change_field_notnull($table, $field); |
|||
} |
|||
|
|||
function hvp_upgrade_2020082800() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
$table = new xmldb_table('hvp'); |
|||
|
|||
if (!$dbman->field_exists($table, 'a11y_title')) { |
|||
$dbman->add_field($table, |
|||
new xmldb_field('a11y_title', XMLDB_TYPE_CHAR, '255', null, null, null, null) |
|||
); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Drop old unused unique index, add nonunique index. |
|||
*/ |
|||
function hvp_upgrade_2020091500() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
$table = new xmldb_table('hvp_xapi_results'); |
|||
$index = new xmldb_index('results', XMLDB_INDEX_NOTUNIQUE, ['content_id', 'user_id']); |
|||
if (!$dbman->index_exists($table, $index)) { |
|||
$dbman->add_index($table, $index); |
|||
} |
|||
|
|||
$oldindex = new xmldb_index('result', XMLDB_INDEX_UNIQUE, ['id', 'content_id', 'user_id']); |
|||
$dbman->drop_index($table, $oldindex); |
|||
} |
|||
|
|||
function hvp_upgrade_2020112600() { |
|||
global $DB; |
|||
$dbman = $DB->get_manager(); |
|||
|
|||
// Add Content Hub fields to main content table. |
|||
$table = new xmldb_table('hvp'); |
|||
if (!$dbman->field_exists($table, 'shared')) { |
|||
$dbman->add_field($table, new xmldb_field('shared', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'completionpass')); |
|||
} |
|||
if (!$dbman->field_exists($table, 'synced')) { |
|||
$dbman->add_field($table, new xmldb_field('synced', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'shared')); |
|||
} |
|||
if (!$dbman->field_exists($table, 'hub_id')) { |
|||
$dbman->add_field($table, new xmldb_field('hub_id', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'synced')); |
|||
} |
|||
|
|||
// Create table for caching content hub metadata. |
|||
$table = new xmldb_table('hvp_content_hub_cache'); |
|||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
|||
$table->add_field('language', XMLDB_TYPE_CHAR, '31', null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('json', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); |
|||
$table->add_field('last_checked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
|||
|
|||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); |
|||
$table->add_index('language', XMLDB_INDEX_UNIQUE, ['language']); |
|||
|
|||
if (!$dbman->table_exists($table)) { |
|||
$dbman->create_table($table); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Hvp module upgrade function. |
|||
* |
|||
* @param string $oldversion The version we are upgrading from |
|||
* |
|||
* @return bool Success |
|||
*/ |
|||
function xmldb_hvp_upgrade($oldversion) { |
|||
$upgrades = [ |
|||
2016011300, |
|||
2016042500, |
|||
2016050600, |
|||
2016051000, |
|||
2016110100, |
|||
2016122800, |
|||
2017040500, |
|||
2017050900, |
|||
2017060900, |
|||
2018090300, |
|||
2019022600, |
|||
2019030700, |
|||
2020080400, |
|||
2020080401, |
|||
2020082800, |
|||
2020091500, |
|||
2020112600, |
|||
]; |
|||
|
|||
foreach ($upgrades as $version) { |
|||
if ($oldversion < $version) { |
|||
call_user_func("hvp_upgrade_{$version}"); |
|||
upgrade_mod_savepoint(true, $version, 'hvp'); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
(function($) { |
|||
|
|||
/** |
|||
* Get closest row of element |
|||
* |
|||
* @param {jQuery} $el |
|||
* @returns {jQuery} |
|||
*/ |
|||
function getRow($el) { |
|||
return $el.closest('.fitem'); |
|||
} |
|||
|
|||
/** |
|||
* Initializes editor |
|||
*/ |
|||
function init() { |
|||
var $editor = $('.h5p-editor'); |
|||
var $fileField = $('input[name="h5pfile"]'); |
|||
|
|||
if (H5PIntegration.hubIsEnabled) { |
|||
// TODO: This can easily break in new themes. Improve robustness of this
|
|||
// by not including h5paction in form, when it should not be used.
|
|||
$('input[name="h5paction"]').parents('.fitem').last().hide(); |
|||
} |
|||
|
|||
const mformId = H5PIntegration.editor && H5PIntegration.editor.formId !== null |
|||
? H5PIntegration.editor.formId |
|||
: 'mform1'; |
|||
|
|||
// Cancel validation and submission of form if clicking cancel button
|
|||
const cancelSubmitCallback = function ($button) { |
|||
return $button.is('[name="cancel"]'); |
|||
}; |
|||
|
|||
H5PEditor.init( |
|||
$('#' + mformId), |
|||
$('input[name="h5paction"]'), |
|||
getRow($fileField), |
|||
getRow($editor), |
|||
$editor, |
|||
$('input[name="h5plibrary"]'), |
|||
$('input[name="h5pparams"]'), |
|||
$('input[name="h5pmaxscore"]'), |
|||
$('input[name="name"]'), |
|||
cancelSubmitCallback |
|||
); |
|||
} |
|||
|
|||
$(document).ready(init); |
|||
})(H5P.jQuery); |
|||
@ -0,0 +1,10 @@ |
|||
H5P Editor PHP Library |
|||
========== |
|||
|
|||
A general library that is supposed to be used in most PHP implementations of H5P. |
|||
|
|||
## License |
|||
|
|||
All code is licensed under MIT License |
|||
|
|||
Open Sans font is licensed under Apache license, Version 2.0 |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,39 @@ |
|||
CKEditor 4 |
|||
========== |
|||
|
|||
Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. |
|||
https://ckeditor.com - See LICENSE.md for license information. |
|||
|
|||
CKEditor 4 is a text editor to be used inside web pages. It's not a replacement |
|||
for desktop text editors like Word or OpenOffice, but a component to be used as |
|||
part of web applications and websites. |
|||
|
|||
## Documentation |
|||
|
|||
The full editor documentation is available online at the following address: |
|||
https://ckeditor.com/docs/ |
|||
|
|||
## Installation |
|||
|
|||
Installing CKEditor is an easy task. Just follow these simple steps: |
|||
|
|||
1. **Download** the latest version from the CKEditor website: |
|||
https://ckeditor.com. You should have already completed this step, but be |
|||
sure you have the very latest version. |
|||
2. **Extract** (decompress) the downloaded file into the root of your website. |
|||
|
|||
**Note:** CKEditor is by default installed in the `ckeditor` folder. You can |
|||
place the files in whichever you want though. |
|||
|
|||
## Checking Your Installation |
|||
|
|||
The editor comes with a few sample pages that can be used to verify that |
|||
installation proceeded properly. Take a look at the `samples` directory. |
|||
|
|||
To test your installation, just call the following page at your website: |
|||
|
|||
http://<your site>/<CKEditor installation path>/samples/index.html |
|||
|
|||
For example: |
|||
|
|||
http://www.example.com/ckeditor/samples/index.html |
|||
@ -0,0 +1,10 @@ |
|||
# Reporting a security issues |
|||
|
|||
If you believe you have found a security issue in the CKEditor 4 software, please contact us immediately. |
|||
|
|||
When reporting a potential security problem, please bear this in mind: |
|||
|
|||
* Make sure to provide as many details as possible about the vulnerability. |
|||
* Please do not disclose publicly any security issues until we fix them and publish security releases. |
|||
|
|||
Contact the security team at security@cksource.com. As soon as we receive the security report, we will work promptly to confirm the issue and then to provide a security fix. |
|||
@ -0,0 +1,10 @@ |
|||
/* |
|||
Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. |
|||
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|||
*/ |
|||
(function(a){if("undefined"==typeof a)throw Error("jQuery should be loaded before CKEditor jQuery adapter.");if("undefined"==typeof CKEDITOR)throw Error("CKEditor should be loaded before CKEditor jQuery adapter.");CKEDITOR.config.jqueryOverrideVal="undefined"==typeof CKEDITOR.config.jqueryOverrideVal?!0:CKEDITOR.config.jqueryOverrideVal;a.extend(a.fn,{ckeditorGet:function(){var a=this.eq(0).data("ckeditorInstance");if(!a)throw"CKEditor is not initialized yet, use ckeditor() with a callback.";return a}, |
|||
ckeditor:function(g,e){if(!CKEDITOR.env.isCompatible)throw Error("The environment is incompatible.");if(!a.isFunction(g)){var m=e;e=g;g=m}var k=[];e=e||{};this.each(function(){var b=a(this),c=b.data("ckeditorInstance"),f=b.data("_ckeditorInstanceLock"),h=this,l=new a.Deferred;k.push(l.promise());if(c&&!f)g&&g.apply(c,[this]),l.resolve();else if(f)c.once("instanceReady",function(){setTimeout(function d(){c.element?(c.element.$==h&&g&&g.apply(c,[h]),l.resolve()):setTimeout(d,100)},0)},null,null,9999); |
|||
else{if(e.autoUpdateElement||"undefined"==typeof e.autoUpdateElement&&CKEDITOR.config.autoUpdateElement)e.autoUpdateElementJquery=!0;e.autoUpdateElement=!1;b.data("_ckeditorInstanceLock",!0);c=a(this).is("textarea")?CKEDITOR.replace(h,e):CKEDITOR.inline(h,e);b.data("ckeditorInstance",c);c.on("instanceReady",function(e){var d=e.editor;setTimeout(function n(){if(d.element){e.removeListener();d.on("dataReady",function(){b.trigger("dataReady.ckeditor",[d])});d.on("setData",function(a){b.trigger("setData.ckeditor", |
|||
[d,a.data])});d.on("getData",function(a){b.trigger("getData.ckeditor",[d,a.data])},999);d.on("destroy",function(){b.trigger("destroy.ckeditor",[d])});d.on("save",function(){a(h.form).submit();return!1},null,null,20);if(d.config.autoUpdateElementJquery&&b.is("textarea")&&a(h.form).length){var c=function(){b.ckeditor(function(){d.updateElement()})};a(h.form).submit(c);a(h.form).bind("form-pre-serialize",c);b.bind("destroy.ckeditor",function(){a(h.form).unbind("submit",c);a(h.form).unbind("form-pre-serialize", |
|||
c)})}d.on("destroy",function(){b.removeData("ckeditorInstance")});b.removeData("_ckeditorInstanceLock");b.trigger("instanceReady.ckeditor",[d]);g&&g.apply(d,[h]);l.resolve()}else setTimeout(n,100)},0)},null,null,9999)}});var f=new a.Deferred;this.promise=f.promise();a.when.apply(this,k).then(function(){f.resolve()});this.editor=this.eq(0).data("ckeditorInstance");return this}});CKEDITOR.config.jqueryOverrideVal&&(a.fn.val=CKEDITOR.tools.override(a.fn.val,function(g){return function(e){if(arguments.length){var m= |
|||
this,k=[],f=this.each(function(){var b=a(this),c=b.data("ckeditorInstance");if(b.is("textarea")&&c){var f=new a.Deferred;c.setData(e,function(){f.resolve()});k.push(f.promise());return!0}return g.call(b,e)});if(k.length){var b=new a.Deferred;a.when.apply(this,k).done(function(){b.resolveWith(m)});return b.promise()}return f}var f=a(this).eq(0),c=f.data("ckeditorInstance");return f.is("textarea")&&c?c.getData():g.call(f)}}))})(window.jQuery); |
|||
@ -0,0 +1,16 @@ |
|||
{ |
|||
"bender": { |
|||
"port": 9001 |
|||
}, |
|||
"server": { |
|||
"port": 9002 |
|||
}, |
|||
"paths": { |
|||
"ckeditor4": "../ckeditor4/", |
|||
"runner": "./src/runner.html" |
|||
}, |
|||
"browsers": { |
|||
"linux": [ "chrome", "firefox" ], |
|||
"macos": [ "safari" ] |
|||
} |
|||
} |
|||
@ -0,0 +1,165 @@ |
|||
/** |
|||
* @license Copyright (c) 2003-2022, CKSource - Frederico Knabben. All rights reserved. |
|||
* For licensing, see LICENSE.md or https://ckeditor.com/license
|
|||
*/ |
|||
|
|||
/** |
|||
* This file was added automatically by CKEditor builder. |
|||
* You may re-use it at any time to build CKEditor again. |
|||
* |
|||
* If you would like to build CKEditor online again |
|||
* (for example to upgrade), visit one the following links: |
|||
* |
|||
* (1) https://ckeditor.com/cke4/builder
|
|||
* Visit online builder to build CKEditor from scratch. |
|||
* |
|||
* (2) https://ckeditor.com/cke4/builder/84b6fa3dae0d9f3cb193260b476e8486
|
|||
* Visit online builder to build CKEditor, starting with the same setup as before. |
|||
* |
|||
* (3) https://ckeditor.com/cke4/builder/download/84b6fa3dae0d9f3cb193260b476e8486
|
|||
* Straight download link to the latest version of CKEditor (Optimized) with the same setup as before. |
|||
* |
|||
* NOTE: |
|||
* This file is not used by CKEditor, you may remove it. |
|||
* Changing this file will not change your CKEditor configuration. |
|||
*/ |
|||
|
|||
var CKBUILDER_CONFIG = { |
|||
skin: 'bootstrapck', |
|||
preset: 'basic', |
|||
ignore: [ |
|||
'.DS_Store', |
|||
'.bender', |
|||
'.editorconfig', |
|||
'.gitattributes', |
|||
'.gitignore', |
|||
'.idea', |
|||
'.jscsrc', |
|||
'.jshintignore', |
|||
'.jshintrc', |
|||
'.mailmap', |
|||
'.npm', |
|||
'.nvmrc', |
|||
'.travis.yml', |
|||
'bender-err.log', |
|||
'bender-out.log', |
|||
'bender.ci.js', |
|||
'bender.js', |
|||
'dev', |
|||
'gruntfile.js', |
|||
'less', |
|||
'node_modules', |
|||
'package-lock.json', |
|||
'package.json', |
|||
'tests' |
|||
], |
|||
plugins : { |
|||
'a11yhelp' : 1, |
|||
'autogrow' : 1, |
|||
'basicstyles' : 1, |
|||
'bidi' : 1, |
|||
'clipboard' : 1, |
|||
'codeTag' : 1, |
|||
'codesnippet' : 1, |
|||
'colorbutton' : 1, |
|||
'colordialog' : 1, |
|||
'elementspath' : 1, |
|||
'enterkey' : 1, |
|||
'entities' : 1, |
|||
'floatingspace' : 1, |
|||
'font' : 1, |
|||
'format' : 1, |
|||
'horizontalrule' : 1, |
|||
'htmlwriter' : 1, |
|||
'indentlist' : 1, |
|||
'justify' : 1, |
|||
'lineheight' : 1, |
|||
'link' : 1, |
|||
'list' : 1, |
|||
'magicline' : 1, |
|||
'maximize' : 1, |
|||
'menubutton' : 1, |
|||
'pastefromword' : 1, |
|||
'pastetext' : 1, |
|||
'removeformat' : 1, |
|||
'resize' : 1, |
|||
'specialchar' : 1, |
|||
'stylescombo' : 1, |
|||
'tabletools' : 1, |
|||
'toolbar' : 1, |
|||
'undo' : 1, |
|||
'wysiwygarea' : 1 |
|||
}, |
|||
languages : { |
|||
'af' : 1, |
|||
'ar' : 1, |
|||
'az' : 1, |
|||
'bg' : 1, |
|||
'bn' : 1, |
|||
'bs' : 1, |
|||
'ca' : 1, |
|||
'cs' : 1, |
|||
'cy' : 1, |
|||
'da' : 1, |
|||
'de' : 1, |
|||
'de-ch' : 1, |
|||
'el' : 1, |
|||
'en' : 1, |
|||
'en-au' : 1, |
|||
'en-ca' : 1, |
|||
'en-gb' : 1, |
|||
'eo' : 1, |
|||
'es' : 1, |
|||
'es-mx' : 1, |
|||
'et' : 1, |
|||
'eu' : 1, |
|||
'fa' : 1, |
|||
'fi' : 1, |
|||
'fo' : 1, |
|||
'fr' : 1, |
|||
'fr-ca' : 1, |
|||
'gl' : 1, |
|||
'gu' : 1, |
|||
'he' : 1, |
|||
'hi' : 1, |
|||
'hr' : 1, |
|||
'hu' : 1, |
|||
'id' : 1, |
|||
'is' : 1, |
|||
'it' : 1, |
|||
'ja' : 1, |
|||
'ka' : 1, |
|||
'km' : 1, |
|||
'ko' : 1, |
|||
'ku' : 1, |
|||
'lt' : 1, |
|||
'lv' : 1, |
|||
'mk' : 1, |
|||
'mn' : 1, |
|||
'ms' : 1, |
|||
'nb' : 1, |
|||
'nl' : 1, |
|||
'no' : 1, |
|||
'oc' : 1, |
|||
'pl' : 1, |
|||
'pt' : 1, |
|||
'pt-br' : 1, |
|||
'ro' : 1, |
|||
'ru' : 1, |
|||
'si' : 1, |
|||
'sk' : 1, |
|||
'sl' : 1, |
|||
'sq' : 1, |
|||
'sr' : 1, |
|||
'sr-latn' : 1, |
|||
'sv' : 1, |
|||
'th' : 1, |
|||
'tr' : 1, |
|||
'tt' : 1, |
|||
'ug' : 1, |
|||
'uk' : 1, |
|||
'vi' : 1, |
|||
'zh' : 1, |
|||
'zh-cn' : 1 |
|||
} |
|||
}; |
|||
File diff suppressed because it is too large
@ -0,0 +1,44 @@ |
|||
/** |
|||
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. |
|||
* For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
|
|||
*/ |
|||
|
|||
CKEDITOR.editorConfig = function( config ) { |
|||
// Define changes to default configuration here.
|
|||
// For complete reference see:
|
|||
// https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html
|
|||
|
|||
// The toolbar groups arrangement, optimized for a single toolbar row.
|
|||
config.toolbarGroups = [ |
|||
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] }, |
|||
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] }, |
|||
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] }, |
|||
{ name: 'forms' }, |
|||
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] }, |
|||
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] }, |
|||
{ name: 'links' }, |
|||
{ name: 'insert' }, |
|||
{ name: 'styles' }, |
|||
{ name: 'colors' }, |
|||
{ name: 'tools' }, |
|||
{ name: 'others' }, |
|||
{ name: 'about' } |
|||
]; |
|||
|
|||
// The default plugins included in the basic setup define some buttons that
|
|||
// are not needed in a basic editor. They are removed here.
|
|||
// config.removeButtons = 'Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript';
|
|||
|
|||
// Dialog windows are also simplified.
|
|||
config.removeDialogTabs = 'image:advanced;link:advanced'; |
|||
|
|||
// Se the most common block elements.
|
|||
config.format_tags = 'p;h1;h2;h3;pre'; |
|||
|
|||
config.autoGrow_minHeight = 80; |
|||
config.height = 80; |
|||
config.autoGrow_onStartup = true; |
|||
config.autoGrow_maxHeight = 500; |
|||
config.colorButton_enableMore = true; |
|||
config.plugins += ',removeRedundantNBSP,customCodeHighlighter'; |
|||
}; |
|||
@ -0,0 +1,208 @@ |
|||
/* |
|||
Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved. |
|||
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license |
|||
*/ |
|||
|
|||
body |
|||
{ |
|||
/* Font */ |
|||
/* Emoji fonts are added to visualise them nicely in Internet Explorer. */ |
|||
font-family: sans-serif, Arial, Verdana, "Trebuchet MS", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; |
|||
font-size: 12px; |
|||
|
|||
/* Text color */ |
|||
color: #333; |
|||
|
|||
/* Remove the background color to make it transparent. */ |
|||
background-color: #fff; |
|||
|
|||
margin: 20px; |
|||
} |
|||
|
|||
.cke_editable |
|||
{ |
|||
font-size: 13px; |
|||
line-height: 1.6; |
|||
|
|||
/* Fix for missing scrollbars with RTL texts. (#10488) */ |
|||
word-wrap: break-word; |
|||
} |
|||
|
|||
blockquote |
|||
{ |
|||
font-style: italic; |
|||
font-family: Georgia, Times, "Times New Roman", serif; |
|||
padding: 2px 0; |
|||
border-style: solid; |
|||
border-color: #ccc; |
|||
border-width: 0; |
|||
} |
|||
|
|||
.cke_contents_ltr blockquote |
|||
{ |
|||
padding-left: 20px; |
|||
padding-right: 8px; |
|||
border-left-width: 5px; |
|||
} |
|||
|
|||
.cke_contents_rtl blockquote |
|||
{ |
|||
padding-left: 8px; |
|||
padding-right: 20px; |
|||
border-right-width: 5px; |
|||
} |
|||
|
|||
a |
|||
{ |
|||
color: #0782C1; |
|||
} |
|||
|
|||
ol,ul,dl |
|||
{ |
|||
/* IE7: reset rtl list margin. (#7334) */ |
|||
*margin-right: 0px; |
|||
/* Preserved spaces for list items with text direction different than the list. (#6249,#8049)*/ |
|||
padding: 0 40px; |
|||
} |
|||
|
|||
h1,h2,h3,h4,h5,h6 |
|||
{ |
|||
font-weight: normal; |
|||
line-height: 1.2; |
|||
} |
|||
|
|||
hr |
|||
{ |
|||
border: 0px; |
|||
border-top: 1px solid #ccc; |
|||
} |
|||
|
|||
img.right |
|||
{ |
|||
border: 1px solid #ccc; |
|||
float: right; |
|||
margin-left: 15px; |
|||
padding: 5px; |
|||
} |
|||
|
|||
img.left |
|||
{ |
|||
border: 1px solid #ccc; |
|||
float: left; |
|||
margin-right: 15px; |
|||
padding: 5px; |
|||
} |
|||
|
|||
pre |
|||
{ |
|||
white-space: pre-wrap; /* CSS 2.1 */ |
|||
word-wrap: break-word; /* IE7 */ |
|||
-moz-tab-size: 4; |
|||
tab-size: 4; |
|||
} |
|||
|
|||
.marker |
|||
{ |
|||
background-color: Yellow; |
|||
} |
|||
|
|||
span[lang] |
|||
{ |
|||
font-style: italic; |
|||
} |
|||
|
|||
figure |
|||
{ |
|||
text-align: center; |
|||
outline: solid 1px #ccc; |
|||
background: rgba(0,0,0,0.05); |
|||
padding: 10px; |
|||
margin: 10px 20px; |
|||
display: inline-block; |
|||
} |
|||
|
|||
figure > figcaption |
|||
{ |
|||
text-align: center; |
|||
display: block; /* For IE8 */ |
|||
} |
|||
|
|||
a > img { |
|||
padding: 1px; |
|||
margin: 1px; |
|||
border: none; |
|||
outline: 1px solid #0782C1; |
|||
} |
|||
|
|||
/* Widget Styles */ |
|||
.code-featured |
|||
{ |
|||
border: 5px solid red; |
|||
} |
|||
|
|||
.math-featured |
|||
{ |
|||
padding: 20px; |
|||
box-shadow: 0 0 2px rgba(200, 0, 0, 1); |
|||
background-color: rgba(255, 0, 0, 0.05); |
|||
margin: 10px; |
|||
} |
|||
|
|||
.image-clean |
|||
{ |
|||
border: 0; |
|||
background: none; |
|||
padding: 0; |
|||
} |
|||
|
|||
.image-clean > figcaption |
|||
{ |
|||
font-size: .9em; |
|||
text-align: right; |
|||
} |
|||
|
|||
.image-grayscale |
|||
{ |
|||
background-color: white; |
|||
color: #666; |
|||
} |
|||
|
|||
.image-grayscale img, img.image-grayscale |
|||
{ |
|||
filter: grayscale(100%); |
|||
} |
|||
|
|||
.embed-240p |
|||
{ |
|||
max-width: 426px; |
|||
max-height: 240px; |
|||
margin:0 auto; |
|||
} |
|||
|
|||
.embed-360p |
|||
{ |
|||
max-width: 640px; |
|||
max-height: 360px; |
|||
margin:0 auto; |
|||
} |
|||
|
|||
.embed-480p |
|||
{ |
|||
max-width: 854px; |
|||
max-height: 480px; |
|||
margin:0 auto; |
|||
} |
|||
|
|||
.embed-720p |
|||
{ |
|||
max-width: 1280px; |
|||
max-height: 720px; |
|||
margin:0 auto; |
|||
} |
|||
|
|||
.embed-1080p |
|||
{ |
|||
max-width: 1920px; |
|||
max-height: 1080px; |
|||
margin:0 auto; |
|||
} |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue