2022-01-14 19:13:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-01-14 19:45:30 +00:00
|
|
|
/*
|
2022-02-06 20:37:02 +00:00
|
|
|
This file is a part of myTinyTodo.
|
|
|
|
|
(C) Copyright 2022 Max Pozdeev <maxpozdeev@gmail.com>
|
|
|
|
|
Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details.
|
2022-01-14 19:45:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2022-01-14 19:13:04 +00:00
|
|
|
// FIXME: experimental, subject to change
|
|
|
|
|
|
|
|
|
|
class DBCore
|
|
|
|
|
{
|
2022-02-06 20:37:02 +00:00
|
|
|
/** @var Database_Abstract $db */
|
|
|
|
|
protected $db;
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/** @var DBCore $defaultdb */
|
|
|
|
|
protected static $defaultInstance;
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param Database_Abstract $db Value of DBConnection::instance() or similar
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Database_Abstract $db) {
|
|
|
|
|
$this->db = $db;
|
|
|
|
|
}
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return Database_Abstract
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function connection()
|
|
|
|
|
{
|
|
|
|
|
if (!isset($this->db)) {
|
|
|
|
|
throw new Exception("DBConnection is not set");
|
|
|
|
|
}
|
|
|
|
|
return $this->db;
|
|
|
|
|
}
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return DBCore
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static function defaultInstance() : DBCore
|
|
|
|
|
{
|
2022-01-14 19:13:04 +00:00
|
|
|
if (!isset(self::$defaultInstance)) {
|
2022-02-06 20:37:02 +00:00
|
|
|
throw new Exception("DBCore defaultInstance is not initialized");
|
2022-01-14 19:13:04 +00:00
|
|
|
}
|
2022-02-06 20:37:02 +00:00
|
|
|
return self::$defaultInstance;
|
|
|
|
|
}
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param DBCore $instance
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function setDefaultInstance(DBCore $instance)
|
|
|
|
|
{
|
|
|
|
|
self::$defaultInstance = $instance;
|
|
|
|
|
}
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-02-06 20:37:02 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @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;
|
|
|
|
|
}
|
2022-01-14 19:13:04 +00:00
|
|
|
|
2022-01-14 19:45:30 +00:00
|
|
|
}
|
|
|
|
|
|