Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: twig tags for feedback modals #364

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ abstract class AbstractMarkupRenderingEngine implements Renderable
*/
public const CSSCLASS_ABSTRACT = 9;

/**
* Use twig tags to generate template
*/
public const TWIG_ORIENTED = 10;

/**
* An array used to 'tag' explored Component object.
*
Expand Down Expand Up @@ -638,6 +643,10 @@ protected function processNode($base = ''): void
$this->includeChoiceComponent($component, $rendering);
}

if ($this->mustTwigFeedbackComponent($component) === true) {
$this->twigFeedbackComponent($component, $rendering);
Copy link

@pribi pribi Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to clear up the naming a bit. If I understand it correctly:

Does this mean if twig feedback component must be used? I propose to rename to:
if ($this->mustUseTwigFeedbackComponent($component) === true) { ... }

and set twig feedback component:
$this->setTwigFeedbackComponent($component, $rendering);

}

$this->setLastRendering($rendering);
}

Expand Down Expand Up @@ -977,7 +986,7 @@ protected function mustTemplateFeedbackComponent(QtiComponent $component): bool
*/
protected function mustTemplateRubricBlockComponent(QtiComponent $component): bool
{
return (self::isRubricBlock($component) && $this->getViewPolicy() === self::TEMPLATE_ORIENTED);
return (self::isRubricBlock($component) && $this->getViewPolicy() === self::TEMPLATE_ORIENTED);
}

/**
Expand Down Expand Up @@ -1208,6 +1217,7 @@ public function getChoiceShowHidePolicy(): int
* * In CONTEXT_STATIC mode, the qti-show/qti-hide classes will be set on the rendered element depending on how the qti:feedbackElement is defined. It will never be discarded from the final rendering.
* * In CONTEXT_AWARE mode, the component will be rendered as an element or discarded from the final rendering depending on the value of the variable referenced by the qti:feedbackElement.
* * In TEMPLATE_ORIENTED mode, the component will be always rendered and enclosed in template tags, that can be processed later on depending on the needs.
* * In TWIG_ORIENTED mode, the component will be rendered and enclosed in twig template tags, that can be processed later on depending on the needs.
*
* @param int $policy AbstractMarkupRenderingEngine::CONTEXT_STATIC or AbstractMarkupRenderingEngine::CONTEXT_AWARE or AbstractMarkupRenderingEngine::TEMPLATE_ORIENTED.
*/
Expand Down Expand Up @@ -1550,4 +1560,27 @@ public function getDocument(): DOMDocument
{
return $this->document;
}

private function twigFeedbackComponent(QtiComponent $component, DOMDocumentFragment $rendering)
{
$ifstatement = sprintf(
'{%% if getPrintedVariable(testSession, "%s", "%%s", false, 10, -1, ";", "", "=") == "%s" %%}',
$component->getOutcomeIdentifier(),
$component->getIdentifier()
);

$rendering->insertBefore(
$rendering->ownerDocument->createTextNode($ifstatement),
$rendering->firstChild
);

$rendering->appendChild(
$rendering->ownerDocument->createTextNode('{% endif %}')
);
}

private function mustTwigFeedbackComponent(QtiComponent $component): bool
{
return (self::isFeedback($component) && $this->getFeedbackShowHidePolicy() === self::TWIG_ORIENTED);
}
}
Loading