MINOR: Moved from use of deprecated SQLMap to SS_Map.

This commit is contained in:
Sam Minnee 2011-10-29 17:08:47 +13:00
parent c8ce6f9f55
commit 22e5617ee2
9 changed files with 31 additions and 32 deletions

View File

@ -17,13 +17,15 @@ class LookupField extends DropdownField {
// Normalize value to array to simplify further processing // Normalize value to array to simplify further processing
$values = (is_array($this->value)) ? $this->value : array(trim($this->value)); $values = (is_array($this->value) || is_object($this->value)) ? $this->value : array(trim($this->value));
$mapped = array(); $mapped = array();
if($source instanceof SQLMap) { if($source instanceof SQLMap) {
foreach($values as $value) $mapped[] = $source->getItem($value); foreach($values as $value) $mapped[] = $source->getItem($value);
} elseif(is_array($source)) { } else if($source instanceof ArrayAccess || is_array($source)) {
$mapped = array_intersect_key($source, array_combine($values, $values)); foreach($values as $value) {
if(isset($source[$value])) $mapped[] = $source[$value];
}
} else { } else {
$mapped = array(); $mapped = array();
} }

View File

@ -44,7 +44,7 @@ class ForeignKey extends Int {
} }
} else { } else {
$titleField = (singleton($hasOneClass)->hasField('Title')) ? "Title" : "Name"; $titleField = (singleton($hasOneClass)->hasField('Title')) ? "Title" : "Name";
$map = new SQLMap(singleton($hasOneClass)->extendedSQL(), "ID", $titleField); $map = DataList::create($hasOneClass)->map("ID", $titleField);
$field = new DropdownField($this->name, $title, $map, null, null, ' '); $field = new DropdownField($this->name, $title, $map, null, null, ' ');
} }

View File

@ -26,7 +26,7 @@ class PrimaryKey extends Int {
public function scaffoldFormField($title = null, $params = null) { public function scaffoldFormField($title = null, $params = null) {
$titleField = ($this->object->hasField('Title')) ? "Title" : "Name"; $titleField = ($this->object->hasField('Title')) ? "Title" : "Name";
$map = new SQLMap($this->object->extendedSQL(), "ID", $titleField); $map = DataList::create(get_class($this->object))->map("ID", $titleField);
return new DropdownField($this->name, $title, $map, null, null, ' '); return new DropdownField($this->name, $title, $map, null, null, ' ');
} }
} }

View File

@ -221,16 +221,15 @@ class Group extends DataObject {
return $this->getManyManyComponents('Members'); return $this->getManyManyComponents('Members');
} }
public function map($filter = "", $sort = "", $blank="") { public static function map($filter = "", $sort = "", $blank="") {
$ret = new SQLMap(singleton('Group')->extendedSQL($filter, $sort)); Deprecation::notice('3.0', 'Use DataList::("Group")->map()');
if($blank){
$blankGroup = new Group();
$blankGroup->Title = $blank;
$blankGroup->ID = 0;
$ret->getItems()->unshift($blankGroup); $list = DataList::create("Group")->where($filter)->sort($sort);
} $map = $list->map();
return $ret;
if($blank) $map->unshift(0, $blank);
return $map;
} }
/** /**

View File

@ -971,17 +971,15 @@ class Member extends DataObject {
* *
* @todo Improve documentation of this function! (Markus) * @todo Improve documentation of this function! (Markus)
*/ */
public function map($filter = "", $sort = "", $blank="") { public static function map($filter = "", $sort = "", $blank="") {
$ret = new SQLMap(singleton('Member')->extendedSQL($filter, $sort)); Deprecation::notice('3.0', 'Use DataList::("Member")->map()');
if($blank) {
$blankMember = Object::create('Member');
$blankMember->Surname = $blank;
$blankMember->ID = 0;
$ret->getItems()->unshift($blankMember); $list = DataList::create("Member")->where($filter)->sort($sort);
} $map = $list->map();
return $ret; if($blank) $map->unshift(0, $blank);
return $map;
} }

View File

