public function fetchDuration(DurationProviderInterface $durationProvider): WidgetProviderInterface
{
return $this;
}
public function getDataCacheKey(DataProviderInterface $dataProvider): ?string
{
// Returns a fixed key to keep the cache working, but with controlled behavior
return 'gumDataProvider-' . md5('G1RSSFeed');
}
public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon
{
// Returns the current date/time to force the cache to always be refreshed
return Carbon::now();
}
So with each update from my Android client to the CMS, that is, every 5 minutes I should update this module, right? More repair that continues to use the same data as if the cache was not updated. Even getDataModifiedDt returning as it does now. Is there anything else I’m doing wrong?
When the module has a data provider, should this update happen automatically? Do I need to open the Layout and save for this to happen?
Is XTR and the Widget Sync task running in your CMS installation? Data is kept up to date in the background via XTR, if it isn’t running then you won’t see any updates.
My installation was done using Docker, so from what I understand I wouldn’t need to create a routine on my server to run xtr as one would already be configured?
I believe it is in fact something in my data provider that is not updating, because when using the native RSS ticjer module with an external RSS the updates worked normally, seeing the RSS module code is with
public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon
{
return null;
}
tentei fazer isso no meu modulo cutomizado, mais infelizmente sem atualização ainda.
@dan Unfortunately, so far I haven’t achieved anything. Follow my current full provider. It’s just the problem of updating that doesn’t happen, only if you open the Layout and save manually, otherwise it always displays the same content in the player.
<?php
namespace Xibo\Custom;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Xibo\Widget\Provider\DataProviderInterface;
use Xibo\Widget\Provider\DurationProviderInterface;
use Xibo\Widget\Provider\WidgetProviderInterface;
use Xibo\Widget\Provider\WidgetProviderTrait;
class g1DataProvider implements WidgetProviderInterface
{
use WidgetProviderTrait;
public function fetchData(DataProviderInterface $dataProvider): WidgetProviderInterface
{
// Criando uma instância do cliente HTTP (Guzzle)
$client = new Client();
// URL do feed RSS do G1
$url = $dataProvider->getProperty('uri');
if (empty($url)) {
throw new InvalidArgumentException(__('Please enter the URI to a valid RSS feed.'), 'uri');
}
// Realizando a requisição GET para o feed RSS
$response = $client->get($url);
$rssContent = $response->getBody()->getContents();
// Carregando o XML
$rss = simplexml_load_string($rssContent, "SimpleXMLElement", LIBXML_NOCDATA);
// Determinar o número total de itens disponíveis no feed (ou no máximo 10)
$totalItems = min(count($rss->channel->item), 10); // Limita o total a 10
// Gerar um índice aleatório dentro do intervalo válido
$aleatorio = rand(0, $totalItems - 1);
// Pegar uma notícia aleatória
$item = $rss->channel->item[$aleatorio];
$title = (string) $item->title; // Título da notícia
$mediaContent = $item->children('media', true)->content->attributes()->url ?? null; // URL da imagem
if ($mediaContent) {
// URL da logo do G1
$logoUrl = 'https://raw.githubusercontent.com/henriquelucas/modulo-g1-rss-xibo/refs/heads/main/g1.png';
// Gerar o HTML com a imagem responsiva, título no rodapé e logo no canto superior esquerdo
$html = "
<div style='
display: flex;
align-items: center;
justify-content: center;
width: 1920px;
height: 1080px;
background-color: #000;'>
<div style='
width: 100%;
height: 100%;
position: relative;'>
<!-- Imagem de fundo -->
<div style='
width: 100%;
height: 100%;
background-image: url(\"{$mediaContent}\");
background-size: cover;
background-position: center;
position: absolute;
top: 0;
left: 0;
z-index: 1;'>
</div>
<!-- Background preto semi-transparente -->
<div style='
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5); /* Transparência no fundo */
z-index: 2;'>
</div>
<!-- Logo do G1 -->
<img src=\"{$logoUrl}\" alt=\"G1 Logo\" style='
position: absolute;
top: 20px;
left: 20px;
width: 200px;
height: auto;
z-index: 3;'>
<!-- Título da notícia -->
<div style='
position: absolute;
bottom: 0;
width: 100%;
background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
color: white;
text-align: left;
padding: 20px;
font-size: 80px;
word-wrap: break-word;
overflow-wrap: break-word;
z-index: 3;'>
<p style='margin: 0; padding: 20px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);font-weight: 600;'>{$title}</p>
</div>
</div>
</div>";
// Adicionando os dados ao provider
$dataProvider->addItem([
'subject' => $title,
'body' => $html,
'date' => Carbon::now(),
'createdAt' => Carbon::now(),
]);
}
// Marcando que os dados foram processados
$dataProvider->setIsHandled();
return $this;
}
public function fetchDuration(DurationProviderInterface $durationProvider): WidgetProviderInterface
{
return $this;
}
public function getDataCacheKey(DataProviderInterface $dataProvider): ?string
{
// Retorna um cache chave único com base no timestamp atual
return 'custom_data_' . time();
}
public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon
{
return null;
}
}