Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Nette,
- Model;
- /**
- * Homepage presenter.
- */
- class BookPresenter extends BasePresenter {
- /**
- *
- * @var \Nette\Database\Context @inject
- */
- public $database;
- public $user;
- private $data_edit_book;
- private $id_edit;
- /** @var Model\BookModel @inject */
- public $model_book;
- public function __construct(Nette\Database\Context $database, Model\UserManager $userManager) {
- parent::__construct();
- $this->database = $database;
- $this->user = $userManager;
- }
- public function renderDefault() {
- $this->template->books = $this->database->table('books')
- ->order('created DESC')
- ->limit(5);
- }
- public function handleDelete($id, $id_capitol) {
- if ($this->isAjax()) {
- $this->database->table('capitols')
- ->where('id', $id_capitol)
- ->delete();
- $this->template->capitols = $this->getCapitols($id);
- }
- $this->redrawControl('wholeList');
- }
- protected function createComponentAddCapitolForm() {
- $form = new Nette\Application\UI\Form;
- $form->getElementPrototype()->class('uk-form ajax');
- $form->setMethod('post');
- $form->addText('title')
- ->setRequired('Musíte něco přece zadat...')
- ->setAttribute('class', 'uk-form-large new-capitol')
- ->setAttribute('placeholder', "Nová kapitola...");
- $form->addSubmit('send', 'Přidat')
- ->setAttribute('class', 'add_capitol uk-button uk-button-primary uk-button-large');
- $form->onSuccess[] = $this->addCapitolForm_onSubmit;
- return $form;
- }
- public function addCapitolForm_onSubmit(Nette\Application\UI\Form $form) {
- $values = $form->getValues();
- $set = array(
- 'books_id' => $this->id_edit,
- 'title' => $values['title']
- );
- $post = $this->database->table('capitols')->insert($set);
- if (!$this->isAjax()) {
- $this->redirect('this');
- } else {
- $this->flashMessage("Příspěvek byl úspěšně publikován.", 'success');
- $this->template->capitols = $this->getCapitols($this->id_edit);
- $this->redrawControl('wholeList');
- $form->setValues(array(), TRUE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement