Esempio n. 1
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     require_once dirname(__DIR__) . DS . 'models' . DS . 'poll.php';
     $options = \Components\Poll\Models\Poll::all()->whereEquals('published', 1)->rows()->raw();
     array_unshift($options, \Html::select('option', '0', '- ' . \Lang::txt('Select Poll') . ' -', 'id', 'title'));
     return \Html::select('genericlist', $options, $control_name . '[' . $name . ']', 'class="inputbox"', 'id', 'title', $value, $control_name . $name);
 }
Esempio n. 2
0
 /**
  * Get module contents
  *
  * @return  void
  */
 public function run()
 {
     require_once Component::path('com_poll') . DS . 'models' . DS . 'poll.php';
     // Load the latest poll
     $this->poll = Poll::current();
     require $this->getLayoutPath();
 }
Esempio n. 3
0
 /**
  * Display module content
  *
  * @return  void
  */
 public function display()
 {
     require_once \Component::path('com_poll') . DS . 'models' . DS . 'poll.php';
     $menu = \App::get('menu');
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     if ($id = $this->params->get('id', 0)) {
         $poll = \Components\Poll\Models\Poll::oneOrNew($id);
     } else {
         $poll = \Components\Poll\Models\Poll::current();
     }
     if ($poll && $poll->id) {
         require $this->getLayoutPath();
     }
 }
Esempio n. 4
0
 /**
  * Add a vote to an option
  *
  * @return  void
  */
 public function voteTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $poll_id = Request::getVar('id', 0, '', 'int');
     $option_id = Request::getVar('voteid', 0, 'post', 'int');
     $poll = Poll::oneOrFail($poll_id);
     if ($poll->get('state') != 1) {
         App::abort(404, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     $cookieName = App::hash(App::get('client')->name . 'poll' . $poll_id);
     // ToDo - may be adding those information to the session?
     $voted = Request::getVar($cookieName, '0', 'COOKIE', 'INT');
     if ($voted || !$option_id) {
         if ($voted) {
             Notify::warning(Lang::txt('COM_POLL_ALREADY_VOTED'));
         }
         if (!$option_id) {
             Notify::warning(Lang::txt('COM_POLL_WARNSELECT'));
         }
     } else {
         // Determine whether cookie should be 'secure' or not
         $secure = false;
         $forceSsl = \Config::get('force_ssl', false);
         if (App::isAdmin() && $forceSsl >= 1) {
             $secure = true;
         } else {
             if (App::isSite() && $forceSsl == 2) {
                 $secure = true;
             }
         }
         setcookie($cookieName, '1', time() + $poll->get('lag'), '/', '', $secure, true);
         $poll->vote($option_id);
         Notify::success(Lang::txt('COM_POLL_THANK_YOU'));
     }
     // set Itemid id for links
     $menu = App::get('menu');
     $items = $menu->getItems('link', 'index.php?option=com_poll&view=poll');
     $itemid = isset($items[0]) ? '&Itemid=' . $items[0]->id : '';
     App::redirect(Route::url('index.php?option=com_poll&id=' . $poll_id . ':' . $poll->get('alias') . $itemid, false));
 }
Esempio n. 5
0
 /**
  * Cancels a task and redirects to listing
  *
  * @return  void
  */
 public function cancelTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if ($id = Request::getVar('id', 0, '', 'int')) {
         if (is_int($id)) {
             $row = Poll::oneOrFail($id);
             $row->checkin();
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }