Ejemplo n.º 1
0
 protected function action_one()
 {
     $id = $this->params[2];
     $this->goods = MGoods::app()->one($id);
     $this->tags = MTags::app()->getTagsForOne($id);
     $this->template = 'goodscard.html';
     var_dump($this->tags);
     echo $this->view->render($this->template, ['goods' => $this->goods, 'tags' => $this->tags]);
 }
Ejemplo n.º 2
0
 public function renderDefault($search)
 {
     //FIXME tagy ::: 'publish_date <=' => new \DateTime()
     $string = Strings::lower(Strings::normalize($search));
     $string = Strings::replace($string, '/[^\\d\\w]/u', ' ');
     $words = Strings::split(Strings::trim($string), '/\\s+/u');
     $words = array_unique(array_filter($words, function ($word) {
         return Strings::length($word) > 1;
     }));
     $words = array_map(function ($word) {
         return Strings::toAscii($word);
     }, $words);
     $string = implode(' ', $words);
     $this->template->tag = $this->tags->findOneBy(['name' => $string]);
     $result = $this->posts->fulltextSearch($string);
     if (count($result) == 0) {
         $this->template->search = $search;
         $this->template->error = 'Nic nebylo nalezeno';
     } else {
         $this->template->search = $search;
         $this->template->result = $result;
     }
 }
Ejemplo n.º 3
0
 public function handleRegenerate($tag_id)
 {
     $this->onBeforeRestrictedFunctionality($this);
     try {
         $tag = $this->tags->findOneBy(['id' => $tag_id]);
         $tag->color = substr(md5(rand()), 0, 6);
         //Short and sweet
         $this->tags->save($tag);
         $this->flashMessage('Tag byl úspěšně regenerován.', 'success');
     } catch (\Exception $exc) {
         $this->flashMessage($exc->getMessage(), 'danger');
     }
     $this->redirect('this');
 }
Ejemplo n.º 4
0
 public function postFormSucceeded(UI\Form $form, Nette\Utils\ArrayHash $vals)
 {
     try {
         if (!$this->post) {
             $this->post = new Entity\Post();
             $this->post->date = new \DateTime();
         }
         $this->post->publish_date = $vals->publish_date ? new \DateTime($vals->publish_date) : new \DateTime('now');
         $this->post->title = $vals->title;
         $this->post->slug = $vals->slug;
         $this->post->body = $vals->editor;
         $this->post->disable_comments = $vals->disable_comments;
         $this->post->draft = FALSE;
         foreach (array_unique(preg_split('/\\s*,\\s*/', $vals->tags)) as $tag_name) {
             $tag = $this->tags->findOneBy(['name' => $tag_name]);
             if (!$tag) {
                 $tag = new Entity\Tag();
                 $tag->name = $tag_name;
                 $tag->color = substr(md5(rand()), 0, 6);
                 //Short and sweet
             }
             if (!empty($tag_name)) {
                 $this->post->addTag($tag);
             }
         }
         $this->posts->save($this->post);
         $this->presenter->flashMessage('Příspěvek byl úspěšně uložen a publikován.', 'success');
         $this->onSave();
     } catch (Kdyby\Doctrine\DuplicateEntryException $exc) {
         //DBALException
         $this->presenter->flashMessage('Tento URL slug je již v databázi uložen, zvolte prosím jiný.', 'danger');
     } catch (Nette\Security\AuthenticationException $exc) {
         $this->presenter->flashMessage('Myslím to vážně, editovat opravdu **ne**můžete!', 'danger');
         $this->redirect('this');
         return;
     }
 }