Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
dndupload_ajax_processor Class Reference

Processes the upload, creating the course module and returning the result. More...

Public Member Functions

 __construct ($courseid, $section, $type, $modulename)
 Set up some basic information needed to handle the upload. More...
 
 process ($displayname=null, $content=null)
 Process the upload - creating the module in the course and returning the result to the browser. More...
 

Public Attributes

const ERROR_OK = 0
 Returned when no error has occurred.
 

Protected Member Functions

 create_course_module ()
 Create the coursemodule to hold the file/content that has been uploaded.
 
 display_name_from_file ($filename)
 Generate the name of the mod instance from the name of the file (remove the extension and convert underscore => space. More...
 
 finish_setup_course_module ($instanceid)
 Called after the mod has set itself up, to finish off any course module settings (set instance id, add to correct section, set visibility, etc.) and send the response. More...
 
 handle_file_upload ()
 Handle uploads containing files - create the course module, ask the upload repository to process the file, ask the mod to set itself up, then return the result to the browser.
 
 handle_other_upload ($content)
 Handle uploads not containing file - create the course module, ask the mod to set itself up, then return the result to the browser. More...
 
 is_file_upload ()
 Check if this upload is a 'file' upload. More...
 
 prepare_module_data ($draftitemid=null, $content=null)
 Gather together all the details to pass on to the mod, so that it can initialise it's own database tables. More...
 
 send_response ($mod)
 Send the details of the newly created activity back to the client browser. More...
 

Protected Attributes

object $cm = null
 The course module that has been created.
 
context_course $context = null
 The course context for capability checking.
 
object $course = null
 The course that we are uploading to.
 
string $displayname = null
 The name to give the new activity instance.
 
dndupload_handler $dnduploadhandler = null
 used to check the allowed file types
 
object $module = null
 The details of the module type that will be created.
 
int $section = null
 The section number we are uploading to.
 
string $type = null
 The type of upload (e.g. More...
 

Detailed Description

Processes the upload, creating the course module and returning the result.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

dndupload_ajax_processor::__construct (   $courseid,
  $section,
  $type,
  $modulename 
)

Set up some basic information needed to handle the upload.

Parameters
int$courseidThe ID of the course we are uploading to
int$sectionThe section number we are uploading to
string$typeThe type of upload (as reported by the browser)
string$modulenameThe name of the module requested to handle this upload

Member Function Documentation

◆ display_name_from_file()

dndupload_ajax_processor::display_name_from_file (   $filename)
protected

Generate the name of the mod instance from the name of the file (remove the extension and convert underscore => space.

Parameters
string$filenamethe filename of the uploaded file
Return values
stringthe display name to use

◆ finish_setup_course_module()

dndupload_ajax_processor::finish_setup_course_module (   $instanceid)
protected

Called after the mod has set itself up, to finish off any course module settings (set instance id, add to correct section, set visibility, etc.) and send the response.

Parameters
int$instanceidid returned by the mod when it was created

◆ handle_other_upload()

dndupload_ajax_processor::handle_other_upload (   $content)
protected

Handle uploads not containing file - create the course module, ask the mod to set itself up, then return the result to the browser.

Parameters
string$contentthe content uploaded to the browser

◆ is_file_upload()

dndupload_ajax_processor::is_file_upload ( )
protected

Check if this upload is a 'file' upload.

Return values
booltrue if it is a 'file' upload, false otherwise

◆ prepare_module_data()

dndupload_ajax_processor::prepare_module_data (   $draftitemid = null,
  $content = null 
)
protected

Gather together all the details to pass on to the mod, so that it can initialise it's own database tables.

Parameters
int$draftitemidoptional the id of the draft area containing the file (for file uploads)
string$contentoptional the content dropped onto the course (for non-file uploads)
Return values
objectdata to pass on to the mod, containing: string $type the 'type' as registered with dndupload_handler (or 'Files') object $course the course the upload was for int $draftitemid optional the id of the draft area containing the files int $coursemodule id of the course module that has already been created string $displayname the name to use for this activity (can be overriden by the mod)

◆ process()

dndupload_ajax_processor::process (   $displayname = null,
  $content = null 
)

Process the upload - creating the module in the course and returning the result to the browser.

Parameters
string$displaynameoptional the name (from the browser) to give the course module instance
string$contentoptional the content of the upload (for non-file uploads)

◆ send_response()

dndupload_ajax_processor::send_response (   $mod)
protected

Send the details of the newly created activity back to the client browser.

Parameters
cm_info$moddetails of the mod just created

Member Data Documentation

◆ $type

string dndupload_ajax_processor::$type = null
protected

The type of upload (e.g.

'Files', 'text/plain')


The documentation for this class was generated from the following file: