From e9b2ca7c06875069fa03379258625490872cc33d Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 31 Jul 2018 18:29:53 +0200 Subject: W 2.4 graphic update table sort engine update --- class/class.w.app.php | 158 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 30 deletions(-) (limited to 'class/class.w.app.php') diff --git a/class/class.w.app.php b/class/class.w.app.php index d178b52..efb8986 100644 --- a/class/class.w.app.php +++ b/class/class.w.app.php @@ -142,15 +142,54 @@ class App } - public function getlister(array $selection = ['id', 'titre'], $tri = 'id', $desc = 'ASC') + + + public function update(Art $art) { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $art->updatelien(); + + $q = $this->bdd->prepare('UPDATE ' . $this->arttable . ' SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien, couleurlienblank = :couleurlienblank, lien = :lien, template = :template WHERE id = :id'); + + $q->bindValue(':id', $art->id()); + $q->bindValue(':titre', $art->titre()); + $q->bindValue(':soustitre', $art->soustitre()); + $q->bindValue(':intro', $art->intro()); + $q->bindValue(':tag', $art->tag('string')); + $q->bindValue(':datecreation', $art->datecreation('string')); + $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); + $q->bindValue(':css', $art->css()); + $q->bindValue(':html', $art->md()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':couleurtext', $art->couleurtext()); + $q->bindValue(':couleurbkg', $art->couleurbkg()); + $q->bindValue(':couleurlien', $art->couleurlien()); + $q->bindValue(':couleurlienblank', $art->couleurlienblank()); + $q->bindValue(':lien', $art->lien('string')); + $q->bindValue(':template', $art->template()); + + $q->execute(); + } + + + + + //____________________________________________ L S T ______________________________ + + + + public function getlister(array $selection = ['id'], array $opt = []) + { + $default = ['tri' => 'id', 'desc' => 'DESC']; + $opt = array_update($default, $opt); + $list = []; - $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif']; - if (is_array($selection) && is_string($tri) && strlen($tri) < 16 && is_string($desc) && strlen($desc) < 5 && in_array($tri, $option)) { + $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif', 'tag', 'secure']; + if (is_array($selection) && is_string($opt['tri']) && strlen($opt['tri']) < 16 && is_string($opt['desc']) && strlen($opt['desc']) < 5 && in_array($opt['tri'], $option)) { $selection = implode(", ", $selection); - $select = 'SELECT ' . $selection . ' FROM ' . $this->arttable . ' ORDER BY ' . $tri . ' ' . $desc; + $select = 'SELECT ' . $selection . ' FROM ' . $this->arttable . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; $req = $this->bdd->query($select); while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { $list[] = new Art($donnees); @@ -159,13 +198,95 @@ class App } } + + + + + + public function getlisteropt(Opt $opt) + { + + + $artlist = []; + + $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->arttable; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $artlist[] = new Art($donnees); + } + return $artlist; + + } + + public function listcalclien(&$artlist) + { + foreach ($artlist as $art) { + $art->calcliento($artlist); + } + } + + public function artcompare($art1, $art2, $method = 'id', $order = 1) + { + $result = ($art1->$method('sort') <=> $art2->$method('sort')); + return $result * $order; + + } + + public function buildsorter($sortby, $order) + { + return function ($art1, $art2) use ($sortby, $order) { + $result = $this->artcompare($art1, $art2, $sortby, $order); + return $result; + }; + } + + + + public function artlistsort(&$artlist, $sortby, $order = 1) + { + return usort($artlist, $this->buildsorter($sortby, $order)); + } + + + + + + + public function filtertagor(array $artlist, array $tagchecked) + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (!empty(array_intersect($art->tag('array'), $tagchecked))) { + $filteredlist[] = $art->id(); + } elseif (empty($tagchecked)) { + $filteredlist[] = $art->id(); + } + } + return $filteredlist; + } + + public function filtersecure(array $artlist, $secure) + { + $filteredlist = []; + foreach ($artlist as $art) { + if ($art->secure() == intval($secure)) { + $filteredlist[] = $art->id(); + } elseif (intval($secure) >= 4) { + $filteredlist[] = $art->id(); + } + } + return $filteredlist; + } + + public function lister() { $req = $this->bdd->query(' SELECT * FROM ' . $this->arttable . ' ORDER BY id '); $donnees = $req->fetchAll(PDO::FETCH_ASSOC); + $req->closeCursor(); return $donnees; - $req->closeCursor(); } @@ -183,32 +304,9 @@ class App return (bool)$donnees['COUNT(*)']; } - public function update(Art $art) - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $art->updatelien(); - - $q = $this->bdd->prepare('UPDATE ' . $this->arttable . ' SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien, couleurlienblank = :couleurlienblank, lien = :lien, template = :template WHERE id = :id'); - - $q->bindValue(':id', $art->id()); - $q->bindValue(':titre', $art->titre()); - $q->bindValue(':soustitre', $art->soustitre()); - $q->bindValue(':intro', $art->intro()); - $q->bindValue(':tag', $art->tag('string')); - $q->bindValue(':datecreation', $art->datecreation('string')); - $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); - $q->bindValue(':css', $art->css()); - $q->bindValue(':html', $art->md()); - $q->bindValue(':secure', $art->secure()); - $q->bindValue(':couleurtext', $art->couleurtext()); - $q->bindValue(':couleurbkg', $art->couleurbkg()); - $q->bindValue(':couleurlien', $art->couleurlien()); - $q->bindValue(':couleurlienblank', $art->couleurlienblank()); - $q->bindValue(':lien', $art->lien('string')); - $q->bindValue(':template', $art->template()); + + // __________________________________________ T A B L E ________________________________________________________ - $q->execute(); - } public function tableexist($dbname, $tablename) { -- cgit v1.2.3