diff options
author | Camil Staps | 2016-07-27 17:14:55 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-27 17:14:55 +0200 |
commit | d6e0bc8728e90e90504b98bc115aeabfdc6335bf (patch) | |
tree | 6d6c59c9b5721ea083e31d0ebebc4455a64fe182 /classes | |
parent | Document Model (diff) |
File: use Model
Diffstat (limited to 'classes')
-rw-r--r-- | classes/File.php | 70 | ||||
-rw-r--r-- | classes/Offer.php | 4 |
2 files changed, 7 insertions, 67 deletions
diff --git a/classes/File.php b/classes/File.php index 656ac5e..2545dc9 100644 --- a/classes/File.php +++ b/classes/File.php @@ -24,66 +24,14 @@ /** * An interface to the file table in the database */ -class File { - /** - * @var PDO $pdo The PDO class for database communication - * @var int $id The id of the file - * @var string $filename The relative path to the file - */ - protected $pdo, $id, $filename; - - /** - * Create a new instance - * - * @param PDO $pdo The PDO class, to access the database - * @param int $id The id of the file to fetch - * - * @throws PDOException If something went wrong with the database - * @throws Exception If the file could not be found - */ - public function __construct($pdo, $id) { - $this->pdo = $pdo; - - $stmt = $this->pdo->prepare("SELECT * FROM `".Constants::db_prefix."file` WHERE `id`=?"); - $stmt->execute(array($id)); - if ($stmt->rowCount() == 0) { - throw new Exception("The file with id '$id' could not be found."); - } - $file = $stmt->fetch(PDO::FETCH_ASSOC); - - $this->id = $file['id']; - $this->filename = $file['filename']; - } - - //------------------------------------------------------------------------------ - // Getters and setters - //------------------------------------------------------------------------------ - - /** - * Get the ID of the file - * - * @return int The ID - */ - public function getId() { - return $this->id; - } - - /** - * Get the relative filename of the file - * - * @see file::getFilenamePath To get the full internal path to the file - * @see file::getFilenameURI To get the full external path to the file - * - * @return string The filename - */ - public function getFilename() { - return $this->filename; - } +class File extends Model { + public + $table = 'file', + $fillable_columns = ['filename']; /** * Get the full internal path to the file * - * @see file::getFilename To get the relative filename * @see file::getFilenameURI To get the full external path to the file * * @return string The path @@ -95,7 +43,6 @@ class File { /** * Get the full external path to the file * - * @see file::getFilename To get the relative filename * @see file::getFilenamePath To get the full internal path to the file * * @return string The URI @@ -136,13 +83,6 @@ class File { // Remove offers linked by invoice_fileId $this->pdo->query("UPDATE `".Constants::db_prefix."offer` SET `invoice_fileId`=NULL WHERE `invoice_fileId`={$this->id}"); - // Remove the record of the file - $stmt = $this->pdo->prepare("DELETE FROM `".Constants::db_prefix."file` WHERE `id`=?"); - $stmt->execute(array($this->id)); - if ($stmt->rowCount() == 1) { - return true; - } else { - return false; - } + return parent::delete(); } } diff --git a/classes/Offer.php b/classes/Offer.php index d08091b..9487f79 100644 --- a/classes/Offer.php +++ b/classes/Offer.php @@ -566,9 +566,9 @@ class Offer { } while (file_exists(Constants::files_folder . $filename)); $file = BusinessAdmin::createFile($this->pdo, $filename); - $this->setInvoiceFileId($file->getId()); + $this->setInvoiceFileId($file->id); } else { - $invoice_nr = str_replace(array('invoice-','.pdf'), array('',''), $file->getFilename()); + $invoice_nr = str_replace(array('invoice-','.pdf'), array('',''), $file->filename); } $list = array(); |