<?php
namespace w3des\AdminBundle\Twig\Runtime;
use Twig\Extension\RuntimeExtensionInterface;
use w3des\AdminBundle\Service\Nodes;
class NodeRuntime implements RuntimeExtensionInterface
{
private Nodes $nodes;
public function __construct(Nodes $nodes)
{
$this->nodes = $nodes;
}
public function getNodes($type, $cfg = [])
{
return $this->nodes->getNodes($type, $cfg);
}
public function getNodeTTL($type, $cfg = [], $field)
{
$nodes = $this->nodes->getNodes($type, $cfg);
if (count($nodes['list']) == 0) {
return null;
}
$f = $nodes['list'][0]->vars->get($field);
return $f->getTimestamp() - time() + 1;
}
public function getNode($type, $cfg = [])
{
$cfg['max'] = 1;
$res = $this->nodes->getNodes($type, $cfg);
if (count($res['list'])) {
return \array_shift($res['list']);
}
return null;
}
}