Commit 2ba54991 authored by Martin Gregor's avatar Martin Gregor
Browse files

pridanie flash message na chyby

parent c867089b
......@@ -13,8 +13,6 @@ class AdminPresenter extends BasePresenter
if (!$this->user->isLoggedIn()) {
$this->redirect('Sign:in');
}
$this->parseArticle('http://www.sme.sk/c/7054947/vydajte-ujgurov-su-to-teroristi-odkazuje-slovensku-cina.html');
}
public function createComponentAddForm()
......@@ -41,25 +39,33 @@ class AdminPresenter extends BasePresenter
if ($values->sentence)
{
$this->insertSentence($values->sentence);
$this->flashMessage('Veta '.$values->sentence.' bola uložená.');
if ($this->insertSentence($values->sentence))
$this->flashMessage('Veta '.$values->sentence.' bola uložená.');
}
if ($values->url)
{
$this->parseArticle($values->url);
$this->flashMessage('Článok '.$values->url.' bol spracovaný.');
}
if ($values->paragraph)
{
$success = TRUE;
foreach (explode('.',$values->paragraph) as $sentence)
{
$this->insertSentence($sentence);
if (!$this->insertSentence($sentence))
{
$success = FALSE;
}
}
if ($success)
{
$this->flashMessage('Vety z paragrafu boli spracované.');
}
$this->flashMessage('Vety z paragrafu boli spracované.');
}
$this->redirect('this');
}
private function insertSentence($sentence)
......@@ -69,8 +75,20 @@ class AdminPresenter extends BasePresenter
$exists = $this->db->table('sentences')->where(['sentence' => $sentence])->count('*');
if ($word_count > 5 && !$exists)
{
$this->db->table('sentences')->insert(['sentence' => $sentence,'word_count' => $word_count]);
$result = $this->db->table('sentences')->insert(['sentence' => $sentence,'word_count' => $word_count]);
if ($result)
{
$this->flashMessage('Veta '.$sentence.' nebola spracovaná', 'error');
return FALSE;
}
}
else
{
$this->flashMessage("Veta '.$sentence.' obsahuje nedostatočný počet slov alebo v systéme už existuje.",'error');
return FALSE;
}
return TRUE;
}
private function parseArticle($url)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment