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.
		
		
		
		
		
			
		
			
				
					
					
						
							52 lines
						
					
					
						
							1.3 KiB
						
					
					
				
			
		
		
	
	
							52 lines
						
					
					
						
							1.3 KiB
						
					
					
				<?php | 
						|
 | 
						|
namespace common\modules\blog\services; | 
						|
 | 
						|
use common\modules\blog\entities\BlogCategory; | 
						|
use common\modules\blog\forms\BlogCategoryForm; | 
						|
use common\modules\blog\repositories\BlogCategoryRepository; | 
						|
use common\modules\blog\repositories\BlogRepository; | 
						|
use core\entities\Meta; | 
						|
 | 
						|
class BlogCategoryManageService | 
						|
{ | 
						|
    private $categories; | 
						|
    private $posts; | 
						|
 | 
						|
    public function __construct(BlogCategoryRepository $categories, BlogRepository $posts) | 
						|
    { | 
						|
        $this->categories = $categories; | 
						|
        $this->posts = $posts; | 
						|
    } | 
						|
 | 
						|
    public function create(BlogCategoryForm $form): BlogCategory | 
						|
    { | 
						|
        $category = BlogCategory::create( | 
						|
        	$form, | 
						|
            $form->slug, | 
						|
            $form->sort | 
						|
        ); | 
						|
        $this->categories->save($category); | 
						|
        return $category; | 
						|
    } | 
						|
 | 
						|
    public function edit($id, BlogCategoryForm $form): void | 
						|
    { | 
						|
        $category = $this->categories->get($id); | 
						|
        $category->edit( | 
						|
        	$form, | 
						|
            $form->slug, | 
						|
            $form->sort | 
						|
        ); | 
						|
        $this->categories->save($category); | 
						|
    } | 
						|
 | 
						|
    public function remove($id): void | 
						|
    { | 
						|
        $category = $this->categories->get($id); | 
						|
        if ($this->posts->existsByCategory($category->id)) { | 
						|
            throw new \DomainException('Unable to remove category with posts.'); | 
						|
        } | 
						|
        $this->categories->remove($category); | 
						|
    } | 
						|
} |