| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/backend-accounting.sk/app/app/classes/ |
Upload File : |
<?php
namespace app\classes;
class PDOCollection {
protected $collection = array();
protected $db;
private $table;
private $idColumn;
/**
* @param string $table <p>table name in database</p>
* @param array $bindArray <p>array of bind parameters in condition string</p>
* @param string $idColumn <p>ID column name</p>
* @param string $condition <p>select condition ("SELECT * FROM $table $condition)</p>
* @param string $condition <p>custom selection (full select string)</p>
*/
public function __construct($table, $idColumn, $customSelection = false, $bindArray = array(), $condition = false) {
$this->table = $table;
$this->idColumn = $idColumn;
$this->db = PDODatabase::getInstance();
$this->collection = $this->db->getRows($table, $idColumn, $customSelection, $bindArray, false, $condition);
}
/**
* Get array of rows (arrays).
* @return array <p>Returns array of rows (arrays).</p>
*/
public function toArray() {
return $this->collection;
}
/**
* Get element array by given key.
* @param mixed $id <p>ID column name</p>
* @return array <p>row array or NULL if element with givent key doesn't exists</p>
*/
public function getItemArray($id) {
if (isset($this->collection[$id])) {
return $this->collection[$id];
}
// trigger_error("Item not found: " . $id, E_USER_NOTICE);
return NULL;
}
/**
* Get id column name.
* @return string <p>id column name</p>
*/
public function getIdColumnName() {
return $this->idColumn;
}
/**
* Remove element from collection by given key.
* @param mixed $index <p>key of element</p>
* @return bool <p>Returns TRUE on success or FALSE on failure (if element doesn't exist).</p>
*/
public function unsetIndex($index) {
if (isset($this->collection[$index])) {
unset($this->collection[$index]);
return true;
}
return false;
}
/**
* Get total elements count in collection.
* @return int <p>elements count</p>
*/
public function getElementsCount() {
return count($this->collection);
}
/**
* Get first item id in collection.
* @return mixed <p>id value</p>
*/
public function getFirstItemId() {
return key($this->collection);
}
}