@@ -2,192 +2,191 @@

class CodeProvider {

public function generateDateField () {

}

public function resolveController($relation) {
$model = new $relation[1];
$reflection = new ReflectionClass($model);
$module = preg_match("/\/modules\/([a-zA-Z0-9]+)\//", $reflection->getFileName(), $matches);
$modulePrefix = (isset($matches[$module]))?"/".$matches[$module]."/":"/";
$controller = $modulePrefix.strtolower(substr($relation[1],0,1)).substr($relation[1],1);
return $controller;
}

static public function generateActiveField($model, $column) {
if (strtoupper($column->dbType) == 'TINYINT(1)'
|| strtoupper($column->dbType) == 'BIT'
|| strtoupper($column->dbType) == 'BOOL'
|| strtoupper($column->dbType) == 'BOOLEAN') {
return "echo \$form->checkBox(\$model,'{$column->name}')";
} else if (strtoupper($column->dbType) == 'DATE') {
$modelname = get_class($model);
} else if (substr(strtoupper($column->dbType), 0, 4) == 'ENUM') {
$string = sprintf("echo CHtml::activeDropDownList(\$model, '%s', array(\n", $column->name);

$enum_values = explode(',', substr($column->dbType, 4, strlen($column->dbType) - 1));

foreach ($enum_values as $value) {
$value = trim($value, "()'");
$string .= "\t\t\t'$value' => Yii::t('app', '" . $value . "') ,\n";
}
$string .= '))';

return $string;
} else {
return null;
}
}

public function generateRelation($model, $relationname, $relation) {
// Use the second attribute of the model, since the first is the id in
// most cases
//
// TODO: remove code, done via _label
if ($columns = CActiveRecord::model($relation[1])->tableSchema->columns) {
$j = 0;
foreach ($columns as $column) {
if (!$column->isForeignKey && !$column->isPrimaryKey) {
$num = $j;
break;
}
$j++;
}

for ($i = 0; $i < $j; $i++)
next($columns);

$field = current($columns);
$style = $relation[0] == 'CManyManyRelation' ? 'checkbox' : 'dropdownlist';

if (is_object($field)) {
if ($relation[0] == 'CManyManyRelation')
$allowEmpty = 'false';
elseif ($relation[0] == 'CHasOneRelation') {
$allowEmpty = (CActiveRecord::model($relation[1])->tableSchema->columns[$relation[2]]->allowNull ? 'true' : 'false');
return "if (\$model->{$relationname} !== null) echo \$model->{$relationname}->_label;";
}
else
$allowEmpty= (CActiveRecord::model($model)->tableSchema->columns[$relation[2]]->allowNull?'true':'false');

return("\$this->widget(
'Relation',
array(
'model' => \$model,
'relation' => '{$relationname}',
'fields' => '_label',
'allowEmpty' => {$allowEmpty},
'style' => '{$style}',
'htmlOptions' => array(
'checkAll' => Yii::t('app', 'Choose all'),
),)
)");
}
}
}

/**
* @param CActiveRecord $modelClass
* @param CDbColumnSchema $column
*/
/* public function generateActiveField($model, $column) {
if (!is_object($model))
$model = CActiveRecord::model($model);
$providerPaths = Yii::app()->controller->module->params['gtc.fullCrud.providers'];
$providerPaths[] = 'ext.gtc.fullCrud.providers.FullCrudFieldProvider';
$field = null;
foreach($providerPaths AS $provider) {
$providerClass = Yii::createComponent($provider);
if (($field = $providerClass::generateActiveField($model, $column)) !== null)
break;
}
if ($field !== null) {
return $field;
} else {
return('echo ' . parent::generateActiveField($model, $column));
}
} */

/**
* @param CActiveRecord $modelClass
* @param CDbColumnSchema $column
*/
public function generateValueField($modelClass, $column, $view = false) {
if ($column->isForeignKey) {

$model = CActiveRecord::model($modelClass);
$table = $model->getTableSchema();
$fk = $table->foreignKeys[$column->name];

// We have to look into relations to find the correct model class (i.e. if models are generated with table prefix)
// TODO: do not repeat yourself (foreach) - this is a hotfix
foreach ($model->relations() as $key => $value) {
if (strcasecmp($value[2], $column->name) == 0)
$relation = $value;
}
$fmodel = CActiveRecord::model($relation[1]);
$fmodelName = $relation[1];

$modelTable = ucfirst($fmodel->tableName());
$fcolumns = $fmodel->attributeNames();

if (method_exists($fmodel,'get_label')) {
$fcolumns[1] = "_label";
}

//$rel = $model->getActiveRelation($column->name);
$relname = strtolower($fk[0]);
foreach ($model->relations() as $key => $value) {
if (strcasecmp($value[2], $column->name) == 0)
$relname = $key;
}
//return("\$model->{$relname}->{$fcolumns[1]}");
//return("CHtml::value(\$model,\"{$relname}.{$fcolumns[1]}\")");
//return("{$relname}.{$fcolumns[1]}");
if ($view === true) {
return "array(
'name'=>'{$column->name}',
'value'=>CHtml::value(\$model,'{$relname}.{$fcolumns[1]}'),
)";
} elseif ($view == 'search')
return "\$form->dropDownList(\$model,'{$column->name}',CHtml::listData({$fmodelName}::model()->findAll(), '{$fmodel->getTableSchema()->primaryKey}', '{$fcolumns[1]}'),array('prompt'=>Yii::t('app', 'All')))";
else
return "array(
'name'=>'{$column->name}',
'value'=>'CHtml::value(\$data,\\'{$relname}.{$fcolumns[1]}\\')',
'filter'=>CHtml::listData({$fmodelName}::model()->findAll(), '{$fcolumns[0]}', '{$fcolumns[1]}'),
)";
//{$relname}.{$fcolumns[1]}
} else if (strtoupper($column->dbType) == 'BOOLEAN'
or strtoupper($column->dbType) == 'TINYINT(1)' or
strtoupper($column->dbType) == 'BIT') {
if ($view) {
return "array(
'name'=>'{$column->name}',
'value'=>\$model->{$column->name}?Yii::t('app', 'Yes'):Yii::t('app', 'No'),
)";
} else
return "array(
'name'=>'{$column->name}',
'value'=>'\$data->{$column->name}?Yii::t(\\'app\\',\\'Yes\\'):Yii::t(\\'app\\', \\'No\\')',
'filter'=>array('0'=>Yii::t('app','No'),'1'=>Yii::t('app','Yes')),
)";
} else if($column->name == 'createtime'
or $column->name == 'updatetime'
or $column->name == 'timestamp')
{
return "array(
'name'=>'{$column->name}',
'value' =>'date(\"Y. m. d G:i:s\", \$data->{$column->name})')";
} else {
return("'" . $column->name . "'");
}
}

