ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 ()
 
 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)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
- 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)
 
 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)
 
 updateOriginalId (?int $original_id=null)
 
 duplicate (bool $set_original_id=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)
 
 toNormalized (Transformations $transformations, array $context=[])
 
 fromNormalized (array $normalized, Transformations $transformations)
 
 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)
 
 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 ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

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 43 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 90 of file class.assMatchingQuestion.php.

97 {
98 global $DIC;
99
101 $this->matchingpairs = [];
102 $this->matching_type = $matching_type;
103 $this->terms = [];
104 $this->definitions = [];
105 $this->randomGroup = $DIC->refinery()->random();
106 }
__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 587 of file class.assMatchingQuestion.php.

587 : void
588 {
589 array_push($this->definitions, $definition);
590 }

◆ 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 425 of file class.assMatchingQuestion.php.

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

◆ addTerm()

assMatchingQuestion::addTerm ( assAnswerMatchingTerm  $term)

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

576 : void
577 {
578 $this->terms[] = $term;
579 }

◆ 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 1313 of file class.assMatchingQuestion.php.

1318 : void {
1319 parent::afterSyncWithOriginal($original_question_id, $clone_question_id, $original_parent_id, $clone_parent_id);
1320
1321 $original_image_path = $this->question_files->buildImagePath($original_question_id, $original_parent_id);
1322 $clone_image_path = $this->question_files->buildImagePath($clone_question_id, $clone_parent_id);
1323
1324 ilFileUtils::delDir($original_image_path);
1325 if (is_dir($clone_image_path)) {
1326 ilFileUtils::makeDirParents($original_image_path);
1327 ilFileUtils::rCopy($clone_image_path, $original_image_path);
1328 }
1329 }
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 686 of file class.assMatchingQuestion.php.

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

◆ calculateReachedPointsForSolution()

assMatchingQuestion::calculateReachedPointsForSolution ( ?array  $found_values)
protected

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

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

◆ checkSubmittedMatchings()

assMatchingQuestion::checkSubmittedMatchings ( array  $submitted_matchings)
private

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

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

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 333 of file class.assMatchingQuestion.php.

338 : void {
339 $image_source_path = $this->getImagePath($source_question_id, $source_parent_id);
340 $image_target_path = $this->getImagePath($target_question_id, $target_parent_id);
341
342 if (!file_exists($image_target_path)) {
343 ilFileUtils::makeDirParents($image_target_path);
344 } else {
345 $this->removeAllImageFiles($image_target_path);
346 }
347
348 foreach ($this->terms as $term) {
349 if ($term->getPicture() === '') {
350 continue;
351 }
352
353 $filename = $term->getPicture();
354 if (!file_exists($image_source_path . $filename)
355 || !copy($image_source_path . $filename, $image_target_path . $filename)) {
356 $this->log->forComponent('qpl')->warning('matching question image could not be copied: '
357 . $image_source_path . $filename);
358 }
359 if (!file_exists($image_source_path . $this->getThumbPrefix() . $filename)
360 || !copy(
361 $image_source_path . $this->getThumbPrefix() . $filename,
362 $image_target_path . $this->getThumbPrefix() . $filename
363 )) {
364 $this->log->forComponent('qpl')->warning('matching question image thumbnail could not be copied: '
365 . $image_source_path . $this->getThumbPrefix() . $filename);
366 }
367 }
368 foreach ($this->definitions as $definition) {
369 if ($definition->getPicture() === '') {
370 continue;
371 }
372 $filename = $definition->getPicture();
373
374 if (!file_exists($image_source_path . $filename)
375 || !copy($image_source_path . $filename, $image_target_path . $filename)) {
376 $this->log->forComponent('qpl')->warning('matching question image could not be copied: '
377 . $image_source_path . $filename);
378 }
379
380 if (!file_exists($image_source_path . $this->getThumbPrefix() . $filename)
381 || !copy(
382 $image_source_path . $this->getThumbPrefix() . $filename,
383 $image_target_path . $this->getThumbPrefix() . $filename
384 )) {
385 $this->log->forComponent('qpl')->warning('matching question image thumbnail could not be copied: '
386 . $image_source_path . $this->getThumbPrefix() . $filename);
387 }
388 }
389 }
$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 326 of file class.assMatchingQuestion.php.

328 : \assQuestion {
329 $target->cloneImages($this->getId(), $this->getObjId(), $target->getId(), $target->getObjId());
330 return $target;
331 }

