src\Objects\Diaporama.php line 20
<?php
namespace App\Objects;
use Klio\KlioBundle\Database\DB;
class Diaporama
{
private $html;
private $url;
private $db;
function __construct($pageHtml, $url = "")
{
!$this->db = false;
$this->html = $pageHtml;
$this->url = $_ENV['URL_BASE_IMAGES'];
}
public function getHtml()
{
preg_match_all('/.*?##([A-Za-z0-9]+)##.*?/i', $this->html, $matches);
foreach ($matches as $match) {
$diaporamaTitle = str_replace('#', '', @$match[0]);
$slick = '<div class="slick" data-name="' . $diaporamaTitle . '">';
$slick .= '</div>';
$this->getImages($diaporamaTitle);
$this->html = str_replace('##' . $diaporamaTitle . '##', $slick, $this->html);
}
return $this->html;
}
public function getImages($diaporamaTitle)
{
if (!$this->db) $this->db = new DB();
$images = $this->db->query(
"
SELECT
*
FROM
diaporamas
WHERE
diaporamas__titre = :title
",
[
'title' => $diaporamaTitle,
],
"rows"
);
if ($images) {
$slick = '<div class="slick" data-name="' . $diaporamaTitle . '">';
foreach ($images as $image) {
$slick .= '<div class="ratio ratio-21x9" style="border:1px solid #ccc; width:100%; background-size:contain; background-position:center; background-repeat:no-repeat; background-image:url(' . $this->url . '/i/diaporamas/' . $image['files__hash'] . '/' . $image['files__name'] . ')"></div>';
}
$slick .= '</div>';
$this->html = str_replace('##' . $diaporamaTitle . '##', $slick, $this->html);
}
}
}