示例#1
0
文件: Home.php 项目: ElPolloLoco/SCPV
 protected function __construct($params)
 {
     $this->params = $params;
     $this->fb = Services\FacebookAPI::getInstance();
     $this->db = Services\DataBase::getInstance();
     $this->db->connectOrCreate();
 }
示例#2
0
 public function buildPage()
 {
     $user = Services\FacebookAPI::getInstance()->getUser();
     if (!$user || $user && !$user->isAdmin()) {
         Page404::getInstance()->buildPage();
         exit;
     }
     $params = $this->params;
     if (isset($params["sub_page"])) {
         foreach ($this->subpages as $subpage) {
             if ($params["sub_page"] == $subpage["slug"] && method_exists($this, $subpage["action"])) {
                 $this->current_subpage = $subpage;
                 $this->{$subpage}["action"]($params);
                 echo $this->getHtml();
                 return;
             }
         }
     }
     if (isset($params["action"]) && method_exists($this, $params["action"])) {
         $this->{$params}["action"]($params);
     }
     $this->current_subpage["action"] = "";
     $this->dashboardSubpage($params);
     echo $this->getHtml();
 }
示例#3
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')]);
     }
 }
示例#4
0
 public function isAdmin()
 {
     $fb_api = Services\FacebookAPI::getInstance();
     return $fb_api->isAdmin($this->getFBId());
 }