From 2f363e8fa26ab849539e64ff7caa21bd164e8979 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 10 Nov 2018 21:43:24 +0100 Subject: sidebars-html-inserts --- w/class/modelart.php | 222 +++------------------------------------------------ 1 file changed, 10 insertions(+), 212 deletions(-) (limited to 'w/class/modelart.php') diff --git a/w/class/modelart.php b/w/class/modelart.php index 37262ad..ef4d61d 100644 --- a/w/class/modelart.php +++ b/w/class/modelart.php @@ -34,14 +34,18 @@ class Modelart extends Modeldb $this->artstore->store($artdata); } - public function get($art) + public function get($id) { - if($art instanceof Art2) { - $id = $art->id(); + if($id instanceof Art2) { + $id = $id->id(); } - $artdata = $this->artstore->findById($id); - if($artdata !== false) { - return new Art2($artdata); + if(is_string($id)) { + $artdata = $this->artstore->findById($id); + if($artdata !== false) { + return new Art2($artdata); + } else { + return false; + } } else { return false; } @@ -59,205 +63,6 @@ class Modelart extends Modeldb $this->artstore->store($artdata); } - - public function exist3($id) - { - - $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . Config::arttable() . ' WHERE id = :id '); - $req->execute(array('id' => $id)); - $donnees = $req->fetch(PDO::FETCH_ASSOC); - - return (bool)$donnees['COUNT(*)']; - } - - public function add3(Art2 $art) - { - - if ($this->exist($art->id())) { - echo 'idalreadyexist'; - } else { - - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $table = Config::arttable(); - $request = "INSERT INTO $table (id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, linkto, template, affcount, editcount) - VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :linkto, :template, :affcount, :editcount)"; - - $q = $this->bdd->prepare($request); - - $q->bindValue(':id', $art->id()); - $q->bindValue(':title', $art->title()); - $q->bindValue(':description', $art->description()); - $q->bindValue(':tag', $art->tag('string')); - $q->bindValue(':date', $now->format('Y-m-d H:i:s')); - $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s')); - $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); - $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); - $q->bindValue(':css', $art->css()); - $q->bindValue(':quickcss', $art->quickcss('json')); - $q->bindValue(':javascript', $art->javascript()); - $q->bindValue(':html', $art->html()); - $q->bindValue(':header', $art->header()); - $q->bindValue(':section', $art->md()); - $q->bindValue(':nav', $art->nav()); - $q->bindValue(':aside', $art->aside()); - $q->bindValue(':footer', $art->footer()); - $q->bindValue(':render', $art->render()); - $q->bindValue(':secure', $art->secure()); - $q->bindValue(':invitepassword', $art->invitepassword()); - $q->bindValue(':interface', $art->interface()); - $q->bindValue(':linkfrom', $art->linkfrom('json')); - $q->bindValue(':linkto', $art->linkto('json')); - $q->bindValue(':template', $art->template('json')); - $q->bindValue(':affcount', $art->affcount()); - $q->bindValue(':editcount', $art->editcount()); - - $q->execute(); - } - } - - - public function delete3(Art2 $art) - { - $req = $this->bdd->prepare('DELETE FROM ' . Config::arttable() . ' WHERE id = :id '); - $req->execute(array('id' => $art->id())); - $req->closeCursor(); - } - - public function get3(Art2 $art) - { - - $req = $this->bdd->prepare('SELECT * FROM ' . Config::arttable() . ' WHERE id = :id '); - $req->execute(array('id' => $art->id())); - $donnees = $req->fetch(PDO::FETCH_ASSOC); - - return new Art2($donnees); - - $req->closeCursor(); - - } - - - - - public function update3(Art2 $art) - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - //$request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id'; - $table = Config::arttable(); - $request = "UPDATE $table SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, linkto = :linkto, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id"; - - $q = $this->bdd->prepare($request); - - $q->bindValue(':id', $art->id()); - $q->bindValue(':title', $art->title()); - $q->bindValue(':description', $art->description()); - $q->bindValue(':tag', $art->tag('string')); - $q->bindValue(':date', $art->date('string')); - $q->bindValue(':datecreation', $art->datecreation('string')); - $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); - $q->bindValue(':daterender', $art->daterender('string')); - $q->bindValue(':css', $art->css()); - $q->bindValue(':quickcss', $art->quickcss('json')); - $q->bindValue(':javascript', $art->javascript()); - $q->bindValue(':html', $art->html()); - $q->bindValue(':header', $art->header()); - $q->bindValue(':section', $art->md()); - $q->bindValue(':nav', $art->nav()); - $q->bindValue(':aside', $art->aside()); - $q->bindValue(':footer', $art->footer()); - $q->bindValue(':render', $art->render()); - $q->bindValue(':secure', $art->secure()); - $q->bindValue(':invitepassword', $art->invitepassword()); - $q->bindValue(':interface', $art->interface()); - $q->bindValue(':linkfrom', $art->linkfrom('json')); - $q->bindValue(':linkto', $art->linkto('json')); - $q->bindValue(':template', $art->template('json')); - $q->bindValue(':affcount', $art->affcount()); - $q->bindValue(':editcount', $art->editcount()); - - $q->execute(); - } - - - - - public function getlister3(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 ' . Config::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 getlisterwhere3(array $select = ['id'], array $whereid = [], $by = 'id', $order = 'DESC') - { - // give an array using SELECTION columns and sort and desc OPTIONS - - - $select = array_intersect(array_unique($select), self::SELECT); - if (empty($select)) { - $select = ' * '; - } else { - $select = implode(", ", $select); - } - - - $whereid = array_unique($whereid); - - $list = []; - - if (!in_array($by, self::BY)) { - $by = 'id'; - } - if (!in_array($order, self::ORDER)) { - $order = 'DESC'; - } - - - if (!empty($whereid)) { - $wherestatements = array_map(function ($element) { - return ' id= ?'; - }, $whereid); - $where = 'WHERE ' . implode(' OR ', $wherestatements); - } else { - $where = ''; - } - - $table = Config::arttable(); - $prepare = "SELECT $select FROM $table $where ORDER BY $by $order"; - $req = $this->bdd->prepare($prepare); - $req->execute($whereid); - while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $list[] = new Art2($donnees); - } - - return $list; - } - - - - - - public function getlisteropt(Opt $opt) { @@ -272,13 +77,6 @@ class Modelart extends Modeldb } - 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')); -- cgit v1.2.3