Returns an array with all columns from the model that have a label

@param array                     $data
@param \MUtil_Model_ModelAbstract $model
@return array
431307
protected function getExcelData($data, \MUtil_Model_ModelAbstract $model)
    {
        $headings = array();
        $emptyMsg = sprintf($this->_('No %s found.'), $this->getTopic(0));
        foreach ($model->getItemsOrdered() as $name) {
            if ($label = $model->get($name, 'label')) {
                $headings[$name] = (string) $label;
            }
        }
        $results = array();
        $results[] = $headings;
        if ($headings) {
            if ($data) {
                foreach ($data as $row) {
                    $results[] = array_intersect_key($row, $headings);
                }
                return $results;
            } else {
                $result = array();
                foreach ($headings as $key => $value) {
                    $result[$key] = $emptyMsg;
                }
                $results[] = $result;
                return $results;
            }
        } else {
            return array($emptyMsg);
        }
    }
48841
private function queryAttributes(Model $model)
    {
        $data = [
            'user_id'    => user()->id,
            'namespace'  => get_class($model),
            'foreign_id' => $model->id
        ];
        (is_null($this->field)) ? array_set($data, 'field_class', get_called_class()) : array_set($data, 'field_id', $this->field->id);
        return $data;
    }
1366477
public function getValue($model, $data)
    {
        /** @type Model $model */
        $model = $this->add($this->getModel());
        $id = $data[$this->foreignName];

        try {

            $this->hook('beforeForeignLoad', array($model, $id));

            $model->load($id);
            $titleField = $model->getTitleField();

            return $model->get($titleField) ?: 'Ref#'.$id;
        } catch (BaseException $e) {
            // record is no longer there it seems
            return null;
        }
    }
620380
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
    {
        if ($this->request->getParam('log')) {
            $model->setFilter(array('gla_id' => $this->request->getParam('log')));
            parent::processSortOnly($model);
        } else {
            parent::processFilterAndSort($model);
        }
    }
1199115
protected function _addExtraDataToExportModel(\MUtil_Model_ModelAbstract $model, array $data, array &$prefixes)
    {
        $this->_addExtraTrackFields($model, $data, $prefixes);      // Create the first 'P' fields after this
        $this->_addExtraRespondentNumber($model, $data, $prefixes);
        $this->_addExtraGenderAge($model, $data, $prefixes);
        $this->_addExtraTokenReceptionCode($model, $data, $prefixes);
        $this->_addExtraTrackReceptionCode($model, $data, $prefixes);
        $this->_addExtraTrackFieldsByCode($model, $data, $prefixes);
    }
535304
protected function getTableAndDatabase($model)
    {
        $table = $model->getConnection()->getTablePrefix() . $model->getTable();

        $database = null;

        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return [$table, $database];
    }
152791
protected static function getRelationColumn($model, $field, $relation)
    {
        return [
            'attribute' => $field,
            'format'    => 'text',
            'visible'   => true,
            'label'     => $model->getRelationLabel($relation, $field),
        ];
    }
386500
protected function processFilterAndSort(\MUtil_Model_ModelAbstract $model)
    {
        $filter['gto_id_respondent']   = $this->respondent->getId();
        if (is_array($this->forOtherOrgs)) {
            $filter['gto_id_organization'] = $this->forOtherOrgs;
        } elseif (true !== $this->forOtherOrgs) {
            $filter['gto_id_organization'] = $this->respondent->getOrganizationId();
        }

        // Filter for valid track reception codes
        $filter[] = 'gr2t_reception_code IN (SELECT grc_id_reception_code FROM gems__reception_codes WHERE grc_success = 1)';
        $filter['grc_success'] = 1;
        // Active round
        // or
        // no round
        // or
        // token is success and completed
        $filter[] = 'gro_active = 1 OR gro_active IS NULL OR (grc_success=1 AND gto_completion_time IS NOT NULL)';
        $filter['gsu_active']  = 1;

        // NOTE! $this->model does not need to be the token model, but $model is a token model
        $tabFilter = $this->model->getMeta('tab_filter');
        if ($tabFilter) {
            $model->addFilter($tabFilter);
        }

        $model->addFilter($filter);

        // \MUtil_Echo::track($model->getFilter());

        $this->processSortOnly($model);
    }
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 );
	}
