/** * Get column list as array (without tree architecture) * @return array */ public function getColumnsArray() { $items = $this->_columns->getItems(); $data = array(); if (!empty($items)) { foreach ($items as $k => $v) { $data[$v['id']] = $v['data']; } } return $data; }
/** * Get list of selected objects * @return array */ public function getSelectedObjects() { $result = array(); $partsArray = $this->_tree->getItems(); if (!empty($partsArray)) { foreach ($partsArray as $part) { $result[] = $part['data']->getObject(); } } return array_unique($result); }
/** * Get objects by class * @param string|array $class * @return array, indexed by object name */ public function getObjectsByClass($class) { if (!is_array($class)) { $class = array($class); } $class = array_map('ucfirst', $class); $items = $this->_tree->getItems(); if (empty($items)) { return array(); } $result = array(); foreach ($items as $config) { if (in_array($config['data']->getClass(), $class, true)) { $result[$config['id']] = $config['data']; } } return $result; }
public function testGetItems() { $tree = new Tree(); $item = new stdClass(); $item->id = 1; $tree->addItem($item->id, 0, $item); $item2 = new stdClass(); $item2->id = 2; $tree->addItem($item2->id, 1, $item2); $data = $tree->getItems(); $this->assertTrue(is_array($data)); $this->assertEquals(count($data), 2); $this->assertEquals($data[1]['data'], $item); $this->assertEquals($data[2]['data'], $item2); }