From ce726c453901af40ef6c36ba18220766a02bfad3 Mon Sep 17 00:00:00 2001 From: junior Date: Wed, 16 Feb 2022 17:32:23 +0000 Subject: [PATCH] Add manufacturer and scale to album model --- class_album.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- install/initial_db.sql | 2 ++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/class_album.php b/class_album.php index 45e2d78..2e32161 100644 --- a/class_album.php +++ b/class_album.php @@ -6,6 +6,8 @@ class Album implements JsonSerializable { private $title = ""; private $thumbnail = ""; private $description = ""; + private $manufacturer = ""; + private $scale = ""; private $createtime = ""; public function getID() { @@ -87,6 +89,40 @@ class Album implements JsonSerializable { } } + public function getManufacturer($flag = 0) { + switch ($flag) { + case HTMLSAFE: + return htmlspecialchars($this->manufacturer); + break; + case HTMLFORMSAFE: + return htmlspecialchars($this->manufacturer, ENT_QUOTES); + break; + case CSVSAFE: + return str_replace('"', '""', $this->manufacturer); + break; + default: + return $this->manufacturer; + break; + } + } + + public function getScale($flag = 0) { + switch ($flag) { + case HTMLSAFE: + return htmlspecialchars($this->scale); + break; + case HTMLFORMSAFE: + return htmlspecialchars($this->scale, ENT_QUOTES); + break; + case CSVSAFE: + return str_replace('"', '""', $this->scale); + break; + default: + return $this->scale; + break; + } + } + public function getCreateTime($flag = 0) { switch ($flag) { case TIMESTAMP: @@ -225,6 +261,8 @@ class Album implements JsonSerializable { 'thumburl' => ($this->getThumbnail() == "") ? "graphics/no-image-available_thm.gif" : THUMBNAILFOLDER . $this->getFolderName() . $this->getThumbnail(), 'title' => $this->getTitle(), 'description' => $this->getDescription(), + 'manufacturer' => $this->getManufacturer(), + 'scale' => $this->getScale(), 'createtime' => $this->getCreateTime(), 'images' => Image::getImagesForAlbum($this->getID()) ]; @@ -249,16 +287,18 @@ class Album implements JsonSerializable { global $globaldbh; $query = "INSERT INTO " . AppDB::TABLE_ALBUMS . " "; - $query .= "(id, foldername, title, thumbnail, description, createtime) "; - $query .= "VALUES(NULL, :foldername, :title, :thumbnail, :description, NOW()) "; + $query .= "(id, foldername, title, thumbnail, description, manufacturer, scale, createtime) "; + $query .= "VALUES(NULL, :foldername, :title, :thumbnail, :description, :manufacturer, :scale, NOW()) "; $query .= "ON DUPLICATE KEY UPDATE "; - $query .= "foldername=:foldername, title=:title, thumbnail=:thumbnail, description=:description"; + $query .= "foldername=:foldername, title=:title, thumbnail=:thumbnail, description=:description, manufacturer=:manufacturer, scale=:scale"; $sth = $globaldbh->prepare($query); $sth->bindValue(":id", (int) $this->getID(), PDO::PARAM_INT); $sth->bindValue(":foldername", $this->getFolderName(), PDO::PARAM_STR); $sth->bindValue(":title", $this->getTitle(), PDO::PARAM_STR); $sth->bindValue(":thumbnail", $this->getThumbnail(), PDO::PARAM_STR); $sth->bindValue(":description", $this->getDescription(), PDO::PARAM_STR); + $sth->bindValue(":manufacturer", $this->getManufacturer(), PDO::PARAM_STR); + $sth->bindValue(":scale", $this->getScale(), PDO::PARAM_STR); $sth->execute(); if ( $this->getID() == 0 ) { $this->setID($globaldbh->lastInsertId()); @@ -270,7 +310,7 @@ class Album implements JsonSerializable { global $globaldbh; $reqid = intval($reqid); - $query = "SELECT id, foldername, title, thumbnail, description, createtime " . + $query = "SELECT id, foldername, title, thumbnail, description, manufacturer, scale, createtime " . "FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id"; $sth = $globaldbh->prepare($query); $sth->bindValue(":id", $reqid, PDO::PARAM_INT); @@ -281,6 +321,8 @@ class Album implements JsonSerializable { $this->setTitle($row['title']); $this->setThumbnail($row['thumbnail']); $this->setDescription($row['description']); + $this->setManufacturer($row['manufacturer']); + $this->setScale($row['scale']); $this->createtime = $row['createtime']; } } diff --git a/install/initial_db.sql b/install/initial_db.sql index 96c05c9..d275df3 100644 --- a/install/initial_db.sql +++ b/install/initial_db.sql @@ -103,6 +103,8 @@ CREATE TABLE `albums` ( `title` varchar(255) NOT NULL, `thumbnail` varchar(255) NOT NULL DEFAULT "", `description` text NOT NULL, + `manufacturer` varchar(255) NOT NULL DEFAULT "", + `scale` varchar(255) NOT NULL DEFAULT "", `createtime` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `al_foldername` (`foldername`)