diff --git a/lang/fr/group.js b/lang/fr/group.js
new file mode 100644
index 0000000..d255676
--- /dev/null
+++ b/lang/fr/group.js
@@ -0,0 +1,14 @@
+module.exports =
+{
+ needCorrectPublishingDate: "La date de publication fournie n'a pas un format valide.",
+ needLanguage: "Vous devez sélectionner la langue de ce quiz.",
+ needNotTooLongTitle: "Le titre du quiz ne doit pas compter plus de 255 caractères.",
+ needTitle: "Merci de fournir un titre à votre quiz.",
+ needUniqueUrl: "L'url du quiz doit être unique.",
+ needUrl: "Merci de fournir l'url à votre quiz.",
+ /*
+ questionnairesName: "quiz",
+ questionnaireNeedBeCompleted: "Quiz incomplet",
+ publishedAt: ", le",
+ publishedBy: "Quiz publié par"*/
+};
\ No newline at end of file
diff --git a/lang/fr/questionnaire.js b/lang/fr/questionnaire.js
index 1c27917..25c6872 100644
--- a/lang/fr/questionnaire.js
+++ b/lang/fr/questionnaire.js
@@ -22,7 +22,8 @@ module.exports =
needIntroduction: "Merci de fournir un texte d'introduction à votre quiz.",
needKnowIfIsPublished: "Il faut savoir si ce quiz est publié.",
needLanguage: "Vous devez sélectionner la langue de ce quiz.",
- needNotTooLongTitle: "Le titre du quiz ne doit pas compter plus de 255 caractères.",
+ needNotTooLongTitle: "Le titre du quiz ne doit pas compter plus de 255 caractères.",
+ needNumberForRank: "Vous devez saisir un nombre entier pour le rang de ce questionnaire dans son groupe.",
needTitle: "Merci de fournir un titre à votre quiz.",
needUniqueUrl: "L'url du quiz doit être unique.",
needUrl: "Merci de fournir l'url à votre quiz.",
diff --git a/models/Group.js b/models/Group.js
new file mode 100644
index 0000000..f78dc5f
--- /dev/null
+++ b/models/Group.js
@@ -0,0 +1,94 @@
+"use strict";
+
+// revoir les requires pour ne prendre que ce j'ai besoin ?
+const striptags = require("striptags");
+
+const slugify = require("slugify");
+const tool = require("../tools/main");
+
+const config = require("../config/main.js");
+const txt = require("../lang/"+config.adminLang+"/group");
+const txtGeneral = require("../lang/"+config.adminLang+"/general");
+
+module.exports = (sequelize, DataTypes) =>
+{
+ const Group = sequelize.define("Groupe",
+ {
+ title:
+ {
+ type: DataTypes.STRING(255), allowNull: false,
+ set(value)
+ {
+ this.setDataValue("title", tool.trimIfNotNull(striptags(value)));
+ },
+ validate:
+ {
+ notNull: { msg: txt.needTitle },
+ len:
+ {
+ args: [1, 255],
+ msg: txt.needNotTooLongTitle
+ }
+ }
+ },
+ slug:
+ {
+ type: DataTypes.STRING(150), allowNull: false,
+ unique:
+ {
+ args: true,
+ msg: txt.needUniqueUrl
+ },
+ set(value)
+ {
+ value=tool.trimIfNotNull(striptags(value));
+ if(value!==null)
+ this.setDataValue("slug", slugify(value.substring(0,150), { lower:true, strict:true }));
+ else if(this.title!==null)
+ this.setDataValue("slug", slugify(this.title.substring(0,150), { lower:true, strict:true }));
+ },
+ validate:
+ {
+ notNull: { msg: txt.needUrl }
+ }
+ },
+ introduction:
+ {
+ type: DataTypes.TEXT, allowNull: true,
+ set(value) { this.setDataValue("introduction", tool.trimIfNotNull(striptags(value,"
"))); }
+ },
+ publishingAt:
+ {
+ type: DataTypes.DATE, comment: "If null, the questionnaire with the questions for each element of the group is not published, but its elements may be.",
+ set(value) { this.setDataValue("publishingAt", tool.trimIfNotNull(value)); },
+ validate:
+ {
+ isDate: { msg: txt.needCorrectPublishingDate }
+ }
+ },
+ language:
+ {
+ type: DataTypes.STRING(4), allowNull: false, defaultValue: "fr",
+ validate:
+ {
+ notNull: { msg: txt.needLanguage },
+ len:
+ {
+ args: [2, 4],
+ msg: txt.needLanguage+" "+txtGeneral.notValidFormat
+ } // en fait, il faudra vérifier l'existence du fichier de la langue choisie.
+ }
+ }
+ },
+ {
+ charset: "utf8mb4",
+ collate: "utf8mb4_unicode_ci"
+ }
+ );
+ Questionnaire.associate = function(models)
+ {
+ Questionnaire.hasMany(models.Questionnaire);
+ Questionnaire.belongsTo(models.User, { as: "Creator", foreignKey: { name: "CreatorId", allowNull: false } });
+ };
+ return Questionnaire;
+};
\ No newline at end of file
diff --git a/models/Questionnaire.js b/models/Questionnaire.js
index 02470fa..1f6cfa3 100644
--- a/models/Questionnaire.js
+++ b/models/Questionnaire.js
@@ -115,6 +115,20 @@ module.exports = (sequelize, DataTypes) =>
msg: txt.needEstimatedTime+" "+txtGeneral.notValidFormat
}
}
+ },
+ rankInGroup:
+ {
+ type: DataTypes.INTEGER(2).UNSIGNED, allowNull: true,
+ comment: "Allows you to classify the questionnaire if it belongs to a group.",
+ validate:
+ {
+ isInt: { msg: txt.needNumberForRank },
+ min:
+ {
+ args: [1],
+ msg: txt.needNumberForRank
+ }
+ }
}
},
{
@@ -129,6 +143,7 @@ module.exports = (sequelize, DataTypes) =>
Questionnaire.hasMany(models.Link);
Questionnaire.hasMany(models.Answer);
Questionnaire.belongsTo(models.User, { as: "Creator", foreignKey: { name: "CreatorId", allowNull: false } });
+ Questionnaire.belongsTo(models.Group, { foreignKey: { name: "GroupId", allowNull: true }, onDelete: 'RESTRICT', onUpdate: 'RESTRICT' });
Questionnaire.belongsToMany(models.Tag, { through: models.QuestionnaireClassification });
Questionnaire.belongsToMany(models.User, { through: models.QuestionnaireAccess });
};
diff --git a/models/wikilerni-crea.sql b/models/wikilerni-crea.sql
index b9883ed..cea623e 100644
--- a/models/wikilerni-crea.sql
+++ b/models/wikilerni-crea.sql
@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Client : localhost:3306
--- Généré le : Mer 26 Août 2020 à 12:22
+-- Généré le : Mer 07 Octobre 2020 à 18:42
-- Version du serveur : 5.7.31-0ubuntu0.18.04.1
-- Version de PHP : 7.2.24-0ubuntu0.18.04.6
@@ -53,6 +53,24 @@ CREATE TABLE `Choices` (
-- --------------------------------------------------------
+--
+-- Structure de la table `Groups`
+--
+
+CREATE TABLE `Groups` (
+ `id` int(11) NOT NULL,
+ `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `slug` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `introduction` text COLLATE utf8mb4_unicode_ci,
+ `publishingAt` datetime DEFAULT NULL COMMENT 'If null, the questionnaire with the questions for each element of the group is not published, but its elements may be.',
+ `language` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
+ `createdAt` datetime NOT NULL,
+ `updatedAt` datetime NOT NULL,
+ `CreatorId` int(11) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+-- --------------------------------------------------------
+
--
-- Structure de la table `Illustrations`
--
@@ -156,9 +174,11 @@ CREATE TABLE `Questionnaires` (
`isPublished` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'May depend on factors other than the date of publication.',
`language` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
`estimatedTime` enum('short','medium','long') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'medium' COMMENT 'Provides an estimate of the time required to complete this questionnaire.',
+ `rankInGroup` int(2) UNSIGNED DEFAULT NULL COMMENT 'Allows you to classify the questionnaire if it belongs to a group.',
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
- `CreatorId` int(11) NOT NULL
+ `CreatorId` int(11) NOT NULL,
+ `GroupId` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
@@ -264,6 +284,14 @@ ALTER TABLE `Choices`
ADD PRIMARY KEY (`id`),
ADD KEY `QuestionId` (`QuestionId`);
+--
+-- Index pour la table `Groups`
+--
+ALTER TABLE `Groups`
+ ADD PRIMARY KEY (`id`),
+ ADD UNIQUE KEY `Questionnaires_slug_unique` (`slug`),
+ ADD KEY `CreatorId` (`CreatorId`);
+
--
-- Index pour la table `Illustrations`
--
@@ -314,7 +342,8 @@ ALTER TABLE `Questionnaires`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `Questionnaires_slug_unique` (`slug`),
ADD KEY `isPublished` (`isPublished`),
- ADD KEY `CreatorId` (`CreatorId`);
+ ADD KEY `CreatorId` (`CreatorId`),
+ ADD KEY `GroupId` (`GroupId`);
--
-- Index pour la table `Questions`
@@ -360,17 +389,22 @@ ALTER TABLE `Users`
-- AUTO_INCREMENT pour la table `Answers`
--
ALTER TABLE `Answers`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;
--
-- AUTO_INCREMENT pour la table `Choices`
--
ALTER TABLE `Choices`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1007;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1016;
+--
+-- AUTO_INCREMENT pour la table `Groups`
+--
+ALTER TABLE `Groups`
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT pour la table `Illustrations`
--
ALTER TABLE `Illustrations`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=39;
--
-- AUTO_INCREMENT pour la table `Links`
--
@@ -385,22 +419,22 @@ ALTER TABLE `Pauses`
-- AUTO_INCREMENT pour la table `Payments`
--
ALTER TABLE `Payments`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT pour la table `Questionnaires`
--
ALTER TABLE `Questionnaires`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=50;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=51;
--
-- AUTO_INCREMENT pour la table `Questions`
--
ALTER TABLE `Questions`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=322;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=327;
--
-- AUTO_INCREMENT pour la table `Subscriptions`
--
ALTER TABLE `Subscriptions`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;
--
-- AUTO_INCREMENT pour la table `Tags`
--
@@ -410,12 +444,12 @@ ALTER TABLE `Tags`
-- AUTO_INCREMENT pour la table `UserDeleteds`
--
ALTER TABLE `UserDeleteds`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT pour la table `Users`
--
ALTER TABLE `Users`
- MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=27;
--
-- Contraintes pour les tables exportées
--
@@ -475,7 +509,8 @@ ALTER TABLE `QuestionnaireClassifications`
-- Contraintes pour la table `Questionnaires`
--
ALTER TABLE `Questionnaires`
- ADD CONSTRAINT `Questionnaires_ibfk_1` FOREIGN KEY (`CreatorId`) REFERENCES `Users` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE;
+ ADD CONSTRAINT `Questionnaires_ibfk_1` FOREIGN KEY (`CreatorId`) REFERENCES `Users` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE,
+ ADD CONSTRAINT `Questionnaires_ibfk_2` FOREIGN KEY (`GroupId`) REFERENCES `Groups` (`id`);
--
-- Contraintes pour la table `Questions`