diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 173c1e9c7..56deb8813 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -114,15 +114,14 @@ public function getForms(): DataResponse { * @return DataResponse */ public function getSharedForms(): DataResponse { - $forms = $this->formMapper->findAll(); + $forms = $this->formMapper->findActiveForms(); $result = []; foreach ($forms as $form) { // Check if the form should be shown on sidebar - if (!$this->formsService->isSharedFormShown($form)) { - continue; + if ($this->formsService->isSharedFormShown($form)) { + $result[] = $this->formsService->getPartialFormArray($form); } - $result[] = $this->formsService->getPartialFormArray($form); } return new DataResponse($result); diff --git a/lib/Db/FormMapper.php b/lib/Db/FormMapper.php index 9b662f0fa..72f5663e4 100644 --- a/lib/Db/FormMapper.php +++ b/lib/Db/FormMapper.php @@ -127,6 +127,30 @@ public function findAllByOwnerId(string $ownerId): array { return $this->findEntities($qb); } + /** + * Get only active forms - thus not archived, closed or expired + * @return Form[] + */ + public function findActiveForms(): array { + $qb = $this->db->getQueryBuilder(); + + $expires = $qb->expr()->orX(); + $expires->add($qb->expr()->eq('expires', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))); + $expires->add($qb->expr()->gt('expires', $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT))); + + $state = $qb->expr()->eq('state', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)); + + $qb->select('*') + ->from($this->getTableName()) + ->where($expires) + ->andWhere($state) + //Last updated forms first, then newest forms first + ->addOrderBy('last_updated', 'DESC') + ->addOrderBy('created', 'DESC'); + + return $this->findEntities($qb); + } + /** * Delete a Form including connected Questions, Submissions and shares. * @param Form $form The form instance to delete diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index c05935834..5ad453c17 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -389,8 +389,6 @@ public function hasUserAccess(Form $form): bool { * @return bool */ public function isSharedFormShown(Form $form): bool { - $access = $form->getAccess(); - // Dont show here to owner, as its in the owned list anyways. if ($form->getOwnerId() === $this->currentUser->getUID()) { return false; @@ -401,6 +399,7 @@ public function isSharedFormShown(Form $form): bool { return false; } + $access = $form->getAccess(); // Shown if permitall and showntoall are both set. if ($access['permitAllUsers'] && $access['showToAllUsers'] && diff --git a/src/components/AppNavigationForm.vue b/src/components/AppNavigationForm.vue index 50da7351a..dab91f713 100644 --- a/src/components/AppNavigationForm.vue +++ b/src/components/AppNavigationForm.vue @@ -108,7 +108,7 @@ import IconDeleteSvg from '@mdi/svg/svg/delete.svg?raw' import FormsIcon from './Icons/FormsIcon.vue' -import { FormState } from '../models/FormStates' +import { FormState } from '../models/FormStates.ts' import logger from '../utils/Logger.js' export default {