Skip to content
This repository
Browse code

API CHANGE Renamed setModel for DataModel instances to setDataModel for

semantics, and also to allow a field name called "Model"
  • Loading branch information...
commit 0882741f549ecd526c2a432b1c68918c1701ccd5 1 parent befc806
Sean Harvey authored May 01, 2012
2  api/VersionedRestfulServer.php
@@ -12,7 +12,7 @@ class VersionedRestfulServer extends Controller {
12 12
 	);
13 13
 	
14 14
 	function handleRequest(SS_HTTPRequest $request, DataModel $model) {
15  
-		$this->setModel($model);
  15
+		$this->setDataModel($model);
16 16
 		Versioned::reading_stage('Live');
17 17
 		$restfulserver = new RestfulServer();
18 18
 		$response = $restfulserver->handleRequest($request, $model);
2  control/Controller.php
@@ -129,7 +129,7 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
129 129
 		$this->urlParams = $request->allParams();
130 130
 		$this->request = $request;
131 131
 		$this->response = new SS_HTTPResponse();
132  
-		$this->setModel($model);
  132
+		$this->setDataModel($model);
133 133
 		
134 134
 		$this->extend('onBeforeInit');
135 135
 
6  control/RequestHandler.php
@@ -91,7 +91,7 @@ public function __construct() {
91 91
 		// Check necessary to avoid class conflicts before manifest is rebuilt
92 92
 		if(class_exists('NullHTTPRequest')) $this->request = new NullHTTPRequest();
93 93
 		
94  
-		// This will prevent bugs if setModel() isn't called.
  94
+		// This will prevent bugs if setDataModel() isn't called.
95 95
 		$this->model = DataModel::inst();
96 96
 		
97 97
 		parent::__construct();
@@ -100,7 +100,7 @@ public function __construct() {
100 100
 	/**
101 101
 	 * Set the DataModel for this request.
102 102
 	 */
103  
-	public function setModel($model) {
  103
+	public function setDataModel($model) {
104 104
 		$this->model = $model;
105 105
 	}
106 106
 	
@@ -134,7 +134,7 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
134 134
 		}
135 135
 	
136 136
 		$this->request = $request;
137  
-		$this->setModel($model);
  137
+		$this->setDataModel($model);
138 138
 		
139 139
 		// We stop after RequestHandler; in other words, at ViewableData
140 140
 		while($handlerClass && $handlerClass != 'ViewableData') {
2  forms/gridfield/GridField.php
@@ -586,7 +586,7 @@ function handleRequest(SS_HTTPRequest $request, DataModel $model) {
586 586
 		}
587 587
 
588 588
 		$this->request = $request;
589  
-		$this->setModel($model);
  589
+		$this->setDataModel($model);
590 590
 
591 591
 		$fieldData = $this->request->requestVar($this->getName());
592 592
 		if($fieldData && $fieldData['GridState']) $this->getState(false)->setValue($fieldData['GridState']);
2  model/DataList.php
@@ -46,7 +46,7 @@ public function __construct($dataClass) {
46 46
 	 *
47 47
 	 * @param DataModel $model 
48 48
 	 */
49  
-	public function setModel(DataModel $model) {
  49
+	public function setDataModel(DataModel $model) {
50 50
 		$this->model = $model;
51 51
 	}
52 52
 	
4  model/DataModel.php
@@ -35,14 +35,14 @@ function __get($class) {
35 35
 			return clone $this->customDataLists[$class];
36 36
 		} else {
37 37
 			$list = DataList::create($class);
38  
-			$list->setModel($this);
  38
+			$list->setDataModel($this);
39 39
 			return $list;
40 40
 		}
41 41
 	}
42 42
 	
43 43
 	function __set($class, $item) {
44 44
 		$item = clone $item;
45  
-		$item->setModel($this);
  45
+		$item->setDataModel($this);
46 46
 		$this->customDataLists[$class] = $item;
47 47
 	}
48 48
 	
16  model/DataObject.php
@@ -399,7 +399,7 @@ function __construct($record = null, $isSingleton = false, $model = null) {
399 399
 	/**
400 400
 	 * Set the DataModel
401 401
 	 */
402  
-	function setModel(DataModel $model) {
  402
+	function setDataModel(DataModel $model) {
403 403
 		$this->model = $model;
404 404
 	}
405 405
 
@@ -1328,7 +1328,7 @@ public function getComponents($componentName, $filter = "", $sort = "", $join =
1328 1328
 		$joinField = $this->getRemoteJoinField($componentName, 'has_many');
1329 1329
 		
1330 1330
 		$result = new HasManyList($componentClass, $joinField);
1331  
-		if($this->model) $result->setModel($this->model);
  1331
+		if($this->model) $result->setDataModel($this->model);
1332 1332
 		$result->setForeignID($this->ID);
1333 1333
 
1334 1334
 		$result = $result->where($filter)->limit($limit)->sort($sort);
@@ -1449,7 +1449,7 @@ public function getManyManyComponents($componentName, $filter = "", $sort = "",
1449 1449
 		
1450 1450
 		$result = new ManyManyList($componentClass, $table, $componentField, $parentField,
1451 1451
 			$this->many_many_extraFields($componentName));
1452  
-		if($this->model) $result->setModel($this->model);
  1452
+		if($this->model) $result->setDataModel($this->model);
1453 1453
 
1454 1454
 		// If this is called on a singleton, then we return an 'orphaned relation' that can have the
1455 1455
 		// foreignID set elsewhere.
@@ -2626,7 +2626,7 @@ public static function get($callerClass = null, $filter = "", $sort = "", $join
2626 2626
 			}
2627 2627
 			
2628 2628
 			$result = DataList::create(get_called_class());
2629  
-			$result->setModel(DataModel::inst());
  2629
+			$result->setDataModel(DataModel::inst());
2630 2630
 			return $result;
2631 2631
 		}
2632 2632
 		
@@ -2641,7 +2641,7 @@ public static function get($callerClass = null, $filter = "", $sort = "", $join
2641 2641
 			$result->limit($limit);
2642 2642
 		}
2643 2643
 		if($join) $result = $result->join($join);
2644  
-		$result->setModel(DataModel::inst());
  2644
+		$result->setDataModel(DataModel::inst());
2645 2645
 		return $result;
2646 2646
 	}
2647 2647
 	
@@ -2653,10 +2653,10 @@ public function Aggregate($class = null) {
2653 2653
 
2654 2654
 	    if($class) {
2655 2655
 			$list = new DataList($class);
2656  
-			$list->setModel(DataModel::inst());
  2656
+			$list->setDataModel(DataModel::inst());
2657 2657
 		} else if(isset($this)) {
2658 2658
 			$list = new DataList(get_class($this));
2659  
-			$list->setModel($this->model);
  2659
+			$list->setDataModel($this->model);
2660 2660
 		}
2661 2661
 	    else throw new InvalidArgumentException("DataObject::aggregate() must be called as an instance method or passed a classname");
2662 2662
 		return $list;
@@ -2752,7 +2752,7 @@ public static function get_one($callerClass, $filter = "", $cache = true, $order
2752 2752
 		}
2753 2753
 		if(!$cache || !isset(DataObject::$_cache_get_one[$callerClass][$cacheKey])) {
2754 2754
 			$dl = DataList::create($callerClass)->where($filter)->sort($orderby);
2755  
-			$dl->setModel(DataModel::inst());
  2755
+			$dl->setDataModel(DataModel::inst());
2756 2756
 			$item = $dl->First();
2757 2757
 
2758 2758
 			if($cache) {
2  security/Security.php
@@ -341,7 +341,7 @@ public function login() {
341 341
 			$tmpPage->ID = -1 * rand(1,10000000);
342 342
 
343 343
 			$controller = new Page_Controller($tmpPage);
344  
-			$controller->setModel($this->model);
  344
+			$controller->setDataModel($this->model);
345 345
 			$controller->init();
346 346
 			//Controller::$currentController = $controller;
347 347
 		} else {
10  tests/model/DataObjectTest.php
@@ -1222,17 +1222,15 @@ class DataObjectTest_CEO extends DataObjectTest_Staff {
1222 1222
 }
1223 1223
 
1224 1224
 class DataObjectTest_TeamComment extends DataObject {
1225  
-	
1226 1225
 	static $db = array(
1227  
-		'Name' => "Varchar",
1228  
-		"Comment" => "Text"
  1226
+		'Name' => 'Varchar',
  1227
+		'Comment' => 'Text'
1229 1228
 	);
1230  
-	
  1229
+
1231 1230
 	static $has_one = array(
1232  
-		'Team' 	=> 'DataObjectTest_Team'
  1231
+		'Team' => 'DataObjectTest_Team'
1233 1232
 	);
1234 1233
 }
1235 1234
 
1236 1235
 DataObject::add_extension('DataObjectTest_Team', 'DataObjectTest_Team_Extension');
1237 1236
 
1238  
-

0 notes on commit 0882741

Please sign in to comment.
Something went wrong with that request. Please try again.