@ -55,7 +55,7 @@ class TableFieldTest extends SapphireTest {
$this->assertEquals(array( $this->assertEquals(array(
1 => 'CustomPerm1', 1 => 'CustomPerm1',
2 => 'CustomPerm2', 2 => 'CustomPerm2',
), $permissions); ), $permissions->toArray());
// Test repeated insert // Test repeated insert
@ -80,7 +80,7 @@ class TableFieldTest extends SapphireTest {
1 => 'CustomPerm1', 1 => 'CustomPerm1',
2 => 'CustomPerm2', 2 => 'CustomPerm2',
3 => 'CustomPerm3', 3 => 'CustomPerm3',
), $permissions); ), $permissions->toArray());
} }
@ -130,7 +130,7 @@ class TableFieldTest extends SapphireTest {
$this->assertEquals(array( $this->assertEquals(array(
101 => 'Perm1 Modified', 101 => 'Perm1 Modified',
102 => 'Perm2 Modified', 102 => 'Perm2 Modified',
), $permissions); ), $permissions->toArray());
} }
function testDelete() { function testDelete() {

View File

@ -59,7 +59,7 @@ class TableListFieldTest extends SapphireTest {
$item3->ID => "a3", $item3->ID => "a3",
$item4->ID => "a4", $item4->ID => "a4",
$item5->ID => "a5" $item5->ID => "a5"
), $itemMap); ), $itemMap->toArray());
} }
function testFirstPageOfPaginatedSourceItemGeneration() { function testFirstPageOfPaginatedSourceItemGeneration() {
@ -92,7 +92,7 @@ class TableListFieldTest extends SapphireTest {
$this->assertEquals(array( $this->assertEquals(array(
$item1->ID => "a1", $item1->ID => "a1",
$item2->ID => "a2" $item2->ID => "a2"
), $itemMap); ), $itemMap->toArray());
} }
function testSecondPageOfPaginatedSourceItemGeneration() { function testSecondPageOfPaginatedSourceItemGeneration() {
@ -123,7 +123,7 @@ class TableListFieldTest extends SapphireTest {
$this->assertNotNull($items); $this->assertNotNull($items);
$itemMap = $items->map("ID", "A") ; $itemMap = $items->map("ID", "A") ;
$this->assertEquals(array($item3->ID => "a3", $item4->ID => "a4"), $itemMap); $this->assertEquals(array($item3->ID => "a3", $item4->ID => "a4"), $itemMap->toArray());
} }
function testSelectOptionsAddRemove() { function testSelectOptionsAddRemove() {

View File

@ -101,10 +101,10 @@ class DataListTest extends SapphireTest {
} }
function testMap() { function testMap() {
$map = DataList::create('DataObjectTest_TeamComment')->map(); $map = DataList::create('DataObjectTest_TeamComment')->map()->toArray();
$expected = array(1=>'Joe', 2=>'Bob', 3=>'Phil'); $expected = array(1=>'Joe', 2=>'Bob', 3=>'Phil');
$this->assertEquals($expected, $map); $this->assertEquals($expected, $map);
$otherMap = DataList::create('DataObjectTest_TeamComment')->map('Name', 'TeamID'); $otherMap = DataList::create('DataObjectTest_TeamComment')->map('Name', 'TeamID')->toArray();
$otherExpected = array ('Joe' => '1','Bob' => '1','Phil' => '2'); $otherExpected = array ('Joe' => '1','Bob' => '1','Phil' => '2');
$this->assertEquals($otherExpected, $otherMap); $this->assertEquals($otherExpected, $otherMap);
} }

View File

@ -37,7 +37,7 @@ class GroupTest extends FunctionalTest {
// We will iterate over the map and build mapOuput to more easily call assertions on the result. // We will iterate over the map and build mapOuput to more easily call assertions on the result.
$map = Group::map(); $map = Group::map();
$mapOutput = $map->getItems()->map('ID', 'Title'); $mapOutput = $map->toArray();
$group1 = $this->objFromFixture('Group', 'group1'); $group1 = $this->objFromFixture('Group', 'group1');
$group2 = $this->objFromFixture('Group', 'group2'); $group2 = $this->objFromFixture('Group', 'group2');