Get all textual columns from a table

@param  Garp_Model_Db  $model  The model
@return array
180197
protected function _getTextualColumns(Garp_Model_Db $model) {
        $columns = $model->info(Zend_Db_Table::METADATA);
        $textTypes = array('varchar', 'text', 'mediumtext', 'longtext', 'tinytext');
        foreach ($columns as $column => $meta) {
            if (!in_array($meta['DATA_TYPE'], $textTypes)) {
                unset($columns[$column]);
            }
        }
        return array_keys($columns);
    }
1213491
public function getColumnsNames(array $columns, $model = null): array
    {
        return array_map(function ($column) use ($model) {
            return $this->getColumnName($column, $model);
        }, $columns);
    }
1049648
public function getModelLinks(Model $model) {
        $models = Configure::read('Admin.modelLinks');

        if (isset($models[$model->qualifiedName])) {
            return $models[$model->qualifiedName];
        }

        return array();
    }
569186
private function getPermissionsByModel(string $model) : array
    {
        $table = TableRegistry::getTableLocator()->get('RolesCapabilities.Capabilities');
        Assert::isInstanceOf($table, CapabilitiesTable::class);

        $groups = $table->getUserGroups($this->user['id']);

        $query = TableRegistry::getTableLocator()->get('RolesCapabilities.Permissions')
            ->find('all')
            ->select('foreign_key')
            ->where([
                // WARNING: this might conflict with APP table's name matching a plugin's table name
                'model' => $model,
                'type IN ' => ['view'],
                'OR' => [
                    ['owner_foreign_key IN ' => array_keys($groups), 'owner_model' => 'Groups'],
                    ['owner_foreign_key' => $this->user['id'], 'owner_model' => 'Users']
                ]
            ])
            ->applyOptions(['accessCheck' => false]);

        $result = [];
        foreach ($query->all() as $permission) {
            $result[] = $permission->get('foreign_key');
        }

        return $result;
    }
486486
public function getColumns()
	{
		$columns = $this->builder()->queryWithBinding(Expressions::getColumns($this->tableName))->get()->all();

		$_columns = [];

		foreach($columns as $column) {
			$_columns[] = Repository::getPlatformColumn($column);
		}

		return $_columns;
	}
802957
protected function _getPrimaryKeysOfAffectedRows(Garp_Model_Db $model, $where) {
        if ($draftableObserver = $model->getObserver('Draftable')) {
            // Unregister so it doesn't screw up the upcoming fetch call
            $model->unregisterObserver($draftableObserver);
        }

        $pkExtractor = new Garp_Db_PrimaryKeyExtractor($model, $where);
        $pks = $pkExtractor->extract();
        if (count($pks)) {
            return array($pks);
        }
        $rows = $model->fetchAll($where);
        $pks = array();
        foreach ($rows as $row) {
            if (!$row->isConnected()) {
                $row->setTable($model);
            }
            $pks[] = (array)$row->getPrimaryKey();
        }
        if ($draftableObserver) {
            $model->registerObserver($draftableObserver);
        }
        return $pks;
    }
937597
public function getModels($columns = array('*'))
    {
        // make sure that we select the version table, if the main table is selected
        $tempColumns = isset($this->query->columns)
            ? array_merge($columns, $this->query->columns)
            : $columns;
        foreach($tempColumns as $column) {
            $segments = explode('.', $column);
            if ($segments[0] == $this->model->getTable()) {
                $this->query->addSelect($this->model->getVersionTable().'.*');
                break;
            }
        }

        return parent::getModels($columns);
    }
291346
protected function scopedAttributes( $model )
	{
		$keys = $this->model->getScopedColumns();

		if ( count( $keys ) == 0 )
			return [];

		$values = array_map( function ( $column ) use ( $model )
		{
			return $model->getAttribute( $column );
		}, $keys );

		return array_combine( $keys, $values );
	}
667456
public function keys(Model $model)
    {
        $pk = $model->getKeyName();

        $pool = [
            [$pk],
            $model->getVisible(),
            $model->getHidden(),
            $model->getFillable(),
            $model->getGuarded(),
            $model->getDates(),
            array_keys($this->getCasts($model))
        ];

        // SoftDeletingTrait
        if (method_exists($model, 'getDeletedAtColumn')) {
            $pool[] = [$model->getDeletedAtColumn()];
        }

        $keysByKey = [];

        foreach ($pool as $i=>$keys) {
            foreach ($keys as $key) {
                if ($keys == ['*'] || $keys == '*') {
                    continue;
                }

                $keysByKey[$key] = true;
            }
        }

        return array_keys($keysByKey);
    }
107959
protected function _generateTableColumns($model)
    {
        $model = TableRegistry::get($model);
        $columns = ConnectionManager::get('default')->schemaCollection()->describe($model->table())->columns();

        $result = [];
        $counter = 0;
        $max = 2;

        if (in_array('id', $columns)) {
            $result['id'] = [];
            unset($columns['id']);
        }

        foreach ($columns as $column) {
            if ($counter < $max) {
                $result[$column] = [];
                unset($columns[$column]);
                $counter++;
            }
        }

        if (in_array('created', $columns)) {
            $result['created'] = [];
        }

        return $result;
    }