◆ createMatchingDefinition()

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

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

1336 {
1337 return new assAnswerMatchingDefinition($term, $picture, $identifier);
1338 }
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 1339 of file class.assMatchingQuestion.php.

1344 $term = $term ?? $this->createMatchingTerm();
1345 $definition = $definition ?? $this->createMatchingDefinition();
1346 return new assAnswerMatchingPair($term, $definition, $points);
1347 }
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 1331 of file class.assMatchingQuestion.php.

1332 {
1333 return new assAnswerMatchingTerm($term, $picture, $identifier);
1334 }
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 668 of file class.assMatchingQuestion.php.

668 : void
669 {
670 unset($this->definitions[$position]);
671 $this->definitions = array_values($this->definitions);
672 }

◆ 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 835 of file class.assMatchingQuestion.php.

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

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 486 of file class.assMatchingQuestion.php.

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

◆ deleteTerm()

assMatchingQuestion::deleteTerm (   $position)

Deletes a term.

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

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

656 : void
657 {
658 unset($this->terms[$position]);
659 $this->terms = array_values($this->terms);
660 }

◆ fetchIndexedValuesFromValuePairs()

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

Reimplemented from assQuestion.

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

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

◆ flushDefinitions()

assMatchingQuestion::flushDefinitions ( )

Deletes all definitions.

See also
$definitions

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

645 : void
646 {
647 $this->definitions = [];
648 }

◆ flushMatchingPairs()

assMatchingQuestion::flushMatchingPairs ( )

Deletes all matching pairs.

See also
$matchingpairs

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

505 : void
506 {
507 $this->matchingpairs = [];
508 }

◆ flushTerms()

assMatchingQuestion::flushTerms ( )

Deletes all terms.

See also
$terms

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

636 : void
637 {
638 $this->terms = [];
639 }

◆ fromNormalized()

assMatchingQuestion::fromNormalized ( array  $normalized,
Transformations  $transformations 
)
Parameters
array<array-key,mixed>$normalized

Reimplemented from assQuestion.

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

