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

Blackboard pool question importer class. More...

Inheritance diagram for qformat_blackboard_six_pool:
qformat_blackboard_six_base qformat_based_on_xml qformat_default

Public Member Functions

 can_import_file ($file)
 Check if the given file is capable of being imported by this plugin. More...
 
 clean_question_name ($name)
 Ensure that a question name does not contain anything nasty, and will fit in the DB field. More...
 
 clean_question_name ($name)
 Ensure that a question name does not contain anything nasty, and will fit in the DB field. More...
 
 cleaned_text_field ($text)
 Same as text_field but text is cleaned. More...
 
 cleaninput ($str)
 A lot of imported files contain unwanted entities. More...
 
 cleaninput ($str)
 A lot of imported files contain unwanted entities. More...
 
 create_default_question_name ($questiontext, $default)
 Construct a reasonable default question name, based on the start of the question text. More...
 
 create_default_question_name ($questiontext, $default)
 Construct a reasonable default question name, based on the start of the question text. More...
 
 export_file_extension ()
 
 exportpreprocess ()
 Do any pre-processing that may be required. More...
 
 exportprocess ($checkcapabilities=true)
 Perform the export. More...
 
 getpath ($xml, $path, $default, $istext=false, $error='')
 Return the value of a node, given a path to the node if it doesn't exist return the default value. More...
 
 getpath ($xml, $path, $default, $istext=false, $error='')
 Return the value of a node, given a path to the node if it doesn't exist return the default value. More...
 
 importpostprocess ()
 Does any post-processing that may be desired Clean the temporary directory if a zip file was imported. More...
 
 importpreprocess ()
 
 importpreprocess ()
 Perform any required pre-processing. More...
 
 importprocess ($filename, $lesson, $pageid)
 
 importprocess ()
 Process the file This method should not normally be overidden. More...
 
 mime_type ()
 The string mime-type of the files that this plugin reads or writes.
 
 process_category ($xml, &$questions)
 Add a category question entry based on the pool file title. More...
 
 process_common ($questiondata)
 Do question import processing common to every qtype. More...
 
 process_essay ($xml, &$questions)
 Process Essay Questions. More...
 
 process_fib ($xml, &$questions)
 Process Fill in the Blank Questions. More...
 
 process_ma ($xml, &$questions)
 Process Multiple Choice Questions With Multiple Answers. More...
 
 process_matching ($xml, &$questions)
 Process Matching Questions. More...
 
 process_mc ($xml, &$questions)
 Process Multiple Choice Questions with single answer. More...
 
 process_tf ($xml, &$questions)
 Process True / False Questions. More...
 
 provide_export ()
 
 provide_import ()
 This plugin provide import. More...
 
 readdata ($filename)
 
 set_can_access_backupdata ($canaccess)
 
 set_display_progress ($displayprogress)
 Change whether to display progress messages. More...
 
 set_filebase ($path)
 Set the path to the root of images tree. More...
 
 set_importcontext ($context)
 
 setCategory ($category)
 set the category More...
 
 setCatfromfile ($catfromfile)
 set catfromfile More...
 
 setCattofile ($cattofile)
 set cattofile More...
 
 setContextfromfile ($contextfromfile)
 set contextfromfile More...
 
 setContexts ($contexts)
 set an array of contexts. More...
 
 setContexttofile ($contexttofile)
 set contexttofile More...
 
 setCourse ($course)
 set the course class variable More...
 
 setFilename ($filename)
 set the filename More...
 
 setMatchgrades ($matchgrades)
 set matchgrades More...
 
 setQuestions ($questions)
 Set the specific questions to export. More...
 
 setRealfilename ($realfilename)
 set the "real" filename (this is what the user typed, regardless of wha happened next) More...
 
 setStoponerror ($stoponerror)
 set stoponerror More...
 
 text_field ($text)
 Given an HTML text with references to images files, store all images in a draft filearea, and return an array with all urls in text recoded, format set to FORMAT_HTML, and itemid set to filearea itemid. More...
 
 try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='')
 Import for questiontype plugins. More...
 
 try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='')
 Import for questiontype plugins Do not override. More...
 

