public function saveInto(\DataObjectInterface $record) { $v = $this->Value(); $allItems = array(); foreach ($this->children as $field) { $fieldname = $field->getName(); if (strpos($fieldname, '__') > 0) { $bits = array_reverse(explode('__', $fieldname)); if (count($bits) > 3) { list($dataFieldName, $id, $classname) = $bits; if (!isset($allItems["{$classname}-{$id}"])) { $item = $this->records->filter(array('ClassName' => $classname, 'ID' => $id))->first(); $allItems["{$classname}-{$id}"] = $item; } $item = $allItems["{$classname}-{$id}"]; if ($item) { if ($field) { $field->setName($dataFieldName); $field->saveInto($item); } } } } } foreach ($allItems as $item) { $item->write(); } parent::saveInto($record); }
public function Menu($level = 1) { if ($level == 1) { $root_elements = new ArrayList($this->get_root_elements()); $result = $root_elements->filter(array("ShowInMenus" => 1)); } else { $dataID = Director::get_current_page()->ID; $site_map = $this->get_site_map(); if (isset($site_map[$dataID])) { $parent = $site_map[$dataID]; $stack = array($parent); if ($parent) { while ($parent = $parent->getParent()) { array_unshift($stack, $parent); } } if (isset($stack[$level - 2])) { $elements = new ArrayList($stack[$level - 2]->getAllChildren()); $result = $elements->filter(array("ShowInMenus" => 1)); } } } $visible = array(); // Remove all entries the can not be viewed by the current user // We might need to create a show in menu permission if (isset($result)) { foreach ($result as $page) { if ($page->canView()) { $visible[] = $page; } } } return new ArrayList($visible); }
/** * $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43))); */ public function testMultipleWithArrayFilterAdvanced() { $list = new ArrayList(array( array('Name' => 'Steve', 'ID' => 1, 'Age'=>21), array('Name' => 'Steve', 'ID' => 2, 'Age'=>18), array('Name' => 'Clair', 'ID' => 2, 'Age'=>21), array('Name' => 'Clair', 'ID' => 2, 'Age'=>52), array('Name' => 'Steve', 'ID' => 3, 'Age'=>43) )); $list->filter(array('Name'=>array('Steve','Clair'),'Age'=>array(21, 43))); $expected = array( array('Name' => 'Steve', 'ID' => 1, 'Age'=>21), array('Name' => 'Clair', 'ID' => 2, 'Age'=>21), array('Name' => 'Steve', 'ID' => 3, 'Age'=>43) ); $this->assertEquals(3, $list->count()); $this->assertEquals($expected, $list->toArray(), 'List should only contain Steve and Steve and Clair'); }