1451 : static
1452 {
1453 $clone = parent::fromNormalized($normalized, $transformations);
1454 $clone->shufflemode = $transformations->int($normalized['shuffle_mode']);
1455 $clone->matching_mode = $transformations->string($normalized['matching_mode']);
1456 $clone->matching_type = $transformations->int($normalized['matching_type']);
1457 $clone->thumb_geometry = $transformations->int($normalized['thumb_geometry']);
1458
1459 foreach ($normalized['matching_pairs'] as $matching_pair) {
1460 $term = $transformations->denormalize($matching_pair['term'], new assAnswerMatchingTerm());
1461 $definition = $transformations->denormalize($matching_pair['definition'], new assAnswerMatchingDefinition());
1462
1463 $clone->matchingpairs[] = new assAnswerMatchingPair($term, $definition, $transformations->float($matching_pair['points']));
1464 $clone->terms[] = $term;
1465 $clone->definitions[] = $definition;
1466 }
1467
1468 return $clone;
1469 }
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\denormalize(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\float(), ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\int(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\string().

+ Here is the call graph for this function:

◆ generateThumbForFile()

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

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

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

References $filename, and ilShellUtil\convertImage().

+ Here is the call graph for this function:

◆ getAdditionalTableName()

assMatchingQuestion::getAdditionalTableName ( )

Reimplemented from assQuestion.

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

986 : string
987 {
988 return "qpl_qst_matching";
989 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getAnswerTableName()

assMatchingQuestion::getAnswerTableName ( )

Reimplemented from assQuestion.

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

991 : array
992 {
993 return ["qpl_a_matching", "qpl_a_mterm"];
994 }

◆ 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 1301 of file class.assMatchingQuestion.php.

1302 {
1303 if ($index !== null) {
1304 return $this->getMatchingPair($index);
1305 } else {
1306 return $this->getMatchingPairs();
1307 }
1308 }
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 1422 of file class.assMatchingQuestion.php.

1422 : array
1423 {
1424 return array_map(
1425 fn(assAnswerMatchingPair $v): string => $v->getDefinition()->getText() . ': '
1426 . $v->getTerm()->getText(),
1427 $this->getMatchingPairs()
1428 );
1429 }

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 571 of file class.assMatchingQuestion.php.

571 : int
572 {
573 return count($this->definitions);
574 }

◆ getDefinitions()

assMatchingQuestion::getDefinitions ( )

Returns the definitions of the matching question.

Returns
array An array containing the definitions
See also
$terms

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

549 : array
550 {
551 return $this->definitions;
552 }

◆ getDefinitionWithIdentifier()

assMatchingQuestion::getDefinitionWithIdentifier (   $a_identifier)

Returns a definition with a given identifier.

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

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

◆ 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 801 of file class.assMatchingQuestion.php.

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

References $filename.

◆ getExpressionTypes()

◆ getMatchingMode()

assMatchingQuestion::getMatchingMode ( )

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

1193 : string
1194 {
1195 return $this->matching_mode;
1196 }

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 465 of file class.assMatchingQuestion.php.

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

◆ 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 527 of file class.assMatchingQuestion.php.

527 : int
528 {
529 return count($this->matchingpairs);
530 }

◆ getMatchingPairs()

assMatchingQuestion::getMatchingPairs ( )

Returns the matchingpairs array.

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

1008 : array
1009 {
1010 return $this->matchingpairs;
1011 }

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 716 of file class.assMatchingQuestion.php.

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

Referenced by isComplete().

+ Here is the caller graph for this function:

◆ getMaximumScoringMatchingPairs()

assMatchingQuestion::getMaximumScoringMatchingPairs ( )

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

727 : array
728 {
729 if ($this->getMatchingMode() == self::MATCHING_MODE_N_ON_N) {
730 return $this->getPositiveScoredMatchingPairs();
731 } elseif ($this->getMatchingMode() == self::MATCHING_MODE_1_ON_1) {
733 }
734
735 return [];
736 }

◆ getMostPositiveScoredUniqueTermMatchingPairs()

assMatchingQuestion::getMostPositiveScoredUniqueTermMatchingPairs ( )
private

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

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

◆ getOperators()

assMatchingQuestion::getOperators ( string  $expression)

Get all available operations for a specific question.

Parameters
$expression

Implements iQuestionCondition.

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

1220 : array
1221 {
1223 }
static getOperatorsByExpression(string $expression)

References ilOperatorsExpressionMapping\getOperatorsByExpression().

+ Here is the call graph for this function:

◆ getPositiveScoredMatchingPairs()

assMatchingQuestion::getPositiveScoredMatchingPairs ( )
private

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

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

◆ getQuestionType()

assMatchingQuestion::getQuestionType ( )

Returns the question type of the question.

Returns
integer The question type of the question

Reimplemented from assQuestion.

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

981 : string
982 {
983 return "assMatchingQuestion";
984 }

◆ getRandomId()

assMatchingQuestion::getRandomId ( )

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

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

◆ 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 1000 of file class.assMatchingQuestion.php.

1000 : string
1001 {
1002 return parent::getRTETextWithMediaObjects();
1003 }

◆ getShuffleMode()

assMatchingQuestion::getShuffleMode ( )

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

108 : int
109 {
110 return $this->shufflemode;
111 }

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 560 of file class.assMatchingQuestion.php.

560 : int
561 {
562 return count($this->terms);
563 }

◆ getTerms()

assMatchingQuestion::getTerms ( )

Returns the terms of the matching question.

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

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

538 : array
539 {
540 return $this->terms;
541 }

◆ getTermWithIdentifier()

assMatchingQuestion::getTermWithIdentifier (   $a_identifier)

Returns a term with a given identifier.

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

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

◆ getThumbGeometry()

assMatchingQuestion::getThumbGeometry ( )

Get the thumbnail geometry.

Returns
integer Geometry

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

1018 : int
1019 {
1020 return $this->thumb_geometry;
1021 }

Referenced by saveAdditionalQuestionDataToDb().

+ Here is the caller graph for this function:

◆ getThumbPrefix()

assMatchingQuestion::getThumbPrefix ( )

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

1085 : string
1086 {
1087 return "thumb.";
1088 }

◆ getThumbSize()

assMatchingQuestion::getThumbSize ( )

Get the thumbnail geometry.

Returns
integer Geometry

Reimplemented from assQuestion.

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

1028 : int
1029 {
1030 return $this->getThumbGeometry();
1031 }

◆ 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 1235 of file class.assMatchingQuestion.php.

1239 $result = new ilUserQuestionResult($this, $active_id, $pass);
1240
1241 $data = $this->db->queryF(
1242 "SELECT ident FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id",
1243 ["integer"],
1244 [$this->getId()]
1245 );
1246
1247 $definitions = [];
1248 for ($index = 1; $index <= $this->db->numRows($data); ++$index) {
1249 $row = $this->db->fetchAssoc($data);
1250 $definitions[$row["ident"]] = $index;
1251 }
1252
1253 $data = $this->db->queryF(
1254 "SELECT ident FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id",
1255 ["integer"],
1256 [$this->getId()]
1257 );
1258
1259 $terms = [];
1260 for ($index = 1; $index <= $this->db->numRows($data); ++$index) {
1261 $row = $this->db->fetchAssoc($data);
1262 $terms[$row["ident"]] = $index;
1263 }
1264
1265 $maxStep = $this->lookupMaxStep($active_id, $pass);
1266
1267 if ($maxStep > 0) {
1268 $data = $this->db->queryF(
1269 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = %s",
1270 ["integer", "integer", "integer","integer"],
1271 [$active_id, $pass, $this->getId(), $maxStep]
1272 );
1273 } else {
1274 $data = $this->db->queryF(
1275 "SELECT value1, value2 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s",
1276 ["integer", "integer", "integer"],
1277 [$active_id, $pass, $this->getId()]
1278 );
1279 }
1280
1281 while ($row = $this->db->fetchAssoc($data)) {
1282 if ($row["value1"] > 0) {
1283 $result->addKeyValue($definitions[$row["value2"]], $terms[$row["value1"]]);
1284 }
1285 }
1286
1287 $points = $this->calculateReachedPoints($active_id, $pass);
1288 $max_points = $this->getMaximumPoints();
1289
1290 $result->setReachedPercentage(($points / $max_points) * 100);
1291
1292 return $result;
1293 }
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 618 of file class.assMatchingQuestion.php.

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

◆ 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 401 of file class.assMatchingQuestion.php.

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

◆ insertTerm()

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

Inserts a term.

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

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

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

◆ isComplete()

assMatchingQuestion::isComplete ( )

Reimplemented from assQuestion.

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

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

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 230 of file class.assMatchingQuestion.php.

230 : void
231 {
232 $query = "
233 SELECT qpl_questions.*,
234 {$this->getAdditionalTableName()}.*
235 FROM qpl_questions
236 LEFT JOIN {$this->getAdditionalTableName()}
237 ON {$this->getAdditionalTableName()}.question_fi = qpl_questions.question_id
238 WHERE qpl_questions.question_id = %s
239 ";
240
241 $result = $this->db->queryF(
242 $query,
243 ['integer'],
244 [$question_id]
245 );
246
247 if ($result->numRows() == 1) {
248 $data = $this->db->fetchAssoc($result);
249 $this->setId((int) $question_id);
250 $this->setObjId((int) $data["obj_fi"]);
251 $this->setTitle((string) $data["title"]);
252 $this->setComment((string) $data["description"]);
253 $this->setOriginalId((int) $data["original_id"]);
254 $this->setNrOfTries((int) $data['nr_of_tries']);
255 $this->setAuthor($data["author"]);
256 $this->setPoints((float) $data["points"]);
257 $this->setOwner((int) $data["owner"]);
258 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc((string) $data["question_text"], 1));
259 $this->setThumbGeometry((int) $data["thumb_geometry"]);
260 $this->setShuffle($data["shuffle"] != '0');
261 $this->setShuffleMode((int) $data['shuffle']);
262 $this->setMatchingMode($data['matching_mode'] === null ? self::MATCHING_MODE_1_ON_1 : $data['matching_mode']);
263
264 try {
265 $this->setLifecycle(new ilAssQuestionLifecycle($data['lifecycle']));
268 }
269
270 try {
271 $this->setAdditionalContentEditingMode($data['add_cont_edit_mode']);
273 }
274 }
275
276 $termids = [];
277 $result = $this->db->queryF(
278 "SELECT * FROM qpl_a_mterm WHERE question_fi = %s ORDER BY term_id ASC",
279 ['integer'],
280 [$question_id]
281 );
282 $this->terms = [];
283 if ($result->numRows() > 0) {
284 while ($data = $this->db->fetchAssoc($result)) {
285 $term = $this->createMatchingTerm($data['term'] ?? '', $data['picture'] ?? '', (int) $data['ident']);
286 $this->terms[] = $term;
287 $termids[$data['term_id']] = $term;
288 }
289 }
290
291 $definitionids = [];
292 $result = $this->db->queryF(
293 "SELECT * FROM qpl_a_mdef WHERE question_fi = %s ORDER BY def_id ASC",
294 ['integer'],
295 [$question_id]
296 );
297
298 $this->definitions = [];
299 if ($result->numRows() > 0) {
300 while ($data = $this->db->fetchAssoc($result)) {
301 $definition = $this->createMatchingDefinition($data['definition'] ?? '', $data['picture'] ?? '', (int) $data['ident']);
302 array_push($this->definitions, $definition);
303 $definitionids[$data['def_id']] = $definition;
304 }
305 }
306
307 $this->matchingpairs = [];
308 $result = $this->db->queryF(
309 "SELECT * FROM qpl_a_matching WHERE question_fi = %s ORDER BY answer_id",
310 ['integer'],
311 [$question_id]
312 );
313 if ($result->numRows() > 0) {
314 while ($data = $this->db->fetchAssoc($result)) {
315 $pair = $this->createMatchingPair(
316 $termids[$data['term_fi']],
317 $definitionids[$data['definition_fi']],
318 (float) $data['points']
319 );
320 array_push($this->matchingpairs, $pair);
321 }
322 }
323 parent::loadFromDb((int) $question_id);
324 }
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(), 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 1046 of file class.assMatchingQuestion.php.

1046 : void
1047 {
1048 $new_terms = [];
1049 foreach ($this->terms as $term) {
1050 if ($term->getPicture() !== '') {
1051 $current_file_path = $this->getImagePath() . $term->getPicture();
1052 if (!file_exists($current_file_path)) {
1053 $new_terms[] = $term;
1054 continue;
1055 }
1056 $new_file_name = $this->buildHashedImageFilename($term->getPicture(), true);
1057 $new_file_path = $this->getImagePath() . $new_file_name;
1058 rename($current_file_path, $new_file_path);
1059 $term = $term->withPicture($new_file_name);
1060 $this->generateThumbForFile($this->getImagePath(), $term->getPicture());
1061 }
1062 $new_terms[] = $term;
1063 }
1064 $this->terms = $new_terms;
1065
1066 $new_definitions = [];
1067 foreach ($this->definitions as $definition) {
1068 if ($definition->getPicture() !== '') {
1069 $current_file_path = $this->getImagePath() . $definition->getPicture();
1070 if (!file_exists($current_file_path)) {
1071 $new_definitions[] = $definition;
1072 continue;
1073 }
1074 $new_file_name = $this->buildHashedImageFilename($definition->getPicture(), true);
1075 $new_file_path = $this->getImagePath() . $new_file_name;
1076 rename($current_file_path, $new_file_path);
1077 $definition = $definition->withPicture($new_file_name);
1078 $this->generateThumbForFile($this->getImagePath(), $definition->getPicture());
1079 }
1080 $new_definitions[] = $definition;
1081 }
1082 $this->definitions = $new_definitions;
1083 }
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 819 of file class.assMatchingQuestion.php.

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

◆ removeTermImage()

assMatchingQuestion::removeTermImage (   $index)

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

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

◆ saveAdditionalQuestionDataToDb()

assMatchingQuestion::saveAdditionalQuestionDataToDb ( )

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

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

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 140 of file class.assMatchingQuestion.php.

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

945 : void
946 {
947 $submitted_matchings = $this->questionpool_request->getMatchingPairs();
948
949 if ($this->checkSubmittedMatchings($submitted_matchings)) {
950 $previewSession->setParticipantsSolution($submitted_matchings);
951 }
952 }
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 131 of file class.assMatchingQuestion.php.

131 : void
132 {
136
137 parent::saveToDb();
138 }
saveAnswerSpecificDataToDb()
Saves the answer specific records into a question types answer 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 917 of file class.assMatchingQuestion.php.

921 : bool {
922 if ($pass === null) {
923 $pass = ilObjTest::_getPass($active_id);
924 }
925
926 $submitted_matchings = $this->questionpool_request->getMatchingPairs();
927 if (!$this->checkSubmittedMatchings($submitted_matchings)) {
928 return false;
929 }
930
931 $this->getProcessLocker()->executeUserSolutionUpdateLockOperation(
932 function () use ($submitted_matchings, $active_id, $pass, $authorized) {
933 $this->removeCurrentSolution($active_id, $pass, $authorized);
934 foreach ($submitted_matchings as $definition => $terms) {
935 foreach ($terms as $i => $term) {
936 $this->saveCurrentSolution($active_id, $pass, $term, $definition, $authorized);
937 }
938 }
939 }
940 );
941
942 return true;
943 }
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 847 of file class.assMatchingQuestion.php.

851 : bool {
852 $result = true;
853 if ($image_tempfilename === '') {
854 return true;
855 }
856
857 $image_filename = str_replace(' ', '_', $image_filename);
858 $imagepath = $this->getImagePath();
859 if (!file_exists($imagepath)) {
860 ilFileUtils::makeDirParents($imagepath);
861 }
862
864 $image_tempfilename,
865 $image_filename,
866 $imagepath . $image_filename
867 )
868 ) {
869 return false;
870 }
871
872 // create thumbnail file
873 $thumbpath = $imagepath . $this->getThumbPrefix() . $image_filename;
875 $imagepath . $image_filename,
876 $thumbpath,
877 'JPEG',
878 (string) $this->getThumbGeometry()
879 );
880
881 if ($result
882 && $image_filename !== $previous_filename
883 && $previous_filename !== ''
884 ) {
885 $this->deleteImagefile($previous_filename);
886 }
887 return $result;
888 }
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 1188 of file class.assMatchingQuestion.php.

