mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
70 lines
1.2 KiB
PHP
70 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
// FIXME: experimental, subject to change
|
||
|
|
|
||
|
|
class DBCore
|
||
|
|
{
|
||
|
|
/** @var Database_Abstract $db */
|
||
|
|
protected $db;
|
||
|
|
|
||
|
|
/** @var DBCore $defaultdb */
|
||
|
|
protected static $defaultInstance;
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @param Database_Abstract $db Value of DBConnection::instance() or similar
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct(Database_Abstract $db) {
|
||
|
|
$this->db = $db;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @return Database_Abstract
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function connection()
|
||
|
|
{
|
||
|
|
if (!isset($this->db)) {
|
||
|
|
throw new Exception("DBConnection is not set");
|
||
|
|
}
|
||
|
|
return $this->db;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @return DBCore
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public static function defaultInstance() : DBCore
|
||
|
|
{
|
||
|
|
if (!isset(self::$defaultInstance)) {
|
||
|
|
throw new Exception("DBCore defaultInstance is not initialized");
|
||
|
|
}
|
||
|
|
return self::$defaultInstance;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @param DBCore $instance
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public static function setDefaultInstance(DBCore $instance)
|
||
|
|
{
|
||
|
|
self::$defaultInstance = $instance;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return int
|
||
|
|
*/
|
||
|
|
public function getListIdByTaskId(int $id): int
|
||
|
|
{
|
||
|
|
$db = $this->db;
|
||
|
|
$listId = (int)$db->sq("SELECT list_id FROM {$db->prefix}todolist WHERE id=". (int)$id);
|
||
|
|
return $listId;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|