Public Attributes

 $canaccessbackupdata = true
 
 $category = null
 
 $catfromfile = 0
 
 $cattofile = 0
 
 $contextfromfile = 0
 
 $contexttofile = 0
 
 $course = null
 
 $displayerrors = true
 
bool $displayprogress = true
 $displayprogress Whether to display progress.
 
string $filebase = ''
 path to path to root of image tree in unzipped archive.
 
 $filename = ''
 
 $importerrors = 0
 
bool $ishtml = true
 Is the current question's question text escaped HTML (true for most if not all Blackboard files).
 
 $matchgrades = 'error'
 
 $qtypeconvert
 
 $questionids = array()
 
 $questions = array()
 
 $realfilename = ''
 
 $stoponerror = true
 
string $tempdir = ''
 path to the temporary directory.
 
 $translator = null
 

Protected Member Functions

 add_blank_combined_feedback ($question)
 Since the lesson module tries to re-use the question bank import classes in a crazy way, this is necessary to stop things breaking.
 
 add_blank_combined_feedback ($question)
 Add a blank combined feedback to a question object. More...
 
 assemble_category_path ($names)
 Convert a list of category names, possibly preceeded by one of the context tokens like $course$, into a string representation of the category path. More...
 
 count_questions ($questions)
 Count all non-category questions in the questions array. More...
 
 count_questions ($questions)
 Count all non-category questions in the questions array. More...
 
 create_category_path ($catpath, $lastcategoryinfo=null)
 find and/or create the category described by a delimited list e.g. More...
 
 create_dummy_question_representing_category (string $categoryname, $categoryinfo)
 Create 'dummy' question for category export. More...
 
 defaultquestion ()
 return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. More...
 
 defaultquestion ()
 return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. More...
 
 error ($message, $text='', $questionname='')
 Handle parsing error. More...
 
 error ($message, $text='', $questionname='')
 Handle parsing error.
 
 exportpostprocess ()
 Do an post-processing that may be required. More...
 
 format_question_text ($question)
 Convert the question text to plain text, so it can safely be displayed during import to let the user see roughly what is going on.
 
 format_question_text ($question)
 Convert the question text to plain text, so it can safely be displayed during import to let the user see roughly what is going on.
 
 get_category_path ($id, $includecontext=true)
 get the category as a path (e.g., tom/dick/harry) More...
 
 presave_process ($content)
 Enable any processing to be done on the content just prior to the file being saved default is to do nothing. More...
 
 readdata ($filename)
 Return complete file within an array, one item per line. More...
 
 readquestion ($lines)
 
 readquestion ($lines)
 Given the data known to define a question in this format, this function converts it into a question object suitable for processing and insertion into Moodle. More...
 
 readquestions ($text)
 Parse the xml document into an array of questions. More...
 
 split_category_path ($path)
 Convert a string, as returned by assemble_category_path(), back into an array of category names. More...
 
 store_file_for_text_field (&$text, $tempdir, $filepathinsidetempdir, $filename)
 Store an image file in a draft filearea. More...
 
 try_exporting_using_qtypes ($name, $question, $extra=null)
 Provide export functionality for plugin questiontypes Do not override. More...
 
 writequestion ($question)
 convert a single question object into text output in the given format. More...
 

Protected Attributes

 $importcontext = null
 

Detailed Description

Blackboard pool question importer class.

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

Member Function Documentation

◆ add_blank_combined_feedback()

qformat_default::add_blank_combined_feedback (   $question)
protectedinherited

Add a blank combined feedback to a question object.

Parameters
objectquestion
Return values
objectquestion

◆ assemble_category_path()

qformat_default::assemble_category_path (   $names)
protectedinherited

Convert a list of category names, possibly preceeded by one of the context tokens like $course$, into a string representation of the category path.

Names are separated by / delimiters. And /s in the name are replaced by //.

To reverse the process and split the paths into names, use split_category_path().

Parameters
array$names
Return values
string

