Refine survey editor flow and auth styling
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Mummert\SurveyBundle\Repository;
|
||||
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
use Contao\StringUtil;
|
||||
use Doctrine\DBAL\ArrayParameterType;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Mummert\SurveyBundle\Model\SurveyModel;
|
||||
|
||||
@@ -67,12 +68,11 @@ final class SurveyRepository
|
||||
s.isLocked,
|
||||
s.updatedAt,
|
||||
COUNT(DISTINCT q.id) AS questionCount,
|
||||
COUNT(DISTINCT a.id) AS answerCount
|
||||
COUNT(DISTINCT CASE WHEN sub.isFinished = 1 THEN sub.id END) AS participationCount
|
||||
FROM tl_survey s
|
||||
INNER JOIN tl_survey_editor e ON COALESCE(NULLIF(e.survey, 0), e.pid) = s.id AND e.member = :member
|
||||
LEFT JOIN tl_survey_content q ON q.pid = s.id
|
||||
LEFT JOIN tl_survey_submission sub ON sub.survey = s.id
|
||||
LEFT JOIN tl_survey_answer a ON a.submission = sub.id
|
||||
GROUP BY s.id
|
||||
ORDER BY s.updatedAt DESC, s.title ASC
|
||||
SQL,
|
||||
@@ -91,7 +91,7 @@ final class SurveyRepository
|
||||
'alias' => $this->ensurePublicAlias(null),
|
||||
'category' => serialize($this->normalizeCategoryIds($data['category'] ?? [])),
|
||||
'description' => (string) ($data['description'] ?? ''),
|
||||
'published' => !empty($data['published']) ? '1' : '',
|
||||
'published' => '',
|
||||
'isLocked' => '',
|
||||
'createdBy' => $memberId,
|
||||
'updatedBy' => $memberId,
|
||||
@@ -212,6 +212,31 @@ final class SurveyRepository
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteCascade(int $surveyId): void
|
||||
{
|
||||
$this->connection->transactional(function () use ($surveyId): void {
|
||||
$submissionIds = array_values(array_map('intval', $this->connection->fetchFirstColumn(
|
||||
'SELECT id FROM tl_survey_submission WHERE survey = ?',
|
||||
[$surveyId],
|
||||
)));
|
||||
|
||||
if ([] !== $submissionIds) {
|
||||
$this->connection->executeStatement(
|
||||
'DELETE FROM tl_survey_answer WHERE submission IN (?)',
|
||||
[$submissionIds],
|
||||
[ArrayParameterType::INTEGER],
|
||||
);
|
||||
}
|
||||
|
||||
$this->connection->delete('tl_survey_submission', ['survey' => $surveyId]);
|
||||
$this->connection->delete('tl_survey_condition', ['pid' => $surveyId]);
|
||||
$this->connection->delete('tl_survey_content', ['pid' => $surveyId]);
|
||||
$this->connection->delete('tl_survey_editor', ['survey' => $surveyId]);
|
||||
$this->connection->delete('tl_survey_editor', ['pid' => $surveyId]);
|
||||
$this->connection->delete('tl_survey', ['id' => $surveyId]);
|
||||
});
|
||||
}
|
||||
|
||||
private function generateRandomPublicAlias(): string
|
||||
{
|
||||
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
|
||||
Reference in New Issue
Block a user