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.
55 lines
1.3 KiB
55 lines
1.3 KiB
6 years ago
|
<?php
|
||
|
|
||
|
namespace common\modules\languages\services;
|
||
|
|
||
|
use common\modules\languages\entities\Language;
|
||
|
use common\modules\languages\forms\LanguageForm;
|
||
|
use common\modules\languages\helpers\LanguageHelper;
|
||
|
use common\modules\languages\repositories\LanguageRepository;
|
||
|
|
||
|
class LanguageManageService
|
||
|
{
|
||
|
private $repository;
|
||
|
|
||
|
public function __construct(LanguageRepository $repository)
|
||
|
{
|
||
|
$this->repository = $repository;
|
||
|
}
|
||
|
|
||
|
public function create(LanguageForm $form): Language
|
||
|
{
|
||
|
$language = Language::create(
|
||
|
$form->name,
|
||
|
$form->title,
|
||
|
$form->status
|
||
|
);
|
||
|
$this->repository->save($language);
|
||
|
return $language;
|
||
|
}
|
||
|
|
||
|
public function edit($id, LanguageForm $form): void
|
||
|
{
|
||
|
$language = $this->repository->get($id);
|
||
|
|
||
|
$language->edit(
|
||
|
$form->name,
|
||
|
$form->title,
|
||
|
$form->status
|
||
|
);
|
||
|
$this->repository->save($language);
|
||
|
}
|
||
|
|
||
|
public function remove($id): void
|
||
|
{
|
||
|
$language = $this->repository->get($id);
|
||
|
$this->repository->remove($language);
|
||
|
}
|
||
|
|
||
|
public function setDefault(Language $language)
|
||
|
{
|
||
|
$this->repository->clearDefaults();
|
||
|
$language->default = Language::DEFAULT_TRUE;
|
||
|
$this->repository->save($language);
|
||
|
}
|
||
|
}
|