/** * @return Models\Users * @throws \Exception */ public function getUser() { if (isset($_SESSION['userId'])) { $user = Models\Users::getById((int) $_SESSION['userId']); } elseif (isset($_SESSION['facebook_access_token'])) { //var_dump('toto');die; $data = $this->fbAPI->get('me?fields=name,email,gender,locale', $_SESSION['facebook_access_token'])->getDecodedBody(); if (!isset($data['email'])) { $data['email'] = false; } $data['FBid'] = $data['id']; $data['smallPictureUrl'] = $this->getSmallPictureUrl(); $data['largePictureUrl'] = $this->getLargePictureUrl(); $user = Models\Users::get(array('FBid' => $data['id'])); if (empty($user)) { $data['id'] = null; $user = Models\Users::Factory($data); } } else { $user = false; } return $user; }
public function admin_usersProfile($params) { $user = Models\Users::getById($params['user_id']); $user_infos['name'] = $user->getName(); $user_infos['email'] = $user->getEmail(); if ($user->getGender() == "female") { $user_infos['gender'] = "Femme"; } else { $user_infos['gender'] = "Homme"; } $user_infos['lang'] = $user->getLocale(); $user_infos['profilepic'] = $user->getSmallPictureUrl(); $user_infos['backgroundpic'] = $user->getLargePictureUrl(); $user_infos['FBid'] = $user->getFBId(); $userAppId = $user->appID($user_infos['FBid']); $user_infos['tests'] = $user->userTests($user->getId()); if (!empty($user_infos['tests'])) { foreach ($user_infos['tests'] as $quizzId) { /** @var $quizz Posts */ $quizz = Posts::getById($quizzId['post_id']); $quizz_infos[$quizzId['post_id']]['title'] = $quizz->getTitle(); $quizz_infos[$quizzId['post_id']]['score'] = $quizzId['total']; $quizz_infos[$quizzId['post_id']]['questions'] = count($quizz->getPostentries()); /** @var $score Score */ $score = Score::get(["user_id" => $userAppId[0]['id'], "post_id" => $quizzId['post_id']]); $users_score = $score->getAllTotals($quizzId['total'], $quizzId['post_id']); $users_number = $score->getAllUsers($quizzId['post_id']); $max_score = $users_score[0]['count(total)']; $all_users = $users_number[0]['count(id)']; $rank = $all_users - $max_score . '/' . $all_users; $quizz_infos[$quizzId['post_id']]['rank'] = $rank; } } $view = Services\View::getInstance(); if (empty($quizz_infos)) { $quizz_infos[0]['title'] = 'Aucun quizz passé'; } return $this->content_page = $view->render("admin/subpages/user.html", ['userInfos' => $user_infos, 'quizzInfos' => array_reverse($quizz_infos)]); }