Exemple #1
0
 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                )";
         }
     }
 }
Exemple #2
0
<div class="view">

    <?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', '" . Awecms::getPrimaryKeyColumn($this) . "' => \$data->" . Awecms::getPrimaryKeyColumn($this) . ")); ?></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 {
Exemple #3
0
?>
']);
<?php 
foreach (CActiveRecord::model($this->modelClass)->relations() as $key => $relation) {
    if ($relation[0] == CActiveRecord::BELONGS_TO || $relation[0] == CActiveRecord::MANY_MANY) {
        printf("\t\t\t\$model->{$key} = \$_POST['{$this->modelClass}']['{$key}'];\n");
    }
}
?>
                try {
                    if($model->save()) {
                        if (isset($_GET['returnUrl'])) {
                                $this->redirect($_GET['returnUrl']);
                        } else {
                                $this->redirect(array('view','id'=>$model-><?php 
echo Awecms::getPrimaryKeyColumn($this);
?>
));
                        }
                    }
                } catch (Exception $e) {
                        $model->addError('<?php 
echo $this->identificationColumn;
?>
', $e->getMessage());
                }

            }

        $this->render('update',array(
                'model'=>$model,
Exemple #4
0
?>
 $this->widget('zii.widgets.CDetailView', array(
'data' => $model,
'attributes' => array(
<?php 
foreach ($this->tableSchema->columns as $column) {
    if ($column->isForeignKey) {
        echo "\t\tarray(\n";
        echo "\t\t\t'name'=>'{$column->name}',\n";
        foreach ($this->relations as $key => $relation) {
            if (($relation[0] == "CHasOneRelation" || $relation[0] == "CBelongsToRelation") && $relation[2] == $column->name) {
                $relatedModel = CActiveRecord::model($relation[1]);
                $identificationColumn = AweCrudCode::getIdentificationColumnFromTableSchema($relatedModel->tableSchema);
                $controller = $this->resolveController($relation);
                $value = "(\$model->{$key} !== null)?";
                $primaryKey = Awecms::getPrimaryKeyColumn($relatedModel);
                $value .= "CHtml::link(\$model->{$key}->{$identificationColumn}, array('{$controller}/view','{$primaryKey}'=>\$model->{$key}->{$primaryKey})).' '";
                //$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 "?>";