◆ can_import_file()

qformat_blackboard_six_base::can_import_file (   $file)
inherited

Check if the given file is capable of being imported by this plugin.

As file_storage::mimetype() may use finfo PHP extension if available, the value returned by $file->get_mimetype for a .dat file is not the same on all servers. So we must made 2 checks to verify if the plugin can import the file.

Parameters
stored_file$filethe file to check
Return values
boolwhether this plugin can import the file

Reimplemented from qformat_default.

◆ clean_question_name() [1/2]

qformat_default::clean_question_name (   $name)
inherited

Ensure that a question name does not contain anything nasty, and will fit in the DB field.

Parameters
string$namethe raw question name.
Return values
stringa safe question name.

◆ clean_question_name() [2/2]

qformat_default::clean_question_name (   $name)
inherited

Ensure that a question name does not contain anything nasty, and will fit in the DB field.

Parameters
string$namethe raw question name.
Return values
stringa safe question name.

◆ cleaned_text_field()

qformat_blackboard_six_base::cleaned_text_field (   $text)
inherited

Same as text_field but text is cleaned.

Parameters
string$texttext to parse and recode
Return values
arraywith keys text, format, itemid.

◆ cleaninput() [1/2]

qformat_based_on_xml::cleaninput (   $str)
inherited

A lot of imported files contain unwanted entities.

This method tries to clean up all known problems.

Parameters
stringstr string to correct
Return values
stringthe corrected string

◆ cleaninput() [2/2]

qformat_based_on_xml::cleaninput (   $str)
inherited

A lot of imported files contain unwanted entities.

This method tries to clean up all known problems.

Parameters
stringstr string to correct
Return values
stringthe corrected string

◆ count_questions() [1/2]

qformat_default::count_questions (   $questions)
protectedinherited

Count all non-category questions in the questions array.

Parameters
arrayquestions An array of question objects.
Return values
intThe count.

◆ count_questions() [2/2]

qformat_default::count_questions (   $questions)
protectedinherited

Count all non-category questions in the questions array.

Parameters
arrayquestions An array of question objects.
Return values
intThe count.

◆ create_category_path()

qformat_default::create_category_path (   $catpath,
  $lastcategoryinfo = null 
)
protectedinherited

find and/or create the category described by a delimited list e.g.

$course$/tom/dick/harry or tom/dick/harry

removes any context string no matter whether $getcontext is set but if $getcontext is set then ignore the context and use selected category context.

Parameters
stringcatpath delimited category path
object$lastcategoryinfoContains category information
Return values
mixedcategory object or null if fails

◆ create_default_question_name() [1/2]

qformat_default::create_default_question_name (   $questiontext,
  $default 
)
inherited

Construct a reasonable default question name, based on the start of the question text.

Parameters
string$questiontextthe question text.
string$defaultdefault question name to use if the constructed one comes out blank.
Return values
stringa reasonable question name.

◆ create_default_question_name() [2/2]

qformat_default::create_default_question_name (   $questiontext,
  $default 
)
inherited

Construct a reasonable default question name, based on the start of the question text.

Parameters
string$questiontextthe question text.
string$defaultdefault question name to use if the constructed one comes out blank.
Return values
stringa reasonable question name.

◆ create_dummy_question_representing_category()

qformat_default::create_dummy_question_representing_category ( string  $categoryname,
  $categoryinfo 
)
protectedinherited

Create 'dummy' question for category export.

Parameters
string$categorynamethe name of the category
object$categoryinfodescription of the category
Return values
stdClass'dummy' question for category

◆ defaultquestion() [1/2]

qformat_default::defaultquestion ( )
protectedinherited

return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields.

This should not be overridden.

Return values
objectdefault question

◆ defaultquestion() [2/2]

qformat_default::defaultquestion ( )
protectedinherited

return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields.

This should not be overridden.

Return values
objectdefault question

◆ error()

qformat_default::error (   $message,
  $text = '',
  $questionname = '' 
)
protectedinherited

Handle parsing error.

