/** * Add a model to the ColumnModel class. * * Give this ColumnModel class a model where to get the columns from. * The public parameters and the customfield parameters are also set. * The $excludeColumns are meant to give up the column names that need to be excluded in the columnModel. * * @TODO: The text parameters need to be excluded. * * @param \GO\Base\Db\ActiveRecord $model * @param Array $excludeColumns */ public function setColumnsFromModel(\GO\Base\Db\ActiveRecord $model, $excludeColumns = array(), $includeColumns = array()) { $attributes = $model->getColumns(); foreach (array_keys($attributes) as $colName) { if (!in_array($colName, $excludeColumns)) { $sortIndex = empty($includeColumns) ? 0 : array_search($colName, $includeColumns); if ($sortIndex !== false) { $column = new Column($colName, $model->getAttributeLabel($colName), $sortIndex); $this->addColumn($column); } } } if (\GO::modules()->customfields && $model->customfieldsRecord) { $cfAttributes = array_keys($model->customfieldsRecord->columns); array_shift($cfAttributes); //remove model_id column foreach ($cfAttributes as $colName) { if (!in_array($colName, $excludeColumns)) { $sortIndex = empty($includeColumns) ? 0 : array_search($colName, $includeColumns); if ($sortIndex !== false) { $column = new Column($colName, $model->customfieldsRecord->getAttributeLabel($colName), $sortIndex); $this->addColumn($column); } } } } }
/** * Checks for dates in the import model and performs an strtotime on it. * * @param \GO\Base\Db\ActiveRecord $model */ private function _parseImportDates(&$model) { $columns = $model->getColumns(); foreach ($columns as $attributeName => $column) { if (!empty($column['gotype']) && $column['gotype'] == 'date' && !empty($model->{$attributeName})) { $model->{$attributeName} = date('Y-m-d', strtotime($model->{$attributeName})); } } }