Process domains and types

@param array $columns
@param array $types
@param \Object\Table $model
@return array
420286
public static function processDomainsAndTypes($columns, $types = null, $model = null) {
		// cache domains and types
		if (empty(self::$domains)) {
			$object = new \Object\Data\Domains();
			// use unprocessed data - a must
			self::$domains = $object->data;
		}
		if (empty(self::$types)) {
			if (!empty($types)) {
				self::$types = $types;
			} else {
				$object = new \Object\Data\Types();
				// use unprocessed data - a must
				self::$types = $object->data;
			}
		}
		$domain_attributes = array_merge(['type'], self::$attributes['schema'], self::$attributes['php'], self::$attributes['misc']);
		$type_attributes = array_merge(self::$attributes['schema'], self::$attributes['php'], self::$attributes['misc']);
		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 ($domain_attributes 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 ($type_attributes 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];
					}
				}
			}
			// we default to string
			if (empty($columns[$k]['php_type'])) {
				$columns[$k]['php_type'] = 'string';
			}
			// sequence type and name
			if (!empty($columns[$k]['sequence']) && !empty($model)) {
				$columns[$k]['sequence_type'] = 'global_simple';
				if ($model->tenant) {
					$columns[$k]['sequence_type'] = 'tenant_simple';
				}
				if ($model->module) {
					$columns[$k]['sequence_type'] = 'module_simple';
				}
			}
		}
		return $columns;
	}
653329
public function columns($columns)
    {
        if (!is_array($columns)) {
            $columns = preg_split('~\s*,\s*~', trim($columns));
        }

        $this->columns = $columns;

        return $this;
    }
455856
public function columns($columns)
    {
        if (is_string($columns)) {
            $columns = preg_split('~\s*,\s*~', trim($columns));
        }

        $this->columns = $columns;

        return $this;
    }
635243
protected function transformModelToArray($columns)
    {
        $model = $this->getModel();

        $extract = [];

        $relationships = null;

        foreach ($columns as $label => $column) {

            $columnModel = $model;

            $modifier = "";
            $urlSuffix = false;

            $apiLabel = (is_numeric($label)) ? $column : $label;

            if (is_callable($column)) {
                $value = $column();
            } else {
                if (stripos($column, ":") !== false) {
                    $parts = explode(":", $column);
                    $column = $parts[0];

                    if (is_numeric($label)) {
                        $apiLabel = $column;
                    }

                    $modifier = strtolower($parts[1]);

                    if (sizeof($parts) > 2) {
                        $urlSuffix = $parts[2];
                    }
                }

                if (stripos($column, ".") !== false) {
                    $parts = explode(".", $column, 2);

                    $column = $parts[0];
                    $columnModel = $columnModel->$column;

                    $column = $parts[1];

                    if (is_numeric($label)) {
                        $apiLabel = $parts[1];
                    }
                }

                if ($columnModel) {
                    $value = $columnModel->$column;
                } else {
                    $value = "";
                }
            }

            if (is_object($value)) {
                // We can't pass objects back through the API! Let's get a JSON friendly structure instead.
                if (!($value instanceof Model) && !($value instanceof Collection)) {
                    // This seems strange however if we just used json_encode we'd be passing the encoded version
                    // back as a string. We decode to get the original structure back again.
                    $value = json_decode(json_encode($value));
                } else {
                    $navigationResource = false;
                    $navigationResourceIsCollection = false;

                    if ($value instanceof Model) {

                        $navigationResource = $this->getRestResourceForModel($value);

                        if ($navigationResource === false) {
                            throw new RestImplementationException(print_r($value, true));
                            continue;
                        }
                    }

                    if ($value instanceof Collection) {
                        $navigationResource = $this->getRestResourceForModelName(SolutionSchema::getModelNameFromClass($value->getModelClassName()));

                        if ($navigationResource === false) {
                            continue;
                        }

                        $navigationResourceIsCollection = true;
                        $navigationResource->setModelCollection($value);
                    }

                    if ($navigationResource) {
                        switch ($modifier) {
                            case "summary":
                                $value = $navigationResource->summary();
                                break;
                            case "link":
                                $link = $navigationResource->link();

                                if (!isset($link->href) || $navigationResourceIsCollection) {

                                    if (!$urlSuffix) {
                                        throw new RestImplementationException("No canonical URL for " . get_class($navigationResource) . " and no URL suffix supplied for property " . $apiLabel);
                                    }

                                    $ourHref = $this->getHref();

                                    // Override the href with this appendage instead.
                                    $link->href = $ourHref . $urlSuffix;
                                }

                                $value = $link;

                                break;
                            default:
                                $value = $navigationResource->get();
                                break;
                        }
                    }
                }
            }

            if ($value !== null || $this->includeNullItems) {
                $extract[$apiLabel] = $value;
            }
        }

        return $extract;
    }
281797
public function getBy($column, $value, array $columns = ['*'])
    {
        $result = $this->getBuilder()
                       ->select($columns)
                       ->where($column, '=', $value)
                       ->first();

        // Reset query builder
        $this->resetBuilder();

        return $result;
    }
161633
public function getColumnNames(array $columns)
    {
        return array_reduce($columns, function ($carry, \tao_models_classes_table_Column $column) {
            /** @var ContextTypePropertyColumn|VariableColumn $column */
            $carry[$this->getColumnId($column)] = $column->getLabel();
            return $carry;
        });
    }
