protected function fetchBlockTrans($block, $lang) { if ($block) { return BlockTranslation::get()->filter(['BlockID' => $block->ID, 'Language' => $lang])->first(); } return null; }
public function write() { $id = parent::write(); foreach (json_decode(SS_LANGUAGES) as $slang => $lang) { if (isset($this->record['Title-' . $slang])) { $existingTrans = BlockTranslation::get()->filter(['BlockID' => $id, 'Language' => $slang])->first(); $trans = ['Language' => $slang]; foreach ($this->record as $key => $value) { if (strpos($key, $slang) !== false) { $key = explode('-', $key); $trans[$key[0]] = $value; } } if ($existingTrans) { DB::query('UPDATE "BlockTranslation" SET "Title"=\'' . $trans['Title'] . '\', "Content"=\'' . pg_escape_string($trans['Content']) . '\' WHERE "ID" = ' . $existingTrans->ID . ';'); } else { $newTrans = BlockTranslation::create(); $newTrans->Title = $trans['Title']; $newTrans->Content = $trans['Content']; $newTrans->Language = $slang; $newTrans->BlockID = $id; $newTrans->write(); } } } }