357056
public function createModelData(Model $model)
    {
        $data = [];

        if ($model->getId()) {
            $data['id'] = $model->getId();
        }
        if ($model->getName()) {
            $data['name'] = $model->getName();
        }
        if ($model->getConcepts()) {
            $data['output_info']['data'] = [];
            $data['output_info']['data'] = $this->addModelConcepts($data['output_info']['data'], $model->getConcepts());
        }
        $data['output_info']['output_config'] = $model->getOutputConfig();

        return $data;
    }
290356
public function formatOutputRecord($data, $model=null)
    {
        $model = $model ? : $this;
        
        if (!$data || !isset($model['primary_key']) || !isset($model['fields'])) {
            return $data;
        }
        
        $fields_names = array_keys($model['fields']);
        foreach ($data as $k => $v){
            if (in_array($k, $fields_names)) {
                $data[$k] = FieldOutputHandler::formatValue($model['fields'][$k], $v);
            }
        }
        
        return $data;
    }
371067
private function getDataSet($label, $data, $index = 0)
    {
        $set = $this->datasets[$index];
        $set['label'] = $label;
        $set['data'] = $data;

        return $set;
    }
1251456
public static function checkModel($errors, Model $model) : array
    {
        $output = [];
        if (!is_array($errors)) {
            return $output;
        }
        foreach ($errors as $attribute => $message) {
            $obj = $model;
            if (strpos($attribute, '.') !== false) {
                list($nested, $attr) = explode('.', $attribute);
                if (isset($obj->{$nested}) && $obj->{$nested} instanceof Model) {
                    $obj       = $obj->{$nested};
                    $attribute = $attr;
                }
            }
            if ($obj->hasProperty($attribute)) {
                $output[Html::getInputId($obj, $attribute)] = $message;
            } else {
                $output[] = $message;
            }
        }
        return $output;
    }
135457
public function getModelColumns()
    {
        $model = $this->getForeignModelInstance();
        $columns = [];
        if ($this->isModel($model)) {
            // At this point we know a model class exists
            // Try to get the database column listing from the database directly
            $tableName = $model->getTable();
            $columns = DB::getSchemaBuilder()->getColumnListing($tableName);
        }

        if (count($columns) == 0) {
            // At this poing we know the column have not yet been identified
            // which also mean that the model does not exists or the table
            // does not existing in the database.
            // Try to find the columns from the resource-file if one found.
            $columns = $this->getFieldNamesFromResource();
        }

        return $columns;
    }
913330
public function getFields($model)
    {
        //
        $table = $this->getTable($model);

        //
        $sql = "DESC `{$table}`";

        //
        $results = $this->getResults($sql);

        //
        $fields = [];

        //
        foreach ($results as $field) {
            $fields[] = $field['Field'];
        }

        //
        return $fields;
    }
649894
private function _getJunctionTableColumns($relationName, $model)
    {
        $junctionTableColumns = [];
        if (array_key_exists($relationName, $this->_relationsExtraColumns)) {
            if (is_callable($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName]($model);
            } elseif (is_array($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName];
            }
            if (!is_array($junctionTableColumns)) {
                throw new RuntimeException(
                    'Junction table columns definition must return an array, got ' . gettype($junctionTableColumns)
                );
            }
        }
        return $junctionTableColumns;
    }
855219
private function cacheModelByKeys(\Tx_Oelib_Model $model, array $data)
    {
        foreach ($this->additionalKeys as $key) {
            if (isset($data[$key])) {
                $value = $data[$key];
                if ($value !== '') {
                    $this->cacheByKey[$key][$value] = $model;
                }
            }
        }

        $this->cacheModelByCombinedKeys($model, $data);
        if (!empty($this->compoundKeyParts)) {
            $this->cacheModelByCompoundKey($model, $data);
        }
    }