Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Sd;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
// https://developers.google.com/search/docs/appearance/structured-data/qapage
class SdQAPage
{
// One question followed by its answers. Users must be able to submit answers to the question.
public static function get_output($data = array())
{
$answers = $data['answers'] ?? array();
$json = array(
"@context" => "https://schema.org",
"@type" => "QAPage",
);
$published_date = Sd::get_date($data['publish_up'] ?? $data['created']);
$author = Sd::get_author('Person', $data['created_by']);
$json["mainEntity"] = array(
"@type" => "Question",
"name" => $data['name'] ?? $data['title'],
"text" => $data['text'] ?? $data['description'],
"answerCount" => \count($answers),
"datePublished" => $published_date,
"author" => $author,
);
foreach ($answers as $answer)
{
$answer = (array) $answer;
$published_date = Sd::get_date($answer['publish_up'] ?? $answer['created']);
$author = Sd::get_author('Person', $answer['created_by']);
$json["mainEntity"]["suggestedAnswer"][] = array(
"@type" => "Answer",
"text" => $answer['text'] ?? $answer['description'],
"datePublished" => $published_date,
"author" => $author,
);
}
Sd::display_sd($json);
}
}