Merge branch 'Issue_#9;_Recreate_Models' into 'master'
Issue #9; recreate models This merge request solves #9. Please evaluate under specific testing, a few errors might be prone. See merge request !7
This commit is contained in:
commit
230be3fe60
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Example extends DatabaseModel{
|
class Example extends Model{
|
||||||
|
|
||||||
public function __construct(&$core){
|
public function __construct(&$core){
|
||||||
parent::__construct($core);
|
parent::__construct($core);
|
||||||
|
|
||||||
|
$this->setType('techfuze/databasemodel', 'DatabaseModel');
|
||||||
$this->fields = array('id', 'key', 'value');
|
$this->fields = array('id', 'key', 'value');
|
||||||
$this->table = 'example';
|
$this->table = 'example';
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
class Model {
|
|
||||||
public function onLoad(){}
|
|
||||||
}
|
|
||||||
class DatabaseModel extends Bus{
|
class DatabaseModel extends Bus{
|
||||||
|
|
||||||
public $fields = array();
|
public $fields = array();
|
18
Core/Mods/databasemodel/moduleInfo.php
Normal file
18
Core/Mods/databasemodel/moduleInfo.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
return array(
|
||||||
|
|
||||||
|
'module_class' => 'DatabaseModel',
|
||||||
|
'module_file' => 'class.model.php',
|
||||||
|
'module_name' => 'databasemodel',
|
||||||
|
|
||||||
|
'abstract' => true,
|
||||||
|
|
||||||
|
'name' => 'DatabaseModel',
|
||||||
|
'description' => 'Abstract type for easy database queries',
|
||||||
|
'author' => 'TechFuze',
|
||||||
|
'version' => '1.0.0',
|
||||||
|
'website' => 'http://fuzeworks.techfuze.net/',
|
||||||
|
|
||||||
|
'date_created' => '26-02-2015',
|
||||||
|
'date_updated' => '26-02-2015',
|
||||||
|
);
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Interpret extends DatabaseModel {
|
class Interpret extends Model {
|
||||||
|
|
||||||
public function __construct(&$core){
|
public function __construct(&$core){
|
||||||
parent::__construct($core);
|
parent::__construct($core);
|
||||||
|
|
||||||
|
$this->setType('techfuze/databasemodel', 'DatabaseModel');
|
||||||
$this->fields = array();
|
$this->fields = array();
|
||||||
$this->table = '';
|
$this->table = '';
|
||||||
}
|
}
|
68
Core/System/class.abstract.model.php
Normal file
68
Core/System/class.abstract.model.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class Model
|
||||||
|
*
|
||||||
|
* Abstract for a model data representation, loads the correct parent type
|
||||||
|
*/
|
||||||
|
abstract class Model extends Bus{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The parent class holder object
|
||||||
|
* Requests get redirected to this class
|
||||||
|
* @access private
|
||||||
|
* @var Parent Object
|
||||||
|
*/
|
||||||
|
private $parentClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the class and Bus
|
||||||
|
* @access public
|
||||||
|
* @param Core Object, gets referenced
|
||||||
|
*/
|
||||||
|
public function __construct(&$core) {
|
||||||
|
parent::__construct($core);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the type of this model. Eg, use techfuze/databasemodel and Databasemodel to get a SQL connected model
|
||||||
|
* @access protected
|
||||||
|
* @param String Module_name, the name of the module where the model can be found
|
||||||
|
* @param String class name, the class to load and connect to
|
||||||
|
*/
|
||||||
|
protected function setType($module_name, $class_name) {
|
||||||
|
$this->core->loadMod($module_name);
|
||||||
|
$this->parentClass = new $class_name($this->core);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a value from the model class
|
||||||
|
* @access public
|
||||||
|
* @param Any key
|
||||||
|
* @return Any value from the model class
|
||||||
|
*/
|
||||||
|
public function __get($name) {
|
||||||
|
return $this->parentClass->$name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value in the model class
|
||||||
|
* @access public
|
||||||
|
* @param Any key
|
||||||
|
* @param Any value
|
||||||
|
*/
|
||||||
|
public function __set($name, $value) {
|
||||||
|
$this->parentClass->$name = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls a function in the model class
|
||||||
|
* @access public
|
||||||
|
* @param String function_name
|
||||||
|
* @param Array values
|
||||||
|
* @return Function return
|
||||||
|
*/
|
||||||
|
public function __call($name, $params) {
|
||||||
|
return call_user_func_array(array($this->parentClass, $name), $params);
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,7 @@ class Core {
|
|||||||
require_once(FUZESYSPATH . "/class.abstract.bus.php");
|
require_once(FUZESYSPATH . "/class.abstract.bus.php");
|
||||||
require_once(FUZESYSPATH . "/class.abstract.event.php");
|
require_once(FUZESYSPATH . "/class.abstract.event.php");
|
||||||
require_once(FUZESYSPATH . "/class.abstract.module.php");
|
require_once(FUZESYSPATH . "/class.abstract.module.php");
|
||||||
|
require_once(FUZESYSPATH . "/class.abstract.model.php");
|
||||||
require_once(FUZESYSPATH . "/class.abstract.eventPriority.php");
|
require_once(FUZESYSPATH . "/class.abstract.eventPriority.php");
|
||||||
|
|
||||||
// Load the core classes
|
// Load the core classes
|
||||||
@ -151,7 +152,15 @@ class Core {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create class object
|
// If it is an abstract module, return an StdClass for the memory address
|
||||||
|
if (isset($cfg->abstract)) {
|
||||||
|
if ($cfg->abstract) {
|
||||||
|
$c = new stdClass();
|
||||||
|
return array($c, $cfg->module_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise create the class object
|
||||||
$CLASS = new $class_name($this);
|
$CLASS = new $class_name($this);
|
||||||
if (method_exists($CLASS, 'setModulePath')) {
|
if (method_exists($CLASS, 'setModulePath')) {
|
||||||
$CLASS->setModulePath($cfg->directory);
|
$CLASS->setModulePath($cfg->directory);
|
||||||
|
@ -7,42 +7,36 @@ class Models extends Bus{
|
|||||||
|
|
||||||
private $models_array = array();
|
private $models_array = array();
|
||||||
private $model_types = array();
|
private $model_types = array();
|
||||||
|
private $models_loaded = false;
|
||||||
|
|
||||||
public function __construct(&$core){
|
public function __construct(&$core){
|
||||||
parent::__construct($core);
|
parent::__construct($core);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadModel($name, $directory = null){
|
public function loadModel($name, $directory = null){
|
||||||
$this->core->loadMod('model');
|
|
||||||
if($directory === null){
|
if($directory === null){
|
||||||
$directory = FUZEPATH . "/Application/Models";
|
$directory = FUZEPATH . "/Application/Models";
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $directory.'/model.'.$name.'.php';
|
$file = $directory.'/model.'.$name.'.php';
|
||||||
if (isset($this->model_types[$name])) {
|
if (isset($this->model_types[$name])) {
|
||||||
$this->logger->logInfo('MODEL LOAD: '.get_class($this->model_types[$name]), get_class($this->model_types[$name]), __FILE__, __LINE__);
|
$this->logger->logInfo('Loading Model: '.get_class($this->model_types[$name]), get_class($this->model_types[$name]));
|
||||||
$this->models_array[$name] = $this->model_types[$name];
|
$this->models_array[$name] = $this->model_types[$name];
|
||||||
} elseif (file_exists($file)){
|
} elseif (file_exists($file)){
|
||||||
require_once($file);
|
require_once($file);
|
||||||
$model = ucfirst($name);
|
$model = ucfirst($name);
|
||||||
$this->logger->logInfo('MODEL LOAD: '.$model, $model, __FILE__, __LINE__);
|
$this->logger->logInfo('Loading Model: '.$model, $model);
|
||||||
$this->models_array[$name] = new $model($this->core);
|
$this->models_array[$name] = new $model($this->core);
|
||||||
} else{
|
} else{
|
||||||
$this->logger->logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'FuzeWorks->Model');
|
$this->logger->logWarning('The requested model: \''.$name.'\' could not be found. Loading empty model', 'Models');
|
||||||
require_once(FUZEPATH . "/Core/System/Models/fz-model-interpret.php");
|
require_once(FUZEPATH . "/Core/System/Models/model.interpret.php");
|
||||||
$this->logger->logInfo('MODEL LOAD: interprated model', 'FuzeWorks->Model', __FILE__, __LINE__);
|
$this->logger->logInfo('Loading Model: interprated databasemodel', 'Models');
|
||||||
$model = new Interpret($this->core);
|
$model = new Interpret($this->core);
|
||||||
$model->table($name);
|
$model->table($name);
|
||||||
$this->models_array[$name] = $model;
|
$this->models_array[$name] = $model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register($NAME, $MODEL_OBJECT) {
|
|
||||||
if (!isset($this->model_types[strtolower($NAME)])) {
|
|
||||||
$this->model_types[strtolower($NAME)] = $MODEL_OBJECT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __get($name){
|
public function __get($name){
|
||||||
if (isset($this->models_array[strtolower($name)])) {
|
if (isset($this->models_array[strtolower($name)])) {
|
||||||
return $this->models_array[strtolower($name)];
|
return $this->models_array[strtolower($name)];
|
||||||
@ -51,10 +45,6 @@ class Models extends Bus{
|
|||||||
return $this->models_array[strtolower($name)];
|
return $this->models_array[strtolower($name)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEmptyModel() {
|
|
||||||
return new \FuzeWorks\V100\DatabaseModel($this->core);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user