Parameters
string$messageinformation about error
string$textimported text that triggered the error
string$questionnameimported question name

◆ export_file_extension()

qformat_default::export_file_extension ( )
inherited
Return values
stringthe file extension (including .) that is normally used for files handled by this plugin.

Reimplemented in qformat_xml, qformat_xhtml, and qformat_gift.

◆ exportpostprocess()

qformat_default::exportpostprocess ( )
protectedinherited

Do an post-processing that may be required.

Return values
boolsuccess

◆ exportpreprocess()

qformat_default::exportpreprocess ( )
inherited

Do any pre-processing that may be required.

Parameters
boolsuccess

Reimplemented in qformat_aiken.

◆ exportprocess()

qformat_default::exportprocess (   $checkcapabilities = true)
inherited

Perform the export.

For most types this should not need to be overrided.

Parameters
bool$checkcapabilitiesWhether to check capabilities when exporting the questions.
Return values
stringThe content of the export.

◆ get_category_path()

qformat_default::get_category_path (   $id,
  $includecontext = true 
)
protectedinherited

get the category as a path (e.g., tom/dick/harry)

Parameters
intid the id of the most nested catgory
Return values
stringthe path

◆ getpath() [1/2]

qformat_based_on_xml::getpath (   $xml,
  $path,
  $default,
  $istext = false,
  $error = '' 
)
inherited

Return the value of a node, given a path to the node if it doesn't exist return the default value.

Parameters
arrayxml data to read
arraypath path to node expressed as array
mixeddefault
boolistext process as text
stringerror if set value must exist, return false and issue message if not
Return values
mixedvalue

◆ getpath() [2/2]

qformat_based_on_xml::getpath (   $xml,
  $path,
  $default,
  $istext = false,
  $error = '' 
)
inherited

Return the value of a node, given a path to the node if it doesn't exist return the default value.

Parameters
arrayxml data to read
arraypath path to node expressed as array
mixeddefault
boolistext process as text
stringerror if set value must exist, return false and issue message if not
Return values
mixedvalue

◆ importpostprocess()

qformat_blackboard_six_base::importpostprocess ( )
inherited

Does any post-processing that may be desired Clean the temporary directory if a zip file was imported.

Return values
boolsuccess

Reimplemented from qformat_default.

◆ importpreprocess()

qformat_default::importpreprocess ( )
inherited

Perform any required pre-processing.

Return values
boolsuccess

◆ importprocess()

qformat_default::importprocess ( )
inherited

Process the file This method should not normally be overidden.

Return values
boolsuccess

◆ presave_process()

qformat_default::presave_process (   $content)
protectedinherited

Enable any processing to be done on the content just prior to the file being saved default is to do nothing.

Parameters
stringoutput text
stringprocessed output text

Reimplemented in qformat_xml, and qformat_xhtml.

◆ process_category()

qformat_blackboard_six_pool::process_category (   $xml,
$questions 
)

Add a category question entry based on the pool file title.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_common()

qformat_blackboard_six_pool::process_common (   $questiondata)

Do question import processing common to every qtype.

Parameters
array$questiondatathe xml tree related to the current question
Return values
objectinitialized question object.

◆ process_essay()

qformat_blackboard_six_pool::process_essay (   $xml,
$questions 
)

Process Essay Questions.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_fib()

qformat_blackboard_six_pool::process_fib (   $xml,
$questions 
)

Process Fill in the Blank Questions.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_ma()

qformat_blackboard_six_pool::process_ma (   $xml,
$questions 
)

Process Multiple Choice Questions With Multiple Answers.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_matching()

qformat_blackboard_six_pool::process_matching (   $xml,
$questions 
)

Process Matching Questions.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_mc()

qformat_blackboard_six_pool::process_mc (   $xml,
$questions 
)

Process Multiple Choice Questions with single answer.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ process_tf()

qformat_blackboard_six_pool::process_tf (   $xml,
$questions 
)

Process True / False Questions.

Parameters
array$xmlthe xml tree
array$questionsthe questions already parsed

◆ provide_export()

