API CHANGE Renamed setModel for DataModel instances to setDataModel for

semantics, and also to allow a field name called "Model"
This commit is contained in:
Sean Harvey 2012-05-01 14:43:52 +12:00
parent befc80676d
commit 0882741f54
9 changed files with 22 additions and 24 deletions

View File

@ -12,7 +12,7 @@ class VersionedRestfulServer extends Controller {
); );
function handleRequest(SS_HTTPRequest $request, DataModel $model) { function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$this->setModel($model); $this->setDataModel($model);
Versioned::reading_stage('Live'); Versioned::reading_stage('Live');
$restfulserver = new RestfulServer(); $restfulserver = new RestfulServer();
$response = $restfulserver->handleRequest($request, $model); $response = $restfulserver->handleRequest($request, $model);

View File

@ -129,7 +129,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
$this->urlParams = $request->allParams(); $this->urlParams = $request->allParams();
$this->request = $request; $this->request = $request;
$this->response = new SS_HTTPResponse(); $this->response = new SS_HTTPResponse();
$this->setModel($model); $this->setDataModel($model);
$this->extend('onBeforeInit'); $this->extend('onBeforeInit');

View File

@ -91,7 +91,7 @@ class RequestHandler extends ViewableData {
// Check necessary to avoid class conflicts before manifest is rebuilt // Check necessary to avoid class conflicts before manifest is rebuilt
if(class_exists('NullHTTPRequest')) $this->request = new NullHTTPRequest(); if(class_exists('NullHTTPRequest')) $this->request = new NullHTTPRequest();
// This will prevent bugs if setModel() isn't called. // This will prevent bugs if setDataModel() isn't called.
$this->model = DataModel::inst(); $this->model = DataModel::inst();
parent::__construct(); parent::__construct();
@ -100,7 +100,7 @@ class RequestHandler extends ViewableData {
/** /**
* Set the DataModel for this request. * Set the DataModel for this request.
*/ */
public function setModel($model) { public function setDataModel($model) {
$this->model = $model; $this->model = $model;
} }
@ -134,7 +134,7 @@ class RequestHandler extends ViewableData {
} }
$this->request = $request; $this->request = $request;
$this->setModel($model); $this->setDataModel($model);
// We stop after RequestHandler; in other words, at ViewableData // We stop after RequestHandler; in other words, at ViewableData
while($handlerClass && $handlerClass != 'ViewableData') { while($handlerClass && $handlerClass != 'ViewableData') {

View File

@ -586,7 +586,7 @@ class GridField extends FormField {
} }
$this->request = $request; $this->request = $request;
$this->setModel($model); $this->setDataModel($model);
$fieldData = $this->request->requestVar($this->getName()); $fieldData = $this->request->requestVar($this->getName());
if($fieldData && $fieldData['GridState']) $this->getState(false)->setValue($fieldData['GridState']); if($fieldData && $fieldData['GridState']) $this->getState(false)->setValue($fieldData['GridState']);

View File

@ -46,7 +46,7 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
* *
* @param DataModel $model * @param DataModel $model
*/ */
public function setModel(DataModel $model) { public function setDataModel(DataModel $model) {
$this->model = $model; $this->model = $model;
} }

View File

@ -35,14 +35,14 @@ class DataModel {
return clone $this->customDataLists[$class]; return clone $this->customDataLists[$class];
} else { } else {
$list = DataList::create($class); $list = DataList::create($class);
$list->setModel($this); $list->setDataModel($this);
return $list; return $list;
} }
} }
function __set($class, $item) { function __set($class, $item) {
$item = clone $item; $item = clone $item;
$item->setModel($this); $item->setDataModel($this);
$this->customDataLists[$class] = $item; $this->customDataLists[$class] = $item;
} }

View File

