ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assMatchingQuestion Class Reference

Class for matching questions. More...

+ Inheritance diagram for assMatchingQuestion:
+ Collaboration diagram for assMatchingQuestion:

Public Member Functions

 __construct ( $title="", $comment="", $author="", $owner=-1, $question="", $matching_type=self::MT_TERMS_DEFINITIONS)
 assMatchingQuestion constructor More...
 
 getShuffleMode ()
 
 setShuffleMode (int $shuffle)
 
 isComplete ()
 
 saveToDb (?int $original_id=null)
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
 loadFromDb ($question_id)
 Loads a assMatchingQuestion object from a database. More...
 
 insertMatchingPair ($position, $term=null, $definition=null, $points=0.0)
 Inserts a matching pair for an matching choice question. More...
 
 addMatchingPair (?assAnswerMatchingTerm $term=null, ?assAnswerMatchingDefinition $definition=null, $points=0.0)
 Adds an matching pair for an matching choice question. More...
 
 getTermWithIdentifier ($a_identifier)
 Returns a term with a given identifier. More...
 
 getDefinitionWithIdentifier ($a_identifier)
 Returns a definition with a given identifier. More...
 
 getMatchingPair ($index=0)
 Returns a matching pair with a given index. More...
 
 deleteMatchingPair ($index=0)
 Deletes a matching pair with a given index. More...
 
 flushMatchingPairs ()
 Deletes all matching pairs. More...
 
 withMatchingPairs (array $pairs)
 
 getMatchingPairCount ()
 Returns the number of matching pairs. More...
 
 getTerms ()
 Returns the terms of the matching question. More...
 
 getDefinitions ()
 Returns the definitions of the matching question. More...
 
 getTermCount ()
 Returns the number of terms. More...
 
 getDefinitionCount ()
 Returns the number of definitions. More...
 
 addTerm (assAnswerMatchingTerm $term)
 
 addDefinition ($definition)
 Adds a definition. More...
 
 insertTerm ($position, ?assAnswerMatchingTerm $term=null)
 Inserts a term. More...
 
 insertDefinition ($position, ?assAnswerMatchingDefinition $definition=null)
 Inserts a definition. More...
 
 flushTerms ()
 Deletes all terms. More...
 
 flushDefinitions ()
 Deletes all definitions. More...
 
 deleteTerm ($position)
 Deletes a term. More...
 
 deleteDefinition ($position)
 Deletes a definition. More...
 
 setTerm ($term, $index)
 Sets a specific term. More...
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getMaximumPoints ()
 Calculates and Returns the maximum points, a learner can reach answering the question. More...
 
 getMaximumScoringMatchingPairs ()
 
 fetchIndexedValuesFromValuePairs (array $valuePairs)
 
 getEncryptedFilename ($filename)
 Returns the encrypted save filename of a matching picture Images are saved with an encrypted filename to prevent users from cheating by guessing the solution from the image filename. More...
 
 removeTermImage ($index)
 
 removeDefinitionImage ($index)
 
 deleteImagefile (string $filename)
 Deletes an imagefile from the system if the file is deleted manually. More...
 
 setImageFile (string $image_tempfilename, string $image_filename, string $previous_filename='')
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 getRandomId ()
 
 setShuffle ($shuffle=true)
 
 getQuestionType ()
 Returns the question type of the question. More...
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 getRTETextWithMediaObjects ()
 Collects all text in the question which could contain media objects which were created with the Rich Text Editor. More...
 
 getMatchingPairs ()
 Returns the matchingpairs array. More...
 
 getThumbGeometry ()
 Get the thumbnail geometry. More...
 
 getThumbSize ()
 Get the thumbnail geometry. More...
 
 setThumbGeometry (int $a_geometry)
 Set the thumbnail geometry. More...
 
 rebuildThumbnails ()
 Rebuild the thumbnail images with a new thumbnail size. More...
 
 getThumbPrefix ()
 
 toJSON ()
 Returns a JSON representation of the question. More...
 
 setMatchingMode (string $matching_mode)
 
 getMatchingMode ()
 
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions ($index=null)
 If index is null, the function returns an array with all anwser options Else it returns the specific answer option. More...
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
- Public Member Functions inherited from assQuestion
 getQuestionType ()
 
 isComplete ()
 
 saveWorkingData (int $active_id, ?int $pass=null, bool $authorized=true)
 
 calculateReachedPoints (int $active_id, ?int $pass=null, bool $authorized_solution=true)
 
 getAdditionalTableName ()
 
 getAnswerTableName ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 MUST return an array of the question settings that can be stored in the log. More...
 
 getCurrentUser ()
 
 getShuffler ()
 
 setShuffler (Transformation $shuffler)
 
 setProcessLocker (ilAssQuestionProcessLocker $processLocker)
 
 getProcessLocker ()
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 toXML (bool $a_include_header=true, bool $a_include_binary=true, bool $a_shuffle=false, bool $test_output=false, bool $force_image_references=false)
 Returns a QTI xml representation of the question. More...
 
 setTitle (string $title="")
 
 setId (int $id=-1)
 
 setTestId (int $id=-1)
 
 setComment (string $comment="")
 
 setShuffle (?bool $shuffle=true)
 
 setAuthor (string $author="")
 
 setOwner (int $owner=-1)
 
 getTitle ()
 
 getTitleForHTMLOutput ()
 
 getTitleFilenameCompliant ()
 
 getId ()
 
 getShuffle ()
 
 getTestId ()
 
 getComment ()
 
 getDescriptionForHTMLOutput ()
 
 getThumbSize ()
 
 setThumbSize (int $a_size)
 
 getMinimumThumbSize ()
 
 getMaximumThumbSize ()
 
 getAuthor ()
 
 getAuthorForHTMLOutput ()
 
 getOwner ()
 
 getObjId ()
 
 setObjId (int $obj_id=0)
 
 getLifecycle ()
 
 setLifecycle (ilAssQuestionLifecycle $lifecycle)
 
 setExternalId (?string $external_id)
 
 getExternalId ()
 
 getSuggestedSolutionOutput ()
 
 getSuggestedSolutions ()
 
 getReachedPoints (int $active_id, int $pass)
 
 getMaximumPoints ()
 
 getAdjustedReachedPoints (int $active_id, int $pass, bool $authorized_solution=true)
 
 calculateResultsFromSolution (int $active_id, int $pass)
 Calculates the question results from a previously saved question solution. More...
 
 persistWorkingState (int $active_id, $pass, bool $authorized=true)
 persists the working state for current testactive and testpass More...
 
 persistPreviewState (ilAssQuestionPreviewSession $preview_session)
 persists the preview state for current user and question More...
 
 validateSolutionSubmit ()
 
 getSuggestedSolutionPath ()
 
 getImagePath ($question_id=null, $object_id=null)
 Returns the image path for web accessable images of a question. More...
 
 getSuggestedSolutionPathWeb ()
 
 getImagePathWeb ()
 Returns the web image path for web accessable images of a question. More...
 
 getTestOutputSolutions (int $activeId, int $pass)
 
 getUserSolutionPreferingIntermediate (int $active_id, ?int $pass=null)
 
 getSolutionValues (int $active_id, ?int $pass=null, bool $authorized=true)
 Loads solutions of a given user from the database an returns it. More...
 
 deleteAnswers (int $question_id)
 
 deleteAdditionalTableData (int $question_id)
 
 delete (int $question_id)
 
 getTotalAnswers ()
 
 cloneXHTMLMediaObjectsOfQuestion (int $source_question_id)
 
 createPageObject ()
 
 clonePageOfQuestion (int $a_q_id)
 
 getPageOfQuestion ()
 
 setOriginalId (?int $original_id)
 
 getOriginalId ()
 
 fixSvgToPng (string $imageFilenameContainingString)
 
 fixUnavailableSkinImageSources (string $html)
 
 loadFromDb (int $question_id)
 
 createNewQuestion (bool $a_create_page=true)
 Creates a new question without an owner when a new question is created This assures that an ID is given to the question if a file upload or something else occurs. More...
 
 saveQuestionDataToDb (?int $original_id=null)
 
 duplicate (bool $for_test=true, string $title='', string $author='', int $owner=-1, $test_obj_id=null)
 
 copyObject (int $target_parent_id, string $title='')
 
 createNewOriginalFromThisDuplicate (int $target_parent_id, string $target_question_title='')
 
 saveToDb (?int $original_id=null)
 
 deleteSuggestedSolutions ()
 
 getSuggestedSolution (int $subquestion_index=0)
 
 resolveInternalLink (string $internal_link)
 
 resolveSuggestedSolutionLinks ()
 
 getInternalLinkHref (string $target)
 
 syncWithOriginal ()
 
 getPoints ()
 
 setPoints (float $points)
 
 getSolutionMaxPass (int $active_id)
 
 isWriteable ()
 
 calculateReachedPointsFromPreviewSession (ilAssQuestionPreviewSession $preview_session)
 
 isPreviewSolutionCorrect (ilAssQuestionPreviewSession $preview_session)
 
 adjustReachedPointsByScoringOptions (float $points, int $active_id)
 Adjust the given reached points by checks for all special scoring options in the test container. More...
 
 buildHashedImageFilename (string $plain_image_filename, bool $unique=false)
 
 getQuestion ()
 
 getQuestionForHTMLOutput ()
 
 setQuestion (string $question="")
 
 getQuestionTypeID ()
 
 cleanupMediaObjectUsage ()
 
 getInstances ()
 
 getActiveUserData (int $active_id)
 Returns the user id and the test id for a given active id. More...
 
 hasSpecificFeedback ()
 
 getNrOfTries ()
 
 setNrOfTries (int $a_nr_of_tries)
 
 setExportImagePath (string $path)
 
 formatSAQuestion ($a_q)
 
 setPreventRteUsage (bool $prevent_rte_usage)
 
 getPreventRteUsage ()
 
 migrateContentForLearningModule (ilAssSelfAssessmentMigrator $migrator)
 
 setSelfAssessmentEditingMode (bool $selfassessmenteditingmode)
 
 getSelfAssessmentEditingMode ()
 
 setDefaultNrOfTries (int $defaultnroftries)
 
 getDefaultNrOfTries ()
 
 syncSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 isAnswered (int $active_id, int $pass)
 
 getAdditionalContentEditingMode ()
 
 setAdditionalContentEditingMode (?string $additionalContentEditingMode)
 
 isAdditionalContentEditingModePageObject ()
 
 isValidAdditionalContentEditingMode (string $additionalContentEditingMode)
 
 getValidAdditionalContentEditingModes ()
 
 getHtmlUserSolutionPurifier ()
 
 getHtmlQuestionContentPurifier ()
 
 setLastChange (int $lastChange)
 
 getLastChange ()
 
 removeIntermediateSolution (int $active_id, int $pass)
 
 removeCurrentSolution (int $active_id, int $pass, bool $authorized=true)
 
 saveCurrentSolution (int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
 
 updateCurrentSolution (int $solutionId, $value1, $value2, bool $authorized=true)
 
 updateCurrentSolutionsAuthorization (int $activeId, int $pass, bool $authorized, bool $keepTime=false)
 
 setStep ($step)
 
 getStep ()
 
 toJSON ()
 
 intermediateSolutionExists (int $active_id, int $pass)
 
 authorizedSolutionExists (int $active_id, ?int $pass)
 
 authorizedOrIntermediateSolutionExists (int $active_id, int $pass)
 
 lookupForExistingSolutions (int $activeId, int $pass)
 Lookup if an authorized or intermediate solution exists. More...
 
 isAddableAnswerOptionValue (int $qIndex, string $answerOptionValue)
 
 addAnswerOptionValue (int $qIndex, string $answerOptionValue, float $points)
 
 removeAllExistingSolutions ()
 
 removeExistingSolutions (int $activeId, int $pass)
 
 resetUsersAnswer (int $activeId, int $pass)
 
 removeResultRecord (int $activeId, int $pass)
 
 fetchValuePairsFromIndexedValues (array $indexedValues)
 
 fetchIndexedValuesFromValuePairs (array $value_pairs)
 
 updateTimestamp ()
 
 getTestPresentationConfig ()
 
 hasWritableOriginalInQuestionPool ()
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_ref_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 getSolutionForTextOutput (int $active_id, int $pass)
 
 getCorrectSolutionForTextOutput (int $active_id, int $pass)
 
 getVariablesAsTextArray (int $active_id, int $pass)
 
 validateSolutionSubmit ()
 
 toLog (AdditionalInformationGenerator $additional_info)
 
 answerToParticipantInteraction (AdditionalInformationGenerator $additional_info, int $test_id, int $active_id, int $pass, string $source_ip, TestParticipantInteractionTypes $interaction_type)
 
 toQuestionAdministrationInteraction (AdditionalInformationGenerator $additional_info, int $test_id, TestQuestionAdministrationInteractionTypes $interaction_type)
 
 saveAdditionalQuestionDataToDb ()
 Saves a record to the question types additional data table. More...
 
 saveAnswerSpecificDataToDb ()
 Saves the answer specific records into a question types answer table. More...
 
- Public Member Functions inherited from iQuestionCondition
 getOperators (string $expression)
 Get all available operations for a specific question. More...
 
 getExpressionTypes ()
 Get all available expression types for a specific question. More...
 
 getUserQuestionResult (int $active_id, int $pass)
 Get the user solution for a question by active_id and the test pass. More...
 
 getAvailableAnswerOptions (?int $index=null)
 If index is null, the function returns an array with all anwser options else it returns the specific answer option. More...
 
 toJSON ()
 

Data Fields

const MT_TERMS_PICTURES = 0
 
const MT_TERMS_DEFINITIONS = 1
 
const MATCHING_MODE_1_ON_1 = '1:1'
 
const MATCHING_MODE_N_ON_N = 'n:n'
 
int $thumb_geometry = 100
 
int $element_height
 
int $matching_type
 
 $matchingpairs
 
- Data Fields inherited from assQuestion
const ADDITIONAL_CONTENT_EDITING_MODE_RTE = 'default'
 
const ADDITIONAL_CONTENT_EDITING_MODE_IPE = 'pageobject'
 
const TRIM_PATTERN = '/^[\p{C}\p{Z}]+|[\p{C}\p{Z}]+$/u'
 
ilAssQuestionFeedback $feedbackOBJ
 
bool $prevent_rte_usage = false
 
bool $selfassessmenteditingmode = false
 
int $defaultnroftries = 0
 
string $questionActionCmd = 'handleQuestionAction'
 
const KEY_VALUES_IMPLOSION_SEPARATOR = ':'
 
- Data Fields inherited from iQuestionCondition
const StringResultExpression = '~TEXT~'
 
const PercentageResultExpression = '%n%'
 
const NumericResultExpression = '#n#'
 
const MatchingResultExpression = ';n:m;'
 
const OrderingResultExpression = '$n,m,o,p$'
 
const NumberOfResultExpression = '+n+'
 
const ExclusiveResultExpression = '*n,m,o,p*'
 
const EmptyAnswerExpression = "?"
 

Protected Member Functions

 cloneQuestionTypeSpecificProperties (\assQuestion $target)
 
 savePreviewData (ilAssQuestionPreviewSession $previewSession)
 
 generateThumbForFile ($path, $file)
 
 calculateReachedPointsForSolution (?array $found_values)
 
 afterSyncWithOriginal (int $original_question_id, int $clone_question_id, int $original_parent_id, int $clone_parent_id)
 {} More...
 
 createMatchingTerm (string $term='', string $picture='', int $identifier=0)
 
 createMatchingDefinition (string $term='', string $picture='', int $identifier=0)
 
 createMatchingPair (?assAnswerMatchingTerm $term=null, ?assAnswerMatchingDefinition $definition=null, float $points=0.0)
 
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
- Protected Member Functions inherited from assQuestion
 solutionValuesToLog (AdditionalInformationGenerator $additional_info, array $solution_values)
 MUST convert the given solution values into an array or a string that can be stored in the log. More...
 
 solutionValuesToText (array $solution_values)
 MUST convert the given solution values into text. More...
 
 getQuestionAction ()
 
 isNonEmptyItemListPostSubmission (string $post_submission_field_name)
 
 savePreviewData (ilAssQuestionPreviewSession $preview_session)
 
 deletePageOfQuestion (int $question_id)
 
 cloneQuestionTypeSpecificProperties (self $target)
 
 removeAllImageFiles (string $image_target_path)
 
 onDuplicate (int $original_parent_id, int $original_question_id, int $duplicate_parent_id, int $duplicate_question_id)
 
 afterSyncWithOriginal (int $original_question_id, int $clone_question_id, int $original_parent_id, int $clone_parent_id)
 
 onCopy (int $sourceParentId, int $sourceQuestionId, int $targetParentId, int $targetQuestionId)
 
 duplicateComments (int $parent_source_id, int $source_id, int $parent_target_id, int $target_id)
 
 deleteComments ()
 
 getNotesManager ()
 
 getNotesDataService ()
 
 getNotesRepo ()
 
 cloneSuggestedSolutions (int $source_question_id, int $target_question_id)
 
 duplicateSuggestedSolutionFiles (int $parent_id, int $question_id)
 Duplicates the files of a suggested solution if the question is duplicated. More...
 
 cloneSuggestedSolutionFiles (int $source_question_id, int $target_question_id)
 
 copySuggestedSolutions (int $target_question_id)
 
 ensureNonNegativePoints (float $points)
 
 purifyAndPrepareTextAreaOutput (string $content)
 
 getRTETextWithMediaObjects ()
 
 getSelfAssessmentFormatter ()
 
 lmMigrateQuestionTypeGenericContent (ilAssSelfAssessmentMigrator $migrator)
 
 lmMigrateQuestionTypeSpecificContent (ilAssSelfAssessmentMigrator $migrator)
 
 duplicateSkillAssignments (int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
 
 buildQuestionDataQuery ()
 
 getCurrentSolutionResultSet (int $active_id, int $pass, bool $authorized=true)
 
 removeSolutionRecordById (int $solutionId)
 
 getSolutionRecordById (int $solutionId)
 
 deleteDummySolutionRecord (int $activeId, int $passIndex)
 
 isDummySolutionRecord (array $solutionRecord)
 
 deleteSolutionRecordByValues (int $activeId, int $passIndex, bool $authorized, array $matchValues)
 
 duplicateIntermediateSolutionAuthorized (int $activeId, int $passIndex)
 
 forceExistingIntermediateSolution (int $activeId, int $passIndex, bool $considerDummyRecordCreation)
 
 lookupMaxStep (int $active_id, int $pass)
 
 buildTestPresentationConfig ()
 
 getSuggestedSolutionsRepo ()
 
 loadSuggestedSolutions ()
 
 answerToLog (AdditionalInformationGenerator $additional_info, int $active_id, int $pass)
 

Protected Attributes

string $matching_mode = self::MATCHING_MODE_1_ON_1
 
array $terms = []
 
array $definitions = []
 
- Protected Attributes inherited from assQuestion
const HAS_SPECIFIC_FEEDBACK = true
 
GeneralQuestionPropertiesRepository $questionrepository
 
RequestDataCollector $questionpool_request
 
QuestionFiles $question_files
 
ilAssQuestionProcessLocker $processLocker
 
ilTestQuestionConfig $testQuestionConfig
 
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo
 
ILIAS $ilias
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilDBInterface $db
 
ilObjUser $current_user
 
SkillUsageService $skillUsageService
 
HTTPServices $http
 
Refinery $refinery
 
Transformation $shuffler
 
LoggingServices $log
 
Container $dic
 
ilAssQuestionLifecycle $lifecycle
 
ilAssQuestionPage $page
 
TestResultRepository $test_result_repository
 
int $id
 
string $title
 
string $comment
 
int $owner
 
string $author
 
int $thumb_size
 
string $question
 
float $points = 0.0
 
bool $shuffle = true
 
int $test_id
 
int $obj_id = 0
 
int $original_id = null
 
int $lastChange = null
 
string $external_id = null
 
int $step = null
 
array $suggested_solutions
 

Private Member Functions

 cloneImages (int $source_question_id, int $source_parent_id, int $target_question_id, int $target_parent_id)
 
 getPositiveScoredMatchingPairs ()
 
 getMostPositiveScoredUniqueTermMatchingPairs ()
 
 checkSubmittedMatchings (array $submitted_matchings)
 

Private Attributes

int $shufflemode = 0
 
RandomGroup $randomGroup
 

Additional Inherited Members

- Static Public Member Functions inherited from assQuestion
static setForcePassResultUpdateEnabled (bool $force_pass_results_update_enabled)
 
static isForcePassResultUpdateEnabled ()
 
static _getSuggestedSolutionOutput (int $question_id)
 
static _getReachedPoints (int $active_id, int $question_id, int $pass)
 
static isFileAvailable (string $file)
 
static saveOriginalId (int $questionId, int $originalId)
 
static resetOriginalId (int $questionId)
 
static instantiateQuestion (int $question_id)
 
static _getSolutionMaxPass (int $question_id, int $active_id)
 Returns the maximum pass a users question solution. More...
 
static getFeedbackClassNameByQuestionType (string $questionType)
 
static _questionExistsInTest (int $question_id, int $test_id)
 
static lookupParentObjId (int $question_id)
 
static implodeKeyValues (array $keyValues)
 
static explodeKeyValues (string $keyValues)
 
static convertISO8601FormatH_i_s_ExtendedToSeconds (string $time)
 
static extendedTrim (string $value)
 Trim non-printable characters from the beginning and end of a string. More...
 
- Static Protected Member Functions inherited from assQuestion
static getNumExistingSolutionRecords (int $activeId, int $pass, int $questionId)
 
- Static Protected Attributes inherited from assQuestion
static $force_pass_results_update_enabled = false
 
static $imageSourceFixReplaceMap
 

Detailed Description

Class for matching questions.

assMatchingQuestion is a class for matching questions.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Björn Heyser bheys.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 40 of file class.assMatchingQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

assMatchingQuestion::__construct (   $title = "",
  $comment = "",
  $author = "",
  $owner = -1,
  $question = "",
  $matching_type = self::MT_TERMS_DEFINITIONS 
)

assMatchingQuestion constructor

The constructor takes possible arguments an creates an instance of the assMatchingQuestion object.

Parameters
string$titleA title string to describe the question
string$commentA comment string to describe the question
string$authorA string containing the name of the questions author
integer$ownerA numerical ID to identify the owner/creator
string$questionThe question string of the matching question
int$matching_type

Definition at line 87 of file class.assMatchingQuestion.php.

94 {
95 global $DIC;
96
98 $this->matchingpairs = [];
99 $this->matching_type = $matching_type;
100 $this->terms = [];
101 $this->definitions = [];
102 $this->randomGroup = $DIC->refinery()->random();
103 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References assQuestion\$author, assQuestion\$comment, $DIC, $matching_type, assQuestion\$owner, assQuestion\$question, assQuestion\$title, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ addDefinition()

assMatchingQuestion::addDefinition (   $definition)

Adds a definition.

Parameters
object$definitionThe definition
See also
$definitions

Definition at line 584 of file class.assMatchingQuestion.php.

584 : void
585 {
586 array_push($this->definitions, $definition);
587 }

◆ addMatchingPair()

assMatchingQuestion::addMatchingPair ( ?assAnswerMatchingTerm  $term = null,
?assAnswerMatchingDefinition  $definition = null,
  $points = 0.0 
)

Adds an matching pair for an matching choice question.

The students have to fill in an order for the matching pair. The matching pair is an ASS_AnswerMatching object that will be created and assigned to the array $this->matchingpairs.

Parameters
assAnswerMatchingTerm | null$termA matching term
assAnswerMatchingDefinition | null$definitionA matching definition
float$pointsThe points for selecting the matching pair, incl. negative.
See also
$matchingpairs

Definition at line 422 of file class.assMatchingQuestion.php.

422 : void
423 {
424 $pair = $this->createMatchingPair($term, $definition, $points);
425 array_push($this->matchingpairs, $pair);
426 }
createMatchingPair(?assAnswerMatchingTerm $term=null, ?assAnswerMatchingDefinition $definition=null, float $points=0.0)

◆ addTerm()

assMatchingQuestion::addTerm ( assAnswerMatchingTerm  $term)

Definition at line 573 of file class.assMatchingQuestion.php.

573 : void
574 {
575 $this->terms[] = $term;
576 }

◆ afterSyncWithOriginal()

assMatchingQuestion::afterSyncWithOriginal ( int  $original_question_id,
int  $clone_question_id,
int  $original_parent_id,
int  $clone_parent_id 
)
protected

{}

Reimplemented from assQuestion.

Definition at line 1309 of file class.assMatchingQuestion.php.

1314 : void {
1315 parent::afterSyncWithOriginal($original_question_id, $clone_question_id, $original_parent_id, $clone_parent_id);
1316
1317 $original_image_path = $this->question_files->buildImagePath($original_question_id, $original_parent_id);
1318 $clone_image_path = $this->question_files->buildImagePath($clone_question_id, $clone_parent_id);
1319
1320 ilFileUtils::delDir($original_image_path);
1321 if (is_dir($clone_image_path)) {
1322 ilFileUtils::makeDirParents($original_image_path);
1323 ilFileUtils::rCopy($clone_image_path, $original_image_path);
1324 }
1325 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

◆ calculateReachedPoints()

assMatchingQuestion::calculateReachedPoints ( int  $active_id,
?int  $pass = null,
bool  $authorized_solution = true 
)

Reimplemented from assQuestion.

Definition at line 683 of file class.assMatchingQuestion.php.

687 : float {
688 $found_values = [];
689 if (is_null($pass)) {
690 $pass = $this->getSolutionMaxPass($active_id);
691 }
692 $result = $this->getCurrentSolutionResultSet($active_id, (int) $pass, $authorized_solution);
693 while ($data = $this->db->fetchAssoc($result)) {
694 if ($data['value1'] === '') {
695 continue;
696 }
697
698 if (!isset($found_values[$data['value2']])) {
699 $found_values[$data['value2']] = [];
700 }
701
702 $found_values[$data['value2']][] = $data['value1'];
703 }
704
705 $points = $this->calculateReachedPointsForSolution($found_values);
706
707 return $points;
708 }
calculateReachedPointsForSolution(?array $found_values)
getCurrentSolutionResultSet(int $active_id, int $pass, bool $authorized=true)
getSolutionMaxPass(int $active_id)

◆ calculateReachedPointsForSolution()

assMatchingQuestion::calculateReachedPointsForSolution ( ?array  $found_values)
protected

Definition at line 1194 of file class.assMatchingQuestion.php.

1194 : float
1195 {
1196 $points = 0.0;
1197 if (!is_array($found_values)) {
1198 return $points;
1199 }
1200 foreach ($found_values as $definition => $terms) {
1201 if (!is_array($terms)) {
1202 continue;
1203 }
1204 foreach ($terms as $term) {
1205 foreach ($this->matchingpairs as $pair) {
1206 if ($pair->getDefinition()->getIdentifier() == $definition
1207 && $pair->getTerm()->getIdentifier() == $term) {
1208 $points += $pair->getPoints();
1209 }
1210 }
1211 }
1212 }
1213 return $points;
1214 }

◆ checkSubmittedMatchings()

assMatchingQuestion::checkSubmittedMatchings ( array  $submitted_matchings)
private

Definition at line 887 of file class.assMatchingQuestion.php.

887 : bool
888 {
889 if ($this->getMatchingMode() == self::MATCHING_MODE_N_ON_N) {
890 return true;
891 }
892
893 $handledTerms = [];
894
895 foreach ($submitted_matchings as $terms) {
896 if (count($terms) > 1) {
897 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("multiple_matching_values_selected"), true);
898 return false;
899 }
900
901 foreach ($terms as $i => $term) {
902 if (isset($handledTerms[$term])) {
903 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("duplicate_matching_values_selected"), true);
904 return false;
905 }
906
907 $handledTerms[$term] = $term;
908 }
909 }
910
911 return true;
912 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ cloneImages()

assMatchingQuestion::cloneImages ( int  $source_question_id,
int  $source_parent_id,
int  $target_question_id,
int  $target_parent_id 
)
private

Definition at line 330 of file class.assMatchingQuestion.php.

335 : void {
336 $image_source_path = $this->getImagePath($source_question_id, $source_parent_id);
337 $image_target_path = $this->getImagePath($target_question_id, $target_parent_id);
338
339 if (!file_exists($image_target_path)) {
340 ilFileUtils::makeDirParents($image_target_path);
341 } else {
342 $this->removeAllImageFiles($image_target_path);
343 }
344
345 foreach ($this->terms as $term) {
346 if ($term->getPicture() === '') {
347 continue;
348 }
349
350 $filename = $term->getPicture();
351 if (!file_exists($image_source_path . $filename)
352 || !copy($image_source_path . $filename, $image_target_path . $filename)) {
353 $this->log->root()->warning('matching question image could not be copied: '
354 . $image_source_path . $filename);
355 }
356 if (!file_exists($image_source_path . $this->getThumbPrefix() . $filename)
357 || !copy(
358 $image_source_path . $this->getThumbPrefix() . $filename,
359 $image_target_path . $this->getThumbPrefix() . $filename
360 )) {
361 $this->log->root()->warning('matching question image thumbnail could not be copied: '
362 . $image_source_path . $this->getThumbPrefix() . $filename);
363 }
364 }
365 foreach ($this->definitions as $definition) {
366 if ($definition->getPicture() === '') {
367 continue;
368 }
369 $filename = $definition->getPicture();
370
371 if (!file_exists($image_source_path . $filename)
372 || !copy($image_source_path . $filename, $image_target_path . $filename)) {
373 $this->log->root()->warning('matching question image could not be copied: '
374 . $image_source_path . $filename);
375 }
376
377 if (!file_exists($image_source_path . $this->getThumbPrefix() . $filename)
378 || !copy(
379 $image_source_path . $this->getThumbPrefix() . $filename,
380 $image_target_path . $this->getThumbPrefix() . $filename
381 )) {
382 $this->log->root()->warning('matching question image thumbnail could not be copied: '
383 . $image_source_path . $this->getThumbPrefix() . $filename);
384 }
385 }
386 }
$filename
Definition: buildRTE.php:78
removeAllImageFiles(string $image_target_path)
getImagePath($question_id=null, $object_id=null)
Returns the image path for web accessable images of a question.

◆ cloneQuestionTypeSpecificProperties()

assMatchingQuestion::cloneQuestionTypeSpecificProperties ( \assQuestion  $target)
protected

Definition at line 323 of file class.assMatchingQuestion.php.

325 : \assQuestion {
326 $target->cloneImages($this->getId(), $this->getObjId(), $target->getId(), $target->getObjId());
327 return $target;
328 }

◆ createMatchingDefinition()

assMatchingQuestion::createMatchingDefinition ( string  $term = '',
string  $picture = '',
int  $identifier = 0 
)
protected

Definition at line 1331 of file class.assMatchingQuestion.php.

1332 {
1333 return new assAnswerMatchingDefinition($term, $picture, $identifier);
1334 }
Class for matching question definitions.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ createMatchingPair()

assMatchingQuestion::createMatchingPair ( ?assAnswerMatchingTerm  $term = null,
?assAnswerMatchingDefinition  $definition = null,
float  $points = 0.0 
)
protected

Definition at line 1335 of file class.assMatchingQuestion.php.

1340 $term = $term ?? $this->createMatchingTerm();
1341 $definition = $definition ?? $this->createMatchingDefinition();
1342 return new assAnswerMatchingPair($term, $definition, $points);
1343 }
Class for matching question pairs.
createMatchingDefinition(string $term='', string $picture='', int $identifier=0)
createMatchingTerm(string $term='', string $picture='', int $identifier=0)

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ createMatchingTerm()

assMatchingQuestion::createMatchingTerm ( string  $term = '',
string  $picture = '',
int  $identifier = 0 
)
protected

Definition at line 1327 of file class.assMatchingQuestion.php.

1328 {
1329 return new assAnswerMatchingTerm($term, $picture, $identifier);
1330 }
Class for matching question terms.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ deleteDefinition()

assMatchingQuestion::deleteDefinition (   $position)

Deletes a definition.

Parameters
integer$positionThe position of the definition in the definition array
See also
$definitions

Definition at line 665 of file class.assMatchingQuestion.php.

665 : void
666 {
667 unset($this->definitions[$position]);
668 $this->definitions = array_values($this->definitions);
669 }

◆ deleteImagefile()

assMatchingQuestion::deleteImagefile ( string  $filename)

Deletes an imagefile from the system if the file is deleted manually.

Parameters
string$filenameImage file filename
Returns
boolean Success

Definition at line 832 of file class.assMatchingQuestion.php.

832 : bool
833 {
834 $deletename = $filename;
835 try {
836 $result = unlink($this->getImagePath() . $deletename)
837 && unlink($this->getImagePath() . $this->getThumbPrefix() . $deletename);
838 } catch (Throwable $e) {
839 $result = false;
840 }
841 return $result;
842 }

References Vendor\Package\$e, and $filename.

◆ deleteMatchingPair()

assMatchingQuestion::deleteMatchingPair (   $index = 0)

Deletes a matching pair with a given index.

The index of the first matching pair is 0, the index of the second matching pair is 1 and so on.

Parameters
integer$indexA nonnegative index of the n-th matching pair
See also
$matchingpairs

Definition at line 483 of file class.assMatchingQuestion.php.

483 : void
484 {
485 if ($index < 0) {
486 return;
487 }
488 if (count($this->matchingpairs) < 1) {
489 return;
490 }
491 if ($index >= count($this->matchingpairs)) {
492 return;
493 }
494 unset($this->matchingpairs[$index]);
495 $this->matchingpairs = array_values($this->matchingpairs);
496 }

◆ deleteTerm()

assMatchingQuestion::deleteTerm (   $position)

Deletes a term.

Parameters
string$term_idThe id of the term to delete
See also
$terms

Definition at line 653 of file class.assMatchingQuestion.php.

653 : void
654 {
655 unset($this->terms[$position]);
656 $this->terms = array_values($this->terms);
657 }

◆ fetchIndexedValuesFromValuePairs()

assMatchingQuestion::fetchIndexedValuesFromValuePairs ( array  $valuePairs)
Parameters
array$valuePairs
Returns
array $indexedValues

Reimplemented from assQuestion.

Definition at line 775 of file class.assMatchingQuestion.php.

775 : array
776 {
777 $indexedValues = [];
778
779 foreach ($valuePairs as $valuePair) {
780 if (!isset($indexedValues[$valuePair['value2']])) {
781 $indexedValues[$valuePair['value2']] = [];
782 }
783
784 $indexedValues[$valuePair['value2']][] = $valuePair['value1'];
785 }
786
787 return $indexedValues;
788 }

◆ flushDefinitions()

assMatchingQuestion::flushDefinitions ( )

Deletes all definitions.

See also
$definitions

Definition at line 642 of file class.assMatchingQuestion.php.

642 : void
643 {
644 $this->definitions = [];
645 }

◆ flushMatchingPairs()

assMatchingQuestion::flushMatchingPairs ( )

Deletes all matching pairs.

See also
$matchingpairs

Definition at line 502 of file class.assMatchingQuestion.php.

502 : void
503 {
504 $this->matchingpairs = [];
505 }

◆ flushTerms()

assMatchingQuestion::flushTerms ( )

Deletes all terms.

See also
$terms

Definition at line 633 of file class.assMatchingQuestion.php.

633 : void
634 {
635 $this->terms = [];
636 }

◆ generateThumbForFile()

assMatchingQuestion::generateThumbForFile (   $path,
  $file 
)
protected

Definition at line 1087 of file class.assMatchingQuestion.php.

1087 : void
1088 {
1089 $filename = $path . $file;
1090 if (file_exists($filename)) {
1091 $thumbpath = $path . $this->getThumbPrefix() . $file;
1092 $path_info = pathinfo($filename);
1093 $ext = "";
1094 switch (strtoupper($path_info['extension'])) {
1095 case 'PNG':
1096 $ext = 'PNG';
1097 break;
1098 case 'GIF':
1099 $ext = 'GIF';
1100 break;
1101 default:
1102 $ext = 'JPEG';
1103 break;
1104 }
1105 ilShellUtil::convertImage($filename, $thumbpath, $ext, (string) $this->getThumbGeometry());
1106 }
1107 }
getThumbGeometry()
Get the thumbnail geometry.
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
$path
Definition: ltiservices.php:30

References $filename, $path, and ilShellUtil\convertImage().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assMatchingQuestion::getAdditionalTableName ( )

Reimplemented from assQuestion.

Definition at line 983 of file class.assMatchingQuestion.php.

983 : string
984 {
985 return "qpl_qst_matching";
986 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assMatchingQuestion::getAnswerTableName ( )

Reimplemented from assQuestion.

Definition at line 988 of file class.assMatchingQuestion.php.

988 : array
989 {
990 return ["qpl_a_matching", "qpl_a_mterm"];
991 }

◆ getAvailableAnswerOptions()

assMatchingQuestion::getAvailableAnswerOptions (   $index = null)

If index is null, the function returns an array with all anwser options Else it returns the specific answer option.

Parameters
null | int$index

Definition at line 1297 of file class.assMatchingQuestion.php.

1298 {
1299 if ($index !== null) {
1300 return $this->getMatchingPair($index);
1301 } else {
1302 return $this->getMatchingPairs();
1303 }
1304 }
getMatchingPair($index=0)
Returns a matching pair with a given index.
getMatchingPairs()
Returns the matchingpairs array.

◆ getCorrectSolutionForTextOutput()

assMatchingQuestion::getCorrectSolutionForTextOutput ( int  $active_id,
int  $pass 
)

Reimplemented from assQuestion.

Definition at line 1418 of file class.assMatchingQuestion.php.

1418 : array
1419 {
1420 return array_map(
1421 fn(assAnswerMatchingPair $v): string => $v->getDefinition()->getText() . ': '
1422 . $v->getTerm()->getText(),
1423 $this->getMatchingPairs()
1424 );
1425 }

References assAnswerMatchingPair\getDefinition(), and assAnswerMatchingPair\getTerm().

+ Here is the call graph for this function:

◆ getDefinitionCount()

assMatchingQuestion::getDefinitionCount ( )

Returns the number of definitions.

Returns
integer The number of definitions
See also
$definitions

Definition at line 568 of file class.assMatchingQuestion.php.

568 : int
569 {
570 return count($this->definitions);
571 }

◆ getDefinitions()

assMatchingQuestion::getDefinitions ( )

Returns the definitions of the matching question.

Returns
array An array containing the definitions
See also
$terms

Definition at line 546 of file class.assMatchingQuestion.php.

546 : array
547 {
548 return $this->definitions;
549 }

◆ getDefinitionWithIdentifier()

assMatchingQuestion::getDefinitionWithIdentifier (   $a_identifier)

Returns a definition with a given identifier.

Definition at line 444 of file class.assMatchingQuestion.php.

445 {
446 foreach ($this->definitions as $definition) {
447 if ($definition->getIdentifier() == $a_identifier) {
448 return $definition;
449 }
450 }
451 return null;
452 }

◆ getEncryptedFilename()

assMatchingQuestion::getEncryptedFilename (   $filename)

Returns the encrypted save filename of a matching picture Images are saved with an encrypted filename to prevent users from cheating by guessing the solution from the image filename.

Parameters
string$filenameOriginal filename
Returns
string Encrypted filename

Definition at line 798 of file class.assMatchingQuestion.php.

798 : string
799 {
800 $extension = "";
801 if (preg_match("/.*\\.(\\w+)$/", $filename, $matches)) {
802 $extension = $matches[1];
803 }
804 return md5($filename) . "." . $extension;
805 }

References $filename.

◆ getExpressionTypes()

◆ getMatchingMode()

assMatchingQuestion::getMatchingMode ( )

Definition at line 1189 of file class.assMatchingQuestion.php.

1189 : string
1190 {
1191 return $this->matching_mode;
1192 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getMatchingPair()

assMatchingQuestion::getMatchingPair (   $index = 0)

Returns a matching pair with a given index.

The index of the first matching pair is 0, the index of the second matching pair is 1 and so on.

Parameters
integer$indexA nonnegative index of the n-th matching pair
Returns
object ASS_AnswerMatching-Object
See also
$matchingpairs

Definition at line 462 of file class.assMatchingQuestion.php.

462 : ?object
463 {
464 if ($index < 0) {
465 return null;
466 }
467 if (count($this->matchingpairs) < 1) {
468 return null;
469 }
470 if ($index >= count($this->matchingpairs)) {
471 return null;
472 }
473 return $this->matchingpairs[$index];
474 }

◆ getMatchingPairCount()

assMatchingQuestion::getMatchingPairCount ( )

Returns the number of matching pairs.

Returns
integer The number of matching pairs of the matching question
See also
$matchingpairs

Definition at line 524 of file class.assMatchingQuestion.php.

524 : int
525 {
526 return count($this->matchingpairs);
527 }

◆ getMatchingPairs()

assMatchingQuestion::getMatchingPairs ( )

Returns the matchingpairs array.

Definition at line 1005 of file class.assMatchingQuestion.php.

1005 : array
1006 {
1007 return $this->matchingpairs;
1008 }

Referenced by saveAnswerSpecificDataToDb().

+ Here is the caller graph for this function:

◆ getMaximumPoints()

assMatchingQuestion::getMaximumPoints ( )

Calculates and Returns the maximum points, a learner can reach answering the question.

Reimplemented from assQuestion.

Definition at line 713 of file class.assMatchingQuestion.php.

713 : float
714 {
715 $points = 0;
716
717 foreach ($this->getMaximumScoringMatchingPairs() as $pair) {
718 $points += $pair->getPoints();
719 }
720
721 return $points;
722 }

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMaximumScoringMatchingPairs()

assMatchingQuestion::getMaximumScoringMatchingPairs ( )

Definition at line 724 of file class.assMatchingQuestion.php.

724 : array
725 {
726 if ($this->getMatchingMode() == self::MATCHING_MODE_N_ON_N) {
727 return $this->getPositiveScoredMatchingPairs();
728 } elseif ($this->getMatchingMode() == self::MATCHING_MODE_1_ON_1) {
730 }
731
732 return [];
733 }

◆ getMostPositiveScoredUniqueTermMatchingPairs()

assMatchingQuestion::getMostPositiveScoredUniqueTermMatchingPairs ( )
private

Definition at line 750 of file class.assMatchingQuestion.php.

750 : array
751 {
752 $matchingPairsByDefinition = [];
753
754 foreach ($this->matchingpairs as $pair) {
755 if ($pair->getPoints() <= 0) {
756 continue;
757 }
758
759 $defId = $pair->getDefinition()->getIdentifier();
760
761 if (!isset($matchingPairsByDefinition[$defId])) {
762 $matchingPairsByDefinition[$defId] = $pair;
763 } elseif ($pair->getPoints() > $matchingPairsByDefinition[$defId]->getPoints()) {
764 $matchingPairsByDefinition[$defId] = $pair;
765 }
766 }
767
768 return $matchingPairsByDefinition;
769 }

◆ getOperators()

assMatchingQuestion::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

Definition at line 1216 of file class.assMatchingQuestion.php.

1216 : array
1217 {
1219 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getPositiveScoredMatchingPairs()

assMatchingQuestion::getPositiveScoredMatchingPairs ( )
private

Definition at line 735 of file class.assMatchingQuestion.php.

735 : array
736 {
737 $matchingPairs = [];
738
739 foreach ($this->matchingpairs as $pair) {
740 if ($pair->getPoints() <= 0) {
741 continue;
742 }
743
744 $matchingPairs[] = $pair;
745 }
746
747 return $matchingPairs;
748 }

◆ getQuestionType()

assMatchingQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

Reimplemented from assQuestion.

Definition at line 978 of file class.assMatchingQuestion.php.

978 : string
979 {
980 return "assMatchingQuestion";
981 }

◆ getRandomId()

assMatchingQuestion::getRandomId ( )

Definition at line 951 of file class.assMatchingQuestion.php.

951 : int
952 {
953 mt_srand((float) microtime() * 1000000);
954 $random_number = mt_rand(1, 100000);
955 $found = false;
956 while ($found) {
957 $found = false;
958 foreach ($this->matchingpairs as $key => $pair) {
959 if (($pair->getTerm()->getIdentifier() == $random_number) || ($pair->getDefinition()->getIdentifier() == $random_number)) {
960 $found = true;
961 $random_number++;
962 }
963 }
964 }
965 return $random_number;
966 }

◆ getRTETextWithMediaObjects()

assMatchingQuestion::getRTETextWithMediaObjects ( )

Collects all text in the question which could contain media objects which were created with the Rich Text Editor.

Reimplemented from assQuestion.

Definition at line 997 of file class.assMatchingQuestion.php.

997 : string
998 {
999 return parent::getRTETextWithMediaObjects();
1000 }

◆ getShuffleMode()

assMatchingQuestion::getShuffleMode ( )

Definition at line 105 of file class.assMatchingQuestion.php.

105 : int
106 {
107 return $this->shufflemode;
108 }

References $shufflemode.

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getTermCount()

assMatchingQuestion::getTermCount ( )

Returns the number of terms.

Returns
integer The number of terms
See also
$terms

Definition at line 557 of file class.assMatchingQuestion.php.

557 : int
558 {
559 return count($this->terms);
560 }

◆ getTerms()

assMatchingQuestion::getTerms ( )

Returns the terms of the matching question.

Returns
assAnswerMatchingTerm[] An array containing the terms
See also
$terms

Definition at line 535 of file class.assMatchingQuestion.php.

535 : array
536 {
537 return $this->terms;
538 }

◆ getTermWithIdentifier()

assMatchingQuestion::getTermWithIdentifier (   $a_identifier)

Returns a term with a given identifier.

Definition at line 431 of file class.assMatchingQuestion.php.

432 {
433 foreach ($this->terms as $term) {
434 if ($term->getIdentifier() == $a_identifier) {
435 return $term;
436 }
437 }
438 return null;
439 }

◆ getThumbGeometry()

assMatchingQuestion::getThumbGeometry ( )

Get the thumbnail geometry.

Returns
integer Geometry

Definition at line 1015 of file class.assMatchingQuestion.php.

1015 : int
1016 {
1017 return $this->thumb_geometry;
1018 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getThumbPrefix()

assMatchingQuestion::getThumbPrefix ( )

Definition at line 1082 of file class.assMatchingQuestion.php.

1082 : string
1083 {
1084 return "thumb.";
1085 }

◆ getThumbSize()

assMatchingQuestion::getThumbSize ( )

Get the thumbnail geometry.

Returns
integer Geometry

Reimplemented from assQuestion.

Definition at line 1025 of file class.assMatchingQuestion.php.

1025 : int
1026 {
1027 return $this->getThumbGeometry();
1028 }

◆ getUserQuestionResult()

assMatchingQuestion::getUserQuestionResult ( int  $active_id,
int  $pass 
)

Get the user solution for a question by active_id and the test pass.

Implements iQuestionCondition.

Definition at line 1231 of file class.assMatchingQuestion.php.

1235 $result = new ilUserQuestionResult($this, $active_id, $pass);
1236
1237 $data = $this->db->queryF(
1238 "SELECT ident FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id",
1239 ["integer"],
1240 [$this->getId()]
1241 );
1242
1243 $definitions = [];
1244 for ($index = 1; $index <= $this->db->numRows($data); ++$index) {
1245 $row = $this->db->fetchAssoc($data);
1246 $definitions[$row["ident"]] = $index;
1247 }
1248
1249 $data = $this->db->queryF(
1250 "SELECT ident FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id",
1251 ["integer"],
1252 [$this->getId()]
1253 );
1254
1255 $terms = [];
1256 for ($index = 1; $index <= $this->db->numRows($data); ++$index) {
1257 $row = $this->db->fetchAssoc($data);
1258 $terms[$row["ident"]] = $index;
1259 }
1260
1261 $maxStep = $this->lookupMaxStep($active_id, $pass);
1262
1263 if ($maxStep > 0) {
1264 $data = $this->db->queryF(
1265 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1266 ["integer", "integer", "integer","integer"],
1267 [$active_id, $pass, $this->getId(), $maxStep]
1268 );
1269 } else {
1270 $data = $this->db->queryF(
1271 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1272 ["integer", "integer", "integer"],
1273 [$active_id, $pass, $this->getId()]
1274 );
1275 }
1276
1277 while ($row = $this->db->fetchAssoc($data)) {
1278 if ($row["value1"] > 0) {
1279 $result->addKeyValue($definitions[$row["value2"]], $terms[$row["value1"]]);
1280 }
1281 }
1282
1283 $points = $this->calculateReachedPoints($active_id, $pass);
1284 $max_points = $this->getMaximumPoints();
1285
1286 $result->setReachedPercentage(($points / $max_points) * 100);
1287
1288 return $result;
1289 }
getMaximumPoints()
Calculates and Returns the maximum points, a learner can reach answering the question.
calculateReachedPoints(int $active_id, ?int $pass=null, bool $authorized_solution=true)
lookupMaxStep(int $active_id, int $pass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $data.

◆ insertDefinition()

assMatchingQuestion::insertDefinition (   $position,
?assAnswerMatchingDefinition  $definition = null 
)

Inserts a definition.

Parameters
object$definitionThe definition
See also
$definitions

Definition at line 615 of file class.assMatchingQuestion.php.

615 : void
616 {
617 if (is_null($definition)) {
618 $definition = $this->createMatchingDefinition();
619 }
620 if ($position < count($this->definitions)) {
621 $part1 = array_slice($this->definitions, 0, $position);
622 $part2 = array_slice($this->definitions, $position);
623 $this->definitions = array_merge($part1, [$definition], $part2);
624 } else {
625 array_push($this->definitions, $definition);
626 }
627 }

◆ insertMatchingPair()

assMatchingQuestion::insertMatchingPair (   $position,
  $term = null,
  $definition = null,
  $points = 0.0 
)

Inserts a matching pair for an matching choice question.

The students have to fill in an order for the matching pair. The matching pair is an ASS_AnswerMatching object that will be created and assigned to the array $this->matchingpairs.

Parameters
integer$positionThe insert position in the matching pairs array
object$termA matching term
object$definitionA matching definition
double$pointsThe points for selecting the matching pair (even negative points can be used)
See also
$matchingpairs

Definition at line 398 of file class.assMatchingQuestion.php.

398 : void
399 {
400 $pair = $this->createMatchingPair($term, $definition, $points);
401
402 if ($position < count($this->matchingpairs)) {
403 $part1 = array_slice($this->matchingpairs, 0, $position);
404 $part2 = array_slice($this->matchingpairs, $position);
405 $this->matchingpairs = array_merge($part1, [$pair], $part2);
406 } else {
407 array_push($this->matchingpairs, $pair);
408 }
409 }

◆ insertTerm()

assMatchingQuestion::insertTerm (   $position,
?assAnswerMatchingTerm  $term = null 
)

Inserts a term.

Parameters
string$termThe text of the term
See also
$terms

Definition at line 595 of file class.assMatchingQuestion.php.

595 : void
596 {
597 if (is_null($term)) {
598 $term = $this->createMatchingTerm();
599 }
600 if ($position < count($this->terms)) {
601 $part1 = array_slice($this->terms, 0, $position);
602 $part2 = array_slice($this->terms, $position);
603 $this->terms = array_merge($part1, [$term], $part2);
604 } else {
605 array_push($this->terms, $term);
606 }
607 }

◆ isComplete()

assMatchingQuestion::isComplete ( )

Reimplemented from assQuestion.

Definition at line 115 of file class.assMatchingQuestion.php.

115 : bool
116 {
117 if (strlen($this->title)
118 && $this->author
119 && $this->question
120 && count($this->matchingpairs)
121 && $this->getMaximumPoints() > 0
122 ) {
123 return true;
124 }
125 return false;
126 }

References getMaximumPoints().

+ Here is the call graph for this function:

◆ loadFromDb()

assMatchingQuestion::loadFromDb (   $question_id)

Loads a assMatchingQuestion object from a database.

Parameters
object$dbA pear DB object
integer$question_idA unique key which defines the multiple choice test in the database

Definition at line 227 of file class.assMatchingQuestion.php.

227 : void
228 {
229 $query = "
230 SELECT qpl_questions.*,
231 {$this->getAdditionalTableName()}.*
232 FROM qpl_questions
233 LEFT JOIN {$this->getAdditionalTableName()}
234 ON {$this->getAdditionalTableName()}.question_fi = qpl_questions.question_id
235 WHERE qpl_questions.question_id = %s
236 ";
237
238 $result = $this->db->queryF(
239 $query,
240 ['integer'],
241 [$question_id]
242 );
243
244 if ($result->numRows() == 1) {
245 $data = $this->db->fetchAssoc($result);
246 $this->setId((int) $question_id);
247 $this->setObjId((int) $data["obj_fi"]);
248 $this->setTitle((string) $data["title"]);
249 $this->setComment((string) $data["description"]);
250 $this->setOriginalId((int) $data["original_id"]);
251 $this->setNrOfTries((int) $data['nr_of_tries']);
252 $this->setAuthor($data["author"]);
253 $this->setPoints((float) $data["points"]);
254 $this->setOwner((int) $data["owner"]);
255 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
256 $this->setThumbGeometry((int) $data["thumb_geometry"]);
257 $this->setShuffle($data["shuffle"] != '0');
258 $this->setShuffleMode((int) $data['shuffle']);
259 $this->setMatchingMode($data['matching_mode'] === null ? self::MATCHING_MODE_1_ON_1 : $data['matching_mode']);
260
261 try {
265 }
266
267 try {
268 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
270 }
271 }
272
273 $termids = [];
274 $result = $this->db->queryF(
275 "SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
276 ['integer'],
277 [$question_id]
278 );
279 $this->terms = [];
280 if ($result->numRows() > 0) {
281 while ($data = $this->db->fetchAssoc($result)) {
282 $term = $this->createMatchingTerm($data['term'] ?? '', $data['picture'] ?? '', (int) $data['ident']);
283 $this->terms[] = $term;
284 $termids[$data['term_id']] = $term;
285 }
286 }
287
288 $definitionids = [];
289 $result = $this->db->queryF(
290 "SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
291 ['integer'],
292 [$question_id]
293 );
294
295 $this->definitions = [];
296 if ($result->numRows() > 0) {
297 while ($data = $this->db->fetchAssoc($result)) {
298 $definition = $this->createMatchingDefinition($data['definition'] ?? '', $data['picture'] ?? '', (int) $data['ident']);
299 array_push($this->definitions, $definition);
300 $definitionids[$data['def_id']] = $definition;
301 }
302 }
303
304 $this->matchingpairs = [];
305 $result = $this->db->queryF(
306 "SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
307 ['integer'],
308 [$question_id]
309 );
310 if ($result->numRows() > 0) {
311 while ($data = $this->db->fetchAssoc($result)) {
312 $pair = $this->createMatchingPair(
313 $termids[$data['term_fi']],
314 $definitionids[$data['definition_fi']],
315 (float) $data['points']
316 );
317 array_push($this->matchingpairs, $pair);
318 }
319 }
320 parent::loadFromDb((int) $question_id);
321 }
setThumbGeometry(int $a_geometry)
Set the thumbnail geometry.
setMatchingMode(string $matching_mode)
setOriginalId(?int $original_id)
setId(int $id=-1)
setAdditionalContentEditingMode(?string $additionalContentEditingMode)
setQuestion(string $question="")
setAuthor(string $author="")
setComment(string $comment="")
setObjId(int $obj_id=0)
setOwner(int $owner=-1)
setNrOfTries(int $a_nr_of_tries)
setLifecycle(ilAssQuestionLifecycle $lifecycle)
setTitle(string $title="")
setPoints(float $points)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...

References $data, Vendor\Package\$e, ilRTE\_replaceMediaObjectImageSrc(), createMatchingDefinition(), createMatchingPair(), createMatchingTerm(), ilAssQuestionLifecycle\getDraftInstance(), ilAssQuestionLifecycle\getInstance(), assQuestion\setAdditionalContentEditingMode(), assQuestion\setAuthor(), assQuestion\setComment(), assQuestion\setId(), assQuestion\setLifecycle(), setMatchingMode(), assQuestion\setNrOfTries(), assQuestion\setObjId(), assQuestion\setOriginalId(), assQuestion\setOwner(), assQuestion\setPoints(), assQuestion\setQuestion(), setShuffle(), setShuffleMode(), setThumbGeometry(), and assQuestion\setTitle().

+ Here is the call graph for this function:

◆ rebuildThumbnails()

assMatchingQuestion::rebuildThumbnails ( )

Rebuild the thumbnail images with a new thumbnail size.

Definition at line 1043 of file class.assMatchingQuestion.php.

1043 : void
1044 {
1045 $new_terms = [];
1046 foreach ($this->terms as $term) {
1047 if ($term->getPicture() !== '') {
1048 $current_file_path = $this->getImagePath() . $term->getPicture();
1049 if (!file_exists($current_file_path)) {
1050 $new_terms[] = $term;
1051 continue;
1052 }
1053 $new_file_name = $this->buildHashedImageFilename($term->getPicture(), true);
1054 $new_file_path = $this->getImagePath() . $new_file_name;
1055 rename($current_file_path, $new_file_path);
1056 $term = $term->withPicture($new_file_name);
1057 $this->generateThumbForFile($this->getImagePath(), $term->getPicture());
1058 }
1059 $new_terms[] = $term;
1060 }
1061 $this->terms = $new_terms;
1062
1063 $new_definitions = [];
1064 foreach ($this->definitions as $definition) {
1065 if ($definition->getPicture() !== '') {
1066 $current_file_path = $this->getImagePath() . $definition->getPicture();
1067 if (!file_exists($current_file_path)) {
1068 $new_definitions[] = $definition;
1069 continue;
1070 }
1071 $new_file_name = $this->buildHashedImageFilename($definition->getPicture(), true);
1072 $new_file_path = $this->getImagePath() . $new_file_name;
1073 rename($current_file_path, $new_file_path);
1074 $definition = $definition->withPicture($new_file_name);
1075 $this->generateThumbForFile($this->getImagePath(), $definition->getPicture());
1076 }
1077 $new_definitions[] = $definition;
1078 }
1079 $this->definitions = $new_definitions;
1080 }
buildHashedImageFilename(string $plain_image_filename, bool $unique=false)

Referenced by saveAnswerSpecificDataToDb().

+ Here is the caller graph for this function:

◆ removeDefinitionImage()

assMatchingQuestion::removeDefinitionImage (   $index)

Definition at line 816 of file class.assMatchingQuestion.php.

816 : void
817 {
818 $definition = $this->definitions[$index] ?? null;
819 if (is_object($definition)) {
820 $this->deleteImagefile($definition->getPicture());
821 $definition = $definition->withPicture('');
822 }
823 }
deleteImagefile(string $filename)
Deletes an imagefile from the system if the file is deleted manually.

◆ removeTermImage()

assMatchingQuestion::removeTermImage (   $index)

Definition at line 807 of file class.assMatchingQuestion.php.

807 : void
808 {
809 $term = $this->terms[$index] ?? null;
810 if (is_object($term)) {
811 $this->deleteImagefile($term->getPicture());
812 $term = $term->withPicture('');
813 }
814 }

◆ saveAdditionalQuestionDataToDb()

assMatchingQuestion::saveAdditionalQuestionDataToDb ( )

Saves a record to the question types additional data table.

Returns
mixed

Implements ilObjQuestionScoringAdjustable.

Definition at line 204 of file class.assMatchingQuestion.php.

205 {
206 $this->db->manipulateF(
207 "DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
208 [ "integer" ],
209 [ $this->getId() ]
210 );
211
212 $this->db->insert($this->getAdditionalTableName(), [
213 'question_fi' => ['integer', $this->getId()],
214 'shuffle' => ['text', $this->getShuffleMode()],
215 'matching_type' => ['text', $this->matching_type],
216 'thumb_geometry' => ['integer', $this->getThumbGeometry()],
217 'matching_mode' => ['text', $this->getMatchingMode()]
218 ]);
219 }

References getAdditionalTableName(), assQuestion\getId(), getMatchingMode(), getShuffleMode(), and getThumbGeometry().

Referenced by saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAnswerSpecificDataToDb()

assMatchingQuestion::saveAnswerSpecificDataToDb ( )

Saves the answer specific records into a question types answer table.

Returns
mixed

Implements ilObjAnswerScoringAdjustable.

Definition at line 137 of file class.assMatchingQuestion.php.

138 {
139 $this->rebuildThumbnails();
140
141 $this->db->manipulateF(
142 "DELETE FROM qpl_a_mterm WHERE question_fi = %s",
143 [ 'integer' ],
144 [ $this->getId() ]
145 );
146
147 // delete old definitions
148 $this->db->manipulateF(
149 "DELETE FROM qpl_a_mdef WHERE question_fi = %s",
150 [ 'integer' ],
151 [ $this->getId() ]
152 );
153
154 $termids = [];
155 // write terms
156 foreach ($this->terms as $key => $term) {
157 $next_id = $this->db->nextId('qpl_a_mterm');
158 $this->db->insert('qpl_a_mterm', [
159 'term_id' => ['integer', $next_id],
160 'question_fi' => ['integer', $this->getId()],
161 'picture' => ['text', $term->getPicture()],
162 'term' => ['text', $term->getText()],
163 'ident' => ['integer', $term->getIdentifier()]
164 ]);
165 $termids[$term->getIdentifier()] = $next_id;
166 }
167
168 $definitionids = [];
169 // write definitions
170 foreach ($this->definitions as $key => $definition) {
171 $next_id = $this->db->nextId('qpl_a_mdef');
172 $this->db->insert('qpl_a_mdef', [
173 'def_id' => ['integer', $next_id],
174 'question_fi' => ['integer', $this->getId()],
175 'picture' => ['text', $definition->getPicture()],
176 'definition' => ['text', $definition->getText()],
177 'ident' => ['integer', $definition->getIdentifier()]
178 ]);
179 $definitionids[$definition->getIdentifier()] = $next_id;
180 }
181
182 $this->db->manipulateF(
183 "DELETE FROM qpl_a_matching WHERE question_fi = %s",
184 [ 'integer' ],
185 [ $this->getId() ]
186 );
188 foreach ($matchingpairs as $key => $pair) {
189 $next_id = $this->db->nextId('qpl_a_matching');
190 $this->db->manipulateF(
191 "INSERT INTO qpl_a_matching (answer_id, question_fi, points, term_fi, definition_fi) VALUES (%s, %s, %s, %s, %s)",
192 [ 'integer', 'integer', 'float', 'integer', 'integer' ],
193 [
194 $next_id,
195 $this->getId(),
196 $pair->getPoints(),
197 $termids[$pair->getTerm()->getIdentifier()],
198 $definitionids[$pair->getDefinition()->getIdentifier()]
199 ]
200 );
201 }
202 }
rebuildThumbnails()
Rebuild the thumbnail images with a new thumbnail size.

References $matchingpairs, assQuestion\getId(), getMatchingPairs(), and rebuildThumbnails().

Referenced by saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePreviewData()

assMatchingQuestion::savePreviewData ( ilAssQuestionPreviewSession  $previewSession)
protected

Reimplemented from assQuestion.

Definition at line 942 of file class.assMatchingQuestion.php.

942 : void
943 {
944 $submitted_matchings = $this->questionpool_request->getMatchingPairs();
945
946 if ($this->checkSubmittedMatchings($submitted_matchings)) {
947 $previewSession->setParticipantsSolution($submitted_matchings);
948 }
949 }
checkSubmittedMatchings(array $submitted_matchings)

References ilAssQuestionPreviewSession\setParticipantsSolution().

+ Here is the call graph for this function:

◆ saveToDb()

assMatchingQuestion::saveToDb ( ?int  $original_id = null)

Reimplemented from assQuestion.

Definition at line 128 of file class.assMatchingQuestion.php.

128 : void
129 {
133
134 parent::saveToDb();
135 }
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer table.
saveAdditionalQuestionDataToDb()
Saves a record to the question types additional data table.
saveQuestionDataToDb(?int $original_id=null)

References assQuestion\$original_id, saveAdditionalQuestionDataToDb(), saveAnswerSpecificDataToDb(), and assQuestion\saveQuestionDataToDb().

+ Here is the call graph for this function:

◆ saveWorkingData()

assMatchingQuestion::saveWorkingData ( int  $active_id,
?int  $pass = null,
bool  $authorized = true 
)

Reimplemented from assQuestion.

Definition at line 914 of file class.assMatchingQuestion.php.

918 : bool {
919 if ($pass === null) {
920 $pass = ilObjTest::_getPass($active_id);
921 }
922
923 $submitted_matchings = $this->questionpool_request->getMatchingPairs();
924 if (!$this->checkSubmittedMatchings($submitted_matchings)) {
925 return false;
926 }
927
928 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
929 function () use ($submitted_matchings, $active_id, $pass, $authorized) {
930 $this->removeCurrentSolution($active_id, $pass, $authorized);
931 foreach ($submitted_matchings as $definition => $terms) {
932 foreach ($terms as $i => $term) {
933 $this->saveCurrentSolution($active_id, $pass, $term, $definition, $authorized);
934 }
935 }
936 }
937 );
938
939 return true;
940 }
saveCurrentSolution(int $active_id, int $pass, $value1, $value2, bool $authorized=true, $tstamp=0)
removeCurrentSolution(int $active_id, int $pass, bool $authorized=true)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.

References ilObjTest\_getPass().

+ Here is the call graph for this function:

◆ setImageFile()

assMatchingQuestion::setImageFile ( string  $image_tempfilename,
string  $image_filename,
string  $previous_filename = '' 
)

Definition at line 844 of file class.assMatchingQuestion.php.

848 : bool {
849 $result = true;
850 if ($image_tempfilename === '') {
851 return true;
852 }
853
854 $image_filename = str_replace(' ', '_', $image_filename);
855 $imagepath = $this->getImagePath();
856 if (!file_exists($imagepath)) {
857 ilFileUtils::makeDirParents($imagepath);
858 }
859
861 $image_tempfilename,
862 $image_filename,
863 $imagepath . $image_filename
864 )
865 ) {
866 return false;
867 }
868
869 // create thumbnail file
870 $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
872 $imagepath . $image_filename,
873 $thumbpath,
874 'JPEG',
875 (string) $this->getThumbGeometry()
876 );
877
878 if ($result
879 && $image_filename !== $previous_filename
880 && $previous_filename !== ''
881 ) {
882 $this->deleteImagefile($previous_filename);
883 }
884 return $result;
885 }
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file

◆ setMatchingMode()

assMatchingQuestion::setMatchingMode ( string  $matching_mode)

Definition at line 1184 of file class.assMatchingQuestion.php.

1184 : void
1185 {
1186 $this->matching_mode = $matching_mode;
1187 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setShuffle()

assMatchingQuestion::setShuffle (   $shuffle = true)

Definition at line 968 of file class.assMatchingQuestion.php.

968 : void
969 {
970 $this->shuffle = (bool) $shuffle;
971 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setShuffleMode()

assMatchingQuestion::setShuffleMode ( int  $shuffle)

Definition at line 110 of file class.assMatchingQuestion.php.

111 {
112 $this->shufflemode = $shuffle;
113 }

References assQuestion\$shuffle.

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setTerm()

assMatchingQuestion::setTerm (   $term,
  $index 
)

Sets a specific term.

Parameters
string$termThe text of the term
string$indexThe index of the term
See also
$terms

Definition at line 678 of file class.assMatchingQuestion.php.

678 : void
679 {
680 $this->terms[$index] = $term;
681 }

◆ setThumbGeometry()

assMatchingQuestion::setThumbGeometry ( int  $a_geometry)

Set the thumbnail geometry.

Parameters
integer$a_geometryGeometry

Definition at line 1035 of file class.assMatchingQuestion.php.

1035 : void
1036 {
1037 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1038 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ solutionValuesToLog()

assMatchingQuestion::solutionValuesToLog ( AdditionalInformationGenerator  $additional_info,
array  $solution_values 
)
protected

MUST convert the given solution values into an array or a string that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

Definition at line 1383 of file class.assMatchingQuestion.php.

1386 : array {
1387 return $this->solutionValuesToText($solution_values);
1388 }
solutionValuesToText(array $solution_values)
MUST convert the given solution values into text.

◆ solutionValuesToText()

assMatchingQuestion::solutionValuesToText ( array  $solution_values)

MUST convert the given solution values into text.

If the text has multiple lines each line MUST be placed as an entry in an array.

Reimplemented from assQuestion.

Definition at line 1390 of file class.assMatchingQuestion.php.

1390 : array
1391 {
1392 $reducer = static function (array $c, assAnswerMatchingTerm|assAnswerMatchingDefinition $v): array {
1393 $c[$v->getIdentifier()] = $v->getText() !== ''
1394 ? $v->getPicture()
1395 : $v->getText();
1396 return $c;
1397 };
1398
1399 $terms_by_identifier = array_reduce(
1400 $this->getTerms(),
1401 $reducer,
1402 []
1403 );
1404
1405 $definitions_by_identifier = array_reduce(
1406 $this->getDefinitions(),
1407 $reducer,
1408 []
1409 );
1410
1411 return array_map(
1412 static fn(array $v): string => $definitions_by_identifier[$v['value2']]
1413 . ':' . $terms_by_identifier[$v['value1']],
1414 $solution_values
1415 );
1416 }
getDefinitions()
Returns the definitions of the matching question.
getTerms()
Returns the terms of the matching question.
$c
Definition: deliver.php:25

References $c.

◆ toJSON()

assMatchingQuestion::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

Definition at line 1112 of file class.assMatchingQuestion.php.

1112 : string
1113 {
1114 $result = [];
1115
1116 $result['id'] = $this->getId();
1117 $result['type'] = (string) $this->getQuestionType();
1118 $result['title'] = $this->getTitleForHTMLOutput();
1119 $result['question'] = $this->formatSAQuestion($this->getQuestion());
1120 $result['nr_of_tries'] = $this->getNrOfTries();
1121 $result['matching_mode'] = $this->getMatchingMode();
1122 $result['shuffle'] = true;
1123 $result['feedback'] = [
1124 'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1125 'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1126 ];
1127
1128 $this->setShuffler($this->randomGroup->shuffleArray(new RandomSeed()));
1129
1130 $terms = [];
1131 foreach ($this->getShuffler()->transform($this->getTerms()) as $term) {
1132 $terms[] = [
1133 "text" => $this->formatSAQuestion($term->getText()),
1134 "id" => $this->getId() . $term->getIdentifier()
1135 ];
1136 }
1137 $result['terms'] = $terms;
1138
1139 $this->setShuffler($this->randomGroup->shuffleArray(new RandomSeed()));
1140
1141 $definitions = [];
1142 foreach ($this->getShuffler()->transform($this->getDefinitions()) as $def) {
1143 $definitions[] = [
1144 "text" => $this->formatSAQuestion((string) $def->getText()),
1145 "id" => $this->getId() . $def->getIdentifier()
1146 ];
1147 }
1148 $result['definitions'] = $definitions;
1149
1150 // #10353
1151 $matchings = [];
1152 foreach ($this->getMatchingPairs() as $pair) {
1153 // fau: fixLmMatchingPoints - ignore matching pairs with 0 or negative points
1154 if ($pair->getPoints() <= 0) {
1155 continue;
1156 }
1157 // fau.
1158
1159 $pid = $pair->getDefinition()->getIdentifier();
1160 if ($this->getMatchingMode() == self::MATCHING_MODE_N_ON_N) {
1161 $pid .= '::' . $pair->getTerm()->getIdentifier();
1162 }
1163
1164 if (!isset($matchings[$pid]) || $matchings[$pid]["points"] < $pair->getPoints()) {
1165 $matchings[$pid] = [
1166 "term_id" => $this->getId() . $pair->getTerm()->getIdentifier(),
1167 "def_id" => $this->getId() . $pair->getDefinition()->getIdentifier(),
1168 "points" => (int) $pair->getPoints()
1169 ];
1170 }
1171 }
1172
1173 $result['matchingPairs'] = array_values($matchings);
1174
1175 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
1176 $result['mobs'] = $mobs;
1177
1178 $this->lng->loadLanguageModule('assessment');
1179 $result['reset_button_label'] = $this->lng->txt("reset_terms");
1180
1181 return json_encode($result);
1182 }
getQuestionType()
Returns the question type of the question.
setShuffler(Transformation $shuffler)
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")

References ilObjMediaObject\_getMobsOfObject(), ILIAS\Survey\Mode\getId(), ILIAS\Repository\int(), ILIAS\Repository\lng(), and ILIAS\Refinery\transform().

+ Here is the call graph for this function:

◆ toLog()

assMatchingQuestion::toLog ( AdditionalInformationGenerator  $additional_info)

MUST return an array of the question settings that can be stored in the log.

Language variables must be generated through the corresponding functions in the AdditionalInformationGenerator. If an array is returned it will be rendered into a line per array entry in the format "key: value". If the key exists as a language variable, it will be translated.

Reimplemented from assQuestion.

Definition at line 1345 of file class.assMatchingQuestion.php.

1345 : array
1346 {
1347 $result = [
1348 AdditionalInformationGenerator::KEY_QUESTION_TYPE => (string) $this->getQuestionType(),
1349 AdditionalInformationGenerator::KEY_QUESTION_TITLE => $this->getTitleForHTMLOutput(),
1350 AdditionalInformationGenerator::KEY_QUESTION_TEXT => $this->formatSAQuestion($this->getQuestion()),
1351 AdditionalInformationGenerator::KEY_QUESTION_SHUFFLE_ANSWER_OPTIONS => $additional_info
1353 'qpl_qst_inp_matching_mode' => $this->getMatchingMode() === self::MATCHING_MODE_1_ON_1 ? '{{ qpl_qst_inp_matching_mode_one_on_one }}' : '{{ qpl_qst_inp_matching_mode_all_on_all }}',
1354 AdditionalInformationGenerator::KEY_FEEDBACK => [
1355 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_INCOMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
1356 AdditionalInformationGenerator::KEY_QUESTION_FEEDBACK_ON_COMPLETE => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
1357 ]
1358 ];
1359
1360 foreach ($this->getTerms() as $term) {
1361 $result[AdditionalInformationGenerator::KEY_QUESTION_MATCHING_TERMS][] = $term->getText();
1362 }
1363
1364 foreach ($this->getDefinitions() as $definition) {
1365 $result[AdditionalInformationGenerator::KEY_QUESTION_MATCHING_DEFINITIONS][] = $this->formatSAQuestion((string) $definition->getText());
1366 }
1367
1368 // #10353
1369 $matching_pairs = [];
1370 $i = 1;
1371 foreach ($this->getMatchingPairs() as $pair) {
1372 $matching_pairs[$i++] = [
1373 AdditionalInformationGenerator::KEY_QUESTION_MATCHING_TERM => $pair->getTerm()->getText(),
1374 AdditionalInformationGenerator::KEY_QUESTION_MATCHING_DEFINITION => $this->formatSAQuestion((string) $pair->getDefinition()->getText()),
1375 AdditionalInformationGenerator::KEY_QUESTION_REACHABLE_POINTS => (int) $pair->getPoints()
1376 ];
1377 }
1378
1379 $result[AdditionalInformationGenerator::KEY_QUESTION_CORRECT_ANSWER_OPTIONS] = $matching_pairs;
1380 return $result;
1381 }

References ILIAS\Test\Logging\AdditionalInformationGenerator\getTrueFalseTagForBool(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ withMatchingPairs()

assMatchingQuestion::withMatchingPairs ( array  $pairs)
Parameters
assAnswerMatchingPair[]

Definition at line 510 of file class.assMatchingQuestion.php.

510 : self
511 {
512 $clone = clone $this;
513 $clone->matchingpairs = $pairs;
514 return $clone;
515 }

Field Documentation

◆ $definitions

array assMatchingQuestion::$definitions = []
protected

Definition at line 73 of file class.assMatchingQuestion.php.

◆ $element_height

int assMatchingQuestion::$element_height

Definition at line 50 of file class.assMatchingQuestion.php.

◆ $matching_mode

string assMatchingQuestion::$matching_mode = self::MATCHING_MODE_1_ON_1
protected

Definition at line 52 of file class.assMatchingQuestion.php.

◆ $matching_type

int assMatchingQuestion::$matching_type

Definition at line 51 of file class.assMatchingQuestion.php.

Referenced by __construct().

◆ $matchingpairs

assMatchingQuestion::$matchingpairs

Definition at line 63 of file class.assMatchingQuestion.php.

Referenced by saveAnswerSpecificDataToDb().

◆ $randomGroup

RandomGroup assMatchingQuestion::$randomGroup
private

Definition at line 54 of file class.assMatchingQuestion.php.

◆ $shufflemode

int assMatchingQuestion::$shufflemode = 0
private

Definition at line 49 of file class.assMatchingQuestion.php.

Referenced by getShuffleMode().

◆ $terms

array assMatchingQuestion::$terms = []
protected

Definition at line 68 of file class.assMatchingQuestion.php.

◆ $thumb_geometry

int assMatchingQuestion::$thumb_geometry = 100

Definition at line 48 of file class.assMatchingQuestion.php.

◆ MATCHING_MODE_1_ON_1

const assMatchingQuestion::MATCHING_MODE_1_ON_1 = '1:1'

◆ MATCHING_MODE_N_ON_N

const assMatchingQuestion::MATCHING_MODE_N_ON_N = 'n:n'

◆ MT_TERMS_DEFINITIONS

const assMatchingQuestion::MT_TERMS_DEFINITIONS = 1

Definition at line 43 of file class.assMatchingQuestion.php.

◆ MT_TERMS_PICTURES

const assMatchingQuestion::MT_TERMS_PICTURES = 0

Definition at line 42 of file class.assMatchingQuestion.php.


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