Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     $fields = Request::getVar('fields', array(), 'post');
     // Save the poll parent information
     $row = Poll::oneOrNew($fields['id'])->set($fields);
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     $row->checkin();
     // Save the poll options
     $options = Request::getVar('polloption', array(), 'post');
     foreach ($options as $i => $text) {
         $option = new Option();
         $option->set('poll_id', (int) $row->get('id'));
         $option->set('text', htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
         if ($fields['id']) {
             $option->set('id', (int) $i);
         }
         if (!$option->save()) {
             Notify::error($option->getError());
             return $this->editTask($row);
         }
     }
     Notify::success(Lang::txt('COM_POLL_ITEM_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     $this->cancelTask();
 }
Exemplo n.º 3
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $fields = array('id' => Request::getInt('id', 0, 'post'), 'title' => Request::getVar('title', '', 'post'), 'alias' => Request::getVar('alias', '', 'post'), 'lag' => Request::getVar('lag', '', 'post'), 'published' => Request::getVar('published', '', 'post'), 'open' => Request::getVar('open', '', 'post'));
     // Save the poll parent information
     $row = Poll::oneOrNew($fields['id'])->set($fields);
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     $row->checkin();
     // Save the poll options
     $options = Request::getVar('polloption', array(), 'post');
     foreach ($options as $i => $text) {
         $option = new Option();
         $option->pollid = (int) $row->id;
         $option->text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
         if ($fields['id']) {
             $option->id = (int) $i;
         }
         if (!$option->save()) {
             Notify::error($option->getError());
         }
     }
     Notify::success(Lang::txt('COM_POLL_ITEM_SAVED'));
     if ($this->_task == 'apply') {
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=com_poll', false));
 }