<?php $possibleIdentifiers = array('name', 'title', 'slug'); $identificationColumn = $this->getIdentificationColumn(); if (!in_array($identificationColumn, $possibleIdentifiers)) { echo "<h2><?php echo CHtml::encode(\$data->getAttributeLabel('{$identificationColumn}')); ?>:</h2>\n"; } echo "<h2><?php echo CHtml::link(CHtml::encode(\$data->{$identificationColumn}), array('view', '{$this->tableSchema->primaryKey}' => \$data->{$this->tableSchema->primaryKey})); ?></h2>\n"; foreach ($this->tableSchema->columns as $column) { if ($column->name !== $identificationColumn && !$column->isPrimaryKey && !in_array(strtolower($column->name), $this->passwordFields)) { $columnName = $column->name; if ($column->isForeignKey) { $relations = $this->getRelations(); foreach ($relations as $relationName => $relation) { if ($relation[2] == $columnName) { $relatedModel = CActiveRecord::model($relation[1]); $columnName = $relationName . '->' . AweCrudCode::getIdentificationColumnFromTableSchema($relatedModel->tableSchema); } } } if (!in_array($column->dbType, $this->booleanTypes)) { echo "\n <?php\n if (!empty(\$data->{$columnName})) {\n ?>"; } echo "\n <div class=\"field\">\n <div class=\"field_name\">\n <b><?php echo CHtml::encode(\$data->getAttributeLabel('{$column->name}')); ?>:</b>\n </div>\n<div class=\"field_value\">\n"; if (in_array($column->dbType, $this->dateTypes)) { /* echo "\techo Yii::app()->getDateFormatter()->formatDateTime(\$data->{$columnName}, 'medium', 'medium'); ?>\n\t<br />\n\n"; */ echo " <?php\n echo date('D, d M y H:i:s', strtotime(\$data->" . $columnName . "));\n ?>\n\n </div>\n </div>\n"; } else { if (in_array($column->dbType, $this->booleanTypes)) { echo "\n <?php\n echo CHtml::encode(\$data->{$columnName} == 1 ? 'True' : 'False');\n ?>\n\n </div>\n </div>";
public function generateGridViewColumn($column) { if ($column->isForeignKey) { $columnName = $column->name; $relations = $this->getRelations(); $relatedModel = null; $relatedModelName = null; foreach ($relations as $relationName => $relation) { if ($relation[2] == $columnName) { $relatedModel = CActiveRecord::model($relation[1]); $relatedColumnName = $relationName . '->' . AweCrudCode::getIdentificationColumnFromTableSchema($relatedModel->tableSchema); $relatedModelName = $relation[1]; } } $filter = ''; if ($relatedModel) { $foreign_pk = Awecms::getPrimaryKeyColumn($relatedModel); $foreign_identificationColumn = self::getIdentificationColumnFromTableSchema($relatedModel->getTableSchema()); $relatedModelName = get_class($relatedModel); $filter = "CHtml::listData({$relatedModelName}::model()->findAll(array('order'=>'{$foreign_identificationColumn}')),'{$foreign_pk}','{$foreign_identificationColumn}')"; } return "array(\n 'name' => '{$column->name}',\n 'value' => 'isset(\$data->{$relatedColumnName})?\$data->{$relatedColumnName}:\"\"',\n 'filter' => {$filter},\n )"; } // Boolean or bit. if (strtoupper($column->dbType) == 'TINYINT(1)' || strtoupper($column->dbType) == 'BIT' || strtoupper($column->dbType) == 'BOOL' || strtoupper($column->dbType) == 'BOOLEAN') { if ($this->isJToggleColumnEnabled) { return "array(\n 'class' => 'JToggleColumn',\n 'name' => '{$column->name}',\n 'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),\n 'model' => get_class(\$model),\n 'htmlOptions' => array('style' => 'text-align:center;')\n )"; } else { return "array(\n 'name' => '{$column->name}',\n 'value' => '(\$data->{$column->name} === 0) ? Yii::t(\\'app\\', \\'No\\') : Yii::t(\\'app\\', \\'Yes\\')',\n 'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),\n )"; } } else { if (strtoupper($column->dbType) == 'DATE' || strtoupper($column->dbType) == 'TIMESTAMP') { return "array(\n 'name' => '{$column->name}',\n 'value' => 'Yii::app()->dateFormatter->format(\"dd/MM/y\",strtotime(\$data->{$column->name}))',\n 'filter' => false,\n )"; } else { return "array(\n 'name' => '{$column->name}',\n 'value' => 'isset(\$data->{$column->name})?\$data->{$column->name}:\"\"',\n 'filter' => false,\n )"; } } }
//$value .= ".CHtml::link(Yii::t('app','Update'), array('{$controller}/update','{$relatedModel->tableSchema->primaryKey}'=>\$model->{$key}->{$relatedModel->tableSchema->primaryKey}), array('class'=>'edit'))"; $value .= ":'n/a'"; echo "\t\t\t'value'=>{$value},\n"; echo "\t\t\t'type'=>'html',\n"; break; } } echo "\t\t),\n"; } else { echo $this->getDetailViewAttribute($column); } } echo ")));"; echo "?>"; foreach (CActiveRecord::model(Yii::import($this->model))->relations() as $key => $relation) { $controller = $this->resolveController($relation); $relatedModel = CActiveRecord::model($relation[1]); $pk = $relatedModel->tableSchema->primaryKey; if ($relation[0] == 'CManyManyRelation' || $relation[0] == 'CHasManyRelation') { $relatedModel = CActiveRecord::model($relation[1]); $identificationColumn = AweCrudCode::getIdentificationColumnFromTableSchema($relatedModel->tableSchema); echo "\n <?php if (count(\$model->{$key})) { ?>\n <h2>"; echo "<?php echo CHtml::link(Yii::t('app', Awecms::pluralize('Sub-Page', '" . ucfirst($key) . "', count(\$model->{$key}))), array('" . $controller . "'));?>"; echo "</h2>\n"; echo CHtml::openTag('ul'); echo "\n <?php if (is_array(\$model->{$key})) foreach(\$model->{$key} as \$foreignobj) { \n\n echo '<li>';\n echo CHtml::link(\$foreignobj->{$identificationColumn}, array('{$controller}/view','{$pk}'=>\$foreignobj->{$pk}));\n\t\t\t\t\t\t\t\n }\n ?>"; echo CHtml::closeTag('ul'); echo ' <?php } ?>'; } }