addFaq($q); } function addFaq($question) { $this->faq[] = [ '@type' => 'Question', 'name' => $question[Question::$QUESTION], 'acceptedAnswer' => [ '@type' => 'Answer', 'text' => $question[Question::$ANSWER] ] ]; } function addNewsArray($news) { foreach ($news as $n) $this->addNews($n); } function addNews($news) { $id = \Site::sectionUrl(substr($news['link'],1),true); if($news['schemaorg_main']) $this->mainID = $id; $el = [ '@type' => 'NewsArticle', 'mainEntityOfPage' => [ '@type' => 'WebPage', '@id' => \Site::sectionUrl(substr($news['link'],1),true) ], 'headline' => News::getName($news), 'datePublished' => self::formatTimeSeo($news[News::$CREATED]), 'dateModified' => self::formatTimeSeo($news[News::$UPDATED]), 'author' => $news['author'], 'publisher' => $news['publisher'], 'description' => $news[News::$ANNOTATION] ]; if($news['preview']) { $el['image'] = \Site::sectionUrl(substr($news['preview'],1),true); } $this->news[] = $el; } function toJson():array { $url = Page::$canonical; $faq = null; if($this->faq){ $a = []; foreach ($this->faq as $q){ $a[] = $q; } $faq = [ "@type"=> "FAQPage", "@id"=> $url.$this->faqLink, 'mainEntity'=>$a ]; } $listItems = []; if($this->news) { $listItems[] = [ 'title'=>'Новости', 'id'=>$url.$this->newsLink, 'list'=>$this->news, ]; } $graphListItems = null; if($listItems){ $graphListItems = []; foreach ($listItems as $v) { $list = []; foreach($v['list'] as $el){ $list[] = [ '@type' => 'ListItem', 'item'=>$el, ]; } $graphListItems[] = [ '@type' => 'ItemList', '@id' => $v['id'], 'name' => $v['title'], 'numberOfItems' => count($v['list']), 'itemListOrder' => 'ItemListUnordered', 'itemListElement'=>$list ]; } } $main = [ '@type' => 'WebPage', '@id' => $url, 'name' => Page::getTitleText(), 'description' => Page::$description, 'url' => $url, //'mainEntity' => [ '@id' => 'https://site.com/games/main-game-page/#main-product' ] ]; if($this->mainID) $main['mainEntity'] = ['@id'=>$this->mainID]; return [ "@context"=> "https://schema.org", "@graph"=> array_diff( array_merge( [$main,$faq,] ,$graphListItems ) , [null]), ]; } }