Skip to content

Commit

Permalink
5.1 : AggregateRating
Browse files Browse the repository at this point in the history
  • Loading branch information
conseilgouz committed Mar 3, 2024
1 parent dcc65f3 commit b007a9c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 169 deletions.
40 changes: 40 additions & 0 deletions plugins/content/vote/src/Extension/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Schemaorg\SchemaorgPrepareProductAggregateRating;
use Joomla\CMS\Schemaorg\SchemaorgPrepareRecipeAggregateRating;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -24,6 +26,8 @@
*/
final class Vote extends CMSPlugin
{
use SchemaorgPrepareProductAggregateRating;
use SchemaorgPrepareRecipeAggregateRating;
/**
* @var \Joomla\CMS\Application\CMSApplication
*
Expand Down Expand Up @@ -123,4 +127,40 @@ private function displayVotingData($context, &$row, &$params, $page)

return $html;
}
/**
* Create SchemaOrg AggregateRating
*
* @param object $schema The schema of the content being passed to the plugin
* @param string $context The context of the content being passed to the plugin
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onSchemaBeforeCompileHead($schema, $context): void
{
$graph = $schema->get('@graph');

$need_vote = PluginHelper::isEnabled('content', 'vote');

if (!$need_vote) {
return;
}
foreach ($graph as $key => &$entry) {
if (!isset($entry['@type'])) {
continue;
}
if ($entry['@type'] == 'Recipe') {
$rating = $this->prepareRecipeAggregateRating($ontext);
continue;
}
$rating = $this->prepareProductAggregateRating($context);
}

if ($rating) {
$graph[] = $rating;
$schema->set('@graph', $graph);
}
}

}
21 changes: 0 additions & 21 deletions plugins/schemaorg/aggregaterating/aggregaterating.xml

This file was deleted.

47 changes: 0 additions & 47 deletions plugins/schemaorg/aggregaterating/services/provider.php

This file was deleted.

101 changes: 0 additions & 101 deletions plugins/schemaorg/aggregaterating/src/Extension/AggregateRating.php

This file was deleted.

0 comments on commit b007a9c

Please sign in to comment.