qformat_default::provide_export ( )
inherited
Return values
boolwhether this plugin provides export functionality.

Reimplemented in qformat_xml, qformat_xhtml, qformat_gift, and qformat_aiken.

◆ provide_import()

qformat_blackboard_six_base::provide_import ( )
inherited

This plugin provide import.

Return values
booltrue

Reimplemented from qformat_default.

◆ readdata()

qformat_default::readdata (   $filename)
protectedinherited

Return complete file within an array, one item per line.

Parameters
stringfilename name of file
Return values
mixedcontents array or false on failure

Reimplemented in qformat_webct, and qformat_blackboard_six.

◆ readquestion()

qformat_default::readquestion (   $lines)
protectedinherited

Given the data known to define a question in this format, this function converts it into a question object suitable for processing and insertion into Moodle.

If your format does not use blank lines to delimit questions (e.g. an XML format) you must override 'readquestions' too

Parameters
$linesmixed data that represents question
Return values
objectquestion object

◆ readquestions()

qformat_blackboard_six_pool::readquestions (   $text)
protected

Parse the xml document into an array of questions.

This could burn memory - but it won't happen that much so fingers crossed!

Parameters
array$textarray of lines from the input file.
Return values
array(of objects) questions objects.

Reimplemented from qformat_default.

◆ set_can_access_backupdata()

qformat_default::set_can_access_backupdata (   $canaccess)
inherited
Parameters
bool$canaccessWhether the current use can access the backup data folder. Determines where export files are saved.

◆ set_display_progress()

qformat_default::set_display_progress (   $displayprogress)
inherited

Change whether to display progress messages.

There is normally no need to use this function as the default for $displayprogress is true. Set to false for unit tests.

Parameters
bool$displayprogress

◆ set_filebase()

qformat_blackboard_six_base::set_filebase (   $path)
inherited

Set the path to the root of images tree.

Parameters
string$pathpath to images root

◆ setCategory()

qformat_default::setCategory (   $category)
inherited

set the category

Parameters
objectcategory the category object

◆ setCatfromfile()

qformat_default::setCatfromfile (   $catfromfile)
inherited

set catfromfile

Parameters
boolcatfromfile allow categories embedded in import file

◆ setCattofile()

qformat_default::setCattofile (   $cattofile)
inherited

set cattofile

Parameters
boolcattofile exports categories within export file

◆ setContextfromfile()

qformat_default::setContextfromfile (   $contextfromfile)
inherited

set contextfromfile

Parameters
bool$contextfromfileallow contexts embedded in import file

◆ setContexts()

qformat_default::setContexts (   $contexts)
inherited

set an array of contexts.

Parameters
array$contextsMoodle course variable

◆ setContexttofile()

qformat_default::setContexttofile (   $contexttofile)
inherited

set contexttofile

Parameters
boolcattofile exports categories within export file

◆ setCourse()

qformat_default::setCourse (   $course)
inherited

set the course class variable

Parameters
courseobject Moodle course variable

◆ setFilename()

qformat_default::setFilename (   $filename)
inherited

set the filename

Parameters
stringfilename name of file to import/export

◆ setMatchgrades()

qformat_default::setMatchgrades (   $matchgrades)
inherited

set matchgrades

Parameters
stringmatchgrades error or nearest for grades

◆ setQuestions()

qformat_default::setQuestions (   $questions)
inherited

Set the specific questions to export.

Should not include questions with parents (sub questions of cloze question type). Only used for question export.

Parameters
arrayof question objects

◆ setRealfilename()

qformat_default::setRealfilename (   $realfilename)
inherited

set the "real" filename (this is what the user typed, regardless of wha happened next)

Parameters
stringrealfilename name of file as typed by user

◆ setStoponerror()

qformat_default::setStoponerror (   $stoponerror)
inherited

set stoponerror

Parameters
boolstoponerror stops database write if any errors reported

◆ split_category_path()

qformat_default::split_category_path (   $path)
protectedinherited

Convert a string, as returned by assemble_category_path(), back into an array of category names.

