2011-05-01 07:33:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of a DataModel - a collection of DataLists for each different data type.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* $model = new DataModel;
|
|
|
|
* $mainMenu = $model->SiteTree->where('"ParentID" = 0 AND "ShowInMenus" = 1');
|
|
|
|
*/
|
|
|
|
class DataModel {
|
|
|
|
protected static $inst;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the global DataModel.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function inst() {
|
2011-05-01 07:33:02 +02:00
|
|
|
if(!self::$inst) self::$inst = new self;
|
|
|
|
return self::$inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the global DataModel, used when data is requested from static methods.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function set_inst(DataModel $inst) {
|
2011-05-01 07:33:02 +02:00
|
|
|
self::$inst = $inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
protected $customDataLists = array();
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __get($class) {
|
2011-05-01 07:33:02 +02:00
|
|
|
if(isset($this->customDataLists[$class])) {
|
|
|
|
return clone $this->customDataLists[$class];
|
|
|
|
} else {
|
|
|
|
$list = DataList::create($class);
|
2012-05-01 04:43:52 +02:00
|
|
|
$list->setDataModel($this);
|
2011-05-01 07:33:02 +02:00
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __set($class, $item) {
|
2011-05-01 07:33:02 +02:00
|
|
|
$item = clone $item;
|
2012-05-01 04:43:52 +02:00
|
|
|
$item->setDataModel($this);
|
2011-05-01 07:33:02 +02:00
|
|
|
$this->customDataLists[$class] = $item;
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|