public function generateDateField() {

}

public function resolveController($relation) {
$model = new $relation[1];
$reflection = new ReflectionClass($model);
$module = preg_match("/\/modules\/([a-zA-Z0-9]+)\//", $reflection->getFileName(), $matches);
$modulePrefix = (isset($matches[$module])) ? "/" . $matches[$module] . "/" : "/";
$controller = $modulePrefix . strtolower(substr($relation[1], 0, 1)) . substr($relation[1], 1);
return $controller;
}

static public function generateActiveField($model, $column) {
die();
if (strtoupper($column->dbType) == 'TINYINT(1)'
|| strtoupper($column->dbType) == 'BIT'
|| strtoupper($column->dbType) == 'BOOL'
|| strtoupper($column->dbType) == 'BOOLEAN') {
return "echo \$form->checkBox(\$model,'{$column->name}')";
} else if (strtoupper($column->dbType) == 'DATE') {
$modelname = get_class($model);
} else if (substr(strtoupper($column->dbType), 0, 4) == 'ENUM') {
$string = sprintf("echo CHtml::activeDropDownList(\$model, '%s', array(\n", $column->name);

$enum_values = explode(',', substr($column->dbType, 4, strlen($column->dbType) - 1));

foreach ($enum_values as $value) {
$value = trim($value, "()'");
$string .= "\t\t\t'$value' => Yii::t('app', '" . $value . "') ,\n";
}
$string .= '))';

return $string;
} else {
return null;
}
}

