Exemple #1
0
 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')]);
     }
 }
Exemple #2
0
 public function save()
 {
     $data = get_object_vars($this);
     $id = $data["id"];
     unset($data["db"]);
     unset($data["table"]);
     $sql_columns_insert = [];
     foreach ($data as $key => $value) {
         $sql_columns_insert[] = ":" . $key;
         $sql_columns_update[] = $key . "=:" . $key;
     }
     if (Options::get($id) !== false) {
         $success = $this->db->exec('UPDATE ' . $this->table . ' SET ' . implode(" , ", $sql_columns_update) . ' WHERE id=:id', $data);
     } else {
         $success = $this->db->exec('INSERT INTO ' . $this->table . '(' . implode(",", array_keys($data)) . ')VALUES (' . implode(',', $sql_columns_insert) . ')', $data);
     }
     return $success;
 }
Exemple #3
0
 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"]]);
 }
Exemple #4
0
 protected function getHtml()
 {
     $js = $this->getJsConst();
     $color = $this->getThemeColors();
     $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();
     } else {
         $link = $this->fb->getLoginLink();
     }
     $view = Services\View::getInstance();
     $content = $view->render('pages/home.html', ['assets_root' => ASSETS_PATH, 'js_const' => $js, 'loginLink' => $link, 'color' => $color, 'connected' => $connected, 'adminConnected' => $adminConnected, 'pictureUrl' => $pictureUrl, 'baseURL' => DOMAIN_NAME, 'userName' => $userName, 'texts' => ["app_title" => Options::get("app_title") ? Options::get("app_title") : "SuperQuizz", "main_text" => Options::get("main_text") ? Options::get("main_text") : "Découvrez notre dernier Quizz !", "sub_text" => Options::get("sub_text") ? Options::get("sub_text") : "Testez vos connaissances, et gagnez de superbes récompenses !"]]);
     return $content;
 }
Exemple #5
0
 protected function getThemeColors()
 {
     return ["main_color" => Options::get("main_color") ? Options::get("main_color") : "#3b5999", "sub_color" => Options::get("sub_color") ? Options::get("sub_color") : "#6a7183", "text_color" => Options::get("text_color") ? Options::get("text_color") : "#333333", "back_color" => Options::get("backgroud_color") ? Options::get("backgroud_color") : "#dfe8f1"];
 }
Exemple #6
0
 public function admin_createExport()
 {
     $user = $this->fb->getUser();
     $users = $user->getAll();
     header('Content-Type: application/excel');
     header('Content-Disposition: attachment; filename="users.csv"');
     $hr = array('ID', 'Nom', 'Adresse mail', 'Langue', 'Genre', 'ID Facebook', 'Score', 'Classement');
     $fp = fopen("php://output", 'w');
     fputcsv($fp, $hr);
     foreach ($users as $fields) {
         $score = Score::get(["user_id" => $fields["id"], "post_id" => Models\Options::get("active_post")]);
         /** @var $score Score */
         $fields["score"] = $score ? $score->getTotal() : "";
         $fields["classement"] = $score ? count($score->getSuperiorsScores()) : "";
         foreach ($fields as $key => $field) {
             if ($field) {
                 $fields[$key] = utf8_decode($field);
             }
         }
         unset($fields["smallPictureUrl"]);
         unset($fields["largePictureUrl"]);
         fputcsv($fp, $fields);
     }
     fclose($fp);
     echo $fp;
     die;
 }