Skip to content

Commit

Permalink
Implement isValidPatch for OpHandlerQuestionGroup (#3605)
Browse files Browse the repository at this point in the history
  • Loading branch information
twilligls committed Nov 17, 2023
1 parent 6e289f0 commit 38c6956
Showing 1 changed file with 9 additions and 20 deletions.
Expand Up @@ -2,6 +2,7 @@

namespace LimeSurvey\Api\Command\V1\SurveyPatch;

use LimeSurvey\Models\Services\Exception\PermissionDeniedException;
use QuestionGroup;
use LimeSurvey\Models\Services\QuestionGroupService;
use LimeSurvey\Api\Command\V1\Transformer\Input\{
Expand Down Expand Up @@ -183,7 +184,7 @@ private function update(OpInterface $op)
$transformedProps = $this->getTransformedProps($op);
$questionGroup = $this->questionGroupService->getQuestionGroupForUpdate(
$surveyId,
$this->getQuestionGroupId($op)
$op->getEntityId()
);
if (isset($transformedProps['questionGroup'])) {
$this->questionGroupService->updateQuestionGroup(
Expand Down Expand Up @@ -272,42 +273,30 @@ private function create(OpInterface $op): array
* }
*
* @param OpInterface $op
* @param QuestionGroupService $groupService
* @return void
* @throws OpHandlerException
* @throws PermissionDeniedException
*/
private function delete(OpInterface $op)
{
$surveyId = $this->getSurveyIdFromContext($op);
$this->questionGroupService->deleteGroup(
$this->getQuestionGroupId($op),
$op->getEntityId(),
$surveyId
);
}

/**
* Extracts and returns gid (question group id) from passed id parameter
*
* @param OpInterface $op
* @return int
* @throws OpHandlerException
**/
private function getQuestionGroupId(OpInterface $op)
{
$id = $op->getEntityId();
if (!isset($id)) {
throw new OpHandlerException('No group id provided');
}
return $id;
}

/**
* Checks if patch is valid for this operation.
* @param OpInterface $op
* @return bool
*/
public function isValidPatch(OpInterface $op): bool
{
// TODO: Implement isValidPatch() method.
if ($this->isUpdateOperation || $this->isDeleteOperation) {
return ((int)$op->getEntityId()) > 0;
}

return true;
}
}

0 comments on commit 38c6956

Please sign in to comment.