Permalink
Browse files

MINOR Use shorthand {class}::get() syntax instead of DataList::create()

in core code.
  • Loading branch information...
1 parent 71256ea commit c3eabffcb97927f57d5b5dba7c282d8967eb4437 @halkyon halkyon committed May 28, 2012
@@ -70,7 +70,7 @@ public function getEditForm($id = null, $fields = null) {
$memberList = GridField::create(
'Members',
false,
- DataList::create('Member'),
+ Member::get(),
$memberListConfig = GridFieldConfig_RecordEditor::create()
->addComponent(new GridFieldExportButton())
)->addExtraClass("members_grid");
@@ -79,7 +79,7 @@ public function getEditForm($id = null, $fields = null) {
$groupList = GridField::create(
'Groups',
false,
- DataList::create('Group'),
+ Group::get(),
GridFieldConfig_RecordEditor::create()
);
$columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
@@ -131,7 +131,7 @@ public function getEditForm($id = null, $fields = null) {
if(Permission::check('APPLY_ROLES')) {
$rolesField = GridField::create('Roles',
false,
- DataList::create('PermissionRole'),
+ PermissionRole::get(),
GridFieldConfig_RecordEditor::create()
);
View
@@ -87,23 +87,22 @@ public function config() {
* or calling on Object and passing the class name as the first parameter. The following
* are equivalent:
* $list = DataList::create('SiteTree');
- * $list = DataList::create('SiteTree');
+ * $list = SiteTree::get();
*
* @param string $class the class name
* @param mixed $arguments,... arguments to pass to the constructor
* @return Object
*/
public static function create() {
- $args = func_get_args();
+ $args = func_get_args();
// Class to create should be the calling class if not Object,
// otherwise the first parameter
$class = get_called_class();
- if($class == 'Object')
- $class = array_shift($args);
-
+ if($class == 'Object') $class = array_shift($args);
+
$class = self::getCustomClass($class);
-
+
return Injector::inst()->createWithArgs($class, $args);
}
@@ -13,7 +13,7 @@
*
* public function getCMSFields() {
* $fields = parent::getCMSFields();
- * $field = new DropdownField('GalleryID', 'Gallery', DataList::create('Gallery')->map('ID', 'Title'));
+ * $field = new DropdownField('GalleryID', 'Gallery', Gallery::get()->map('ID', 'Title'));
* $field->setEmptyString('(Select one)');
* $fields->addFieldToTab('Root.Content', $field, 'Content');
* </code>
@@ -498,7 +498,7 @@ public function viewfile($request) {
} else {
$url = Director::makeRelative($request->getVar('FileURL'));
$url = preg_replace('/_resampled\/[^-]+-/', '', $url);
- $file = DataList::create('File')->filter('Filename', $url)->first();
+ $file = File::get()->filter('Filename', $url)->first();
if(!$file) $file = new File(array(
'Title' => basename($url),
'Filename' => $url
@@ -720,7 +720,7 @@ protected function getFiles($parentID = null) {
$wheres = array();
foreach($exts as $ext) $wheres[] = '"Filename" LIKE \'%.' . $ext . '\'';
- $files = DataList::create('File')->where(implode(' OR ', $wheres));
+ $files = File::get()->where(implode(' OR ', $wheres));
// Limit by folder (if required)
if($parentID) $files->filter('ParentID', $parentID);
@@ -528,7 +528,7 @@ public function attach($request) {
$return = array();
- $files = DataList::create('File')->byIDs($request->postVar('ids'));
+ $files = File::get()->byIDs($request->postVar('ids'));
foreach($files as $file) {
$this->attachFile($file);
$file = $this->customiseFile($file);
View
@@ -60,7 +60,7 @@ class Versioned extends DataExtension {
"Version" => "Int",
"WasPublished" => "Boolean",
"AuthorID" => "Int",
- "PublisherID" => "Int"
+ "PublisherID" => "Int"
);
/**
@@ -138,8 +138,8 @@ function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
switch($dataQuery->getQueryParam('Versioned.mode')) {
// Noop
case '':
- break;
-
+ break;
+
// Reading a specific data from the archive
case 'archive':
$date = $dataQuery->getQueryParam('Versioned.date');
@@ -186,31 +186,30 @@ function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
// Return all version instances
case 'all_versions':
case 'latest_versions':
- foreach($query->getFrom() as $alias => $join) {
- if($alias != $baseTable) {
- $query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
- }
- $query->renameTable($alias, $alias . '_versions');
- }
+ foreach($query->getFrom() as $alias => $join) {
+ if($alias != $baseTable) {
+ $query->setJoinFilter($alias, "\"$alias\".\"RecordID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$alias\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
+ }
+ $query->renameTable($alias, $alias . '_versions');
+ }
- // Add all <basetable>_versions columns
- foreach(self::$db_for_versions_table as $name => $type) {
- $query->selectField(sprintf('"%s_versions"."%s"', $baseTable, $name), $name);
- }
- $query->selectField(sprintf('"%s_versions"."%s"', $baseTable, 'RecordID'), "ID");
-
- // latest_version has one more step
- // Return latest version instances, regardless of whether they are on a particular stage
- // This provides "show all, including deleted" functonality
- if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
- $archiveTable = self::requireArchiveTempTable($baseTable);
- $query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
- }
+ // Add all <basetable>_versions columns
+ foreach(self::$db_for_versions_table as $name => $type) {
+ $query->selectField(sprintf('"%s_versions"."%s"', $baseTable, $name), $name);
+ }
+ $query->selectField(sprintf('"%s_versions"."%s"', $baseTable, 'RecordID'), "ID");
+
+ // latest_version has one more step
+ // Return latest version instances, regardless of whether they are on a particular stage
+ // This provides "show all, including deleted" functonality
+ if($dataQuery->getQueryParam('Versioned.mode') == 'latest_versions') {
+ $archiveTable = self::requireArchiveTempTable($baseTable);
+ $query->addInnerJoin($archiveTable, "\"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\" AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"");
+ }
- break;
-
- default:
- throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
+ break;
+ default:
+ throw new InvalidArgumentException("Bad value for query parameter Versioned.mode: " . $dataQuery->getQueryParam('Versioned.mode'));
}
}
@@ -686,7 +685,7 @@ function stagesDiffer($stage1, $stage2) {
if(!is_numeric($this->owner->ID)) {
return true;
}
-
+
// We test for equality - if one of the versions doesn't exist, this will be false
//TODO: DB Abstraction: if statement here:
$stagesAreEqual = DB::query("SELECT CASE WHEN \"$table1\".\"Version\"=\"$table2\".\"Version\" THEN 1 ELSE 0 END FROM \"$table1\" INNER JOIN \"$table2\" ON \"$table1\".\"ID\" = \"$table2\".\"ID\" AND \"$table1\".\"ID\" = {$this->owner->ID}")->value();
@@ -875,10 +874,10 @@ static function reading_archived_date($date) {
* @return DataObject
*/
static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') {
- // TODO: No identity cache operating
- $items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
- return $items->First();
- }
+ // TODO: No identity cache operating
+ $items = self::get_by_stage($class, $stage, $filter, $sort, null, 1);
+ return $items->First();
+ }
/**
* Gets the current version number of a specific record.
@@ -992,9 +991,9 @@ function doRollbackTo($version) {
*/
static function get_latest_version($class, $id) {
$baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
- $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
- return $list->First();
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
+ $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
+ return $list->First();
}
/**
@@ -1020,9 +1019,9 @@ function isLatestVersion() {
* In particular, this will query deleted records as well as active ones.
*/
static function get_including_deleted($class, $filter = "", $sort = "") {
- $list = DataList::create($class)->where($filter)->sort($sort);
- $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
- return $list;
+ $list = DataList::create($class)->where($filter)->sort($sort);
+ $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions");
+ return $list;
}
/**
@@ -1031,20 +1030,20 @@ static function get_including_deleted($class, $filter = "", $sort = "") {
*/
static function get_version($class, $id, $version) {
$baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
- $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
- return $list->First();
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version);
+ $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
+ return $list->First();
}
/**
* Return a list of all versions for a given id
* @return DataList
*/
static function get_all_versions($class, $id) {
- $baseClass = ClassInfo::baseDataClass($class);
- $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
- $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
- return $list;
+ $baseClass = ClassInfo::baseDataClass($class);
+ $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id");
+ $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions');
+ return $list;
}
function contentcontrollerInit($controller) {
View
@@ -68,7 +68,7 @@ public function getCMSFields() {
new TextField("Title", $this->fieldLabel('Title')),
$parentidfield = DropdownField::create( 'ParentID',
$this->fieldLabel('Parent'),
- DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
+ Group::get()->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
)->setEmptyString(' ')
),
@@ -240,7 +240,7 @@ public function Members($filter = "", $sort = "", $join = "", $limit = "") {
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific ones.
$result->dataQuery()->removeFilterOn('Group_Members');
// Now set all children groups as a new foreign key
- $groups = DataList::create("Group")->byIDs($this->collateFamilyIDs());
+ $groups = Group::get()->byIDs($this->collateFamilyIDs());
$result = $result->forForeignID($groups->column('ID'))->where($filter)->sort($sort)->limit($limit);
if($join) $result = $result->join($join);
@@ -257,7 +257,7 @@ public function DirectMembers() {
public static function map($filter = "", $sort = "", $blank="") {
Deprecation::notice('3.0', 'Use DataList::("Group")->map()');
- $list = DataList::create("Group")->where($filter)->sort($sort);
+ $list = Group::get()->where($filter)->sort($sort);
$map = $list->map();
if($blank) $map->unshift(0, $blank);
@@ -284,7 +284,7 @@ public function collateFamilyIDs() {
// Get the children of *all* the groups identified in the previous chunk.
// This minimises the number of SQL queries necessary
- $chunkToAdd = DataList::create('Group')->where("\"ParentID\" IN ($idList)")->column('ID');
+ $chunkToAdd = Group::get()->where("\"ParentID\" IN ($idList)")->column('ID');
}
return $familyIDs;
View
@@ -963,7 +963,7 @@ public function DirectGroups() {
public static function map($filter = "", $sort = "", $blank="") {
Deprecation::notice('3.0', 'Use DataList::("Member")->map()');
- $list = DataList::create("Member")->where($filter)->sort($sort);
+ $list = Member::get()->where($filter)->sort($sort);
$map = $list->map();
if($blank) $map->unshift(0, $blank);
@@ -1062,7 +1062,7 @@ public static function mapInCMSGroups($groups = null) {
? "\"GroupID\" IN (" . implode( ',', $groupIDList ) . ")"
: "";
- return DataList::create("Member")->where($filterClause)->sort("\"Surname\", \"FirstName\"")
+ return Member::get()->where($filterClause)->sort("\"Surname\", \"FirstName\"")
->innerJoin("Group_Members", "\"MemberID\"=\"Member\".\"ID\"")
->innerJoin("Group", "\"Group\".\"ID\"=\"GroupID\"")
->map();
@@ -1148,7 +1148,7 @@ public function getCMSFields() {
$fields->removeByName('Groups');
if(Permission::check('EDIT_PERMISSIONS')) {
- $groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
+ $groupsMap = Group::get()->map('ID', 'Breadcrumbs')->toArray();
asort($groupsMap);
$fields->addFieldToTab('Root.Main',
ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
@@ -69,7 +69,7 @@ public function testGridFieldSetCustomConfig() {
* @covers GridField::setModelClass
*/
public function testGridFieldModelClass() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$this->assertEquals('Member', $obj->getModelClass(), 'Should return Member');
$obj->setModelClass('DataModel');
$this->assertEquals('DataModel', $obj->getModelClass(), 'Should return Member');
@@ -89,7 +89,7 @@ public function testGridFieldModelClassThrowsException() {
* @covers GridField::getList
*/
public function testSetAndGetList() {
- $list = DataList::create('Member');
+ $list = Member::get();
$arrayList = ArrayList::create(array(1,2,3));
$obj = new GridField('testfield', 'testfield', $list);
$this->assertEquals($list, $obj->getList());
@@ -110,7 +110,7 @@ public function testGetState() {
* @covers GridField::getColumns
*/
public function testGetColumns(){
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = array (
0 => 'FirstName',
1 => 'Surname',
@@ -123,7 +123,7 @@ public function testGetColumns(){
* @covers GridField::getColumnCount
*/
public function testGetColumnCount() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$this->assertEquals(3, $obj->getColumnCount());
}
@@ -5,7 +5,7 @@ class GridFieldDataColumnsTest extends SapphireTest {
* @covers GridFieldDataColumns::getDisplayFields
*/
public function testGridFieldGetDefaultDisplayFields() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = singleton('Member')->summaryFields();
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$this->assertEquals($expected, $columns->getDisplayFields($obj));
@@ -16,7 +16,7 @@ public function testGridFieldGetDefaultDisplayFields() {
* @covers GridFieldDataColumns::getDisplayFields
*/
public function testGridFieldCustomDisplayFields() {
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$expected = array('Email' => 'Email');
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields($expected);
@@ -29,7 +29,7 @@ public function testGridFieldCustomDisplayFields() {
*/
public function testGridFieldDisplayFieldsWithBadArguments() {
$this->setExpectedException('InvalidArgumentException');
- $obj = new GridField('testfield', 'testfield', DataList::create('Member'));
+ $obj = new GridField('testfield', 'testfield', Member::get());
$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(new stdClass());
}
Oops, something went wrong. Retry.

0 comments on commit c3eabff

Please sign in to comment.