/** * Test different data sources */ public function testSources() { // Array $items = array('a' => 'Apple', 'b' => 'Banana', 'c' => 'Cranberry'); $field = new CheckboxSetField('Field', null, $items); $this->assertEquals($items, $field->getSource()); // SS_List $list = new ArrayList(array(new ArrayData(array('ID' => 'a', 'Title' => 'Apple')), new ArrayData(array('ID' => 'b', 'Title' => 'Banana')), new ArrayData(array('ID' => 'c', 'Title' => 'Cranberry')))); $field2 = new CheckboxSetField('Field', null, $list); $this->assertEquals($items, $field2->getSource()); $field3 = new CheckboxSetField('Field', null, $list->map()); $this->assertEquals($items, $field3->getSource()); }
/** * Get a member SQLMap of members in specific groups * * If no $groups is passed, all members will be returned * * @param mixed $groups - takes a SS_List, an array or a single Group.ID * @return SS_Map Returns an SS_Map that returns all Member data. */ public static function map_in_groups($groups = null) { $groupIDList = array(); if ($groups instanceof SS_List) { foreach ($groups as $group) { $groupIDList[] = $group->ID; } } elseif (is_array($groups)) { $groupIDList = $groups; } elseif ($groups) { $groupIDList[] = $groups; } // No groups, return all Members if (!$groupIDList) { return Member::get()->sort(array('Surname' => 'ASC', 'FirstName' => 'ASC'))->map(); } $membersList = new ArrayList(); // This is a bit ineffective, but follow the ORM style foreach (Group::get()->byIDs($groupIDList) as $group) { $membersList->merge($group->Members()); } $membersList->removeDuplicates('ID'); return $membersList->map(); }
public function testMap() { $list = new ArrayList(array(array('ID' => 1, 'Name' => 'Steve'), (object) array('ID' => 3, 'Name' => 'Bob'), array('ID' => 5, 'Name' => 'John'))); $map = $list->map('ID', 'Name'); // Items added after calling map should not be included retroactively $list->add(array('ID' => 7, 'Name' => 'Andrew')); $this->assertInstanceOf('SilverStripe\\ORM\\SS_Map', $map); $this->assertEquals(array(1 => 'Steve', 3 => 'Bob', 5 => 'John'), $map->toArray()); }