Commit 8afb1ecb authored by Martin Gregor's avatar Martin Gregor
Browse files

oprava ukladania udajov

parent a3e08a7a
......@@ -90,7 +90,7 @@ class HomepagePresenter extends BasePresenter
foreach ($values as $id => $value)
{
if (strstr($id,'sentence'))
if (strstr($id,'sentence') && $id != 'sentence_id')
{
$s_id = intval(str_replace('sentence','',$id));
$sentences[$s_id]['type'] = $value;
......@@ -122,18 +122,20 @@ class HomepagePresenter extends BasePresenter
$this->storeCorrection($id,$correction,$values['words'],$values['note']);
}
}
$this->redirect('default');
}
private function correctTranslation($id, $value)
{
$translation = $this->db->table('translations')->get($id);
if ($value == 'correct')
{
$translation->update(['correct_count' => 'correct_count + 1']);
$correct_count = $this->db->table('translations')->where(['id' => $id])->select('correct_count')->fetch()->correct_count;
$this->db->table('translations')->where(['id' => $id])->update(['correct_count' => $correct_count + 1]);
}
else
{
$translation->update(['incorrect_count' => 'incorrect_count + 1']);
$incorrect_count = $this->db->table('translations')->where(['id' => $id])->select('incorrect_count')->fetch()->incorrect_count;
$this->db->table('translations')->where(['id' => $id])->update(['incorrect_count' => $incorrect_count + 1]);
}
}
......@@ -142,7 +144,9 @@ class HomepagePresenter extends BasePresenter
$correction_id = $this->db->table('corrections')->select('id')->where(['translation_id' => $trans_id,'correction' => $correction])->fetch();
if ($correction_id)
{
$correction->update(['use_count' => 'use_count + 1','updated_at' => date('Y-m-d H:i:s',time())]);
$correction_id = $correction_id->id;
$use_count = $this->db->table('corrections')->select('use_count')->where(["id" => $correction_id])->fetch()->use_count;
$this->table('corrections')->where(['id' => $correction_id])->update(['use_count' => $use_count + 1,'updated_at' => date('Y-m-d H:i:s',time())]);
}
else
{
......@@ -158,10 +162,14 @@ class HomepagePresenter extends BasePresenter
$this->db->table('word_en')->insert(['word_en' => $word]);
$word_en_id = $this->db->lastInsertId();
}
else
{
$word_en_id = $word_en_id->word_en_id;
}
$word_sk_id = $this->db->table('word_translation')->select('word_sk_id')
->where(['translation_id' => $trans_id,'word_position' => $position])->fetch();
if ($word_sk_id)
$this->db->table('word_correction')->insert(['correction_id' => $correction_id,'word_sk_id' => $word_sk_id, 'word_en_id' => $word_en_id]);
if ($word_sk_id->word_sk_id)
$this->db->table('word_correction')->insert(['correction_id' => $correction_id,'word_sk_id' => $word_sk_id->word_sk_id, 'word_en_id' => $word_en_id]);
}
}
......@@ -227,7 +235,9 @@ class HomepagePresenter extends BasePresenter
if ($translation_id)
{
$this->db->table('translations')->update(['view_count' => 'view_count + 1','updated_at' => date('Y-m-d H:i:s',time())]);
$translation_id = $translation_id->id;
$view_count = $this->db->table('translations')->select('view_count')->where(['id' => $translation_id])->fetch()->view_count;
$this->db->table('translations')->where(['id' => $translation_id])->update(['view_count' => $view_count + 1,'updated_at' => date('Y-m-d H:i:s',time())]);
$this->storeWords($this->sentences[$sentence],$translation_id);
}
......@@ -251,20 +261,15 @@ class HomepagePresenter extends BasePresenter
{
$word_en_id = $this->db->table('word_en')->where(['word_en' => $word])->select('id')->fetch();
$word_sk_id = $this->db->table('word_sk')->where(['word_sk' => $this->words[$position]])->select('id')->fetch();
if ($word_en_id)
{
$exists = $this->db->table('word_translation')->where(['word_en_id' => $word_en_id, 'word_sk_id' => $word_sk_id, 'translation_id' => $translation_id])->count('*');
if (!$exists)
{
$this->db->table('word_translation')->insert(['word_en_id' => $word_en_id, 'word_sk_id' => $word_sk_id, 'translation_id' => $translation_id, 'word_position' => $position]);
}
if (!$word_en_id)
$word_en_id = $this->db->table('word_en')->insert(['word_en' => $word]);
if (!$word_sk_id)
$word_sk_id = $this->db->table('word_sk')->insert(['word_sk' => $this->words[$position]]);
}
else
$exists = $this->db->table('word_translation')->where(['word_en_id' => $word_en_id->id, 'word_sk_id' => $word_sk_id->id, 'translation_id' => $translation_id])->count('*');
if (!$exists)
{
$word_sk = $this->db->table('word_sk')->insert(['word_sk' => $this->words[$position]]);
$word_en = $this->db->table('word_en')->insert(['word_en' => $word]);
$this->db->table('word_translation')->insert(['word_en_id' => $word_en->id, 'word_sk_id' => $word_sk->id, 'translation_id' => $translation_id, 'word_position' => $position]);
$this->db->table('word_translation')->insert(['word_en_id' => $word_en_id->id, 'word_sk_id' => $word_sk_id->id, 'translation_id' => $translation_id, 'word_position' => $position]);
}
}
}
......
Supports Markdown
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