1188 : void
1189 {
1190 $this->matching_mode = $matching_mode;
1191 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setShuffle()

assMatchingQuestion::setShuffle (   $shuffle = true)

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

971 : void
972 {
973 $this->shuffle = (bool) $shuffle;
974 }

Referenced by loadFromDb().

+ Here is the caller graph for this function:

◆ setShuffleMode()

assMatchingQuestion::setShuffleMode ( int  $shuffle)

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

114 {
115 $this->shufflemode = $shuffle;
116 }

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 681 of file class.assMatchingQuestion.php.

681 : void
682 {
683 $this->terms[$index] = $term;
684 }

◆ setThumbGeometry()

assMatchingQuestion::setThumbGeometry ( int  $a_geometry)

Set the thumbnail geometry.

Parameters
integer$a_geometryGeometry

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

1038 : void
1039 {
1040 $this->thumb_geometry = ($a_geometry < 1) ? 100 : $a_geometry;
1041 }

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 1387 of file class.assMatchingQuestion.php.

1390 : array {
1391 return $this->solutionValuesToText($solution_values);
1392 }
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 1394 of file class.assMatchingQuestion.php.

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

References Vendor\Package\$c.

◆ toJSON()

assMatchingQuestion::toJSON ( )

Returns a JSON representation of the question.

Reimplemented from assQuestion.

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

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

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

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

+ Here is the call graph for this function:

◆ toNormalized()

assMatchingQuestion::toNormalized ( Transformations  $transformations,
array  $context = [] 
)
Parameters
array<string,mixed>$context
Returns
array<array-key, mixed>|float|bool|int|string|null

Reimplemented from assQuestion.

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

1435 : array|float|bool|int|string|null
1436 {
1437 return [
1438 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
1439 'shuffle_mode' => $this->shufflemode,
1440 'matching_mode' => $this->matching_mode,
1441 'matching_type' => $this->matching_type,
1442 'thumb_geometry' => $this->thumb_geometry,
1443 'matching_pairs' => $transformations->normalize($this->matchingpairs, ['question_id' => $this->getId()]),
1444 ];
1445 }

References ILIAS\Survey\Mode\getId(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\normalize().

+ Here is the call graph for this function:

◆ withMatchingPairs()

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

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

513 : self
514 {
515 $clone = clone $this;
516 $clone->matchingpairs = $pairs;
517 return $clone;
518 }

Field Documentation

◆ $definitions

array assMatchingQuestion::$definitions = []
protected

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

◆ $element_height

int assMatchingQuestion::$element_height

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

◆ $matching_mode

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

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

◆ $matching_type

int assMatchingQuestion::$matching_type

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

Referenced by __construct().

◆ $matchingpairs

assMatchingQuestion::$matchingpairs

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

Referenced by saveAnswerSpecificDataToDb().

◆ $randomGroup

RandomGroup assMatchingQuestion::$randomGroup
private

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

◆ $shufflemode

int assMatchingQuestion::$shufflemode = 0
private

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

Referenced by getShuffleMode().

◆ $terms

array assMatchingQuestion::$terms = []
protected

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

◆ $thumb_geometry

int assMatchingQuestion::$thumb_geometry = 100

Definition at line 51 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 46 of file class.assMatchingQuestion.php.

◆ MT_TERMS_PICTURES

const assMatchingQuestion::MT_TERMS_PICTURES = 0

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


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