Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This file is subject to the terms and conditions defined in
- file 'LICENSE', which is part of this source code package.
- © 2022 OtteIT s.r.o.
- All Rights Reserved.
- Author: Vilem Otte <dev@otte.cz>
- */
- require_once(__DIR__."/../../db.php");
- /**
- * Rum currency class
- *
- * Functionality for currency creating, reading, updating and deleting
- */
- class Rum_Currency
- {
- /**
- * Database class instance
- */
- private $conn;
- /**
- * Currency ID
- */
- public $id;
- /**
- * Currency name
- */
- public $name;
- /**
- * Currency symbol
- */
- public $symbol;
- /**
- * Constructor
- *
- * @param dbconn Database connection instance
- */
- public function __construct($dbconn)
- {
- $this->conn = $dbconn;
- $this->id = null;
- $this->name = null;
- $this->symbol = null;
- }
- /**
- * Create currency record
- *
- * Creates single currency record with name and symbol
- *
- * @return _ Currency ID on success, null on failure
- */
- public function Create()
- {
- $query = "INSERT INTO currency (name, symbol) VALUES('" . $this->conn->EscapeString($this->name) . "', '" . $this->conn->EscapeString($this->symbol) . "')";
- $result = $this->conn->Query($query);
- if ($result == false)
- {
- return null;
- }
- else
- {
- $this->id = $this->conn->GetLastInsertID();
- return $this->id;
- }
- }
- /**
- * Reads currency records
- *
- * Reads currency records filtered by specific id, name and symbol
- *
- * @return _ Null on failure, array of objects on success ordered by name
- */
- public function Read()
- {
- $query = "SELECT * FROM currency WHERE 1 = 1";
- if ($this->id != null)
- {
- $query .= " AND id = '" . $this->conn->EscapeString($this->id) . "'";
- }
- if ($this->name != null)
- {
- $query .= " AND name = '" . $this->conn->EscapeString($this->name) . "'";
- }
- if ($this->symbol != null)
- {
- $query .= " AND symbol = '" . $this->conn->EscapeString($this->symbol) . "'";
- }
- $query .= " ORDER BY name ";
- $result = $this->conn->Query($query);
- if ($result == false)
- {
- return null;
- }
- else
- {
- $numRows = $this->conn->GetRowsCount($result);
- $output = [];
- for ($i = 0; $i < $numRows; $i++)
- {
- $row = $this->conn->GetRow($result, $i);
- $output[$i] = (object)array();
- $output[$i]->id = $row['id'];
- $output[$i]->name = $row['name'];
- $output[$i]->symbol = $row['symbol'];
- }
- return $output;
- }
- }
- /**
- * Update currency record
- *
- * Updates single currency record, requires name and symbol
- *
- * @return _ Null on failure, true on success
- */
- public function Update()
- {
- $query = "UPDATE currency SET
- name = '" . $this->conn->EscapeString($this->name) . "',
- symbol = '" . $this->conn->EscapeString($this->symbol) . "' ";
- $query .= "WHERE id = '" . $this->conn->EscapeString($this->id) . "'";
- $result = $this->conn->Query($query);
- if ($result == false)
- {
- return null;
- }
- else
- {
- return true;
- }
- }
- /**
- * Delete currency record
- *
- * Removes currency record from database
- *
- * @return _ Null on failure, true on success
- */
- public function Delete()
- {
- $query = "DELETE FROM currency WHERE id = '" . $this->conn->EscapeString($this->id) . "'";
- $result = $this->conn->Query($query);
- if ($result == false)
- {
- return null;
- }
- else
- {
- return true;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement