/** * Update the Step metadata. * * @param Step $step * @param \stdClass $metadata * * @throws ValidationException */ public function updateMetadata(Step $step, \stdClass $metadata) { $errors = $this->validator->validateStepMetadata($metadata); if (count($errors) > 0) { throw new ValidationException('Step metadata are not valid', $errors); } // Update Step $step->setTitle($metadata->title); $step->setText($metadata->description); $step->setMaxAttempts(!empty($metadata->maxAttempts) ? (int) $metadata->maxAttempts : 0); // Save to DB $this->om->persist($step); $this->om->flush(); }
/** * Update the Exercise metadata. * * @param Exercise $exercise * @param \stdClass $metadata * * @throws ValidationException */ public function updateMetadata(Exercise $exercise, \stdClass $metadata) { $errors = $this->validator->validateExerciseMetadata($metadata); if (count($errors) > 0) { throw new ValidationException('Exercise metadata are not valid', $errors); } // Update ResourceNode $node = $exercise->getResourceNode(); $node->setName($metadata->title); // Update Exercise $exercise->setDescription($metadata->description); $exercise->setType($metadata->type); $exercise->setPickSteps($metadata->pick ? $metadata->pick : 0); $exercise->setShuffle($metadata->random); $exercise->setKeepSteps($metadata->keepSteps); $exercise->setMaxAttempts($metadata->maxAttempts); $exercise->setLockAttempt($metadata->lockAttempt); $exercise->setDispButtonInterrupt($metadata->dispButtonInterrupt); $exercise->setMetadataVisible($metadata->metadataVisible); $exercise->setMarkMode($metadata->markMode); $exercise->setCorrectionMode($metadata->correctionMode); $exercise->setAnonymous($metadata->anonymous); $exercise->setDuration($metadata->duration); $exercise->setStatistics($metadata->statistics ? true : false); $exercise->setMinimalCorrection($metadata->minimalCorrection ? true : false); $correctionDate = null; if (!empty($metadata->correctionDate) && CorrectionMode::AFTER_DATE === $metadata->correctionMode) { $correctionDate = \DateTime::createFromFormat('Y-m-d\\TH:i:s', $metadata->correctionDate); } $exercise->setDateCorrection($correctionDate); // Save to DB $this->om->persist($exercise); $this->om->flush(); }