src\Objects\Diaporama.php line 25

  1. <?php
  2. namespace App\Objects;
  3. use Klio\KlioBundle\Database\DB;
  4. class Diaporama
  5. {
  6.     private $html;
  7.     private $url;
  8.     private $db;
  9.     function __construct($pageHtml$url "")
  10.     {
  11.         !$this->db false;
  12.         $this->html $pageHtml;
  13.         $this->url $_ENV['URL_BASE_IMAGES'];
  14.     }
  15.     public function getHtml()
  16.     {
  17.         preg_match_all('/.*?##([A-Za-z0-9]+)##.*?/i'$this->html$matches);
  18.         foreach ($matches as $match) {
  19.             $diaporamaTitle str_replace('#''', @$match[0]);
  20.             $slick '<div class="slick" data-name="' $diaporamaTitle '">';
  21.             $slick .= '</div>';
  22.             $this->getImages($diaporamaTitle);
  23.             $this->html str_replace('##' $diaporamaTitle '##'$slick$this->html);
  24.         }
  25.         return $this->html;
  26.     }
  27.     public function getImages($diaporamaTitle)
  28.     {
  29.         if (!$this->db$this->db = new DB();
  30.         $images $this->db->query(
  31.             "
  32.             SELECT 
  33.                 * 
  34.             FROM 
  35.                 diaporamas
  36.             WHERE 
  37.                 diaporamas__titre = :title 
  38.             ",
  39.             [
  40.                 'title' => $diaporamaTitle,
  41.             ],
  42.             "rows"
  43.         );
  44.         if ($images) {
  45.             $slick '<div class="slick"  data-name="' $diaporamaTitle '">';
  46.             foreach ($images as $image) {
  47.               $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>';
  48.             }
  49.             $slick .= '</div>';
  50.             $this->html str_replace('##' $diaporamaTitle '##'$slick$this->html);
  51.         }
  52.     }
  53. }