public function generateRelation($model, $relationname, $relation) {
// Use the second attribute of the model, since the first is the id in
// most cases
//
// TODO: remove code, done via _label
if ($columns = CActiveRecord::model($relation[1])->tableSchema->columns) {
$j = 0;
foreach ($columns as $column) {
if (!$column->isForeignKey && !$column->isPrimaryKey) {
$num = $j;
break;
}
$j++;
}

for ($i = 0; $i < $j; $i++)
next($columns);

$field = current($columns);
$style = $relation[0] == 'CManyManyRelation' ? 'checkbox' : 'dropdownlist';

if (is_object($field)) {
if ($relation[0] == 'CManyManyRelation')
$allowEmpty = 'false';
elseif ($relation[0] == 'CHasOneRelation') {
$allowEmpty = (CActiveRecord::model($relation[1])->tableSchema->columns[$relation[2]]->allowNull ? 'true' : 'false');
return "if (\$model->{$relationname} !== null) echo \$model->{$relationname}->_label;";
}
else
$allowEmpty = (CActiveRecord::model($model)->tableSchema->columns[$relation[2]]->allowNull ? 'true' : 'false');

return("\$this->widget(
'Relation',
array(
'model' => \$model,
'relation' => '{$relationname}',
'fields' => '_label',
'allowEmpty' => {$allowEmpty},
'style' => '{$style}',
'htmlOptions' => array(
'checkAll' => Yii::t('app', 'Choose all'),
),)
)");
}
}
}

/**
* @param CActiveRecord $modelClass
* @param CDbColumnSchema $column
*/
/* public function generateActiveField($model, $column) {
if (!is_object($model))
$model = CActiveRecord::model($model);
$providerPaths = Yii::app()->controller->module->params['gtc.fullCrud.providers'];
$providerPaths[] = 'ext.gtc.fullCrud.providers.FullCrudFieldProvider';
$field = null;
foreach($providerPaths AS $provider) {
$providerClass = Yii::createComponent($provider);
if (($field = $providerClass::generateActiveField($model, $column)) !== null)
break;
}
if ($field !== null) {
return $field;
} else {
return('echo ' . parent::generateActiveField($model, $column));
}
} */

/**
* @param CActiveRecord $modelClass
* @param CDbColumnSchema $column
*/
public function generateValueField($modelClass, $column, $view = false) {
if ($column->isForeignKey) {

$model = CActiveRecord::model($modelClass);
$table = $model->getTableSchema();
$fk = $table->foreignKeys[$column->name];

// We have to look into relations to find the correct model class (i.e. if models are generated with table prefix)
// TODO: do not repeat yourself (foreach) - this is a hotfix
foreach ($model->relations() as $key => $value) {
if (strcasecmp($value[2], $column->name) == 0)
$relation = $value;
}
$fmodel = CActiveRecord::model($relation[1]);
$fmodelName = $relation[1];

$modelTable = ucfirst($fmodel->tableName());
$fcolumns = $fmodel->attributeNames();

if (method_exists($fmodel, 'get_label')) {
$fcolumns[1] = "_label";
}

//$rel = $model->getActiveRelation($column->name);
$relname = strtolower($fk[0]);
foreach ($model->relations() as $key => $value) {
if (strcasecmp($value[2], $column->name) == 0)
$relname = $key;
}
//return("\$model->{$relname}->{$fcolumns[1]}");
//return("CHtml::value(\$model,\"{$relname}.{$fcolumns[1]}\")");
//return("{$relname}.{$fcolumns[1]}");
if ($view === true) {
return "array(
'name'=>'{$column->name}',
'value'=>CHtml::value(\$model,'{$relname}.{$fcolumns[1]}'),
)";
} elseif ($view == 'search')
return "\$form->dropDownList(\$model,'{$column->name}',CHtml::listData({$fmodelName}::model()->findAll(), '{$fmodel->getTableSchema()->primaryKey}', '{$fcolumns[1]}'),array('prompt'=>Yii::t('app', 'All')))";
else
return "array(
'name'=>'{$column->name}',
'value'=>'CHtml::value(\$data,\\'{$relname}.{$fcolumns[1]}\\')',
'filter'=>CHtml::listData({$fmodelName}::model()->findAll(), '{$fcolumns[0]}', '{$fcolumns[1]}'),
)";
//{$relname}.{$fcolumns[1]}
} else if (strtoupper($column->dbType) == 'BOOLEAN'
or strtoupper($column->dbType) == 'TINYINT(1)' or
strtoupper($column->dbType) == 'BIT') {
if ($view) {
return "array(
'name'=>'{$column->name}',
'value'=>\$model->{$column->name}?Yii::t('app', 'Yes'):Yii::t('app', 'No'),
)";
} else
return "array(
'name'=>'{$column->name}',
'value'=>'\$data->{$column->name}?Yii::t(\\'app\\',\\'Yes\\'):Yii::t(\\'app\\', \\'No\\')',
'filter'=>array('0'=>Yii::t('app','No'),'1'=>Yii::t('app','Yes')),
)";
} else if ($column->name == 'createtime'
or $column->name == 'updatetime'
or $column->name == 'timestamp') {
return "array(
'name'=>'{$column->name}',
'value' =>'date(\"Y. m. d G:i:s\", \$data->{$column->name})')";
} else {
return("'" . $column->name . "'");
}
}

}

@@ -5,83 +5,83 @@
Yii::import('ext.gtc.fullCrud.CodeProvider');

class FullCrudCode extends CrudCode {
// validation method; 0 = none, 1 = ajax, 2 = client-side, 3 = both
public $validation = 3;
public $identificationColumn = null;
public $baseControllerClass='Controller';
public $codeProvider;
// validation method; 0 = none, 1 = ajax, 2 = client-side, 3 = both
public $validation = 3;
public $identificationColumn = null;
public $baseControllerClass='Controller';
public $codeProvider;

public function prepare() {
$this->codeProvider = new CodeProvider;
if(!$this->identificationColumn)
$this->identificationColumn = $this->tableSchema->primaryKey;
public function prepare() {
$this->codeProvider = new CodeProvider;
if(!$this->identificationColumn)
$this->identificationColumn = $this->tableSchema->primaryKey;

if(!array_key_exists(
$this->identificationColumn, $this->tableSchema->columns))
$this->addError('identificationColumn', 'The specified column can not be found in the models attributes. <br /> Please specify a valid attribute. If unsure, leave the field empty.');
parent::prepare();
}
if(!array_key_exists(
$this->identificationColumn, $this->tableSchema->columns))
$this->addError('identificationColumn', 'The specified column can not be found in the models attributes. <br /> Please specify a valid attribute. If unsure, leave the field empty.');
parent::prepare();
}

public function rules()
{
return array_merge(parent::rules(), array(
array('validation', 'required'),
array('identificationColumn', 'safe'),
));
}
public function rules()
{
return array_merge(parent::rules(), array(
array('validation', 'required'),
array('identificationColumn', 'safe'),
));
}

public function validateModel($attribute,$params)
{
// check your import paths, if you get an error here
// PHP error can't be catched as an exception
if($this->model)
Yii::import($this->model, true);
parent::validateModel($attribute,$params);
}
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), array(
'validation'=>'Validation method',
));
}
public function validateModel($attribute,$params)
{
// check your import paths, if you get an error here
// PHP error can't be catched as an exception
if($this->model)
Yii::import($this->model, true);
parent::validateModel($attribute,$params);
}
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), array(
'validation'=>'Validation method',
));
}

public function init() {
parent::init();
}
public function init() {
parent::init();
}

// Which column will most probably be the one that gets used to list
// a model ? It may be the first non-numeric column.
public function suggestName($columns) {
$j = 0;
foreach ($columns as $column) {
if (!$column->isForeignKey
&& !$column->isPrimaryKey
&& $column->type != 'INT'
&& $column->type != 'INTEGER'
&& $column->type != 'BOOLEAN') {
$num = $j;
break;
}
$j++;
}
// Which column will most probably be the one that gets used to list
// a model ? It may be the first non-numeric column.
public function suggestName($columns) {
$j = 0;
foreach ($columns as $column) {
if (!$column->isForeignKey
&& !$column->isPrimaryKey
&& $column->type != 'INT'
&& $column->type != 'INTEGER'
&& $column->type != 'BOOLEAN') {
$num = $j;
break;
}
$j++;
}

for ($i = 0; $i < $j; $i++)
next($columns);
for ($i = 0; $i < $j; $i++)
next($columns);

if (is_object(current($columns)))
return current($columns);
else {
$column = reset($columns);
return $column;
}
}
if (is_object(current($columns)))
return current($columns);
else {
$column = reset($columns);
return $column;
}
}

public function getRelations() {
return CActiveRecord::model($this->modelClass)->relations();
}
public function getRelations() {
return CActiveRecord::model($this->modelClass)->relations();
}

}

?>
@@ -2,70 +2,70 @@

class FullCrudGenerator extends CCodeGenerator {

public $codeModel = 'ext.gtc.fullCrud.FullCrudCode';
public $codeModel = 'ext.gtc.fullCrud.FullCrudCode';

/**
* Returns the model names and, if possible, the attributes in an array.
* Only non abstract and superclasses of CActiveRecord models are returned.
* The array is used to build the autocomplete field and the
* list of possible columns in the FullCrud form.
* @return array key = names and value = attributes of the models
*/
protected function getModels() {
$models = array();
$aliases = array();
$aliases[] = 'application.models';
foreach (Yii::app()->getModules() as $moduleName => $config) {
if($moduleName != 'gii')
$aliases[] = $moduleName . ".models";
}
/**
* Returns the model names and, if possible, the attributes in an array.
* Only non abstract and superclasses of CActiveRecord models are returned.
* The array is used to build the autocomplete field and the
* list of possible columns in the FullCrud form.
* @return array key = names and value = attributes of the models
*/
protected function getModels() {
$models = array();
$aliases = array();
$aliases[] = 'application.models';
foreach (Yii::app()->getModules() as $moduleName => $config) {
if($moduleName != 'gii')
$aliases[] = $moduleName . ".models";
}

foreach ($aliases as $alias) {
if (!is_dir(Yii::getPathOfAlias($alias))) continue;
$files = scandir(Yii::getPathOfAlias($alias));
Yii::import($alias.".*");
foreach ($files as $file) {
if ($fileClassName = $this->checkFile($file, $alias)) {
$classname = sprintf('%s.%s',$alias,$fileClassName);
Yii::import($classname);
try {
$model = @new $fileClassName;
if(is_object($model) && $model->getMetaData())
$models[$classname] = $model->attributes;
else
$models[$classname] = array();
} catch (ErrorException $e) {
break;
} catch (CDbException $e) {
break;
} catch (Exception $e) {
break;
}
}
}
}
foreach ($aliases as $alias) {
if (!is_dir(Yii::getPathOfAlias($alias))) continue;
$files = scandir(Yii::getPathOfAlias($alias));
Yii::import($alias.".*");
foreach ($files as $file) {
if ($fileClassName = $this->checkFile($file, $alias)) {
$classname = sprintf('%s.%s',$alias,$fileClassName);
Yii::import($classname);
try {
$model = @new $fileClassName;
if(is_object($model) && $model->getMetaData())
$models[$classname] = $model->attributes;
else
$models[$classname] = array();
} catch (ErrorException $e) {
break;
} catch (CDbException $e) {
break;
} catch (Exception $e) {
break;
}
}
}
}

return $models;
}
return $models;
}

private function checkFile($file, $alias = '') {
if (substr($file, 0, 1) !== '.'
&& substr($file, 0, 2) !== '..'
&& substr($file, 0, 4) !== 'Base'
&& $file != 'GActiveRecord'
&& strtolower(substr($file, -4)) === '.php') {
$fileClassName = substr($file, 0, strpos($file, '.'));
if (class_exists($fileClassName)
&& is_subclass_of($fileClassName, 'CActiveRecord')) {
$fileClass = new ReflectionClass($fileClassName);
if ($fileClass->isAbstract())
return null;
else
return $models[] = $fileClassName;
}
}
}
private function checkFile($file, $alias = '') {
if (substr($file, 0, 1) !== '.'
&& substr($file, 0, 2) !== '..'
&& substr($file, 0, 4) !== 'Base'
&& $file != 'GActiveRecord'
&& strtolower(substr($file, -4)) === '.php') {
$fileClassName = substr($file, 0, strpos($file, '.'));
if (class_exists($fileClassName)
&& is_subclass_of($fileClassName, 'CActiveRecord')) {
$fileClass = new ReflectionClass($fileClassName);
if ($fileClass->isAbstract())
return null;
else
return $models[] = $fileClassName;
}
}
}

}

?>
?>

This file was deleted.

@@ -37,19 +37,19 @@
$model = new $this->modelClass;
echo "<ul>";
foreach ($model->relations() AS $key => $relation) {
echo "<li>" .
Yii::t("app", substr(str_replace("Relation", "", $relation[0]), 1)) . " " .
CHtml::link(Yii::t("app", $relation[1]), array($this->codeProvider->resolveController($relation) . '/admin')) . // TODO: render dynamic links
" </li>";
echo "<li>" .
Yii::t("app", substr(str_replace("Relation", "", $relation[0]), 1)) . " " .
CHtml::link(Yii::t("app", $relation[1]), array($this->codeProvider->resolveController($relation) . '/admin')) . // TODO: render dynamic links
" </li>";
}
echo "</ul>";
?>


<?php echo "<?php echo CHtml::link(Yii::t('app', 'Advanced Search'),'#',array('class'=>'search-button')); ?>"; ?>
<div class="search-form" style="display:none">
<?php echo "<?php \$this->renderPartial('_search',array(
'model'=>\$model,
<div class="search-form" style="display: none">
<?php echo "<?php \$this->renderPartial('_search',array(
'model'=>\$model,
)); ?>\n"; ?>
</div>

@@ -64,16 +64,16 @@
<?php
$count = 0;
foreach ($this->tableSchema->columns as $column) {
if (++$count == 7)
echo "\t\t/*\n";
if (++$count == 7)
echo " /*\n";

if (strtoupper($column->dbType) == 'TEXT')
echo "#";
echo "\t\t" . $this->codeProvider->generateValueField($this->modelClass, $column) . ",\n";
if (strtoupper($column->dbType) == 'TEXT')
echo "#";
echo " " . $this->codeProvider->generateValueField($this->modelClass, $column) . ",\n";
}

if ($count >= 7)
echo "\t\t*/\n";
echo " */\n";
?>

array(
@@ -2,17 +2,13 @@

class <?php echo $this->controllerClass; ?> extends <?php echo $this->baseControllerClass."\n"; ?>
{
public $layout='//layouts/column2';

public function filters()
{
public function filters() {
return array(
'accessControl',
);
}

public function accessRules()
{
public function accessRules() {
return array(
array('allow',
'actions'=>array('index','view'),
@@ -23,7 +19,7 @@ public function accessRules()
'users'=>array('@'),
),
array('allow',
'actions'=>array('admin','delete'),
'actions'=>array('*'),
'users'=>array('admin'),
),
array('deny',
@@ -32,7 +28,7 @@ public function accessRules()
);
}

public function beforeAction($action){
public function beforeAction($action) {
parent::beforeAction($action);
// map identifcationColumn to id
if (!isset($_GET['id']) && isset($_GET['<?php echo $this->identificationColumn; ?>'])) {
@@ -50,16 +46,14 @@ public function beforeAction($action){
return true;
}

public function actionView($id)
{
public function actionView($id) {
$model = $this->loadModel($id);
$this->render('view',array(
'model' => $model,
));
}

public function actionCreate()
{
public function actionCreate() {
$model = new <?php echo $this->modelClass; ?>;

<?php if($this->validation == 1 || $this->validation == 3) { ?>
@@ -99,8 +93,7 @@ public function actionCreate()
}


public function actionUpdate($id)
{
public function actionUpdate($id) {
$model = $this->loadModel($id);

<?php if($this->validation == 1 || $this->validation == 3) { ?>
@@ -142,8 +135,7 @@ public function actionUpdate($id)
));
}

public function actionDelete($id)
{
public function actionDelete($id) {
if(Yii::app()->request->isPostRequest)
{
try {
@@ -162,16 +154,14 @@ public function actionDelete($id)
Yii::t('app', 'Invalid request. Please do not repeat this request again.'));
}

public function actionIndex()
{
public function actionIndex() {
$dataProvider=new CActiveDataProvider('<?php echo $this->modelClass; ?>');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

public function actionAdmin()
{
public function actionAdmin() {
$model=new <?php echo $this->modelClass; ?>('search');
$model->unsetAttributes();

@@ -183,20 +173,11 @@ public function actionAdmin()
));
}

public function loadModel($id)
{
public function loadModel($id) {
$model=<?php echo $this->modelClass; ?>::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,Yii::t('app', 'The requested page does not exist.'));
return $model;
}

protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($this->modelClass); ?>-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}

This file was deleted.

@@ -0,0 +1,28 @@
<?php

class NewsModule extends CWebModule
{
public function init()
{
// this method is called when the module is being created
// you may place code here to customize the module or the application

// import the module-level models and components
$this->setImport(array(
'news.models.*',
'news.components.*',
));
}

public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}
}
@@ -0,0 +1,9 @@
<?php

class DefaultController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
}
@@ -0,0 +1,176 @@
<?php

class NewsController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new News;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['News']))
{
$model->attributes=$_POST['News'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['News']))
{
$model->attributes=$_POST['News'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('update',array(
'model'=>$model,
));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('News');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new News('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['News']))
$model->attributes=$_GET['News'];

$this->render('admin',array(
'model'=>$model,
));
}

/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=News::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='news-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
@@ -0,0 +1,93 @@
<?php

/**
* This is the model class for table "news".
*
* The followings are the available columns in table 'news':
* @property integer $id
* @property string $title
* @property string $content
* @property integer $user_id
*/
class News extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return News the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}

/**
* @return string the associated database table name
*/
public function tableName()
{
return 'news';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title, content, user_id', 'required'),
array('user_id', 'numerical', 'integerOnly'=>true),
array('title', 'length', 'max'=>255),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, title, content, user_id', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'title' => 'Title',
'content' => 'Content',
'user_id' => 'User',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title,true);
$criteria->compare('content',$this->content,true);
$criteria->compare('user_id',$this->user_id);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
@@ -0,0 +1,15 @@
<?php
$this->breadcrumbs=array(
$this->module->id,
);
?>
<h1><?php echo $this->uniqueId . '/' . $this->action->id; ?></h1>

<p>
This is the view content for action "<?php echo $this->action->id; ?>".
The action belongs to the controller "<?php echo get_class($this); ?>"
in the "<?php echo $this->module->id; ?>" module.
</p>
<p>
You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
</p>
@@ -0,0 +1,36 @@
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'news-form',
'enableAjaxValidation'=>false,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'title'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'content'); ?>
<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'content'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->textField($model,'user_id'); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
@@ -0,0 +1,34 @@
<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>

<div class="row">
<?php echo $form->label($model,'id'); ?>
<?php echo $form->textField($model,'id'); ?>
</div>

<div class="row">
<?php echo $form->label($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
</div>

<div class="row">
<?php echo $form->label($model,'content'); ?>
<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
</div>

<div class="row">
<?php echo $form->label($model,'user_id'); ?>
<?php echo $form->textField($model,'user_id'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton('Search'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->
@@ -0,0 +1,20 @@
<div class="view">

<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('title')); ?>:</b>
<?php echo CHtml::encode($data->title); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('content')); ?>:</b>
<?php echo CHtml::encode($data->content); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('user_id')); ?>:</b>
<?php echo CHtml::encode($data->user_id); ?>
<br />


</div>
@@ -0,0 +1,53 @@
<?php
$this->breadcrumbs=array(
'News'=>array('index'),
'Manage',
);

$this->menu=array(
array('label'=>'List News', 'url'=>array('index')),
array('label'=>'Create News', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('news-grid', {
data: $(this).serialize()
});
return false;
});
");
?>

<h1>Manage News</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'news-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'title',
'content',
'user_id',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
@@ -0,0 +1,15 @@
<?php
$this->breadcrumbs=array(
'News'=>array('index'),
'Create',
);

$this->menu=array(
array('label'=>'List News', 'url'=>array('index')),
array('label'=>'Manage News', 'url'=>array('admin')),
);
?>

<h1>Create News</h1>

<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
@@ -0,0 +1,17 @@
<?php
$this->breadcrumbs=array(
'News',
);

$this->menu=array(
array('label'=>'Create News', 'url'=>array('create')),
array('label'=>'Manage News', 'url'=>array('admin')),
);
?>

<h1>News</h1>

<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
@@ -0,0 +1,18 @@
<?php
$this->breadcrumbs=array(
'News'=>array('index'),
$model->title=>array('view','id'=>$model->id),
'Update',
);

$this->menu=array(
array('label'=>'List News', 'url'=>array('index')),
array('label'=>'Create News', 'url'=>array('create')),
array('label'=>'View News', 'url'=>array('view', 'id'=>$model->id)),
array('label'=>'Manage News', 'url'=>array('admin')),
);
?>

<h1>Update News <?php echo $model->id; ?></h1>

<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
@@ -0,0 +1,26 @@
<?php
$this->breadcrumbs=array(
'News'=>array('index'),
$model->title,
);

$this->menu=array(
array('label'=>'List News', 'url'=>array('index')),
array('label'=>'Create News', 'url'=>array('create')),
array('label'=>'Update News', 'url'=>array('update', 'id'=>$model->id)),
array('label'=>'Delete News', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
array('label'=>'Manage News', 'url'=>array('admin')),
);
?>

<h1>View News #<?php echo $model->id; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'title',
'content',
'user_id',
),
)); ?>
@@ -62,7 +62,8 @@ public function actionCreate()
{
$model = new Page;


$this->performAjaxValidation($model, 'page-form');

if(isset($_POST['Page'])) {
$model->attributes = $_POST['Page'];

@@ -89,6 +90,7 @@ public function actionUpdate($id)
{
$model = $this->loadModel($id);

$this->performAjaxValidation($model, 'page-form');

if(isset($_POST['Page']))
{
@@ -161,4 +163,13 @@ public function loadModel($id)
throw new CHttpException(404,Yii::t('app', 'The requested page does not exist.'));
return $model;
}

protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='page-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
@@ -6,7 +6,7 @@
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'page-form',
'enableAjaxValidation'=>false,
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
));

@@ -28,9 +28,9 @@

<ul></ul>

<?php echo CHtml::link(Yii::t('app', 'Advanced Search'),'#',array('class'=>'search-button')); ?><div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
<?php echo CHtml::link(Yii::t('app', 'Advanced Search'),'#',array('class'=>'search-button')); ?><div class="search-form" style="display: none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div>

@@ -41,27 +41,27 @@
'filter'=>$model,
'columns'=>array(

'id',
'user_id',
# 'title',
'content',
'status',
'created_at',
/*
'modified_at',
'parent',
'order',
'type',
'comment_status',
array(
'name'=>'tags_enabled',
'value'=>'$data->tags_enabled?Yii::t(\'app\',\'Yes\'):Yii::t(\'app\', \'No\')',
'filter'=>array('0'=>Yii::t('app','No'),'1'=>Yii::t('app','Yes')),
),
'permission',
'password',
'views',
*/
'id',
'user_id',
# 'title',
'content',
'status',
'created_at',
/*
'modified_at',
'parent',
'order',
'type',
'comment_status',
array(
'name'=>'tags_enabled',
'value'=>'$data->tags_enabled?Yii::t(\'app\',\'Yes\'):Yii::t(\'app\', \'No\')',
'filter'=>array('0'=>Yii::t('app','No'),'1'=>Yii::t('app','Yes')),
),
'permission',
'password',
'views',
*/

array(
'class'=>'CButtonColumn',

This file was deleted.

Large diffs are not rendered by default.