Improve usage of namespace + Create PollService in /Framadate/Service namespace
This commit is contained in:
parent
2480d441d4
commit
d54f2e4759
@ -38,8 +38,7 @@ class FramaDB
|
|||||||
return $this->pdo->query($sql);
|
return $this->pdo->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findPollById($poll_id)
|
function findPollById($poll_id) {
|
||||||
{
|
|
||||||
|
|
||||||
// Open database
|
// Open database
|
||||||
if (preg_match(';^[\w\d]{16}$;i', $poll_id)) {
|
if (preg_match(';^[\w\d]{16}$;i', $poll_id)) {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
|
use Framadate\FramaDB;
|
||||||
|
use Framadate\Utils;
|
||||||
|
|
||||||
if (ini_get('date.timezone') == '') {
|
if (ini_get('date.timezone') == '') {
|
||||||
date_default_timezone_set('Europe/Paris');
|
date_default_timezone_set('Europe/Paris');
|
||||||
@ -36,25 +38,19 @@ $smarty->cache_dir = 'cache/';
|
|||||||
$smarty->caching = false;
|
$smarty->caching = false;
|
||||||
|
|
||||||
$smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
|
$smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
|
||||||
$smarty->assign('SERVER_URL', \Framadate\Utils::get_server_name());
|
$smarty->assign('SERVER_URL', Utils::get_server_name());
|
||||||
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
|
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
|
||||||
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
|
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
|
||||||
$smarty->assign('lang', $lang);
|
$smarty->assign('lang', $lang);
|
||||||
$smarty->assign('langs', $ALLOWED_LANGUAGES);
|
$smarty->assign('langs', $ALLOWED_LANGUAGES);
|
||||||
$smarty->assign('date_format', $date_format);
|
$smarty->assign('date_format', $date_format);
|
||||||
|
|
||||||
function smarty_modifier_poll_url($poll_id, $admin=false){return \Framadate\Utils::getUrlSondage($poll_id, $admin);}
|
function smarty_modifier_poll_url($poll_id, $admin=false){return Utils::getUrlSondage($poll_id, $admin);}
|
||||||
// End- Smarty
|
// End- Smarty
|
||||||
|
|
||||||
|
|
||||||
use Framadate\FramaDB;
|
|
||||||
use Framadate\Form;
|
|
||||||
use Framadate\Choice;
|
|
||||||
use Framadate\Utils;
|
|
||||||
|
|
||||||
if (session_id() == '') {
|
if (session_id() == '') {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
$connect = new Framadate\FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
|
$connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {"Framadate": "app/classes/"}
|
"psr-4": {"Framadate\\": "app/classes/Framadate/"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
studs.php
15
studs.php
@ -16,7 +16,7 @@
|
|||||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
namespace Framadate;
|
use Framadate\Services\PollService;
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
@ -65,6 +65,11 @@ function computeBestMoments($votes) {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Services */
|
||||||
|
/*----------*/
|
||||||
|
|
||||||
|
$pollService = new PollService($connect);
|
||||||
|
|
||||||
/* PAGE */
|
/* PAGE */
|
||||||
/* ---- */
|
/* ---- */
|
||||||
|
|
||||||
@ -73,7 +78,7 @@ if(!empty($_GET['poll'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$poll = $connect->findPollById($poll_id);
|
$poll = $pollService->findById($poll_id);
|
||||||
|
|
||||||
if (!$poll) {
|
if (!$poll) {
|
||||||
$smarty->assign('error', 'This poll doesn\'t exist');
|
$smarty->assign('error', 'This poll doesn\'t exist');
|
||||||
@ -82,9 +87,9 @@ if (!$poll) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data
|
// Retrieve data
|
||||||
$slots = $connect->allSlotsByPollId($poll_id);
|
$slots = $pollService->allSlotsByPollId($poll_id);
|
||||||
$votes = $connect->allUserVotesByPollId($poll_id);
|
$votes = $pollService->allUserVotesByPollId($poll_id);
|
||||||
$comments = $connect->allCommentsByPollId($poll_id);
|
$comments = $pollService->allCommentsByPollId($poll_id);
|
||||||
|
|
||||||
// Assign data to template
|
// Assign data to template
|
||||||
$smarty->assign('poll_id', $poll_id);
|
$smarty->assign('poll_id', $poll_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user