Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Moodle Qtype Moopt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
Moodle Qtype Moopt
Commits
61a91249
Commit
61a91249
authored
1 year ago
by
Isabel
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev/isabel_188' into develop
parents
a36a5a1c
c13218a8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
externallib.php
+7
-4
7 additions, 4 deletions
externallib.php
locallib.php
+16
-11
16 additions, 11 deletions
locallib.php
with
23 additions
and
15 deletions
externallib.php
+
7
−
4
View file @
61a91249
...
@@ -42,7 +42,7 @@ class qtype_moopt_external extends external_api {
...
@@ -42,7 +42,7 @@ class qtype_moopt_external extends external_api {
'taskuuid'
=>
new
external_value
(
PARAM_RAW
,
'task\'s uuid'
,
VALUE_OPTIONAL
),
'taskuuid'
=>
new
external_value
(
PARAM_RAW
,
'task\'s uuid'
,
VALUE_OPTIONAL
),
'maxscoregradinghints'
=>
new
external_value
(
PARAM_FLOAT
,
'maximum score'
,
VALUE_OPTIONAL
),
'maxscoregradinghints'
=>
new
external_value
(
PARAM_FLOAT
,
'maximum score'
,
VALUE_OPTIONAL
),
'filesdisplayedingeneralfeedback'
=>
new
external_value
(
PARAM_RAW
,
'general feedback'
,
VALUE_OPTIONAL
),
'filesdisplayedingeneralfeedback'
=>
new
external_value
(
PARAM_RAW
,
'general feedback'
,
VALUE_OPTIONAL
),
'enablefileinput'
=>
new
external_value
(
PARAM_BOOL
,
'Enable file submissions'
),
'enablefileinput'
=>
new
external_value
(
PARAM_BOOL
,
'Enable file submissions'
,
VALUE_OPTIONAL
),
'freetextfilesettings'
=>
new
external_multiple_structure
(
'freetextfilesettings'
=>
new
external_multiple_structure
(
new
external_single_structure
(
new
external_single_structure
(
array
(
array
(
...
@@ -56,7 +56,6 @@ class qtype_moopt_external extends external_api {
...
@@ -56,7 +56,6 @@ class qtype_moopt_external extends external_api {
)
)
,
'Free text settings'
,
VALUE_OPTIONAL
),
,
'Free text settings'
,
VALUE_OPTIONAL
),
'moodleValidationProformaNamespace'
=>
new
external_value
(
PARAM_TEXT
,
'detected namespace'
,
VALUE_OPTIONAL
),
'moodleValidationProformaNamespace'
=>
new
external_value
(
PARAM_TEXT
,
'detected namespace'
,
VALUE_OPTIONAL
),
'moodleValidationWarningInvalidNamespace'
=>
new
external_value
(
PARAM_TEXT
,
'warning message in case of invalid XML namespace'
,
VALUE_OPTIONAL
),
'moodleValidationWarnings'
=>
new
external_multiple_structure
(
'moodleValidationWarnings'
=>
new
external_multiple_structure
(
new
external_single_structure
(
new
external_single_structure
(
array
(
array
(
...
@@ -86,6 +85,8 @@ class qtype_moopt_external extends external_api {
...
@@ -86,6 +85,8 @@ class qtype_moopt_external extends external_api {
$unzipinfo
=
unzip_task_file_in_draft_area
(
$draftid
,
$usercontext
);
$unzipinfo
=
unzip_task_file_in_draft_area
(
$draftid
,
$usercontext
);
if
(
$unzipinfo
==
null
)
{
if
(
$unzipinfo
==
null
)
{
return
[
'error'
=>
'Error extracting zip file'
];
return
[
'error'
=>
'Error extracting zip file'
];
}
else
if
(
isset
(
$unzipinfo
[
'error'
]))
{
return
$unzipinfo
;
}
}
$taskxmlfilename
=
$unzipinfo
[
'xml'
];
$taskxmlfilename
=
$unzipinfo
[
'xml'
];
$taskzipfilename
=
$unzipinfo
[
'zip'
]
??
null
;
$taskzipfilename
=
$unzipinfo
[
'zip'
]
??
null
;
...
@@ -96,8 +97,7 @@ class qtype_moopt_external extends external_api {
...
@@ -96,8 +97,7 @@ class qtype_moopt_external extends external_api {
$returnval
=
array
();
$returnval
=
array
();
if
(
$namespace
==
null
)
{
if
(
$namespace
==
null
)
{
$returnval
[
'error'
]
=
get_string
(
'invalidproformanamespace'
,
'qtype_moopt'
,
$returnval
[
'moodleValidationWarningInvalidNamespace'
]
=
get_string
(
'invalidproformanamespace'
,
'qtype_moopt'
,
implode
(
", "
,
PROFORMA_TASK_XML_NAMESPACES
));
implode
(
", "
,
PROFORMA_TASK_XML_NAMESPACES
));
}
else
{
}
else
{
...
@@ -195,6 +195,9 @@ class qtype_moopt_external extends external_api {
...
@@ -195,6 +195,9 @@ class qtype_moopt_external extends external_api {
$encoding
=
$child
->
attributes
->
getNamedItem
(
'encoding'
)
->
nodeValue
;
$encoding
=
$child
->
attributes
->
getNamedItem
(
'encoding'
)
->
nodeValue
;
$filecontent
=
get_text_content_from_file
(
$usercontext
,
$draftid
,
$keepfilename
,
$filecontent
=
get_text_content_from_file
(
$usercontext
,
$draftid
,
$keepfilename
,
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
],
true
,
$encoding
);
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
],
true
,
$encoding
);
if
(
$filecontent
===
null
){
$returnval
[
'error'
]
=
"Encoding of file "
.
$pathinfo
[
'basename'
]
.
" couldn't be detected."
;
}
$defaultfilename
=
basename
(
$child
->
nodeValue
);
$defaultfilename
=
basename
(
$child
->
nodeValue
);
$fileid
=
$file
->
attributes
->
getNamedItem
(
'id'
)
->
nodeValue
;
$fileid
=
$file
->
attributes
->
getNamedItem
(
'id'
)
->
nodeValue
;
$enablefreetext
=
true
;
$enablefreetext
=
true
;
...
...
This diff is collapsed.
Click to expand it.
locallib.php
+
16
−
11
View file @
61a91249
...
@@ -120,6 +120,7 @@ use qtype_moopt\utility\proforma_xml\separate_feedback_handler;
...
@@ -120,6 +120,7 @@ use qtype_moopt\utility\proforma_xml\separate_feedback_handler;
/*
/*
* Unzips the task zip file in the given draft area into the area
* Unzips the task zip file in the given draft area into the area
* moodle doesn't display thrown exceptions, so we handle them as array with key 'error' in calling function
*
*
* @param type $draftareaid
* @param type $draftareaid
* @param type $usercontext
* @param type $usercontext
...
@@ -129,7 +130,6 @@ use qtype_moopt\utility\proforma_xml\separate_feedback_handler;
...
@@ -129,7 +130,6 @@ use qtype_moopt\utility\proforma_xml\separate_feedback_handler;
* 'xml' => (string) the name of the xml file (mandatory)
* 'xml' => (string) the name of the xml file (mandatory)
* ]
* ]
* Returns false, if there is no file in the given draft area.
* Returns false, if there is no file in the given draft area.
* @throws invalid_parameter_exception
*/
*/
function
unzip_task_file_in_draft_area
(
$draftareaid
,
$usercontext
)
{
function
unzip_task_file_in_draft_area
(
$draftareaid
,
$usercontext
)
{
global
$USER
;
global
$USER
;
...
@@ -141,8 +141,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
...
@@ -141,8 +141,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
if
(
$area
[
'filecount'
]
==
0
)
{
if
(
$area
[
'filecount'
]
==
0
)
{
return
false
;
return
false
;
}
else
if
(
$area
[
'filecount'
]
>
1
||
$area
[
'foldercount'
]
!=
0
)
{
}
else
if
(
$area
[
'filecount'
]
>
1
||
$area
[
'foldercount'
]
!=
0
)
{
throw
new
invalid_parameter_exception
(
$error
=
'Only one file is allowed to be in this draft area: A ProFormA-Task as either ZIP or XML file. Check for additional folders as well.'
;
'Only one file is allowed to be in this draft area: A ProFormA-Task as either ZIP or XML file.'
);
return
array
(
'error'
=>
$error
);
}
}
// Get name of the file.
// Get name of the file.
...
@@ -164,7 +164,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
...
@@ -164,7 +164,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
return
array
(
'xml'
=>
$filename
);
return
array
(
'xml'
=>
$filename
);
}
}
if
(
$filetype
!=
'zip'
)
{
if
(
$filetype
!=
'zip'
)
{
throw
new
invalid_parameter_exception
(
'Supplied file must be a xml or zip file.'
);
$error
=
'Supplied file must be a xml or zip file.'
;
return
array
(
'error'
=>
$error
);
}
}
$zipfilename
=
$filename
;
$zipfilename
=
$filename
;
$result
=
array
(
'zip'
=>
$zipfilename
);
$result
=
array
(
'zip'
=>
$zipfilename
);
...
@@ -215,7 +216,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
...
@@ -215,7 +216,8 @@ function unzip_task_file_in_draft_area($draftareaid, $usercontext) {
}
}
if
(
!
array_key_exists
(
'xml'
,
$result
))
{
if
(
!
array_key_exists
(
'xml'
,
$result
))
{
throw
new
invalid_parameter_exception
(
'Supplied zip file must contain the file task.xml.'
);
$error
=
'Supplied zip file must contain the file task.xml.'
;
return
array
(
'error'
=>
$error
);
}
}
return
$result
;
return
$result
;
...
@@ -292,18 +294,21 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
...
@@ -292,18 +294,21 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
// TODO: make sure the mimetype is plain text
// TODO: make sure the mimetype is plain text
// even task.xmls may contain mistakes (eg PDF )
// even task.xmls may contain mistakes (eg PDF )
//check if encoding of attached file is utf-8 else convert
//check if encoding of attached file is utf-8 else convert
if encoding could be detectet
$content
=
$file
->
get_content
();
$content
=
$file
->
get_content
();
$test_encodings
=
array
(
'UTF-8'
,
'ISO-8859-1'
,
'ISO-8859-15'
,
'Windows-1252'
,
'UTF-16'
);
if
(
$attached
){
if
(
$attached
){
if
(
$encoding
!=
null
){
if
(
$encoding
!=
null
){
$enc
=
$encoding
;
$enc
=
$encoding
;
}
else
{
}
else
{
$enc
=
mb_detect_encoding
(
$content
,
null
,
tru
e
);
$enc
=
mb_detect_encoding
(
$content
,
null
,
fals
e
);
if
(
$enc
==
=
false
){
if
(
$enc
==
false
){
throw
new
invalid_parameter_exception
(
'Encoding of attached file '
.
$filepath
.
$filename
.
' could\'nt be detectet.'
);
$enc
=
mb_detect_encoding
(
$content
,
$test_encodings
,
true
);
}
}
}
}
if
(
$enc
!==
'UTF-8'
){
if
(
$enc
==
false
){
return
null
;
}
else
if
(
$enc
!==
'UTF-8'
){
$content
=
mb_convert_encoding
(
$content
,
'UTF-8'
,
$enc
);
$content
=
mb_convert_encoding
(
$content
,
'UTF-8'
,
$enc
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment