Blame view

framework/model/DataModel.php 1.28 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  <?php
  
  /**
   * Representation of a DataModel - a collection of DataLists for each different 
   * data type.
   * 
   * Usage:
   * <code>
   * $model = new DataModel;
   * $mainMenu = $model->SiteTree->where('"ParentID" = 0 AND "ShowInMenus" = 1');
   * </code>
   *
   * @package framework
   * @subpackage model
   */
  class DataModel {
  
  	/**
  	 * @var DataModel
  	 */
  	protected static $inst;
  	
  	/**
  	 * @var array $customDataLists
  	 */
  	protected $customDataLists = array();
  
  	/**
  	 * Get the global DataModel.
  	 *
  	 * @return DataModel
  	 */
  	public static function inst() {
  		if(!self::$inst) {
  			self::$inst = new self;
  		}
  		
  		return self::$inst;
  	}
  	
  	/**
  	 * Set the global DataModel, used when data is requested from static 
  	 * methods.
  	 *
  	 * @return DataModel
  	 */
  	public static function set_inst(DataModel $inst) {
  		self::$inst = $inst;
  	}
  	
  	/**
  	 * @param string
  	 *
  	 * @return DataList
  	 */
  	public function __get($class) {
  		if(isset($this->customDataLists[$class])) {
  			return clone $this->customDataLists[$class];
  		} else {
  			$list = DataList::create($class);
  			$list->setDataModel($this);
  
  			return $list;
  		}
  	}
  	
  	/**
  	 * @param string
  	 * @param DataList
  	 */
  	public function __set($class, $item) {
  		$item = clone $item;
  		$item->setDataModel($this);
  		$this->customDataLists[$class] = $item;
  	}
  	
  }