Commit cdd6c0cc authored by Fredy Nurman Saleh's avatar Fredy Nurman Saleh

fixing indent & comply PSR-2

parent 2c98af20
...@@ -392,8 +392,8 @@ class Generator extends \yii\gii\generators\crud\Generator ...@@ -392,8 +392,8 @@ class Generator extends \yii\gii\generators\crud\Generator
FileHelper::createDirectory($tmpDir); FileHelper::createDirectory($tmpDir);
$tmpFile = $tmpDir.'/'.md5($template); $tmpFile = $tmpDir.'/'.md5($template);
file_put_contents($tmpFile, $code); file_put_contents($tmpFile, $code);
$command = Yii::getAlias('@vendor/bin/phptidy').' replace '.$tmpFile;
shell_exec('..'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'phptidy replace '.$tmpFile); shell_exec($command);
return file_get_contents($tmpFile); return file_get_contents($tmpFile);
} else { } else {
......
...@@ -10,17 +10,16 @@ use yii\helpers\StringHelper; ...@@ -10,17 +10,16 @@ use yii\helpers\StringHelper;
/** @var \yii\db\ActiveRecord $model */ /** @var \yii\db\ActiveRecord $model */
/** @var $generator \schmunk42\giiant\generators\crud\Generator */ /** @var $generator \schmunk42\giiant\generators\crud\Generator */
## TODO: move to generator (?); cleanup ## TODO: move to generator (?); cleanup
$model = new $generator->modelClass(); $model = new $generator->modelClass();
$model->setScenario('crud'); $model->setScenario('crud');
$safeAttributes = $model->safeAttributes(); $safeAttributes = $model->safeAttributes();
if (empty($safeAttributes)) if (empty($safeAttributes)) {
{
$model->setScenario('default'); $model->setScenario('default');
$safeAttributes = $model->safeAttributes(); $safeAttributes = $model->safeAttributes();
} }
if (empty($safeAttributes)) if (empty($safeAttributes)) {
{
$safeAttributes = $model->getTableSchema()->columnNames; $safeAttributes = $model->getTableSchema()->columnNames;
} }
...@@ -108,15 +107,11 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>; ...@@ -108,15 +107,11 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
<?php <?php
foreach ($safeAttributes as $attribute) foreach ($safeAttributes as $attribute) {
{
$format = $generator->attributeFormat($attribute); $format = $generator->attributeFormat($attribute);
if (!$format) if (!$format) {
{
continue; continue;
} } else {
else
{
echo $format.",\n"; echo $format.",\n";
} }
} }
...@@ -128,11 +123,9 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>; ...@@ -128,11 +123,9 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<hr/> <hr/>
<?= '<?= ' ?>Html::a('<span class="glyphicon glyphicon-trash"></span> ' . <?= <?= '<?= ' ?>Html::a('<span class="glyphicon glyphicon-trash"></span> ' . <?= $generator->generateString(
$generator->generateString(
'Delete' 'Delete'
) ) ?>, ['delete', <?= $urlParams ?>],
?>, ['delete', <?= $urlParams ?>],
[ [
'class' => 'btn btn-danger', 'class' => 'btn btn-danger',
'data-confirm' => '' . <?= $generator->generateString('Are you sure to delete this item?') ?> . '', 'data-confirm' => '' . <?= $generator->generateString('Are you sure to delete this item?') ?> . '',
...@@ -141,10 +134,11 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>; ...@@ -141,10 +134,11 @@ $this->params['breadcrumbs'][] = <?= $generator->generateString('View') ?>;
<?= "<?php \$this->endBlock(); ?>\n\n"; ?> <?= "<?php \$this->endBlock(); ?>\n\n"; ?>
<?php <?php
// get relation info $ prepare add button // get relation info $ prepare add button
$model = new $generator->modelClass(); $model = new $generator->modelClass();
$label = substr(strrchr($model::className(), '\\'), 1); $label = substr(strrchr($model::className(), '\\'), 1);
$items = <<<EOS $items = <<<EOS
[ [
'label' => '<b class=""># '.\$model->{$model->primaryKey()[0]}.'</b>', 'label' => '<b class=""># '.\$model->{$model->primaryKey()[0]}.'</b>',
'content' => \$this->blocks['{$label}'], 'content' => \$this->blocks['{$label}'],
...@@ -153,14 +147,12 @@ $items = <<<EOS ...@@ -153,14 +147,12 @@ $items = <<<EOS
EOS; EOS;
foreach ($generator->getModelRelations($generator->modelClass, ['has_many']) as $name => $relation) foreach ($generator->getModelRelations($generator->modelClass, ['has_many']) as $name => $relation) {
{
echo "\n<?php \$this->beginBlock('$name'); ?>\n"; echo "\n<?php \$this->beginBlock('$name'); ?>\n";
$showAllRecords = false; $showAllRecords = false;
if ($relation->via !== null) if ($relation->via !== null) {
{
$pivotName = Inflector::pluralize($generator->getModelByTableName($relation->via->from[0])); $pivotName = Inflector::pluralize($generator->getModelByTableName($relation->via->from[0]));
$pivotRelation = $model->{'get'.$pivotName}(); $pivotRelation = $model->{'get'.$pivotName}();
$pivotPk = key($pivotRelation->link); $pivotPk = key($pivotRelation->link);
...@@ -174,9 +166,7 @@ EOS; ...@@ -174,9 +166,7 @@ EOS;
)."'=>\$model->{$model->primaryKey()[0]}]], )."'=>\$model->{$model->primaryKey()[0]}]],
['class'=>'btn btn-info btn-xs'] ['class'=>'btn btn-info btn-xs']
) ?>\n"; ) ?>\n";
} } else {
else
{
$addButton = ''; $addButton = '';
} }
...@@ -201,14 +191,11 @@ EOS; ...@@ -201,14 +191,11 @@ EOS;
echo "</div>\n</div>\n"; #<div class='clearfix'></div>\n"; echo "</div>\n</div>\n"; #<div class='clearfix'></div>\n";
// render pivot grid // render pivot grid
if ($relation->via !== null) if ($relation->via !== null) {
{
$pjaxId = "pjax-{$pivotName}"; $pjaxId = "pjax-{$pivotName}";
$gridRelation = $pivotRelation; $gridRelation = $pivotRelation;
$gridName = $pivotName; $gridName = $pivotName;
} } else {
else
{
$pjaxId = "pjax-{$name}"; $pjaxId = "pjax-{$name}";
$gridRelation = $relation; $gridRelation = $relation;
$gridName = $name; $gridName = $name;
...@@ -238,7 +225,7 @@ EOS; ...@@ -238,7 +225,7 @@ EOS;
?> ?>
<?= <?=
// render tabs // render tabs
"<?= Tabs::widget( "<?= Tabs::widget(
[ [
'id' => 'relation-tabs', 'id' => 'relation-tabs',
...@@ -247,6 +234,6 @@ EOS; ...@@ -247,6 +234,6 @@ EOS;
] ]
); );
?>"; ?>";
?> ?>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment