You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
811 B
36 lines
811 B
<?php |
|
|
|
namespace common\modules\languages\repositories; |
|
|
|
use common\modules\languages\entities\Language; |
|
use core\repositories\NotFoundException; |
|
|
|
class LanguageRepository |
|
{ |
|
public function get($id): Language |
|
{ |
|
if (!$language = Language::findOne($id)) { |
|
throw new NotFoundException('Language is not found.'); |
|
} |
|
return $language; |
|
} |
|
|
|
public function save(Language $language): void |
|
{ |
|
if (!$language->save()) { |
|
throw new \RuntimeException('Saving error.'); |
|
} |
|
} |
|
|
|
public function remove(Language $language): void |
|
{ |
|
if (!$language->delete()) { |
|
throw new \RuntimeException('Removing error.'); |
|
} |
|
} |
|
|
|
public function clearDefaults() |
|
{ |
|
Language::updateAll(['default' => 0]); |
|
} |
|
} |