diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index cb85521015a..49575b9a3ac 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -269,7 +269,8 @@ class mod_assign_external extends external_api { * @since Moodle 2.4 */ public static function get_assignments($courseids = array(), $capabilities = array()) { - global $USER, $DB; + global $USER, $DB, $CFG; + require_once("$CFG->dirroot/mod/assign/locallib.php"); $params = self::validate_parameters( self::get_assignments_parameters(), @@ -336,7 +337,9 @@ class mod_assign_external extends external_api { 'm.maxattempts, ' . 'm.markingworkflow, ' . 'm.markingallocation, ' . - 'm.requiresubmissionstatement'; + 'm.requiresubmissionstatement, '. + 'm.intro, '. + 'm.introformat'; $coursearray = array(); foreach ($courses as $id => $course) { $assignmentarray = array(); @@ -370,7 +373,7 @@ class mod_assign_external extends external_api { } $configrecords->close(); - $assignmentarray[]= array( + $assignment = array( 'id' => $module->assignmentid, 'cmid' => $module->id, 'course' => $module->course, @@ -398,6 +401,34 @@ class mod_assign_external extends external_api { 'requiresubmissionstatement' => $module->requiresubmissionstatement, 'configs' => $configarray ); + + // Return or not intro and file attachments depending on the plugin settings. + $assign = new assign($context, null, null); + + if ($assign->show_intro()) { + + list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, + $module->introformat, $context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0); + + $fs = get_file_storage(); + if ($files = $fs->get_area_files($context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, + 0, 'timemodified', false)) { + + $assignment['introattachments'] = array(); + foreach ($files as $file) { + $filename = $file->get_filename(); + + $assignment['introattachments'][] = array( + 'filename' => $filename, + 'mimetype' => $file->get_mimetype(), + 'fileurl' => moodle_url::make_webservice_pluginfile_url( + $context->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0, '/', $filename)->out(false) + ); + } + } + } + + $assignmentarray[] = $assignment; } } $coursearray[]= array( @@ -450,7 +481,19 @@ class mod_assign_external extends external_api { 'markingworkflow' => new external_value(PARAM_INT, 'enable marking workflow'), 'markingallocation' => new external_value(PARAM_INT, 'enable marking allocation'), 'requiresubmissionstatement' => new external_value(PARAM_INT, 'student must accept submission statement'), - 'configs' => new external_multiple_structure(self::get_assignments_config_structure(), 'configuration settings') + 'configs' => new external_multiple_structure(self::get_assignments_config_structure(), 'configuration settings'), + 'intro' => new external_value(PARAM_RAW, + 'assignment intro, not allways returned because it deppends on the activity configuration', VALUE_OPTIONAL), + 'introformat' => new external_format_value('intro', VALUE_OPTIONAL), + 'introattachments' => new external_multiple_structure( + new external_single_structure( + array ( + 'filename' => new external_value(PARAM_FILE, 'file name'), + 'mimetype' => new external_value(PARAM_RAW, 'mime type'), + 'fileurl' => new external_value(PARAM_URL, 'file download url') + ) + ), 'intro attachments files', VALUE_OPTIONAL + ) ), 'assignment information object'); }