Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions app/V1Module/presenters/base/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ private function processParamsLoose(array $paramData)
} else {
$param->conformsToDefinition($paramValue);
}

// Path and query parameter might need patching, so they have correct type for
// being injected into the presenter method.
if (
$param->type === Type::Path || $param->type === Type::Query
&& array_key_exists($param->name, $this->params)
) {
foreach ($param->validators as $validator) {
$validator->patchQueryParameter($this->params[$param->name]);
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/helpers/MetaFormats/Validators/BaseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ public function validate(mixed $value): bool
// return false by default to enforce overriding in derived types
return false;
}

/**
* Patches the query/path parameter value after successful validation.
* This is useful for special data types that needs to be converted to a different type before being used
* in the presenter method (e.g., convert strings like "true"/"false" to booleans).
* Note: this method is not called for values that did not pass validation.
* @param mixed $value The value to be patched. Passed by reference, so it can be modified by the method.
*/
public function patchQueryParameter(mixed &$value): void
{
// no-op by default, can be overridden by validators that need to change the value before validation
}
}
9 changes: 9 additions & 0 deletions app/helpers/MetaFormats/Validators/VArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ public function validate(mixed $value): bool
}
return true;
}

public function patchQueryParameter(mixed &$value): void
{
if (is_array($value) && $this->nestedValidator !== null) {
foreach ($value as &$element) {
$this->nestedValidator->patchQueryParameter($element);
}
}
}
}
27 changes: 21 additions & 6 deletions app/helpers/MetaFormats/Validators/VBool.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,29 @@ public function validate(mixed $value): bool

if (!$this->strict) {
// FILTER_VALIDATE_BOOL is not used because it additionally allows "on", "yes", "off", "no" and ""
return $value === 0
|| $value === 1
|| $value === "0"
|| $value === "1"
|| $value === "false"
|| $value === "true";

if ($value === 0 || $value === 1) {
return true;
}

if (is_string($value)) {
$lower = strtolower(trim($value));
return $lower === "0"
|| $lower === "1"
|| $lower === "false"
|| $lower === "true";
}
}

return false;
}

public function patchQueryParameter(mixed &$value): void
{
if (is_string($value)) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
} else {
$value = (bool)$value;
}
}
}
5 changes: 3 additions & 2 deletions app/model/repository/PlagiarismDetectionBatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public function findByToolAndSolution(?string $detectionTool, ?AssignmentSolutio
$sub = $qb->getEntityManager()->createQueryBuilder()
->select("ds")->from(PlagiarismDetectedSimilarity::class, "ds");
$sub->andWhere("ds.batch = b.id")
->andWhere("ds.testedSolution = :sid")->setParameter("sid", $solution->getId());
$qb->andWhere($qb->expr()->exists($sub->getDQL()));
->andWhere("ds.testedSolution = :sid");
$qb->andWhere($qb->expr()->exists($sub->getDQL()))
->setParameter("sid", $solution->getId());
}
$qb->orderBy("b.createdAt", "DESC");
return $qb->getQuery()->getResult();
Expand Down
Loading