diff --git a/admin/index.php b/admin/index.php index a320e25..f1cc487 100644 --- a/admin/index.php +++ b/admin/index.php @@ -16,104 +16,103 @@ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ -namespace Framadate; + +use Framadate\Services\AdminPollService; +use Framadate\Services\LogService; +use Framadate\Services\PollService; +use Framadate\Services\SuperAdminService; +use Framadate\Utils; include_once __DIR__ . '/../app/inc/init.php'; include_once __DIR__ . '/../bandeaux.php'; +/* Services */ +/*----------*/ +$logService = new LogService(); +$pollService = new PollService($connect, $logService); +$adminPollService = new AdminPollService($connect, $pollService, $logService); +$superAdminService = new SuperAdminService($connect); + // Ce fichier index.php se trouve dans le sous-repertoire ADMIN de Studs. Il sert à afficher l'intranet de studs // pour modifier les sondages directement sans avoir reçu les mails. C'est l'interface d'aministration // de l'application. // Affichage des balises standards -Utils::print_header( _('Polls administrator') ); +Utils::print_header(_('Polls administrator')); bandeau_titre(_('Polls administrator')); -$sondage=$connect->Execute('SELECT * FROM sondage'); +$polls = $superAdminService->findAllPolls(); + +echo '
'."\n"; +echo '' . "\n"; bandeau_pied(true); - -// si on annule la suppression, rafraichissement de la page -/*if (Utils::issetAndNoEmpty('annulesuppression') === true) { - // TODO -}*/ diff --git a/adminstuds.php b/adminstuds.php index 9883e42..0ab3563 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -36,7 +36,7 @@ $editingVoteId = 0; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 35797d1..15ae3ce 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -274,4 +274,21 @@ class FramaDB { return $prepared->fetchAll(); } + public function findAllPolls() { + $prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' ORDER BY end_date ASC'); + $prepared->execute([]); + + return $prepared->fetchAll(); + } + + public function countVotesByPollId($poll_id) { + $prepared = $this->prepare('SELECT count(1) nb FROM ' . Utils::table('vote') . ' WHERE poll_id = ?'); + + $prepared->execute([$poll_id]); + $result = $prepared->fetch(); + $prepared->closeCursor(); + + return $result->nb; + } + } diff --git a/app/classes/Framadate/Services/LogService.php b/app/classes/Framadate/Services/LogService.php index 61c5e79..8ccb48f 100644 --- a/app/classes/Framadate/Services/LogService.php +++ b/app/classes/Framadate/Services/LogService.php @@ -8,10 +8,7 @@ namespace Framadate\Services; */ class LogService { - private $output; - - function __construct($output) { - $this->output = $output; + function __construct() { } /** @@ -21,7 +18,7 @@ class LogService { * @param $message string some message */ function log($tag, $message) { - error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, $this->output); + error_log(date('Ymd His') . ' [' . $tag . '] ' . $message . "\n", 3, LOG_FILE); } } diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 828be5a..949afcb 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -75,6 +75,10 @@ class PollService { return $this->connect->insertComment($poll_id, $name, $comment); } + public function countVotesByPollId($poll_id) { + return $this->connect->countVotesByPollId($poll_id); + } + function computeBestChoices($votes) { $result = []; foreach ($votes as $vote) { diff --git a/app/classes/Framadate/Services/SuperAdminService.php b/app/classes/Framadate/Services/SuperAdminService.php new file mode 100644 index 0000000..bea7b14 --- /dev/null +++ b/app/classes/Framadate/Services/SuperAdminService.php @@ -0,0 +1,29 @@ +connect = $connect; + } + + /** + * Return the list of all polls. + * + * @return array All the polls + */ + public function findAllPolls() { + return $this->connect->findAllPolls(); + } + +} + \ No newline at end of file diff --git a/choix_autre.php b/choix_autre.php index 95ba3cd..e9bd1d1 100644 --- a/choix_autre.php +++ b/choix_autre.php @@ -27,7 +27,7 @@ include_once __DIR__ . '/app/inc/init.php'; /* Service */ /*---------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp']); $purgeService = new PurgeService($connect, $logService); diff --git a/choix_date.php b/choix_date.php index 5170306..bfe0790 100644 --- a/choix_date.php +++ b/choix_date.php @@ -28,7 +28,7 @@ include_once __DIR__ . '/app/inc/init.php'; /* Service */ /*---------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $mailService = new MailService($config['use_smtp']); $purgeService = new PurgeService($connect, $logService); diff --git a/exportcsv.php b/exportcsv.php index 34b4155..f5efcd7 100644 --- a/exportcsv.php +++ b/exportcsv.php @@ -36,7 +36,7 @@ $poll = null; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); /* PAGE */ diff --git a/studs.php b/studs.php index b7c91c8..b04ce05 100644 --- a/studs.php +++ b/studs.php @@ -36,7 +36,7 @@ $editingVoteId = 0; /* Services */ /*----------*/ -$logService = new LogService(LOG_FILE); +$logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); $mailService = new MailService($config['use_smtp']);