491484
protected function buildColumns($columns)
    {
        if (!is_array($columns)) {
            if ($columns instanceof Aggregation) {
                $columns->setFieldsSql($this->buildColumns($columns->getFields()));

                return $this->getAdapter()->quoteSql($columns->toSQL());
            } elseif (false !== strpos($columns, '(')) {
                return $this->getAdapter()->quoteSql($columns);
            }
            $columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY);
        }
        foreach ($columns as $i => $column) {
            if ($column instanceof Expression) {
                $columns[$i] = $this->getAdapter()->quoteSql($column->toSQL());
            } elseif (false !== strpos($column, 'AS')) {
                if (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $column, $matches)) {
                    list(, $rawColumn, $rawAlias) = $matches;
                    $columns[$i] = $this->getQuotedName($rawColumn).' AS '.$this->getQuotedName($rawAlias);
                }
            } elseif (false === strpos($column, '(')) {
                $columns[$i] = $this->getQuotedName($column);
            }
        }

        return is_array($columns) ? implode(', ', $columns) : $columns;
    }
309307
public function select($columns = [])
    {
        $expr = new ColumnExpression($this->sql);

        if ($columns instanceof Closure) {
            $columns($expr);
        } else {
            if (!is_array($columns)) {
                $columns = [$columns];
            }
            $expr->columns($columns);
        }
    }
923344
public function hasColumns($table, array $columns)
    {
        $tableColumns = array_map('strtolower', array_keys($this->getColumnListing($table)));

        foreach ($columns as $column) {
            if (!in_array(strtolower($column), $tableColumns)) {
                return false;
            }
        }

        return true;
    }
1163178
private function extractTypeValues(array $columnList, array $types)
    {
        $typeValues = [];

        foreach ($columnList as $columnIndex => $columnName) {
            $typeValues[] = $types[$columnName] ?? ParameterType::STRING;
        }

        return $typeValues;
    }
57329
protected function column($type, $parameters = array())
		{
			$parameters = array_merge(compact('type'), $parameters);
			$this->columns[] = new Fluent($parameters);
			return end($this->columns);
		}
1016503
private function validateColumns($columns): array
    {
        foreach($columns as $e=>$r){
            $columns[$e] = $this->validateColumn($r);
        }
        return $columns;

    }
540308
public static function process(ActiveRecord $model, $type)
    {
        $value = self::value($type);

        if (isset($model['votes'])) {
            $model['votes'] += $value;

            $vote = new self([
                'entity_id' => $model['id'],
                'vote' => $value,
                'entity' => self::modelEntityType($model)
            ]);

            if ($vote->save() && $model->save()) {
                return $model;
            }
        }

        return false;
    }
463612
public function columns(array $fields) : self
    {
        foreach ($fields as $k => $v) {
            if (strpos($v, '*') !== false) {
                $temp = explode('.', $v);
                if (count($temp) === 1) {
                    $table = $this->definition->getName();
                    $cols = $this->definition->getColumns();
                } else if (count($temp) === 2) {
                    $table = $temp[0];
                    if ($this->definition->hasRelation($table)) {
                        $cols = $this->definition->getRelation($table)->table->getColumns();
                    } else if (isset($this->joins[$table])) {
                        $cols = $this->joins[$table]->table->getColumns();
                    } else {
                        throw new DBException('Invalid foreign table name');
                    }
                } else {
                    array_pop($temp);
                    $this->with(implode('.', $temp));
                    $table = array_reduce(
                        $temp,
                        function ($carry, $item) use (&$table) {
                            return $table->getRelation($item)->table;
                        }
                    );
                    $cols = $table->getColumns();
                    $table = implode(static::SEP, $temp);
                }
                unset($fields[$k]);
                foreach ($cols as $col) {
                    $fields[] = $table . '.' . $col;
                }
            }
        }
        $primary = $this->definition->getPrimaryKey();
        foreach ($fields as $k => $v) {
            try {
                $fields[$k] = $this->getColumn($v)['name'];
            } catch (DBException $e) {
                $fields[$k] = $v;
            }
        }
        foreach ($primary as $field) {
            $field = $this->getColumn($field)['name'];
            if (!in_array($field, $fields)) {
                $fields[] = $field;
            }
        }
        $this->fields = $fields;
        return $this;
    }
760097
public static function getModelColumns(string $model = '', string $connectionManager = 'default'): array
    {
        $result = $columns = [];

        if (empty($model)) {
            return $result;
        }

        // making sure that model is in table naming conventions.
        $model = Inflector::tableize($model);

        try {
            $connection = ConnectionManager::get($connectionManager);
            $schema = $connection->getSchemaCollection();
            $table = $schema->describe($model);
            $columns = $table->columns();
        } catch (MissingDatasourceConfigException $e) {
            return $result;
        } catch (Exception $e) {
            return $result;
        }

        // A table with no columns?
        if (empty($columns)) {
            return $result;
        }

        foreach ($columns as $column) {
            $result[$column] = $column;
        }

        return $result;
    }
633231
public function fieldsAs(array $types){
		$i=0;
		if(JArray::isAssociative($types)){
			foreach ($types as $type=>$attributes){
				if(\is_int($type))
					$this->fieldAs($i++,$attributes,[]);
				else{
					$type=preg_replace('/\d/', '', $type );
					$this->fieldAs($i++,$type,$attributes);
				}
			}
		}else{
			foreach ($types as $type){
				$this->fieldAs($i++,$type);
			}
		}
	}
857884
final public static function getTypedColumns($columns)
    {
        static::checkUnknownColumn($columns);

        $result = Utils::arrayWhitelist(
            array_combine(self::getColumns(), static::COLUMNS),
            (array) $columns
        );

        return (is_string($columns))
            ? array_values($result)[0]
            : $result;
    }