Gitlab CSE Unil
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
M. Chardon
moodle-assignfeedback_editpdfplus
Commits
1ffa90b3
Commit
1ffa90b3
authored
Jun 01, 2018
by
M. Chardon
Browse files
noettoyage et optimisation code avec sonarqube
parent
a0f7790a
Changes
6
Hide whitespace changes
Inline
Side-by-side
ajax.php
View file @
1ffa90b3
...
...
@@ -33,6 +33,10 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_sesskey
();
const
PLUGIN_NAME
=
"assignfeedback_editpdfplus"
;
const
PERMISSION_ASSIGN_GRADE
=
"mod/assign:grade"
;
const
PERMISSION_ASSIGN_SUBMIT
=
"mod/assign:submit"
;
$action
=
optional_param
(
'action'
,
''
,
PARAM_ALPHANUM
);
$assignmentid
=
required_param
(
'assignmentid'
,
PARAM_INT
);
$userid
=
required_param
(
'userid'
,
PARAM_INT
);
...
...
@@ -52,11 +56,11 @@ if (!$assignment->can_view_submission($userid)) {
if
(
$action
===
'pollconversions'
)
{
$draft
=
true
;
if
(
!
has_capability
(
'mod/assign:grade'
,
$context
))
{
if
(
!
has_capability
(
PERMISSION_ASSIGN_GRADE
,
$context
))
{
// A student always sees the readonly version.
$readonly
=
true
;
$draft
=
false
;
require_capability
(
'mod/assign:submit'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_SUBMIT
,
$context
);
}
if
(
$readonly
)
{
...
...
@@ -96,7 +100,7 @@ if ($action === 'pollconversions') {
$index
=
count
(
$response
->
pages
);
$page
=
new
stdClass
();
//$comments = page_editor::get_comments($grade->id, $index, $draft);
$page
->
url
=
moodle_url
::
make_pluginfile_url
(
$context
->
id
,
'assignfeedback_editpdfplus'
,
$filearea
,
$grade
->
id
,
'/'
,
$pagefile
->
get_filename
())
->
out
();
$page
->
url
=
moodle_url
::
make_pluginfile_url
(
$context
->
id
,
PLUGIN_NAME
,
$filearea
,
$grade
->
id
,
'/'
,
$pagefile
->
get_filename
())
->
out
();
//$page->comments = $comments;
if
(
$imageinfo
=
$pagefile
->
get_imageinfo
())
{
$page
->
width
=
$imageinfo
[
'width'
];
...
...
@@ -109,7 +113,7 @@ if ($action === 'pollconversions') {
$page
->
annotations
=
$annotations
;
$response
->
pages
[]
=
$page
;
$component
=
'assignfeedback_editpdfplus'
;
$component
=
PLUGIN_NAME
;
$filearea
=
document_services
::
PAGE_IMAGE_FILEAREA
;
$filepath
=
'/'
;
$fs
=
get_file_storage
();
...
...
@@ -128,7 +132,7 @@ if ($action === 'pollconversions') {
echo
json_encode
(
$response
);
die
();
}
else
if
(
$action
==
'savepage'
)
{
require_capability
(
'mod/assign:grade'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_GRADE
,
$context
);
$response
=
new
stdClass
();
$response
->
errors
=
array
();
...
...
@@ -141,19 +145,18 @@ if ($action === 'pollconversions') {
$added
=
page_editor
::
set_annotations
(
$grade
->
id
,
$index
,
$page
->
annotations
);
if
(
$added
!=
count
(
$page
->
annotations
))
{
array_push
(
$response
->
errors
,
get_string
(
'couldnotsavepage'
,
'assignfeedback_editpdfplus'
,
$index
+
1
));
array_push
(
$response
->
errors
,
get_string
(
'couldnotsavepage'
,
PLUGIN_NAME
,
$index
+
1
));
}
echo
json_encode
(
$response
);
die
();
}
else
if
(
$action
==
'generatepdf'
)
{
$refresh
=
optional_param
(
'refresh'
,
false
,
PARAM_BOOL
);
if
(
!
$refresh
)
{
require_capability
(
'mod/assign:grade'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_GRADE
,
$context
);
}
else
{
require_capability
(
'mod/assign:submit'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_SUBMIT
,
$context
);
}
$response
=
new
stdClass
();
$grade
=
$assignment
->
get_user_grade
(
$userid
,
true
,
$attemptnumber
);
...
...
@@ -161,7 +164,7 @@ if ($action === 'pollconversions') {
$response
->
url
=
''
;
if
(
$file
)
{
$url
=
moodle_url
::
make_pluginfile_url
(
$assignment
->
get_context
()
->
id
,
'assignfeedback_editpdfplus'
,
document_services
::
FINAL_PDF_FILEAREA
,
$grade
->
id
,
'/'
,
$file
->
get_filename
(),
false
);
$url
=
moodle_url
::
make_pluginfile_url
(
$assignment
->
get_context
()
->
id
,
PLUGIN_NAME
,
document_services
::
FINAL_PDF_FILEAREA
,
$grade
->
id
,
'/'
,
$file
->
get_filename
(),
false
);
$response
->
url
=
$url
->
out
(
true
);
$response
->
filename
=
$file
->
get_filename
();
}
...
...
@@ -198,7 +201,7 @@ if ($action === 'pollconversions') {
.
"<p>La correction du devoir a été mise à jour. Vous pouvez accéder au document en suivant ce <a href='"
.
$response
->
url
.
"'>lien</a></p>"
.
"<i>Ceci est un mail automatique.</i>"
;
.
"<i>Ceci est un mail automatique
, merci de ne pas y répondre
.</i>"
;
foreach
(
$teachers
as
$teacher
)
{
$res
=
email_to_user
(
$teacher
,
$USER
,
"[Moodle] Mise à jour devoir"
,
$body
,
$bodyhtml
);
}
...
...
@@ -207,7 +210,7 @@ if ($action === 'pollconversions') {
echo
json_encode
(
$response
);
die
();
}
else
if
(
$action
==
'revertchanges'
)
{
require_capability
(
'mod/assign:grade'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_GRADE
,
$context
);
$grade
=
$assignment
->
get_user_grade
(
$userid
,
true
,
$attemptnumber
);
...
...
@@ -216,7 +219,7 @@ if ($action === 'pollconversions') {
echo
json_encode
(
$result
);
die
();
}
else
if
(
$action
==
'deletefeedbackdocument'
)
{
require_capability
(
'mod/assign:grade'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_GRADE
,
$context
);
$grade
=
$assignment
->
get_user_grade
(
$userid
,
true
,
$attemptnumber
);
$result
=
document_services
::
delete_feedback_document
(
$assignment
,
$userid
,
$attemptnumber
);
...
...
@@ -225,7 +228,7 @@ if ($action === 'pollconversions') {
echo
json_encode
(
$result
);
die
();
}
else
if
(
$action
==
'updatestudentview'
)
{
require_capability
(
'mod/assign:submit'
,
$context
);
require_capability
(
PERMISSION_ASSIGN_SUBMIT
,
$context
);
$response
=
new
stdClass
();
$response
->
errors
=
array
();
...
...
@@ -238,7 +241,7 @@ if ($action === 'pollconversions') {
$added
=
page_editor
::
update_annotations_status
(
$page
->
annotations
);
if
(
$added
!=
count
(
$page
->
annotations
))
{
array_push
(
$response
->
errors
,
get_string
(
'couldnotsavepage'
,
'assignfeedback_editpdfplus'
,
$index
+
1
));
array_push
(
$response
->
errors
,
get_string
(
'couldnotsavepage'
,
PLUGIN_NAME
,
$index
+
1
));
}
echo
json_encode
(
$response
);
die
();
...
...
backup/moodle2/backup_assignfeedback_editpdfplus_subplugin.class.php
View file @
1ffa90b3
...
...
@@ -35,6 +35,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class
backup_assignfeedback_editpdfplus_subplugin
extends
backup_subplugin
{
const
GRADEID
=
'gradeid'
;
/**
* Returns the subplugin information to attach to feedback element
* @return backup_subplugin_element
...
...
@@ -44,10 +46,10 @@ class backup_assignfeedback_editpdfplus_subplugin extends backup_subplugin {
// Create XML elements.
$subplugin
=
$this
->
get_subplugin_element
();
$subpluginwrapper
=
new
backup_nested_element
(
$this
->
get_recommended_name
());
$subpluginelementfiles
=
new
backup_nested_element
(
'feedback_editpdfplus_files'
,
null
,
array
(
'gradeid'
));
$subpluginelementfiles
=
new
backup_nested_element
(
'feedback_editpdfplus_files'
,
null
,
array
(
self
::
GRADEID
));
$subpluginelementannotations
=
new
backup_nested_element
(
'feedback_editpdfplus_annotations'
);
$subpluginelementannotation
=
new
backup_nested_element
(
'feedback_editpdfplus_annotation'
,
null
,
array
(
'gradeid'
,
'pageno'
,
'x'
,
'y'
,
'endx'
,
'endy'
,
'cartridgex'
,
'cartridgey'
,
'path'
,
'toolid'
,
'textannot'
,
'colour'
,
'draft'
,
'answerrequested'
,
'studentanswer'
,
'studentstatus'
,
'displaylock'
,
'displayrotation'
,
'borderstyle'
,
'parent_annot'
)
'feedback_editpdfplus_annotation'
,
null
,
array
(
self
::
GRADEID
,
'pageno'
,
'x'
,
'y'
,
'endx'
,
'endy'
,
'cartridgex'
,
'cartridgey'
,
'path'
,
'toolid'
,
'textannot'
,
'colour'
,
'draft'
,
'answerrequested'
,
'studentanswer'
,
'studentstatus'
,
'displaylock'
,
'displayrotation'
,
'borderstyle'
,
'parent_annot'
)
);
// Connect XML elements into the tree.
...
...
@@ -57,12 +59,12 @@ class backup_assignfeedback_editpdfplus_subplugin extends backup_subplugin {
$subpluginwrapper
->
add_child
(
$subpluginelementannotations
);
// Set source to populate the data.
$subpluginelementfiles
->
set_source_sql
(
'SELECT id AS gradeid from {assign_grades} where id = :
gradeid'
,
array
(
'gradeid'
=>
backup
::
VAR_PARENTID
));
$subpluginelementannotation
->
set_source_table
(
'assignfeedback_editpp_annot'
,
array
(
'gradeid'
=>
backup
::
VAR_PARENTID
));
$subpluginelementfiles
->
set_source_sql
(
'SELECT id AS gradeid from {assign_grades} where id = :
'
.
self
::
GRADEID
,
array
(
self
::
GRADEID
=>
backup
::
VAR_PARENTID
));
$subpluginelementannotation
->
set_source_table
(
'assignfeedback_editpp_annot'
,
array
(
self
::
GRADEID
=>
backup
::
VAR_PARENTID
));
// We only need to backup the files in the final pdf area, and the readonly page images - the others can be regenerated.
$subpluginelementfiles
->
annotate_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
FINAL_PDF_FILEAREA
,
'gradeid'
);
$subpluginelementfiles
->
annotate_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
PAGE_IMAGE_READONLY_FILEAREA
,
'gradeid'
);
$subpluginelementfiles
->
annotate_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
FINAL_PDF_FILEAREA
,
self
::
GRADEID
);
$subpluginelementfiles
->
annotate_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
PAGE_IMAGE_READONLY_FILEAREA
,
self
::
GRADEID
);
return
$subplugin
;
}
}
backup/moodle2/restore_assignfeedback_editpdfplus_subplugin.class.php
View file @
1ffa90b3
...
...
@@ -36,6 +36,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class
restore_assignfeedback_editpdfplus_subplugin
extends
restore_subplugin
{
const
GRADE
=
'grade'
;
/**
* Returns the paths to be handled by the subplugin at assignment level
* @return array
...
...
@@ -66,8 +68,8 @@ class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {
$data
=
(
object
)
$data
;
// In this case the id is the old gradeid which will be mapped.
$this
->
add_related_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
FINAL_PDF_FILEAREA
,
'grade'
,
null
,
$data
->
gradeid
);
$this
->
add_related_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
PAGE_IMAGE_READONLY_FILEAREA
,
'grade'
,
null
,
$data
->
gradeid
);
$this
->
add_related_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
FINAL_PDF_FILEAREA
,
self
::
GRADE
,
null
,
$data
->
gradeid
);
$this
->
add_related_files
(
'assignfeedback_editpdfplus'
,
\
assignfeedback_editpdfplus\document_services
::
PAGE_IMAGE_READONLY_FILEAREA
,
self
::
GRADE
,
null
,
$data
->
gradeid
);
}
/**
...
...
@@ -81,7 +83,7 @@ class restore_assignfeedback_editpdfplus_subplugin extends restore_subplugin {
$oldgradeid
=
$data
->
gradeid
;
// The mapping is set in the restore for the core assign activity
// when a grade node is processed.
$data
->
gradeid
=
$this
->
get_mappingid
(
'grade'
,
$data
->
gradeid
);
$data
->
gradeid
=
$this
->
get_mappingid
(
self
::
GRADE
,
$data
->
gradeid
);
$DB
->
insert_record
(
'assignfeedback_editpp_annot'
,
$data
);
}
...
...
classes/combined_document.php
View file @
1ffa90b3
...
...
@@ -188,7 +188,6 @@ class combined_document {
switch
(
$status
)
{
case
\
core_files\conversion
::
STATUS_COMPLETE
:
continue
;
break
;
default
:
$converter
->
poll_conversion
(
$conversion
);
}
...
...
externallib.php
View file @
1ffa90b3
...
...
@@ -37,48 +37,123 @@ use \assignfeedback_editpdfplus\admin_editor;
class
assignfeedback_editpdfplus_external
extends
external_api
{
const
PLUGINNAME
=
"assignfeedback_editpdfplus"
;
const
DATAJSON
=
'jsonformdata'
;
const
MESSAGELIB
=
'message'
;
const
COURSELIB
=
"course"
;
const
COURSEID
=
"courseid"
;
const
AXEID
=
"axeid"
;
const
AXEIDDESC
=
"Axe ID"
;
const
AXELIB
=
"axelabel"
;
const
AXELIBDESC
=
"Axe label"
;
const
TOOLID
=
"toolid"
;
const
TOOLIDDESC
=
"Tool ID"
;
const
TOOLLIBDESC
=
"Tool label"
;
const
TOOLTYPE
=
"typetool"
;
const
TOOLTYPEDESC
=
"Type of tool"
;
const
TOOLSELECTED
=
"selecttool"
;
const
BOUTONLIBTOOL
=
"button"
;
const
ENABLETOOL
=
"enable"
;
const
ENABLETOOLDESC
=
"Tool is enabled"
;
/**
* Returns description of method parameters
* @return external_function_parameters
* Returns description of method parameters
for general calling
* @return
\
external_function_parameters
*/
public
static
function
submit_axis_form_parameters
()
{
public
static
function
submit_generic_form_parameters
()
{
$message
=
'The data from the grading form, encoded as a json array'
;
return
new
external_function_parameters
(
array
(
'jsonformdata'
=>
new
external_value
(
PARAM_RAW
,
'The data from the grading form, encoded as a json array'
)
self
::
DATAJSON
=>
new
external_value
(
PARAM_RAW
,
$message
)
)
);
}
/**
* Submit axis form for adding or edditing
* @global $USER
* @global $PAGE
* @global $DB
* @param String $jsonformdata
* @return array
*
* Form return generic structure
* @return \external_single_structure
*/
public
static
function
submit_axis_form
(
$jsonformdata
)
{
global
$USER
,
$PAGE
,
$DB
;
public
static
function
submit_generic_form_returns
()
{
return
new
external_single_structure
(
array
(
self
::
MESSAGELIB
=>
new
external_value
(
PARAM_TEXT
,
self
::
MESSAGELIB
,
VALUE_OPTIONAL
)
)
);
}
$params
=
self
::
validate_parameters
(
self
::
submit_axis_form_parameters
(),
array
(
'jsonformdata'
=>
$jsonformdata
));
/**
* Form return tool structure
* @return \external_multiple_structure
*/
public
static
function
submit_tool_form_returns
()
{
return
new
external_multiple_structure
(
new
external_single_structure
(
array
(
self
::
AXEID
=>
new
external_value
(
PARAM_INT
,
self
::
AXEIDDESC
),
self
::
TOOLSELECTED
=>
new
external_value
(
PARAM_INT
,
self
::
TOOLIDDESC
),
self
::
ENABLETOOL
=>
new
external_value
(
PARAM_INT
,
self
::
ENABLETOOLDESC
,
VALUE_OPTIONAL
),
self
::
TOOLID
=>
new
external_value
(
PARAM_INT
,
self
::
TOOLIDDESC
),
self
::
TOOLTYPE
=>
new
external_value
(
PARAM_INT
,
self
::
TOOLTYPEDESC
,
VALUE_OPTIONAL
),
self
::
BOUTONLIBTOOL
=>
new
external_value
(
PARAM_TEXT
,
self
::
TOOLLIBDESC
,
VALUE_OPTIONAL
),
self
::
MESSAGELIB
=>
new
external_value
(
PARAM_TEXT
,
self
::
MESSAGELIB
,
VALUE_OPTIONAL
)
)
)
);
}
$serialiseddata
=
json_decode
(
$params
[
'jsonformdata'
]);
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public
static
function
submit_axis_form_parameters
()
{
return
self
::
submit_generic_form_parameters
();
}
/**
* Extract and parse json data string into an array
* @param external_function_parameters $externalFunctionParameter
* @param String $jsonformdata
* @return array decoded data
*/
public
static
function
getParseData
(
$externalFunctionParameter
,
$jsonformdata
)
{
$params
=
self
::
validate_parameters
(
$externalFunctionParameter
,
array
(
self
::
DATAJSON
=>
$jsonformdata
));
$serialiseddata
=
json_decode
(
$params
[
self
::
DATAJSON
]);
$data
=
array
();
parse_str
(
$serialiseddata
,
$data
);
return
$data
;
}
$warnings
=
array
();
if
(
WS_SERVER
)
{
// Assume form submission if coming from WS.
$USER
->
ignoresesskey
=
true
;
}
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$data
[
'courseid'
]),
'*'
,
MUST_EXIST
);
/**
* Set Page context from the course id given. It returns the context found.
* @global $DB
* @global $PAGE
* @param int $courseid Current course id
* @return context course's context
*/
public
static
function
setPageContext
(
$courseid
)
{
global
$DB
,
$PAGE
;
$course
=
$DB
->
get_record
(
self
::
COURSELIB
,
array
(
'id'
=>
$courseid
),
'*'
,
MUST_EXIST
);
$context
=
context_course
::
instance
(
$course
->
id
,
MUST_EXIST
);
$PAGE
->
set_context
(
$context
);
return
$context
;
}
public
static
function
getMessageError
()
{
return
array
(
self
::
MESSAGELIB
=>
get_string
(
"admin_messageko"
,
self
::
PLUGINNAME
));
}
/**
* Submit axis form for adding or edditing
* @param String $jsonformdata
* @return array
*/
public
static
function
submit_axis_form
(
$jsonformdata
)
{
$data
=
self
::
getParseData
(
self
::
submit_axis_form_parameters
(),
$jsonformdata
);
$context
=
self
::
setPageContext
(
$data
[
self
::
COURSEID
]);
$customdata
=
(
object
)
$data
;
$formparams
=
array
(
$customdata
);
...
...
@@ -91,16 +166,12 @@ class assignfeedback_editpdfplus_external extends external_api {
if
(
$validateddata
->
axeid
)
{
admin_editor
::
edit_axis
(
$validateddata
->
axeid
,
$validateddata
->
label
);
$axeid
=
$validateddata
->
axeid
;
return
array
(
array
(
'axeid'
=>
$axeid
,
'axelabel'
=>
$validateddata
->
label
));
}
else
{
$axeid
=
admin_editor
::
add_axis
(
$validateddata
->
label
,
$context
->
id
);
return
array
(
array
(
'axeid'
=>
$axeid
,
'axelabel'
=>
$validateddata
->
label
));
}
}
else
{
$warnings
[]
=
array
(
'message'
=>
get_string
(
'admin_messageko'
,
'assignfeedback_editpdfplus'
));
return
array
(
array
(
self
::
AXEID
=>
$axeid
,
self
::
AXELIB
=>
$validateddata
->
label
));
}
return
$warnings
;
return
array
(
self
::
getMessageError
());
}
/**
...
...
@@ -111,9 +182,9 @@ class assignfeedback_editpdfplus_external extends external_api {
return
new
external_multiple_structure
(
new
external_single_structure
(
array
(
'axeid'
=>
new
external_value
(
PARAM_INT
,
'axis id'
),
'axelabel'
=>
new
external_value
(
PARAM_TEXT
,
'axis label'
),
'message'
=>
new
external_value
(
PARAM_TEXT
,
'message'
,
VALUE_OPTIONAL
)
self
::
AXEID
=>
new
external_value
(
PARAM_INT
,
self
::
AXEIDDESC
),
self
::
AXELIB
=>
new
external_value
(
PARAM_TEXT
,
self
::
AXELIBDESC
),
self
::
MESSAGELIB
=>
new
external_value
(
PARAM_TEXT
,
self
::
MESSAGELIB
,
VALUE_OPTIONAL
)
)
)
);
...
...
@@ -124,41 +195,18 @@ class assignfeedback_editpdfplus_external extends external_api {
* @return external_function_parameters
*/
public
static
function
submit_axis_del_form_parameters
()
{
return
new
external_function_parameters
(
array
(
'jsonformdata'
=>
new
external_value
(
PARAM_RAW
,
'The data from the grading form, encoded as a json array'
)
)
);
return
self
::
submit_generic_form_parameters
();
}
/**
* Submit axis form for deleting
* @global $USER
* @global $PAGE
* @global $DB
* @param String $jsonformdata
* @return array
*/
public
static
function
submit_axis_del_form
(
$jsonformdata
)
{
global
$USER
,
$PAGE
,
$DB
;
$params
=
self
::
validate_parameters
(
self
::
submit_axis_form_parameters
(),
array
(
'jsonformdata'
=>
$jsonformdata
));
$serialiseddata
=
json_decode
(
$params
[
'jsonformdata'
]);
$data
=
array
();
parse_str
(
$serialiseddata
,
$data
);
$warnings
=
array
();
$data
=
self
::
getParseData
(
self
::
submit_axis_form_parameters
(),
$jsonformdata
);
if
(
WS_SERVER
)
{
// Assume form submission if coming from WS.
$USER
->
ignoresesskey
=
true
;
}
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$data
[
'courseid'
]),
'*'
,
MUST_EXIST
);
$context
=
context_course
::
instance
(
$course
->
id
,
MUST_EXIST
);
$PAGE
->
set_context
(
$context
);
self
::
setPageContext
(
$data
[
self
::
COURSEID
]);
$customdata
=
(
object
)
$data
;
$formparams
=
array
(
$customdata
);
...
...
@@ -167,17 +215,13 @@ class assignfeedback_editpdfplus_external extends external_api {
$mform
=
new
axis_del_form
(
null
,
$formparams
,
'post'
,
''
,
null
,
true
,
$data
);
$validateddata
=
$mform
->
get_data
();
if
(
$validateddata
)
{
if
(
$validateddata
->
axeid
&&
admin_editor
::
del_axis
(
$validateddata
->
axeid
))
{
$message
=
"1"
;
return
array
(
array
(
'message'
=>
$message
));
}
}
else
{
$message
=
get_string
(
'admindeltool_messageko'
,
'assignfeedback_editpdfplus'
);
$warnings
[]
=
array
(
'message'
=>
$message
);
if
(
$validateddata
&&
$validateddata
->
axeid
&&
admin_editor
::
del_axis
(
$validateddata
->
axeid
))
{
$message
=
"1"
;
return
array
(
array
(
self
::
MESSAGELIB
=>
$message
));
}
$warnings
=
array
();
$message
=
get_string
(
'admindeltool_messageko'
,
self
::
PLUGINNAME
);
$warnings
[]
=
array
(
self
::
MESSAGELIB
=>
$message
);
return
$warnings
;
}
...
...
@@ -187,78 +231,58 @@ class assignfeedback_editpdfplus_external extends external_api {
*/
public
static
function
submit_axis_del_form_returns
()
{
return
new
external_multiple_structure
(
new
external_single_structure
(
array
(
'message'
=>
new
external_value
(
PARAM_TEXT
,
'message'
,
VALUE_OPTIONAL
)
)
)
self
::
submit_generic_form_returns
()
);
}
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public
static
function
submit_tool_edit_form_parameters
()
{
return
new
external_function_parameters
(
array
(
'jsonformdata'
=>
new
external_value
(
PARAM_RAW
,
'The data from the grading form, encoded as a json array'
)
)
);
}
/**
* Submit tool form for edditing
* @global $USER
* @global $PAGE
* @global $DB
* @param String $jsonformdata
* Submit tool form for adding or edditing
* @param String $jsonformdata json tool
* @param String $mode add or edit the tool
* @return array
*/
public
static
function
submit_tool_edit_form
(
$jsonformdata
)
{
global
$USER
,
$PAGE
,
$DB
;
$params
=
self
::
validate_parameters
(
self
::
submit_axis_form_parameters
(),
array
(
'jsonformdata'
=>
$jsonformdata
));
$serialiseddata
=
json_decode
(
$params
[
'jsonformdata'
]);
$data
=
array
();
parse_str
(
$serialiseddata
,
$data
);
$warnings
=
array
();
if
(
WS_SERVER
)
{
// Assume form submission if coming from WS.
$USER
->
ignoresesskey
=
true
;
}
public
static
function
submit_tool_form
(
$jsonformdata
,
$mode
)
{
$data
=
self
::
getParseData
(
self
::
submit_axis_form_parameters
(),
$jsonformdata
);
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$data
[
'courseid'
]),
'*'
,
MUST_EXIST
);
$context
=
context_course
::
instance
(
$course
->
id
,
MUST_EXIST
);
$PAGE
->
set_context
(
$context
);
$context
=
self
::
setPageContext
(
$data
[
self
::
COURSEID
]);
$customdata
=
(
object
)
$data
;
//$formparams = array($customdata);
$sessionkey
=
sesskey
();
if
(
$sessionkey
==
$customdata
->
sesskey
&&
$customdata
->
toolid
)
{
$tool
=
admin_editor
::
edit_tool
(
$customdata
);
if
(
$sessionkey
==
$customdata
->
sesskey
&&
$mode
)
{
$tool
=
null
;
if
(
$mode
==
"add"
)
{
$tool
=
admin_editor
::
add_tool
(
$customdata
,
$context
->
id
);
}
elseif
(
$mode
==
"edit"
)
{
$tool
=
admin_editor
::
edit_tool
(
$customdata
);
}
if
(
$tool
)
{
$tools
=
admin_editor
::
get_tools_by_axis
(
$tool
->
axis
);
$res
=
array
();
foreach
(
$tools
as
$toolTmp
)
{
$res
[]
=
array
(
'axeid'
=>
$tool
->
axis
,
'
sel
ecttool'
=>
$tool
->
id
,
'enable'
=>
$toolTmp
->
enabled
,
'toolid'
=>
$toolTmp
->
id
,
'typetool'
=>
$toolTmp
->
type
,
'button'
=>
$toolTmp
->
label
,
'message'
=>
''
);
$res
[]
=
array
(
self
::
AXEID
=>
$tool
->
axis
,
sel
f
::
TOOLSELECTED
=>
$tool
->
id
,
self
::
ENABLETOOL
=>
$toolTmp
->
enabled
,
self
::
TOOLID
=>
$toolTmp
->
id
,
self
::
TOOLTYPE
=>
$toolTmp
->
type
,
self
::
BOUTONLIBTOOL
=>
$toolTmp
->
label
,
self
::
MESSAGELIB
=>
''
);
}
return
$res
;
}
else
{
$warnings
[]
=
array
(
'message'
=>
get_string
(
'admin_messageko'
,
'assignfeedback_editpdfplus'
));
}
}
else
{
$warnings
[]
=
array
(
'message'
=>
get_string
(
'admin_messageko'
,
'assignfeedback_editpdfplus'
));
}
return
array
(
self
::
getMessageError
());
}
return
$warnings
;
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public
static
function
submit_tool_edit_form_parameters
()
{
return
self
::
submit_generic_form_parameters
();
}
/**
* Submit tool form for edditing
* @param String $jsonformdata
* @return array
*/
public
static
function
submit_tool_edit_form
(
$jsonformdata
)
{
return
self
::
submit_tool_form
(
$jsonformdata
,
"edit"
);
}
/**
...
...
@@ -266,19 +290,7 @@ class assignfeedback_editpdfplus_external extends external_api {
* @return \external_multiple_structure
*/
public
static
function
submit_tool_edit_form_returns
()
{
return
new
external_multiple_structure
(
new
external_single_structure
(
array
(
'axeid'
=>
new
external_value
(
PARAM_INT
,
'axe id'
),
'selecttool'
=>
new
external_value
(
PARAM_INT
,
'tool id'
),
'enable'
=>
new
external_value
(
PARAM_INT
,
'tool enable'
),
'toolid'
=>
new
external_value
(
PARAM_INT
,
'tool id'
),
'typetool'
=>
new
external_value
(
PARAM_INT
,
'tool type'
),
'button'
=>
new
external_value
(
PARAM_TEXT
,
'tool label'
),
'message'
=>
new
external_value
(
PARAM_TEXT
,
'message'
,
VALUE_OPTIONAL
)
)
)
);
return
self
::
submit_tool_form_returns
();
}
/**
...
...
@@ -286,64 +298,16 @@ class assignfeedback_editpdfplus_external extends external_api {
* @return external_function_parameters
*/
public
static
function
submit_tool_add_form_parameters
()
{
return
new
external_function_parameters
(
array
(
'jsonformdata'
=>
new
external_value
(
PARAM_RAW
,
'The data from the grading form, encoded as a json array'
)
)
);
return
self
::
submit_generic_form_parameters
();
}
/**
* Submit tool form for adding
* @global $USER
* @global $PAGE
* @global $DB
* @param String $jsonformdata
* @return array
*/
public
static
function
submit_tool_add_form
(
$jsonformdata
)
{
global
$USER
,
$PAGE
,
$DB
;
$params
=
self
::
validate_parameters
(
self
::
submit_axis_form_parameters
(),
array
(
'jsonformdata'
=>
$jsonformdata
));
$serialiseddata
=
json_decode
(
$params
[
'jsonformdata'
]);
$data
=
array
();
parse_str
(
$serialiseddata
,
$data
);
$warnings
=
array
();