/** * Process domains * * @param array $columns * @return array */ public static function process_domains($columns, $types = null) { if (empty(self::$domains)) { $object = new object_data_domains(); self::$domains = $object->data; } if (empty(self::$types)) { if (!empty($types)) { self::$types = $types; } else { $object = new object_data_types(); self::$types = $object->data; } } foreach ($columns as $k => $v) { if (isset($v['domain'])) { // check if domain exists if (!isset(self::$domains[$v['domain']])) { throw new Exception('Domain: ' . $v['domain'] . '?'); } // populate domain attributes foreach (['type', 'default', 'length', 'null', 'precision', 'scale', 'format', 'format_options', 'align', 'validator_method', 'validator_params', 'placeholder', 'searchable', 'tree'] as $v2) { if (array_key_exists($v2, self::$domains[$v['domain']]) && !array_key_exists($v2, $columns[$k])) { $columns[$k][$v2] = self::$domains[$v['domain']][$v2]; } } } // populate type attributes if (isset($columns[$k]['type']) && isset(self::$types[$columns[$k]['type']])) { foreach (['default', 'php_type', 'format', 'format_options', 'align', 'validator_method', 'validator_params', 'placeholder', 'searchable', 'tree'] as $v2) { if (array_key_exists($v2, self::$types[$columns[$k]['type']]) && !array_key_exists($v2, $columns[$k])) { $columns[$k][$v2] = self::$types[$columns[$k]['type']][$v2]; } } } else { // we default to string $columns[$k]['php_type'] = 'string'; } } return $columns; }