diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
commit | a91c916248f967da2d4218b575e665242b7c975b (patch) | |
tree | 3c767e9b7b62161253aef2d93030f4b38fd47d49 /w/class/modelartlist.php | |
parent | 7b2e48276b2a3ceff83c906d38077f8d0479c3df (diff) | |
download | wcms-a91c916248f967da2d4218b575e665242b7c975b.tar.gz wcms-a91c916248f967da2d4218b575e665242b7c975b.zip |
phoenixreborn\'NWY
Diffstat (limited to 'w/class/modelartlist.php')
-rw-r--r-- | w/class/modelartlist.php | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/w/class/modelartlist.php b/w/class/modelartlist.php new file mode 100644 index 0000000..acbdce5 --- /dev/null +++ b/w/class/modelartlist.php @@ -0,0 +1,159 @@ +<?php + +class Modelartlist extends Modeldb +{ + + + public function getlister(array $selection = ['id'], array $opt = []) + { + // give an array using SELECTION columns and sort and desc OPTIONS + + $default = ['tri' => 'id', 'desc' => 'DESC']; + $opt = array_update($default, $opt); + + $list = []; + $option = ['datecreation', 'title', 'id', 'description', '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 ' . $opt['tri'] . ' ' . $opt['desc']; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art2($donnees); + } + return $list; + } + } + + + + + + + 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 Art2($donnees); + } + return $artlist; + + } + + public function listcalclinkfrom(&$artlist) + { + foreach ($artlist as $art) { + $art->calclinkto($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 filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (empty($tagchecked)) { + $filteredlist[] = $art->id(); + } else { + $inter = (array_intersect($art->tag('array'), $tagchecked)); + if ($tagcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $art->id(); + } + } elseif ($tagcompare == 'AND') { + if (!array_diff($tagchecked, $art->tag('array'))) { + $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; + + } + + public function tag(array $artlist, $tagchecked) + { + $artcheckedlist = []; + foreach ($artlist as $art) { + if (in_array($tagchecked, $art->tag('array'))) { + $artcheckedlist[] = $art; + } + } + return $artcheckedlist; + } + + public function taglist(array $artlist, array $tagcheckedlist) + { + $taglist = []; + foreach ($tagcheckedlist as $tag) { + $taglist[$tag] = $this->tag($artlist, $tag); + } + return $taglist; + } + + public function count() + { + return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); + } + +} + + + + + +?>
\ No newline at end of file |