Index: src/include/class.cotisations_membres.php ================================================================== --- src/include/class.cotisations_membres.php +++ src/include/class.cotisations_membres.php @@ -24,11 +24,11 @@ || !$db->simpleQuerySingle('SELECT 1 FROM cotisations WHERE id = ?;', false, (int) $data['id_cotisation'])) { throw new UserException('Cotisation inconnue.'); } - $data['id_cotisation'] = $data['id_cotisation'] ? (int) $data['id_cotisation'] : null; + $data['id_cotisation'] = (int) $data['id_cotisation']; if (empty($data['id_membre']) || !$db->simpleQuerySingle('SELECT 1 FROM membres WHERE id = ?;', false, (int) $data['id_membre'])) { throw new UserException('Membre inconnu ou invalide.'); @@ -46,15 +46,10 @@ { $db = DB::getInstance(); $this->_checkFields($data); - if (empty($data['id_membre'])) - { - throw new UserException('Membre inconnu ou invalide.'); - } - $db->exec('BEGIN;'); $db->simpleInsert('cotisations_membres', [ 'date' => $data['date'], 'id_cotisation' => $data['id_cotisation'], @@ -100,11 +95,10 @@ * @return integer true en cas de succès */ public function delete($id) { $db = DB::getInstance(); - return $db->simpleExec('DELETE FROM cotisations_membres WHERE id = ?;', (int) $id); } public function get($id) { ADDED src/include/class.rappels.php Index: src/include/class.rappels.php ================================================================== --- src/include/class.rappels.php +++ src/include/class.rappels.php @@ -0,0 +1,125 @@ +simpleQuerySingle('SELECT 1 FROM cotisations WHERE id = ?;', false, (int) $data['id_cotisation'])) + { + throw new UserException('Cotisation inconnue.'); + } + + $data['id_cotisation'] = (int) $data['id_cotisation']; + + if (empty($data['delai']) || !is_numeric($data['delai']) || (int)$data['delai'] < 0) + { + throw new UserException('Délai avant rappel invalide : doit être indiqué en nombre de jours.'); + } + + $data['delai'] = (int) $data['delai']; + + if (!isset($data['sujet']) || trim($data['sujet']) === '') + { + throw new UserException('Le sujet du rappel ne peut être vide.'); + } + + $data['sujet'] = trim($data['sujet']); + + if (!isset($data['texte']) || trim($data['texte']) === '') + { + throw new UserException('Le contenu du rappel ne peut être vide.'); + } + + $data['texte'] = trim($data['texte']); + } + + /** + * Ajouter un rappel + * @param array $data Données du rappel + * @return integer Numéro ID du rappel créé + */ + public function add($data) + { + $db = DB::getInstance(); + + $this->_checkFields($data); + + $db->simpleInsert('rappels', $data); + + return $db->lastInsertRowId(); + } + + /** + * Modifier un rappel automatique + * @param integer $id Numéro du rappel + * @param array $data Données du rappel + * @return boolean TRUE si tout s'est bien passé + * @throws UserException En cas d'erreur dans une donnée à modifier + */ + public function edit($id, $data) + { + $db = DB::getInstance(); + + $this->_checkFields($data); + + return $db->simpleUpdate('rappels', $data, 'id = ' . (int)$id); + } + + /** + * Supprimer un rappel automatique + * @param integer $id Numéro du rappel + * @return boolean TRUE en cas de succès + */ + public function delete($id) + { + $db = DB::getInstance(); + + $db->exec('BEGIN;'); + $db->simpleExec('DELETE FROM rappels WHERE id = ?;', (int) $id); + $db->simpleExec('DELETE FROM rappels_envoyes WHERE id_rappel = ?;', (int) $id); + $db->exec('END;'); + + return true; + } + + /** + * Renvoie les données sur un rappel + * @param integer $id Numéro du rappel + * @return array Données du rappel + */ + public function get($id) + { + return DB::getInstance()->simpleQuerySingle('SELECT * FROM rappels WHERE id = ?;', true, (int)$id); + } + + /** + * Liste des rappels triés par cotisation + * @return array Liste des rappels + */ + public function listByCotisation() + { + return DB::getInstance()->simpleStatementFetch('SELECT r.*, c.intitule FROM rappels AS r + INNER JOIN cotisations ON c.id = r.id_cotisation ORDER BY r.id_cotisation, r.delai, r.sujet;'); + } + + /** + * Liste des rappels pour une cotisation donnée + * @param integer $id Numéro du rappel + * @return array Liste des rappels + */ + public function listForCotisation($id) + { + return DB::getInstance()->simpleStatementFetch('SELECT * FROM rappels + WHERE id_cotisation = ? ORDER BY delai, sujet;', \SQLITE3_ASSOC, (int)$id); + } +} ADDED src/include/class.rappels_envoyes.php Index: src/include/class.rappels_envoyes.php ================================================================== --- src/include/class.rappels_envoyes.php +++ src/include/class.rappels_envoyes.php @@ -0,0 +1,115 @@ +simpleQuerySingle('SELECT 1 FROM cotisations WHERE id = ?;', false, (int) $data['id_cotisation'])) + { + throw new UserException('Cotisation inconnue.'); + } + + $data['id_cotisation'] = (int) $data['id_cotisation']; + } + + if (empty($data['id_membre']) + || !$db->simpleQuerySingle('SELECT 1 FROM membres WHERE id = ?;', false, (int) $data['id_membre'])) + { + throw new UserException('Membre inconnu.'); + } + + $data['id_membre'] = (int) $data['id_membre']; + + if (empty($data['media']) || !is_numeric($data['delai']) + || !in_array((int)$data['media'], [self::MEDIA_EMAIL, self::MEDIA_COURRIER, self::MEDIA_TELEPHONE, self::MEDIA_AUTRE])) + { + throw new UserException('Média invalide.'); + } + + $data['media'] = (int) $data['media']; + + if (empty($data['date']) || !utils::checkDate($data['date'])) + { + throw new UserException('La date indiquée n\'est pas valide.'); + } + } + + /** + * Enregistrer un rappel + * @param array $data Données du rappel + * @return integer Numéro ID du rappel créé + */ + public function add($data) + { + $db = DB::getInstance(); + + $this->_checkFields($data); + + $db->simpleInsert('rappels_envoyes', $data); + + return $db->lastInsertRowId(); + } + + /** + * Supprimer un rappel enregistré + * @param integer $id Numéro du rappel + * @return boolean TRUE en cas de succès + */ + public function delete($id) + { + $db = DB::getInstance(); + $db->simpleExec('DELETE FROM rappels_envoyes WHERE id = ?;', (int) $id); + return true; + } + + /** + * Renvoie les données sur un rappel + * @param integer $id Numéro du rappel + * @return array Données du rappel + */ + public function get($id) + { + return DB::getInstance()->simpleQuerySingle('SELECT * FROM rappels_envoyes WHERE id = ?;', true, (int)$id); + } + + /** + * Liste des rappels envoyés à un membre + * @param integer $id Numéro du membre + * @return array Liste des rappels + */ + public function listForMember($id) + { + return DB::getInstance()->simpleStatementFetch('SELECT re.*, r.id_cotisation, r.delai, c.intitule + FROM rappels_envoyes AS re INNER JOIN rappels AS r ON r.id = re.id_rappel + INNER JOIN cotisations ON c.id = r.id_cotisation + WHERE re.id_membre = ? + ORDER BY re.date DESC;', \SQLITE3_ASSOC, (int)$id); + } + + /** + * Liste des rappels pour une cotisation donnée + * @param integer $id Numéro du rappel + * @return array Liste des rappels + */ + public function listForCotisation($id) + { + return DB::getInstance()->simpleStatementFetch('SELECT * FROM rappels_envoyes + WHERE id_rappel = ? ORDER BY date DESC;', \SQLITE3_ASSOC, (int)$id); + } +} Index: src/include/data/0.6.0.sql ================================================================== --- src/include/data/0.6.0.sql +++ src/include/data/0.6.0.sql @@ -48,16 +48,16 @@ ); CREATE TABLE rappels_envoyes -- Enregistrement des rappels envoyés à qui et quand ( + id INTEGER NOT NULL PRIMARY KEY, + id_membre INTEGER NOT NULL REFERENCES membres (id), - id_rappel INTEGER NOT NULL REFERENCES rappels (id), + id_rappel INTEGER NULL REFERENCES rappels (id), date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, - media INTEGER NOT NULL, -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre - - PRIMARY KEY(id_membre, id_rappel, date) + media INTEGER NOT NULL -- Média utilisé pour le rappel : 1 = email, 2 = courrier, 3 = autre ); -- Mise à jour des catégories CREATE TABLE membres_categories_tmp Index: src/templates/admin/membres/cotisations/index.tpl ================================================================== --- src/templates/admin/membres/cotisations/index.tpl +++ src/templates/admin/membres/cotisations/index.tpl @@ -2,11 +2,13 @@
Cotisation |
---|