Improve usage of namespace + Create PollService in /Framadate/Service namespace

This commit is contained in:
Olivier PEREZ 2014-12-16 00:02:01 +01:00
parent 2480d441d4
commit d54f2e4759
4 changed files with 17 additions and 17 deletions

View File

@ -38,8 +38,7 @@ class FramaDB
return $this->pdo->query($sql);
}
function findPollById($poll_id)
{
function findPollById($poll_id) {
// Open database
if (preg_match(';^[\w\d]{16}$;i', $poll_id)) {

View File

@ -16,6 +16,8 @@
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\FramaDB;
use Framadate\Utils;
if (ini_get('date.timezone') == '') {
date_default_timezone_set('Europe/Paris');
@ -36,25 +38,19 @@ $smarty->cache_dir = 'cache/';
$smarty->caching = false;
$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('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
$smarty->assign('lang', $lang);
$smarty->assign('langs', $ALLOWED_LANGUAGES);
$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
use Framadate\FramaDB;
use Framadate\Form;
use Framadate\Choice;
use Framadate\Utils;
if (session_id() == '') {
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;

View File

@ -4,6 +4,6 @@
},
"autoload": {
"psr-0": {"Framadate": "app/classes/"}
"psr-4": {"Framadate\\": "app/classes/Framadate/"}
}
}

View File

@ -16,7 +16,7 @@
* 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\PollService;
include_once __DIR__ . '/app/inc/init.php';
@ -65,6 +65,11 @@ function computeBestMoments($votes) {
return $result;
}
/* Services */
/*----------*/
$pollService = new PollService($connect);
/* PAGE */
/* ---- */
@ -73,7 +78,7 @@ if(!empty($_GET['poll'])) {
}
$poll = $connect->findPollById($poll_id);
$poll = $pollService->findById($poll_id);
if (!$poll) {
$smarty->assign('error', 'This poll doesn\'t exist');
@ -82,9 +87,9 @@ if (!$poll) {
}
// Retrieve data
$slots = $connect->allSlotsByPollId($poll_id);
$votes = $connect->allUserVotesByPollId($poll_id);
$comments = $connect->allCommentsByPollId($poll_id);
$slots = $pollService->allSlotsByPollId($poll_id);
$votes = $pollService->allUserVotesByPollId($poll_id);
$comments = $pollService->allCommentsByPollId($poll_id);
// Assign data to template
$smarty->assign('poll_id', $poll_id);