54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\ArticlesBundle\GTM\PageViews;
|
|
|
|
use KupShop\ComponentsBundle\Interfaces\GTMComponentInterface;
|
|
use KupShop\ComponentsBundle\Twig\BaseComponent;
|
|
use KupShop\GTMBundle\PageType\ArticlePageType;
|
|
|
|
class Article extends ArticlePageType implements GTMComponentInterface
|
|
{
|
|
/**
|
|
* @param \KupShop\ArticlesBundle\Twig\Components\Articles\Detail\View $component
|
|
*/
|
|
public function getPushData($component): object
|
|
{
|
|
$a = new \stdClass();
|
|
$article = $component->articleForGTM();
|
|
$a->category = $article['section']['name'] ?? '';
|
|
$a->name = $article['title'];
|
|
$a->tags = array_values($article['tags'] ?? []);
|
|
$a->authors = array_values(array_map(function ($author) {
|
|
return [
|
|
'name' => $author['name'],
|
|
'email' => $author['email'],
|
|
'id' => $author['id'],
|
|
];
|
|
}, $article['authors'] ?? []));
|
|
$a->date_created = date_create($article['date'])->format('Y-m-d');
|
|
$a->read_time = $article['data']['readTime'] ?? false;
|
|
|
|
return (object) ['article' => $a];
|
|
}
|
|
|
|
protected function getFirstRelatedBranch($aID)
|
|
{
|
|
return sqlQueryBuilder()
|
|
->select('ab.name')
|
|
->from('articles_relation', 'ar')
|
|
->leftJoin('ar', 'articles_branches', 'ab', 'ar.id_branch = ab.id')
|
|
->where('ar.id_art=:aID')
|
|
->setParameter('aID', $aID)
|
|
->setMaxResults(1)
|
|
->execute()
|
|
->fetchOne();
|
|
}
|
|
|
|
public function getPageTypeString(BaseComponent $component): ?string
|
|
{
|
|
return 'article';
|
|
}
|
|
}
|