267113
public function getIndexGridColumns($model, $fields)
    {
        $id = Yii::$app->request->getQueryParam('id');
        $relationName = Yii::$app->request->getQueryParam('relation');
        $multiple = Yii::$app->request->getQueryParam('multiple', 'true') === 'true';
        foreach ($fields as $key => $field) {
            if (((is_array($field) || (!is_string($field) && is_callable($field))) && $key === $relationName)
                || $field === $relationName
            ) {
                unset($fields[$key]);
            }
        }
        return array_merge([
            [
                'class'         => 'yii\grid\CheckboxColumn',
                'multiple'      => $multiple,
                'headerOptions' => ['class' => 'column-serial'],
                'checkboxOptions' => function ($model, $key, $index, $column) use ($id, $relationName) {
                    /** @var \yii\db\ActiveRecord $model */
                    $options = [
                        'value' => is_array($key)
                            ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
                            : $key,
                    ];
                    if (empty($relationName) || $model->$relationName === null || trim($id) === '') {
                        return $options;
                    }
                    $relation = $model->getRelation($relationName);
                    if ($relation->multiple) {
                        /** @var \yii\db\ActiveRecord $relationClass */
                        $relationClass = $relation->modelClass;
                        if (Action::importKey($relationClass::primaryKey(), $id)
                            === $model->getAttributes(array_keys($relation->link))
                        ) {
                            $options['checked']  = true;
                            $options['disabled'] = true;
                        }
                    } elseif (Action::exportKey($relation->one()->getPrimaryKey()) === $id) {
                        $options['checked']  = true;
                        $options['disabled'] = true;
                    }
                    return $options;
                },
            ],
            [
                'class'         => 'yii\grid\SerialColumn',
                'headerOptions' => ['class' => 'column-serial'],
            ],
        ], self::getGridColumns($model, $fields));
    }
827615
public function sources($model = null) {
		$params = compact('model');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
			$result = $this->_execute($sql);
			$sources = [];

			foreach ($result as $row) {
				$sources[] = $row[0];
			}
			return $sources;
		});
	}
405951
public static function getSlug($model)
    {
        $i18nModels = $model->i18n;
        $slugs = [];
        foreach ($i18nModels as $i18nModel) {
            if (empty($i18nModel->body)) continue; // skip languages for news without body
            $slugs[$i18nModel->lang_code] = $i18nModel->slug;
        }

        //$langs = array_keys(LangHelper::activeLanguages()); // better use as container-module's member:
        $module = Module::getModuleByClassname(Module::className());
        $langHelper = $module->langHelper;
        $langs = array_keys($langHelper::activeLanguages());
        $slug = '';
        foreach ($langs as $lang) {
            if (!empty($slugs[$lang])) {
                $slug = $slugs[$lang];
                break;
            }
        }
        if (strlen($slug) > static::$slugMaxLen) {
            $slug = substr($slug, 0, static::$slugMaxLen);
        }
        $slug = trim($slug, '-');
        return $slug;
    }
848730
protected function migratePivotAttributes(Model $model)
    {
        $values = [];

        foreach ($model->getAttributes() as $key => $value) {
            // To get the pivots attributes we will just take any of the attributes which
            // begin with "pivot_" and add those to this arrays, as well as unsetting
            // them from the parent's models since they exist in a different table.
            if (strpos($key, 'pivot_') === 0) {
                $values[substr($key, 6)] = $value;

                $model->{$key} = null;
            }
        }

        return $values;
    }
690726
protected function getModelFields(\atk4\data\Model $model)
    {
        $fields = [];
        foreach ($model->elements as $f) {
            if (!$f instanceof \atk4\data\Field) {
                continue;
            }

            if ($f->isEditable() || $f->isVisible()) {
                $fields[] = $f->short_name;
            }
        }

        return $fields;
    }
1003968
public function children( $model )
	{
		$query = $this->model->newQuery();

		$query->where( $this->model->getQualifiedParentColumnName(), '=', $model->getKey() );

		// We must also add the scoped column values to the query to compute valid
		// left and right indexes.
		foreach ( $this->scopedAttributes( $model ) as $fld => $value )
			$query->where( $this->qualify( $fld ), '=', $value );

		$query->orderBy( $this->model->getQualifiedLeftColumnName() );
		$query->orderBy( $this->model->getQualifiedRightColumnName() );
		$query->orderBy( $this->model->getQualifiedKeyName() );

		return $query->get();
	}
80117
public function getColumns($table)
    {
        $query = $this->getUtilityQuery()->showColumns($table);

        $results = $this->query($query, $this->getBinds());
        
        $columns = [];
        foreach ($results as $column) {
            $key = null;
            if ($column['pk'] == 1) {
                $key = 'PRI';
            }
            
            $columns[] = [
                'Field'     => $column['name'],
                'Type'      => $column['type'],
                'Default'   => $column['dflt_value'],
                'Null'      => $column['notnull'] != 1,
                'Key'       => $key
            ];
        }
        
        return $columns;
    }