Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Nette,
  6.     Model;
  7.  
  8. /**
  9.  * Homepage presenter.
  10.  */
  11. class BookPresenter extends BasePresenter {
  12.  
  13.     /**
  14.      *
  15.      * @var \Nette\Database\Context @inject
  16.      */
  17.     public $database;
  18.     public $user;
  19.     private $data_edit_book;
  20.     private $id_edit;
  21.  
  22.     /** @var Model\BookModel @inject */
  23.     public $model_book;
  24.  
  25.     public function __construct(Nette\Database\Context $database, Model\UserManager $userManager) {
  26.         parent::__construct();
  27.         $this->database = $database;
  28.         $this->user = $userManager;
  29.     }
  30.  
  31.     public function renderDefault() {
  32.  
  33.         $this->template->books = $this->database->table('books')
  34.                 ->order('created DESC')
  35.                 ->limit(5);
  36.     }
  37.  
  38.     public function handleDelete($id, $id_capitol) {
  39.         if ($this->isAjax()) {
  40.             $this->database->table('capitols')
  41.                     ->where('id', $id_capitol)
  42.                     ->delete();
  43.             $this->template->capitols = $this->getCapitols($id);
  44.         }
  45.  
  46.         $this->redrawControl('wholeList');
  47.     }
  48.  
  49.     protected function createComponentAddCapitolForm() {
  50.         $form = new Nette\Application\UI\Form;
  51.         $form->getElementPrototype()->class('uk-form ajax');
  52.         $form->setMethod('post');
  53.         $form->addText('title')
  54.                 ->setRequired('Musíte něco přece zadat...')
  55.                 ->setAttribute('class', 'uk-form-large new-capitol')
  56.                 ->setAttribute('placeholder', "Nová kapitola...");
  57.  
  58.         $form->addSubmit('send', 'Přidat')
  59.                 ->setAttribute('class', 'add_capitol uk-button uk-button-primary uk-button-large');
  60.         $form->onSuccess[] = $this->addCapitolForm_onSubmit;
  61.  
  62.         return $form;
  63.     }
  64.  
  65.     public function addCapitolForm_onSubmit(Nette\Application\UI\Form $form) {
  66.         $values = $form->getValues();
  67.         $set = array(
  68.             'books_id' => $this->id_edit,
  69.             'title' => $values['title']
  70.         );
  71.         $post = $this->database->table('capitols')->insert($set);
  72.         if (!$this->isAjax()) {
  73.             $this->redirect('this');
  74.         } else {
  75.             $this->flashMessage("Příspěvek byl úspěšně publikován.", 'success');
  76.             $this->template->capitols = $this->getCapitols($this->id_edit);
  77.             $this->redrawControl('wholeList');
  78.             $form->setValues(array(), TRUE);
  79.         }
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement