Commit d5a93fac authored by Martin Gregor's avatar Martin Gregor
Browse files

Fix admina pri pridavani viet, pridanie placeholdera a flash messages

parent fa53300b
......@@ -21,10 +21,10 @@ class AdminPresenter extends BasePresenter
{
$form = new UI\Form;
$form->addText('sentence', 'Veta:')
->setDefaultValue('Sem napíšte vetu.');
->setAttribute('placeholder','Sem napíšte vetu.');
$form->addText('url', 'sme.sk URL:')
->setDefaultValue('http://www.sme.sk/c/7054947/vydajte-ujgurov-su-to-teroristi-odkazuje-slovensku-cina.html');
->setAttribute('placeholder','http://www.sme.sk/c/7054947/vydajte-ujgurov-su-to-teroristi-odkazuje-slovensku-cina.html');
$form->addSubmit('send', 'Parsovať/Vložiť');
......@@ -37,20 +37,27 @@ class AdminPresenter extends BasePresenter
{
$values = $form->getValues();
if ($values->sentence) {
if ($values->sentence)
{
$this->insertSentence($values->sentence);
} else if ($values->url) {
$this->flashMessage('Veta '.$values->sentence.' bola uložená.');
}
else if ($values->url)
{
$this->parseArticle($values->url);
$this->flashMessage('Článok '.$values->url.' bol spracovaný.');
}
}
private function insertSentence($sentence)
{
$sentence = trim($sentence);
$sentence = trim($sentence,'  "\'„“');
$word_count = count(explode(' ',$sentence));
$exists = $this->db->table('sentences')->count('*')->where('sentence' => $sentence);
if ($word_count > 3 && !$exists)
$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]);
}
}
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