@ -399,7 +399,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
/** /**
* Set the DataModel * Set the DataModel
*/ */
function setModel(DataModel $model) { function setDataModel(DataModel $model) {
$this->model = $model; $this->model = $model;
} }
@ -1328,7 +1328,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$joinField = $this->getRemoteJoinField($componentName, 'has_many'); $joinField = $this->getRemoteJoinField($componentName, 'has_many');
$result = new HasManyList($componentClass, $joinField); $result = new HasManyList($componentClass, $joinField);
if($this->model) $result->setModel($this->model); if($this->model) $result->setDataModel($this->model);
$result->setForeignID($this->ID); $result->setForeignID($this->ID);
$result = $result->where($filter)->limit($limit)->sort($sort); $result = $result->where($filter)->limit($limit)->sort($sort);
@ -1449,7 +1449,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$result = new ManyManyList($componentClass, $table, $componentField, $parentField, $result = new ManyManyList($componentClass, $table, $componentField, $parentField,
$this->many_many_extraFields($componentName)); $this->many_many_extraFields($componentName));
if($this->model) $result->setModel($this->model); if($this->model) $result->setDataModel($this->model);
// If this is called on a singleton, then we return an 'orphaned relation' that can have the // If this is called on a singleton, then we return an 'orphaned relation' that can have the
// foreignID set elsewhere. // foreignID set elsewhere.
@ -2626,7 +2626,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
} }
$result = DataList::create(get_called_class()); $result = DataList::create(get_called_class());
$result->setModel(DataModel::inst()); $result->setDataModel(DataModel::inst());
return $result; return $result;
} }
@ -2641,7 +2641,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$result->limit($limit); $result->limit($limit);
} }
if($join) $result = $result->join($join); if($join) $result = $result->join($join);
$result->setModel(DataModel::inst()); $result->setDataModel(DataModel::inst());
return $result; return $result;
} }
@ -2653,10 +2653,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if($class) { if($class) {
$list = new DataList($class); $list = new DataList($class);
$list->setModel(DataModel::inst()); $list->setDataModel(DataModel::inst());
} else if(isset($this)) { } else if(isset($this)) {
$list = new DataList(get_class($this)); $list = new DataList(get_class($this));
$list->setModel($this->model); $list->setDataModel($this->model);
} }
else throw new InvalidArgumentException("DataObject::aggregate() must be called as an instance method or passed a classname"); else throw new InvalidArgumentException("DataObject::aggregate() must be called as an instance method or passed a classname");
return $list; return $list;
@ -2752,7 +2752,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
} }
if(!$cache || !isset(DataObject::$_cache_get_one[$callerClass][$cacheKey])) { if(!$cache || !isset(DataObject::$_cache_get_one[$callerClass][$cacheKey])) {
$dl = DataList::create($callerClass)->where($filter)->sort($orderby); $dl = DataList::create($callerClass)->where($filter)->sort($orderby);
$dl->setModel(DataModel::inst()); $dl->setDataModel(DataModel::inst());
$item = $dl->First(); $item = $dl->First();
if($cache) { if($cache) {

View File

@ -341,7 +341,7 @@ class Security extends Controller {
$tmpPage->ID = -1 * rand(1,10000000); $tmpPage->ID = -1 * rand(1,10000000);
$controller = new Page_Controller($tmpPage); $controller = new Page_Controller($tmpPage);
$controller->setModel($this->model); $controller->setDataModel($this->model);
$controller->init(); $controller->init();
//Controller::$currentController = $controller; //Controller::$currentController = $controller;
} else { } else {

View File

@ -1222,17 +1222,15 @@ class DataObjectTest_CEO extends DataObjectTest_Staff {
} }
class DataObjectTest_TeamComment extends DataObject { class DataObjectTest_TeamComment extends DataObject {
static $db = array( static $db = array(
'Name' => "Varchar", 'Name' => 'Varchar',
"Comment" => "Text" 'Comment' => 'Text'
); );
static $has_one = array( static $has_one = array(
'Team' => 'DataObjectTest_Team' 'Team' => 'DataObjectTest_Team'
); );
} }
DataObject::add_extension('DataObjectTest_Team', 'DataObjectTest_Team_Extension'); DataObject::add_extension('DataObjectTest_Team', 'DataObjectTest_Team_Extension');