static function findFieldAttributes($attributes = array(), $modules = null, $byModule = false, $byType = false) { $fields = array(); if (empty($modules)) { $modules = VardefBrowser::getModules(); } foreach ($modules as $module) { if (!empty($GLOBALS['beanList'][$module])) { $object = $GLOBALS['beanList'][$module]; if ($object == 'aCase') { $object = 'Case'; } VardefManager::loadVardef($module, $object); if (empty($GLOBALS['dictionary'][$object]['fields'])) { continue; } foreach ($GLOBALS['dictionary'][$object]['fields'] as $name => $def) { $fieldAttributes = !empty($attributes) ? $attributes : array_keys($def); foreach ($fieldAttributes as $k) { if (isset($def[$k])) { $v = var_export($def[$k], true); $key = is_array($def[$k]) ? null : $def[$k]; if ($k == 'type') { if (isset($def['dbType'])) { $v = var_export($def['dbType'], true); } } if ($byModule) { $fields[$module][$object][$def['type']][$k][$key] = $v; } else { if ($byType) { $fields[$def['type']][$k][$key] = $v; } else { if (!is_array($def[$k])) { if (isset($fields[$k][$key])) { $fields[$k][$key]['refs']++; } else { $fields[$k][$key] = array('attribute' => $v, 'refs' => 1); } } else { $fields[$k]['_array'][] = $def[$k]; } } } } } } } } return $fields; }
public function testfindFieldAttributes() { //check with emptty attributes array $attributes = array(); $fields1 = VardefBrowser::findFieldAttributes(); $this->assertTrue(is_array($fields1)); //check with emptty attributes array and prefilled modules array. $attributes = array(); $modules = array('Users'); $fields2 = VardefBrowser::findFieldAttributes($attributes, $modules, true, true); $this->assertTrue(is_array($fields2)); //check with a very specific attribute and empty modules array. $attributes = array('category'); $fields3 = VardefBrowser::findFieldAttributes($attributes); $this->assertTrue(is_array($fields3)); //check that all three arrays returned, are not same. $this->assertNotSame($fields1, $fields2); $this->assertNotSame($fields1, $fields3); $this->assertNotSame($fields2, $fields3); }