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.

54 lines
1.2 KiB

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