Each category name is cleaned by a call to clean_param(, PARAM_TEXT), which matches the cleaning in question/category_form.php.

Parameters
string$path
Return values
arrayof category names.

◆ store_file_for_text_field()

qformat_blackboard_six_base::store_file_for_text_field ( $text,
  $tempdir,
  $filepathinsidetempdir,
  $filename 
)
protectedinherited

Store an image file in a draft filearea.

Parameters
array$text,ifitemid element don't exists it will be created
string$tempdirpath to root of image tree
string$filepathinsidetempdirpath to image in the tree
string$filenameimage's name
Return values
stringnew name of the image as it was stored

◆ text_field()

qformat_blackboard_six_base::text_field (   $text)
inherited

Given an HTML text with references to images files, store all images in a draft filearea, and return an array with all urls in text recoded, format set to FORMAT_HTML, and itemid set to filearea itemid.

Parameters
string$texttext to parse and recode
Return values
arraywith keys text, format, itemid.

Reimplemented from qformat_based_on_xml.

◆ try_exporting_using_qtypes()

qformat_default::try_exporting_using_qtypes (   $name,
  $question,
  $extra = null 
)
protectedinherited

Provide export functionality for plugin questiontypes Do not override.

Parameters
namequestiontype name
questionobject data to export
extramixed any addition format specific data needed
Return values
stringthe data to append to export or false if error (or unhandled)

◆ try_importing_using_qtypes() [1/2]

qformat_default::try_importing_using_qtypes (   $data,
  $question = null,
  $extra = null,
  $qtypehint = '' 
)
inherited

Import for questiontype plugins.

Parameters
mixed$dataThe segment of data containing the question
object$questionprocessed (so far) by standard import code if appropriate
object$extramixed any additional format specific data that may be passed by the format
string$qtypehinthint about a question type from format
Return values
objectquestion object suitable for save_options() or false if cannot handle

◆ try_importing_using_qtypes() [2/2]

qformat_default::try_importing_using_qtypes (   $data,
  $question = null,
  $extra = null,
  $qtypehint = '' 
)
inherited

Import for questiontype plugins Do not override.

Parameters
datamixed The segment of data containing the question
questionobject processed (so far) by standard import code if appropriate
extramixed any additional format specific data that may be passed by the format
qtypehinthint about a question type from format
Return values
objectquestion object suitable for save_options() or false if cannot handle

◆ writequestion()

qformat_default::writequestion (   $question)
protectedinherited

convert a single question object into text output in the given format.

This must be overriden

Parameters
objectquestion question object
Return values
mixedquestion export text or null if not implemented

Reimplemented in qformat_xml, qformat_xhtml, qformat_gift, and qformat_aiken.

Member Data Documentation

◆ $qtypeconvert

qformat_default::$qtypeconvert
inherited
Initial value:
= array('numerical' => LESSON_PAGE_NUMERICAL,
'multichoice' => LESSON_PAGE_MULTICHOICE,
'truefalse' => LESSON_PAGE_TRUEFALSE,
'shortanswer' => LESSON_PAGE_SHORTANSWER,
'essay' => LESSON_PAGE_ESSAY
)

The documentation for this class was generated from the following file:
LESSON_PAGE_MATCHING
const LESSON_PAGE_MATCHING
Matching question type.
Definition: matching.php:29
LESSON_PAGE_SHORTANSWER
const LESSON_PAGE_SHORTANSWER
Short answer question type.
Definition: shortanswer.php:29
LESSON_PAGE_MULTICHOICE
const LESSON_PAGE_MULTICHOICE
Multichoice question type.
Definition: multichoice.php:29
LESSON_PAGE_ESSAY
const LESSON_PAGE_ESSAY
Essay question type.
Definition: essay.php:29
LESSON_PAGE_NUMERICAL
const LESSON_PAGE_NUMERICAL
Numerical question type.
Definition: numerical.php:29
LESSON_PAGE_TRUEFALSE
const LESSON_PAGE_TRUEFALSE
True/False question type.
Definition: truefalse.php:29