Example #1
0
 public static function Instance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public function get_filled_template_poll($pid, $templateName)
 {
     $mPoll = M_Poll::Instance();
     $pid = (int) $pid;
     if (!$pid) {
         return '';
     }
     $user['hostname'] = $_SERVER['REMOTE_ADDR'];
     $user['uid'] = M_Users::Instance()->GetUid();
     $this->show_result['status'] = $mPoll->is_voted($pid, $user);
     if ($this->isPost()) {
         if (isset($_POST['poll_result'])) {
             $this->show_result['status'] = true;
         } elseif (isset($_POST['poll_vote'])) {
             M_Poll::Instance()->save_vote($_POST, $user);
             //$this->redirect(M_Link::ToPage("poll", (int)$_POST['pid']));
             $this->redirect($_SERVER['REQUEST_URI']);
         }
     }
     $this->poll = $mPoll->get_result_poll($pid);
     if (empty($this->poll)) {
         return '';
     }
     if ($this->show_result['status'] == true) {
         $this->show_result['value'] = 0;
         foreach ($this->poll as $answer) {
             $this->show_result['value'] += $answer['res'];
         }
     }
     // Формирование контента страницы
     $templatePoll = $this->Template($templateName, $this);
     return $templatePoll;
 }
Example #3
0
 public function action_getpolls()
 {
     foreach (M_Poll::Instance()->all() as $key => $val) {
         $data[$key]['pid'] = $val['pid'];
         $data[$key]['question'] = $val['question'];
     }
     echo json_encode($data);
 }