Questtype ?Textinput?: add support for field sizes (Issue #252) and general improvements
This commit is contained in:
commit
8d903135a5
3476 changed files with 599099 additions and 0 deletions
83
models/DatabaseModel.inc
Normal file
83
models/DatabaseModel.inc
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* NRE
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
* @copyright 2013 coderkun (http://www.coderkun.de)
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://www.coderkun.de/projects/nre
|
||||
*/
|
||||
|
||||
namespace nre\models;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of a database model.
|
||||
*
|
||||
* @author coderkun <olli@coderkun.de>
|
||||
*/
|
||||
class DatabaseModel extends \nre\core\Model
|
||||
{
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @static
|
||||
* @var DatabaseDriver
|
||||
*/
|
||||
protected $db = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new datamase model.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @throws DriverNotFoundException
|
||||
* @throws DriverNotValidException
|
||||
* @param string $type Database type
|
||||
* @param array $config Connection settings
|
||||
*/
|
||||
function __construct($type, $config)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Load database driver
|
||||
$this->loadDriver($type);
|
||||
|
||||
// Establish database connection
|
||||
$this->connect($type, $config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the database driver.
|
||||
*
|
||||
* @throws DriverNotFoundException
|
||||
* @throws DriverNotValidException
|
||||
* @param string $driverName Name of the database driver
|
||||
*/
|
||||
private function loadDriver($driverName)
|
||||
{
|
||||
\nre\core\Driver::load($driverName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Establish a connection to the database.
|
||||
*
|
||||
* @throws DatamodelException
|
||||
* @param string $driverName Name of the database driver
|
||||
* @param array $config Connection settings
|
||||
*/
|
||||
private function connect($driverName, $config)
|
||||
{
|
||||
$this->db = \nre\core\Driver::factory($driverName, $config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue