Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions Console/Templates/boost3/actions/controller_actions.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* <?php echo $admin ?>index method
*
* @return void
*/
public function <?php echo $admin ?>index() {
$this-><?php echo $currentModelName ?>->recursive = 0;
$this->set('<?php echo $pluralName ?>', $this->Paginator->paginate());
}

/**
* <?php echo $admin ?>view method
*
* @param string $id
* @return void
*/
public function <?php echo $admin ?>view($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
throw new NotFoundException(__('Invalid %s', __('<?php echo strtolower($singularHumanName); ?>')));
}
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
}

<?php $compact = array(); ?>
/**
* <?php echo $admin ?>add method
*
* @return void
*/
public function <?php echo $admin ?>add() {
if ($this->request->is('post')) {
$this-><?php echo $currentModelName; ?>->create();
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s has been saved', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-success'
)
);
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('%s saved.', __('<?php echo ucfirst(strtolower($currentModelName)); ?>')), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s could not be saved. Please, try again.', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-error'
)
);
<?php endif; ?>
}
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
foreach ($modelObj->{$assoc} as $associationName => $relation):
if (!empty($associationName)):
$otherModelName = $this->_modelName($associationName);
$otherPluralName = $this->_pluralName($associationName);
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
$compact[] = "'{$otherPluralName}'";
endif;
endforeach;
endforeach;
if (!empty($compact)):
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
endif;
?>
}

<?php $compact = array(); ?>
/**
* <?php echo $admin ?>edit method
*
* @param string $id
* @return void
*/
public function <?php echo $admin; ?>edit($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
throw new NotFoundException(__('Invalid %s', __('<?php echo strtolower($singularHumanName); ?>')));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s has been saved', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-success'
)
);
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('The %s has been saved.', __('<?php echo strtolower($singularHumanName); ?>')), array('action' => 'index'));
<?php endif; ?>
} else {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s could not be saved. Please, try again.', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-error'
)
);
<?php endif; ?>
}
} else {
$this->request->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
foreach ($modelObj->{$assoc} as $associationName => $relation):
if (!empty($associationName)):
$otherModelName = $this->_modelName($associationName);
$otherPluralName = $this->_pluralName($associationName);
echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
$compact[] = "'{$otherPluralName}'";
endif;
endforeach;
endforeach;
if (!empty($compact)):
echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
endif;
?>
}

/**
* <?php echo $admin ?>delete method
*
* @param string $id
* @return void
*/
public function <?php echo $admin; ?>delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
throw new NotFoundException(__('Invalid %s', __('<?php echo strtolower($singularHumanName); ?>')));
}
if ($this-><?php echo $currentModelName; ?>->delete()) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s deleted', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-success'
)
);
$this->redirect(array('action' => 'index'));
<?php else: ?>
$this->flash(__('%s deleted', __('<?php echo ucfirst(strtolower($singularHumanName)); ?>')), array('action' => 'index'));
<?php endif; ?>
}
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(
__('The %s was not deleted', __('<?php echo strtolower($singularHumanName); ?>')),
'alert',
array(
'plugin' => 'BoostCake',
'class' => 'alert-error'
)
);
<?php else: ?>
$this->flash(__('%s was not deleted', __('<?php echo ucfirst(strtolower($singularHumanName)); ?>')), array('action' => 'index'));
<?php endif; ?>
$this->redirect(array('action' => 'index'));
}
67 changes: 67 additions & 0 deletions Console/Templates/boost3/classes/controller.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
echo "<?php\n";
echo "App::uses('{$plugin}AppController', '{$pluginPath}Controller');\n";
?>
/**
* <?php echo $controllerName; ?> Controller
*
<?php
if (!is_array($components) || (count($components) == 1 && $components[0] == 'Paginator')) {
$components = array();
}
if (!$isScaffold) {
$defaultModel = Inflector::singularize($controllerName);
echo " * @property {$defaultModel} \${$defaultModel}\n";
if (!empty($components)) {
foreach ($components as $component) {
echo " * @property {$component}Component \${$component}\n";
}
}
}
?>
*/
class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {

<?php if ($isScaffold): ?>
/**
* Scaffold
*
* @var mixed
*/
public $scaffold;
<?php else: ?>
<?php
if (!is_array($helpers)) {
$helpers = array();
}
if (count($helpers)):
echo "/**\n * Helpers\n *\n * @var array\n */\n";
echo "\tpublic \$helpers = array(";
for ($i = 0, $len = count($helpers); $i < $len; $i++):
if ($i != $len - 1):
echo "'" . Inflector::camelize($helpers[$i]) . "', ";
else:
echo "'" . Inflector::camelize($helpers[$i]) . "'";
endif;
endfor;
echo ");\n";
endif;

if (count($components)):
echo "/**\n * Components\n *\n * @var array\n */\n";
echo "\tpublic \$components = array(";
for ($i = 0, $len = count($components); $i < $len; $i++):
if ($i != $len - 1):
echo "'" . Inflector::camelize($components[$i]) . "', ";
else:
echo "'" . Inflector::camelize($components[$i]) . "'";
endif;
endfor;
echo ");\n";
endif;

echo $actions;

endif; ?>

}
82 changes: 82 additions & 0 deletions Console/Templates/boost3/views/form.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<div class="row">
<div class="col-md-9">
<?="<?=\$this->Form->create('{$modelClass}', array(
'class' => 'form-horizontal',
'inputDefaults' => array(
'label' => array(
'class' => 'col-md-3 control-label',
),
'div' => array(
'class' => 'form-group',
),
'wrapInput' => array(
'class' => 'col-md-9'
),
'class' => 'form-control'
)
));
?>"; ?>
<fieldset>
<legend><?="<?=__('" . Inflector::humanize($action) . " %s', __('" . $singularHumanName . "')); ?>"; ?></legend>
<?php
echo "\t\t\t\t<?php\n";
$id = null;
foreach ($fields as $field) {
if (strpos($action, 'add') !== false && $field == $primaryKey) {
continue;
} elseif (!in_array($field, array('created', 'modified', 'updated'))) {
if ($field == $primaryKey) {
$id = "\t\t\t\techo \$this->Form->hidden('{$field}');\n";
} else {
if ($this->templateVars['schema'][$field]['null'] == false) {
$required = ", array(\n\t\t\t\t\t'required' => 'required',\n\t\t\t\t\t'afterInput' => '<span class=\"help-block\"><span class=\"text-danger\">' . __('Required') . '</span></span>&nbsp;')\n\t\t\t\t";
} else {
$required = null;
}
echo "\t\t\t\techo \$this->Form->input('{$field}'{$required});\n";
}
}
}
echo $id;
unset($id);
if (!empty($associations['hasAndBelongsToMany'])) {
foreach ($associations['hasAndBelongsToMany'] as $assocName => $assocData) {
echo "\t\t\t\techo \$this->Form->input('{$assocName}');\n";
}
}
echo "\t\t\t\t?>\n";
echo "\t\t\t\t<?=\$this->Form->submit(__('Submit'));?>\n";
?>
</fieldset>
<?php
echo "<?=\$this->Form->end();?>\n";
?>
</div>

<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?= "<?=__('Actions'); ?>"; ?></h3>
</div>

<ul class="list-group">
<? if(strpos($action, 'add') === false): ?>
<li class="list-group-item"><?="<?=\$this->Form->postLink(__('Delete'), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), null, __('Are you sure you want to delete # %s?', \$this->Form->value('{$modelClass}.{$primaryKey}'))); ?>"; ?></li>
<? endif; ?>
<li class="list-group-item"><?="<?=\$this->Html->link(__('List %s', __('" . $pluralHumanName . "')), array('action' => 'index'));?>"; ?></li>
<?php
$done = array();
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t\t<li class=\"list-group-item\"><?=\$this->Html->link(__('List %s', __('" . Inflector::humanize($details['controller']) . "')), array('controller' => '{$details['controller']}', 'action' => 'index')); ?></li>\n";
echo "\t\t\t<li class=\"list-group-item\"><?=\$this->Html->link(__('New %s', __('" . Inflector::humanize(Inflector::underscore($alias)) . "')), array('controller' => '{$details['controller']}', 'action' => 'add')); ?></li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
</div>
</div>
Loading