コード例 #1
0
ファイル: Ajax.php プロジェクト: ElPolloLoco/SCPV
 private function postAction($params)
 {
     $post = Options::get("active_post");
     $user = Services\FacebookAPI::getInstance()->getUser();
     if ($post && $user && ($post = Posts::getById($post))) {
         /** @var $post Posts */
         /** @var $score Score */
         $score = Score::get(["user_id" => $user->getId(), "post_id" => $post->getId()]);
         if (!$score) {
             $score = Score::Factory(["user_id" => $user->getId(), "post_id" => $post->getId(), "score" => [], "start" => date('Y-m-d H:i:s')]);
         }
         /** @var $post_entry PostEntry */
         $post_entries = $post->getPostentries();
         $score_data = $score->getScore();
         if (isset($params["answer"])) {
             $answer = $post_entries[count($score_data)];
             $answer = PostEntry::getById($answer)->getAnswer();
             $score_data[] = $params["answer"] == $answer ? 1 : 0;
             $score->setScore($score_data);
         }
         $pe_index = count($score_data);
         $score->save();
         $post_entry = isset($post_entries[$pe_index]) ? $post_entries[$pe_index] : null;
         $post_entry = PostEntry::getById($post_entry);
         if ($post_entry) {
             $post_form = new Services\Fields();
             $post_form->Title($post->getTitle(), "h1 class=\"quizz-title center\"");
             $post_form->desc($post_entry->getQuestion());
             foreach ($post_entry->getPropositions() as $k => $p) {
                 $post_form->radio(["name" => "post_entry", "slug" => "post_entry_{$k}", "id" => "post_entry_{$k}", "label" => $p]);
             }
             $post_form->submit(["action" => "send_post_answer", "slug" => "send_post_answer", "icon" => "send", "class" => "right", "text" => "Suivant", "noajax" => true]);
             echo json_encode(["html" => $post_form->render()]);
             exit;
         } else {
             $result = array_count_values($score_data);
             $result = isset($result[1]) ? $result[1] : 0;
             $score->setTotal($result);
             $score->setEnd(date('Y-m-d H:i:s'));
             $score->setTime($score->getTime());
             $score->save();
             $users_score = $score->getSuperiorsScores();
             $users_number = $score->getAllUsers($post->getId());
             $max_score = $users_score[0]['count(total)'];
             $all_users = $users_number[0]['count(id)'];
             $percent = $all_users > 1 ? $max_score / $all_users * 100 : 100;
             $time = $score->getTime();
             $view = Services\View::getInstance();
             echo json_encode(["html" => $view->render('partials/show-result.html', ['result' => $result, 'total' => count($score_data), 'users' => round($percent * 2) / 2, 'url' => "http://" . DOMAIN_NAME, 'app_id' => APP_ID, 'time' => $time])]);
         }
     } else {
         $view = Services\View::getInstance();
         echo json_encode(["html" => $view->render('partials/no-quizz.html')]);
     }
 }
コード例 #2
0
ファイル: Profile.php プロジェクト: ElPolloLoco/SCPV
 public function buildPage()
 {
     $connected = null;
     $adminConnected = null;
     $pictureUrl = null;
     $userName = null;
     $link = null;
     if (!empty($_SESSION['connected'])) {
         $this->user = $this->fb->getUser();
         $connected = true;
         $adminConnected = $this->user ? $this->fb->isAdmin($this->user->getFBId()) : false;
         $pictureUrl = $this->user->getSmallPictureUrl();
         $userName = $this->user->getName();
         $userAppId = $this->user->appID($this->user->getFBId());
         if (!empty($userAppId)) {
             $userTests = $this->user->userTests($userAppId[0]['id']);
         }
     }
     if (!empty($userTests)) {
         foreach ($userTests 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 = View::getInstance();
     if (empty($quizz_infos)) {
         $quizz_infos[0]['title'] = 'Aucun quizz passé';
     }
     echo $view->render('pages/profile.html', ['connected' => $connected, 'assets_root' => ASSETS_PATH, 'js_const' => $this->getJsConst(), 'adminConnected' => $adminConnected, 'pictureUrl' => $pictureUrl, 'userName' => $userName, 'color' => $this->getThemeColors(), 'quizzInfos' => isset($quizz_infos) ? array_reverse($quizz_infos) : [], 'texts' => ["app_title" => Options::get("app_title") ? Options::get("app_title") : "SuperQuizz"]]);
 }
コード例 #3
0
ファイル: Admin.php プロジェクト: ElPolloLoco/SCPV
 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)]);
 }