Order&Reorder Questions
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
parent
e87a94a5dc
commit
d061e759b5
6 changed files with 166 additions and 19 deletions
|
|
@ -46,7 +46,7 @@ class QuestionMapper extends QBMapper {
|
|||
* @return Question[]
|
||||
*/
|
||||
|
||||
public function findByForm(int $formId): array {
|
||||
public function findByForm(int $formId, bool $loadDeleted = false): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
|
|
@ -55,6 +55,16 @@ class QuestionMapper extends QBMapper {
|
|||
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
|
||||
);
|
||||
|
||||
if (!$loadDeleted) {
|
||||
// Don't load questions, that are marked as deleted (marked by order==0).
|
||||
$qb->andWhere(
|
||||
$qb->expr()->neq('order', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
// Sort Questions by order
|
||||
$qb->orderBy('order');
|
||||
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +75,7 @@ class QuestionMapper extends QBMapper {
|
|||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
// First delete corresponding options.
|
||||
$questionEntities = $this->findByForm($formId);
|
||||
$questionEntities = $this->findByForm($formId, true); // findByForm - loadDeleted=true
|
||||
foreach ($questionEntities as $questionEntity) {
|
||||
$this->optionMapper->deleteByQuestion($questionEntity->id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue