src/Service/SeoHelper.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. class SeoHelper {
  4.     protected $seoGenerator;
  5.     protected $name;
  6.     protected $description;
  7.     protected $tags = [];
  8.     public function __construct(
  9.         \Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGeneratorInterface,
  10.         \Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $params,
  11.         \Vich\UploaderBundle\Templating\Helper\UploaderHelper $uploaderHelper,
  12.         \Liip\ImagineBundle\Imagine\Cache\CacheManager $cacheManager,
  13.         \Leogout\Bundle\SeoBundle\Provider\SeoGeneratorProvider $seoGenerator
  14.     ) {
  15.         $this->urlGeneratorInterface $urlGeneratorInterface;
  16.         $this->uploaderHelper $uploaderHelper;
  17.         $this->cacheManager $cacheManager;
  18.         $this->seoGenerator $seoGenerator;
  19.         $this->params $params;
  20.     }
  21.     public function setArticleSeo(\App\Entity\BlogArticle $article) {
  22.         $imagePath $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  23.         $resourcePath $this->cacheManager->generateUrl($imagePath'blog_list');
  24.         $link $this->urlGeneratorInterface->generate('client_blog_article_view', [
  25.             'slug' => $article->getSlug()
  26.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  27.         $this->seoGenerator->get('basic')
  28.             ->setTitle($article->getTitle())
  29.             ->setDescription($article->getMetaDescription())
  30.             ->setKeywords($article->getMetaDescription())
  31.             ->setCanonical($link)
  32.             ->setRobots(truetrue)
  33.         ;
  34.         $this->seoGenerator->get('og')
  35.             ->setType('article')
  36.             ->setTitle($article->getTitle())
  37.             ->setDescription($article->getMetaDescription())
  38.             ->setImage($resourcePath)
  39.             ->setURL($link)
  40.         ;
  41.     }
  42.     public function setCourseSeo(\App\Entity\Course $article) {
  43.         $imagePath $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  44.         $resourcePath $this->cacheManager->generateUrl($imagePath'course_list');
  45.         $link $this->urlGeneratorInterface->generate('client_course_view', [
  46.             'slug' => $article->getSlug()
  47.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  48.         $this->seoGenerator->get('basic')
  49.             ->setTitle($article->getTitle())
  50.             ->setDescription($article->getMetaDescription())
  51.             ->setKeywords($article->getMetaDescription())
  52.             ->setCanonical($link)
  53.             ->setRobots(truetrue)
  54.         ;
  55.         $this->seoGenerator->get('og')
  56.             ->setType('article')
  57.             ->setTitle($article->getTitle())
  58.             ->setDescription($article->getMetaDescription())
  59.             ->setImage($resourcePath)
  60.             ->setURL($link)
  61.         ;
  62.     }
  63.     public function setCareerPathSeo(\App\Entity\CareerPath $article) {
  64.         $imagePath $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  65.         $resourcePath $this->cacheManager->generateUrl($imagePath'career_path_list');
  66.         $link $this->urlGeneratorInterface->generate('client_career_path_view', [
  67.             'slug' => $article->getSlug()
  68.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  69.         $this->seoGenerator->get('basic')
  70.             ->setTitle($article->getTitle())
  71.             ->setDescription($article->getMetaDescription())
  72.             ->setKeywords($article->getMetaDescription())
  73.             ->setCanonical($link)
  74.             ->setRobots(truetrue)
  75.         ;
  76.         $this->seoGenerator->get('og')
  77.             ->setType('article')
  78.             ->setTitle($article->getTitle())
  79.             ->setDescription($article->getMetaDescription())
  80.             ->setImage($resourcePath)
  81.             ->setURL($link)
  82.         ;
  83.     }
  84.     public function setBlogCategorySeo(\App\Entity\BlogCategory $category) {
  85.         //$imagePath = $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  86.         //$resourcePath = $this->cacheManager->generateUrl($imagePath, 'blog_list');
  87.         $link $this->urlGeneratorInterface->generate('client_blog_category_article_list', [
  88.             'slug' => $category->getSlug()
  89.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  90.         $this->seoGenerator->get('basic')
  91.             ->setTitle($category->getTitle())
  92.             ->setDescription($category->getMetaDescription())
  93.             ->setKeywords($category->getMetaDescription())
  94.             ->setCanonical($link)
  95.             ->setRobots(truetrue)
  96.         ;
  97.         $this->seoGenerator->get('og')
  98.             ->setType('website')
  99.             ->setTitle($category->getTitle())
  100.             ->setDescription($category->getMetaDescription())
  101.             //->setImage($category)
  102.             ->setURL($link)
  103.         ;
  104.     }
  105.     public function setCourseCategorySeo(\App\Entity\CourseCategory $category) {
  106.         //$imagePath = $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  107.         //$resourcePath = $this->cacheManager->generateUrl($imagePath, 'blog_list');
  108.         $link $this->urlGeneratorInterface->generate('client_course_category_list', [
  109.             'slug' => $category->getSlug()
  110.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  111.         $this->seoGenerator->get('basic')
  112.             ->setTitle($category->getTitle())
  113.             ->setDescription($category->getMetaDescription())
  114.             ->setKeywords($category->getMetaDescription())
  115.             ->setCanonical($link)
  116.             ->setRobots(truetrue)
  117.         ;
  118.         $this->seoGenerator->get('og')
  119.             ->setType('website')
  120.             ->setTitle($category->getTitle())
  121.             ->setDescription($category->getMetaDescription())
  122.             //->setImage($category)
  123.             ->setURL($link)
  124.         ;
  125.     }
  126.     public function setCareerPathCategorySeo(\App\Entity\CareerPathCategory $category) {
  127.         //$imagePath = $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  128.         //$resourcePath = $this->cacheManager->generateUrl($imagePath, 'blog_list');
  129.         $link $this->urlGeneratorInterface->generate('client_career_path_category_list', [
  130.             'slug' => $category->getSlug()
  131.         ], $this->urlGeneratorInterface::ABSOLUTE_URL);
  132.         $this->seoGenerator->get('basic')
  133.             ->setTitle($category->getTitle())
  134.             ->setDescription($category->getMetaDescription())
  135.             ->setKeywords($category->getMetaDescription())
  136.             ->setCanonical($link)
  137.             ->setRobots(truetrue)
  138.         ;
  139.         $this->seoGenerator->get('og')
  140.             ->setType('website')
  141.             ->setTitle($category->getTitle())
  142.             ->setDescription($category->getMetaDescription())
  143.             //->setImage($category)
  144.             ->setURL($link)
  145.         ;
  146.     }
  147.     public function setInternalSeo(String $titleString $url) {
  148.         //$imagePath = $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  149.         //$resourcePath = $this->cacheManager->generateUrl($imagePath, 'blog_list');
  150.         $link $this->urlGeneratorInterface->generate($url, [], $this->urlGeneratorInterface::ABSOLUTE_URL);
  151.         $this->seoGenerator->get('basic')
  152.             ->setTitle($title)
  153.             //->setDescription($page->getMetaDescription())
  154.             //->setKeywords($page->getMetaDescription())
  155.             ->setCanonical($link)
  156.             ->setRobots(truetrue)
  157.         ;
  158.         $this->seoGenerator->get('og')
  159.             ->setType('website')
  160.             ->setTitle($title)
  161.             //->setDescription($page->getMetaDescription())
  162.             //->setImage($category)
  163.             ->setURL($link)
  164.         ;
  165.     }
  166.     public function setPageSeo(\App\Entity\Page $page$url) {
  167.         //$imagePath = $this->uploaderHelper->asset($article->getImageFull(), 'imageFile');
  168.         //$resourcePath = $this->cacheManager->generateUrl($imagePath, 'blog_list');
  169.         $link $this->urlGeneratorInterface->generate($url, [], $this->urlGeneratorInterface::ABSOLUTE_URL);
  170.         $this->seoGenerator->get('basic')
  171.             ->setTitle($page->getTitle())
  172.             ->setDescription($page->getMetaDescription())
  173.             ->setKeywords($page->getMetaDescription())
  174.             ->setCanonical($link)
  175.             ->setRobots(truetrue)
  176.         ;
  177.         $this->seoGenerator->get('og')
  178.             ->setType('website')
  179.             ->setTitle($page->getTitle())
  180.             ->setDescription($page->getMetaDescription())
  181.             //->setImage($category)
  182.             ->setURL($link)
  183.         ;
  184.     }
  185. }