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.aff.php | 417 ++++++++++++++++++++++++++++++-------------------- class/class.w.app.php | 158 +++++++++++++++---- class/class.w.art.php | 94 ++++++++++-- class/class.w.opt.php | 207 +++++++++++++++++++++++++ 4 files changed, 660 insertions(+), 216 deletions(-) create mode 100644 class/class.w.opt.php (limited to 'class') diff --git a/class/class.w.aff.php b/class/class.w.aff.php index cacec99..9f1177a 100644 --- a/class/class.w.aff.php +++ b/class/class.w.aff.php @@ -58,12 +58,11 @@ class Aff public function lecture(Art $art, App $app) { - echo '
'; if ($art->secure() == 1) { - echo '

cet article est privé

'; + echo 'This article is private'; } if ($art->secure() == 2) { - echo "

cet article n'est pas publié

"; + echo "This article is not published yet"; } if ($app->session() >= $art->secure()) { @@ -85,17 +84,14 @@ class Aff } csstemplate($app) ?> -

titre() ?>

soustitre() ?>
html($app) ?>
-
'; } public function edit(Art $art, App $app, $list) @@ -103,45 +99,50 @@ class Aff if ($app->session() >= self::$edit) { ?> -
-
-
-
+ + + + + +
Infos - - - - - - - - - - +
+ + + + + + + + + + +
-
+
CSS +
- + template() == 'NULL') { + echo ''; + } else { + echo ''; + } + foreach ($list as $item) { + + if ($item->id() == $art->template()) { + echo ''; + } else { + echo ''; + } + } + ?> @@ -153,20 +154,17 @@ class Aff +
-
- Contenu - -
+ -
-
- - - + +
+ +
-
+ -
-
- - - '; - ?> - - - - - - - - - -
+
+
+
+ + + '; + ?> + + + + + + + + + +
+
- - ' : '' ?> + ' : '' ?> <?= $edit == 1 ? '✏' : '' ?> <?= $art->titre() ?> @@ -243,132 +244,206 @@ public function arthead(Art $art, $cssread = '', $edit = 0) public function search() { ?> + + '; - echo '
    '; - foreach ($getlist as $item) { - if (in_array($tag, $item->tag('array'))) { - echo '
  • ' . $item->titre() . ' - ' . $item->intro(); - if ($app->session() >= $app::EDITOR) { - echo ' - modifier
  • '; - } else { - echo ''; - } +public function tag($getlist, $tag, $app) +{ + echo '
    '; + echo '
      '; + foreach ($getlist as $item) { + if (in_array($tag, $item->tag('array'))) { + echo '
    • ' . $item->titre() . ' - ' . $item->intro(); + if ($app->session() >= $app::EDITOR) { + echo ' - modifier
    • '; + } else { + echo ''; } } - echo '
    '; - echo '
    '; } + echo '
'; + echo '
'; +} - public function lien($getlist, $lien, App $app) - { - echo '
'; - echo '
    '; - foreach ($getlist as $item) { - if (in_array($lien, $item->lien('array'))) { - echo '
  • ' . $item->titre() . ' - ' . $item->intro(); - if ($app->session() >= $app::EDITOR) { - echo ' - modifier - liens
  • '; - } else { - echo ''; - } +public function lien($getlist, $lien, App $app) +{ + echo '
    '; + echo '
      '; + foreach ($getlist as $item) { + if (in_array($lien, $item->lien('array'))) { + echo '
    • ' . $item->titre() . ' - ' . $item->intro(); + if ($app->session() >= $app::EDITOR) { + echo ' - modifier - liens
    • '; + } else { + echo ''; } } - echo '
    '; - echo '
    '; } + echo '
'; + echo '
'; +} - public function dump($getlist) - { - echo '
    '; +public function dump($getlist) +{ + echo '
      '; + foreach ($getlist as $item) { + echo '
    • '; + var_dump($item); + echo '
    • '; + } + echo '
    '; +} + +public function header() +{ + echo '
    '; + $this->search(); + echo '
    '; +} + + +public function home2table(App $app, $getlist) +{ + + + if ($app->session() >= $app::EDITOR) { + echo ''; + echo ''; foreach ($getlist as $item) { - echo '
  • '; - var_dump($item); - echo '
  • '; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; } - echo ' '; + echo '
    titletagsummary↘ to↗ fromlast modificationdate of creationprivacy⚙ edit
    ' . $item->titre() . '' . $item->tag('sort') . '' . $item->intro() . '' . $item->liento('sort') . '' . $item->lien('sort') . '' . $item->datemodif('hrdi') . '' . $item->datecreation('hrdi') . '' . $item->secure('string') . 'edit
    '; } +} +public function option(App $app, Opt $opt) +{ + if ($app->session() >= $app::EDITOR) { + echo '
    '; - public function home2table(App $app, $getlist) - { - echo '
    '; - echo '
    '; - echo '

    W

    '; - $this->search(); - if ($app->session() >= $app::EDITOR) { - echo '

    Home

    '; - echo ''; - echo ''; - foreach ($getlist as $item) { - $liento = 0; - $lienfrom = 0; - - foreach ($getlist as $lien) { - if (in_array($item->id(), $lien->lien('array'))) { - $liento++; - } - } - foreach ($item->lien('array') as $count) { - $lienfrom++; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
    titrerésumélien fromlien todernière modifdate de créationedit
    ' . $item->titre() . '' . $item->intro() . '' . $lienfrom . '' . $liento . '' . $item->datemodif('hrdi') . '' . $item->datecreation('hrdi') . 'modifier
    '; + + $this->optiontag($opt); + $this->optionprivacy($opt); + $this->optionsort($opt); + + + + + echo ''; + + echo '
    '; + + } + +} + +public function optiontag(Opt $opt) +{ + + echo '
    Tag
      '; + foreach ($opt->taglist() as $tagor => $count) { + if (in_array($tagor, $opt->tagor())) { + echo '
    • '; + } else { + echo '
    • '; } - echo ''; - echo '
    '; } + echo '
'; - public function aside(App $app) - { - if ($app->session() >= $app::EDITOR) { - echo ' '; +public function optionsort(Opt $opt) +{ + echo '
Sort'; + echo ''; + echo 'order() == '1' ? "checked" : "") . ' />'; + echo 'order() == '-1' ? "checked" : "") . ' />'; + + echo '
'; + +} + +public function map(App $app, $url) +{ + echo '
'; + + $map = ""; + $link = ""; + foreach ($app->getlister(['id', 'lien']) as $item) { + foreach ($item->lien('array') as $lien) { + $map = $map . '
' . $item->id() . ' --> ' . $lien; } + $link = $link . '
click ' . $item->id() . ' "' . $url . '/w/?id=' . $item->id() . '"'; } + echo $map; + echo $link; - public function nav($app) - { - echo '
'; +} - echo 'home'; +public function aside(App $app) +{ + if ($app->session() >= $app::EDITOR) { + echo ' '; + } +} + +public function nav($app) +{ + echo ' 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) { diff --git a/class/class.w.art.php b/class/class.w.art.php index 9640470..d757e0d 100644 --- a/class/class.w.art.php +++ b/class/class.w.art.php @@ -20,6 +20,7 @@ class Art private $couleurlien; private $couleurlienblank; private $lien; + private $liento; private $template; const LEN = 255; @@ -59,8 +60,7 @@ class Art $this->setintro('resumé'); $this->settag('sans tag,'); $this->setdatecreation($now); - $this->setcss('section {} -a:hover {}'); + $this->setcss(''); $this->sethtml('contenu'); $this->setsecure(2); $this->setcouleurtext('#000000'); @@ -74,27 +74,50 @@ a:hover {}'); public function updatelien() { $this->lien = search($this->md(), self::DEBUT, self::FIN); + } + public static function classvarlist() + { + $classvarlist = []; + foreach (get_class_vars(__class__) as $var => $default) { + $classvarlist[] = $var; + } + return ['artvarlist' => $classvarlist]; } + + + + public function calcliento($getlist) + { + $liento = []; + foreach ($getlist as $lien) { + if (in_array($this->id(), $lien->lien('array'))) { + $liento[] = $lien->id(); + } + } + $this->setliento($liento); + } + + // _____________________________________________________ G E T ____________________________________________________ - public function id() + public function id($type = 'string') { return $this->id; } - public function titre() + public function titre($type = 'string') { return $this->titre; } - public function soustitre() + public function soustitre($type = 'string') { return $this->soustitre; } - public function intro() + public function intro($type = 'string') { return $this->intro; } @@ -102,18 +125,19 @@ a:hover {}'); public function tag($option) { if ($option == 'string') { - $tag = implode(", ", $this->tag); + return implode(", ", $this->tag); } elseif ($option == 'array') { - $tag = $this->tag; + return $this->tag; + } elseif ($option == 'sort') { + return count($this->tag); } - return $tag; } public function datecreation($option) { if ($option == 'string') { return $this->datecreation->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { + } elseif ($option == 'date' || $option == 'sort') { return $this->datecreation; } elseif ($option == 'hrdi') { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); @@ -126,7 +150,7 @@ a:hover {}'); { if ($option == 'string') { return $this->datemodif->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { + } elseif ($option == 'date' || $option == 'sort') { return $this->datemodif; } elseif ($option == 'hrdi') { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); @@ -134,7 +158,7 @@ a:hover {}'); } } - public function css() + public function css($type = 'string') { return $this->css; } @@ -166,7 +190,7 @@ a:hover {}'); foreach ($this->lien('array') as $id) { $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'intro'], 'id') as $item) { + foreach ($app->getlister(['id', 'intro']) as $item) { if ($item->id() == $id) { $title = $item->intro(); } @@ -185,9 +209,16 @@ a:hover {}'); } - public function secure() + public function secure($type = 'int') { - return $this->secure; + if ($type == 'string') { + if ($this->secure == 0) $secure = 'public'; + if ($this->secure == 1) $secure = 'private'; + if ($this->secure == 2) $secure = 'not published'; + return $secure; + } else { + return $this->secure; + } } public function couleurtext() @@ -216,12 +247,27 @@ a:hover {}'); $lien = implode(", ", $this->lien); } elseif ($option == 'array') { $lien = $this->lien; + } elseif ($option == 'sort') { + return count($this->lien); } return $lien; } - public function template() + public function liento($option) + { + if ($option == 'string') { + $liento = implode(", ", $this->liento); + } elseif ($option == 'array') { + $liento = $this->liento; + } elseif ($option == 'sort') { + return count($this->liento); + } + return $liento; + + } + + public function template($type = 'string') { return $this->template; } @@ -229,6 +275,7 @@ a:hover {}'); + // _____________________________________________________ S E T ____________________________________________________ public function setid($id) @@ -263,7 +310,11 @@ a:hover {}'); { if (strlen($tag) < self::LEN and is_string($tag)) { $tag = strip_tags(trim(strtolower($tag))); - $taglist = explode(", ", $tag); + $tag = str_replace('*', '', $tag); + $tag = str_replace(' ', '', $tag); + + $taglist = explode(",", $tag); + $taglist = array_filter($taglist); $this->tag = $taglist; } } @@ -350,6 +401,15 @@ a:hover {}'); } } + public function setliento($liento) + { + if (is_array($liento)) { + $this->liento = $liento; + } + + + } + public function settemplate($template) { $template = strip_tags($template); diff --git a/class/class.w.opt.php b/class/class.w.opt.php new file mode 100644 index 0000000..76b3905 --- /dev/null +++ b/class/class.w.opt.php @@ -0,0 +1,207 @@ + '0', 'max' => '0']; + private $lienfrom = ['min' => '0', 'max' => '0']; + private $col = ['id']; + private $taglist = []; + + private $artvarlist; + + public function __construct(array $donnees = []) + { + $this->hydrate($donnees); + } + + public function hydrate(array $donnees) + { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + + public function reset() + { + $varlist = get_class_vars(__class__); + + foreach ($varlist as $var => $default) { + $method = 'set' . $var; + $this->$method($default); + } + } + + public function dump() + { + var_dump($this); + } + + + + + + // _______________________________________________ G E T _______________________________________________ + + public function sortby() + { + return $this->sortby; + } + + public function order() + { + return $this->order; + } + + public function secure() + { + return $this->secure; + } + + public function tagor($type = 'array') + { + return $this->tagor; + } + + public function liento($type = 'array') + { + return $this->liento; + } + + public function lienfrom($type = 'array') + { + return $this->lienfrom; + } + + public function col($type = 'array') + { + if ($type == 'string') { + return implode(', ', $this->col); + } else { + return ($this->col); + } + } + + public function artvarlist() + { + return $this->artvarlist; + } + + public function taglist() + { + return $this->taglist; + } + + + // __________________________________________________ S E T _____________________________________________ + + public function setsortby($sortby) + { + if (is_string($sortby) && in_array($sortby, $this->artvarlist())) { + $this->sortby = strtolower(strip_tags($sortby)); + } + } + + public function setorder($order) + { + $order = intval($order); + if (in_array($order, [-1, 0, 1])) { + $this->order = $order; + } + } + + public function settagor($tagor) + { + if (is_array($tagor)) { + // $tagorlist = []; + // foreach ($tagor as $tag) { + // if (array_key_exists($tag, $this->taglist())) { + // $tagorlist[] = $tag; + // } + // } + $this->tagor = $tagor; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 && $secure <= 5) { + $this->secure = intval($secure); + } + } + + public function setliento($n0, $n1) + { + $stock = [intval($n1), intval($n2)]; + $sorted = asort($stock); + $this->liento = ['min' => $stock[0], 'max' => $stock[1]]; + } + + public function setlienfrom($n0, $n1) + { + $stock = [intval($n1), intval($n2)]; + $sorted = asort($stock); + $this->lienfrom = ['min' => $stock[0], 'max' => $stock[1]]; + } + + public function setlientomin($min) + { + $this->liento['min'] = intval($min); + } + + public function setlientomax($max) + { + $this->liento['max'] = intval($max); + } + + public function setlienfrommin($min) + { + $this->lienfrom['min'] = intval($min); + } + + public function setlienfrommax($max) + { + $this->lienfrom['max'] = intval($max); + } + + public function setcol($col) + { + if (is_array($col)) { + $this->col = array_intersect($this->artvarlist(), $col); + } + } + + public function setartvarlist(array $artvarlist) + { + $this->artvarlist = $artvarlist; + } + + public function settaglist(array $artlist) + { + $taglist = []; + foreach ($artlist as $art) { + foreach ($art->tag('array') as $tag) { + if (!array_key_exists($tag, $taglist)) { + $taglist[$tag] = 1; + } else { + $taglist[$tag]++; + } + } + } + $taglistsorted = arsort($taglist); + $this->taglist = $taglist; + } + +} + + + + +?> \ No newline at end of file -- cgit v1.2.3