private\page\Controller.php line 140
<?php
use App\Objects\Menu;
use App\Objects\Image;
use App\Objects\ColonneDroite;
use Klio\KlioBundle\Database\DB;
use Klio\KlioBundle\Symfony\Controller;
class PrivateController
{
public function render(Controller $ROUTE)
{
$rootPageId = "9214d0f6ee3c31330460c63c9b7fec32f6293942";
$url = __PATH__;
$ROUTE->addJs("Scripts.js");
// Identifie la rubrique du site dans laquelle on se trouve
// Puis associe la rubrique à la classe correspondante pour gérer le CSS
$isPaie = preg_match("/\/paie\b(\/.*|.{0})/", $url);
$isCooperative = preg_match("/\/cooperative\b(\/.*|.{0})/", $url);
$isFormation = preg_match("/\/formation\b(\/.*|.{0})/", $url);
$isMediation = preg_match("/\/mediation\b(\/.*|.{0})/", $url);
$isDanse = preg_match("/\/bureau_danse\b(\/.*|.{0})/", $url);
$isConseil = preg_match("/\/conseil\b(\/.*|.{0})/", $url);
$destination = "";
$classTitle = "";
if ($isPaie) {
$classTitle = "color-paie";
$destination = "paie";
}
if ($isCooperative) {
$classTitle = "color-cooperative";
$destination = "cooperative";
}
if ($isFormation) {
$classTitle = "color-formation";
$destination = "formations";
}
if ($isMediation) {
$classTitle = "color-mediation";
$destination = "mediation";
}
if ($isDanse) {
$classTitle = "color-danse";
$destination = "bureau_danse";
}
if ($isConseil) {
$classTitle = "color-conseil";
$destination = "conseil";
}
$TWIG['color'] = $classTitle;
$DB = new DB();
$rubriques = $DB->query(
"SELECT * from colonne_droite where colonne_droite__cible = :cible ORDER BY colonne_droite__placement",
["cible" => $destination],
"rows"
);
if ($rubriques !== []) {
$colonnes = new ColonneDroite($destination);
$files = $colonnes->getFiles();
for ($a = 0; $a < count($rubriques); $a++) {
$rubriques[$a]["class"] = "linked color" . $a + 1;
$image = $colonnes->getImages($files, $rubriques[$a]["colonne_droite__id"]);
if ($image) {
$rubriques[$a]["img_link"] = $image->getUrl();
$rubriques[$a]["extension"] = $image->getExtension();
} else {
$rubriques[$a]["img_link"] = null;
$rubriques[$a]["extension"] = null;
}
$pdf = $colonnes->getPdf($files, $rubriques[$a]["colonne_droite__id"]);
if ($pdf)
$rubriques[$a]["pdf_link"] = $pdf->getUrl();
else
$rubriques[$a]["pdf_link"] = null;
}
$TWIG["rubriques"] = $rubriques;
} else
$TWIG["rubriques"] = null;
$page = $DB->query("
SELECT
*
FROM
pages
LEFT JOIN files ON files__table_id = pages__id AND files__field = 'pages_photos'
WHERE
pages__url like :url
ORDER BY
pages__node_position,pages__num
", array('url' => $url), "row");
if ($page) {
$pageId = $page['pages__id'];
$images = $DB->query(
"
SELECT *
FROM
files
WHERE
files__table_id= :id ",
array('id' => $pageId),
"rows"
);
$page['pages__tags_id'] = str_replace('["', "", $page['pages__tags_id']);
$page['pages__tags_id'] = str_replace('"]', "", $page['pages__tags_id']);
$page['pages__tags_id'] = str_replace('"', "", $page['pages__tags_id']);
$tableauTags = explode(",", $page['pages__tags_id']);
$pages = $DB->query(
"
SELECT *
FROM
pages
WHERE pages__url not like :url
",
array('url' => $url),
"rows"
);
$pagesWithSameTags = [];
$counterPage = 0;
$counter = 0;
foreach ($tableauTags as $tags => $tag) {
foreach ($pages as $champs => $champ) {
if (str_contains($champ['pages__tags_id'], $tag) && !empty($tag)) {
$pagesWithSameTags[] = $champ;
}
$counter++;
}
}
// Compter les occurrences de chaque valeur de pages__id
$occurrences = array_count_values(array_column($pagesWithSameTags, 'pages__id'));
// Trier le tableau des occurrences par ordre décroissant
arsort($occurrences);
// Extraire les clés triées
$sortedKeys = array_keys($occurrences);
// Créer un nouveau tableau classé
$newArray = array();
foreach ($sortedKeys as $key) {
foreach ($pagesWithSameTags as $item) {
if ($item['pages__id'] == $key) {
$newArray[] = $item;
break; // Sortir de la boucle interne après avoir ajouté l'élément correspondant
}
}
}
// Éliminer les doublons du nouveau tableau
$newArray = array_unique($newArray, SORT_REGULAR);
$TWIG['page_tags'] = $newArray;
$TWIG['og_url'] = __HOST__ . $url;
$TWIG['og_description'] = "";
}
if ($page) {
/*
On teste si la page en cours est parente ou enfant.
*/
$isParent = $page['pages__node_parent'] == $rootPageId;
/*
Si elle est parente, on affecte à $parentId l'id de la page.
Si elle est enfant, on lui affecte l'identifiant de la page parente'
*/
$parentId = $isParent ? $page['pages__id'] : $page['pages__node_parent'];
//
$sql =
"
SELECT
*
FROM
pages
WHERE
pages__node_parent = :id or pages__id =:id
ORDER BY
pages__node_parent != '" . $rootPageId . "', pages__node_position
";
$relatedPages = $DB->query($sql, array('id' => $parentId));
$TWIG['title'] = $page['pages__name'];
$TWIG['page_subtitle'] = $page['pages__sous_titre'];
$TWIG['page_title'] = $page['pages__titre'];
$TWIG['page_video'] = $page['pages__video'];
$page_content = $page['pages__html'];
$TWIG['og_description'] = $page['pages__description'];
$TWIG['relatedPages'] = $relatedPages;
$TWIG['images'] = [];
$TWIG['images'] = $this->getImages($images);
$TWIG['page_content'] = '<div>' . $page_content . '</div>';
$ROUTE->addCss('Page.scss');
$ROUTE->setTemplate('Page.twig');
$ROUTE->addTrustedTwig($TWIG);
} else {
$ROUTE->setRouteFound(false);
}
}
/*
Pour chaque fichier de la table files, on teste si c'est bien une photo.
Si c'est le cas, on l'ajoute à un tableau d'images et on le retourne
*/
function getImages($files)
{
$images = [];
foreach ($files as $file) {
if ($file['files__name'] && $file['files__folder'] && $file['files__hash'] && $file['files__field'] == 'pages_photos') {
$image = new Image($file['files__name'], $file['files__folder'], $file['files__extension'], $file['files__hash'], null, $file["files__copyright"]);
$images[] = $image;
}
}
return $images;
}
}