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.
53 lines
1.2 KiB
53 lines
1.2 KiB
<?php |
|
|
|
namespace common\modules\banners\services; |
|
|
|
use common\modules\banners\entities\BannerPlace; |
|
use common\modules\banners\forms\BannerPlaceForm; |
|
use common\modules\banners\repositories\BannerPlaceRepository; |
|
use yii\db\StaleObjectException; |
|
|
|
class BannerPlaceManageService |
|
{ |
|
private BannerPlaceRepository $repository; |
|
|
|
public function __construct(BannerPlaceRepository $repository) |
|
{ |
|
$this->repository = $repository; |
|
} |
|
|
|
public function create(BannerPlaceForm $form): BannerPlace |
|
{ |
|
$place = BannerPlace::create( |
|
$form->title, |
|
$form->width, |
|
$form->height, |
|
$form->active |
|
); |
|
$this->repository->save($place); |
|
|
|
return $place; |
|
} |
|
|
|
public function edit($id, BannerPlaceForm $form): void |
|
{ |
|
$place = $this->repository->get($id); |
|
$place->edit( |
|
$form->title, |
|
$form->width, |
|
$form->height, |
|
$form->active |
|
); |
|
$this->repository->save($place); |
|
} |
|
|
|
/** |
|
* @param $id |
|
* @throws StaleObjectException |
|
*/ |
|
public function remove($id): void |
|
{ |
|
$place = $this->repository->get($id); |
|
$this->repository->remove($place); |
|
} |
|
}
|
|
|