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
42 changes: 28 additions & 14 deletions Controller/BoostCakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ public function index() {
* @return void
*/
public function bootstrap2() {
$this->Session->setFlash(__('Alert notice message testing...'), 'alert', array(
$this->Flash->set(__('Alert notice message testing...'), [
'key' => 'notice',
'element' => 'alert',
'plugin' => 'BoostCake',
), 'notice');
$this->Session->setFlash(__('Alert success message testing...'), 'alert', array(
]);
$this->Flash->set(__('Alert success message testing...'), [
'key' => 'success',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-success'
), 'success');
$this->Session->setFlash(__('Alert error message testing...'), 'alert', array(
]);
$this->Flash->set(__('Alert error message testing...'), [
'key' => 'error',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-error'
), 'error');
]);
}

/**
Expand All @@ -59,22 +65,30 @@ public function bootstrap2() {
* @return void
*/
public function bootstrap3() {
$this->Session->setFlash(__('Alert success message testing...'), 'alert', array(
$this->Flash->set(__('Alert success message testing...'), [
'key' => 'success',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-success'
), 'success');
$this->Session->setFlash(__('Alert info message testing...'), 'alert', array(
]);
$this->Flash->set(__('Alert info message testing...'), [
'key' => 'info',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-info'
), 'info');
$this->Session->setFlash(__('Alert warning message testing...'), 'alert', array(
]);
$this->Flash->set(__('Alert warning message testing...'), [
'key' => 'warning',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-warning'
), 'warning');
$this->Session->setFlash(__('Alert danger message testing...'), 'alert', array(
]);
$this->Flash->set(__('Alert danger message testing...'), [
'key' => 'danger',
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-danger'
), 'danger');
]);
}

}
6 changes: 3 additions & 3 deletions View/BoostCake/bootstrap2.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
<h2>Alerts</h2>
</div>

<?php echo $this->Session->flash('notice'); ?>
<?php echo $this->Session->flash('success'); ?>
<?php echo $this->Session->flash('error'); ?>
<?php echo $this->Flash->render('notice'); ?>
<?php echo $this->Flash->render('success'); ?>
<?php echo $this->Flash->render('error'); ?>

<pre class="prettyprint"><?php
echo h(file_get_contents(dirname(__DIR__) . '/Elements/bootstrap2/alerts.ctp'));
Expand Down
8 changes: 4 additions & 4 deletions View/BoostCake/bootstrap3.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@
<h2>Alerts</h2>
</div>

<?php echo $this->Session->flash('success'); ?>
<?php echo $this->Session->flash('info'); ?>
<?php echo $this->Session->flash('warning'); ?>
<?php echo $this->Session->flash('danger'); ?>
<?php echo $this->Flash->render('success'); ?>
<?php echo $this->Flash->render('info'); ?>
<?php echo $this->Flash->render('warning'); ?>
<?php echo $this->Flash->render('danger'); ?>

<pre class="prettyprint"><?php
echo h(file_get_contents(dirname(__DIR__) . '/Elements/bootstrap3/alerts.ctp'));
Expand Down
11 changes: 7 additions & 4 deletions View/Elements/bootstrap2/alerts.ctp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php
// View
echo $this->Session->flash();
echo $this->Flash->render();

// Controller
$this->Session->setFlash(__('Alert notice message testing...'), 'alert', array(
$this->Flash->set(__('Alert notice message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
));

$this->Session->setFlash(__('Alert success message testing...'), 'alert', array(
$this->Flash->set(__('Alert success message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-success'
));

$this->Session->setFlash(__('Alert error message testing...'), 'alert', array(
$this->Flash->set(__('Alert error message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-error'
));
Expand Down
14 changes: 9 additions & 5 deletions View/Elements/bootstrap3/alerts.ctp
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php
// View
echo $this->Session->flash();
echo $this->Flash->render();

// Controller
$this->Session->setFlash(__('Alert success message testing...'), 'alert', array(
$this->Flash->set(__('Alert success message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-success'
));

$this->Session->setFlash(__('Alert info message testing...'), 'alert', array(
$this->Flash->set(__('Alert info message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-info'
));

$this->Session->setFlash(__('Alert warning message testing...'), 'alert', array(
$this->Flash->set(__('Alert warning message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-warning'
));

$this->Session->setFlash(__('Alert danger message testing...'), 'alert', array(
$this->Flash->set(__('Alert danger message testing...'), array(
'element' => 'alert',
'plugin' => 'BoostCake',
'class' => 'alert-danger'
));
Expand Down
107 changes: 107 additions & 0 deletions View/Helper/BoostCakeAccordionHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Helper to assist in the usage of Boostratp 3 Accordion JS
*
* @link http://getbootstrap.com/javascript/#collapse
*
* Usage:
* $helpers = array('Accordion' => array('className' => 'BoostCake.BoostCakeAccordion'));
*
* $this->Accordion->create(array(
* 'thing 1' => 'lorem ipsum...',
* 'thing 2' => 'foobar and stuff...',
* ));
*
* $this->Accordion->create(array(
* array(
* 'heading' => 'thing 1',
* 'body' => 'lorem ipsum...',
* ),
* array(
* 'heading' => 'thing 2',
* 'body' => 'foobar and stuff...',
* ),
* ));
*/
class BoostCakeAccordionHelper extends AppHelper {

/**
* Create an Accordion from groupped data
*
* @param array $data
* - array( array('heading' => '...', 'body' => '...'), ... )
* in this case, we loop through all nodes and look for explicitly set 'heading' and 'body'
* - array( 'group1' => '...')
* in this case 'group1' is the heading, and the value '...' is the body
* @param array $options
* 'panelClass' = 'panel-default'
* 'id' = uniqueId()
* 'inCount' = 1 (int of the group you want displayed by default)
* @return string $html for Accordion
*/
public function create($data, $options = array()) {
if (empty($data) || !is_array($data)) {
return '';
}
$defaults = array(
'id' => $this->uniqueId(),
'panelClass' => 'panel-default',
'count' => 1,
'inCount' => 1,
);
$options = Hash::merge($defaults, $options);
$nodes = array();
foreach ($data as $key => $val) {
if (is_array($val)) {
// passed in an array for $val (explicitly setting heading and body
$nodes[] = $this->node($val, $options);
} else {
// passed in $key = heading, and $val = body
$nodes[] = $this->node(array('heading' => $key, 'body' => $val), $options);
}
$options['count']++;
}
return sprintf('<div class="panel-group" id="%s">%s</div>', $options['id'], implode("\n", $nodes));
}

/**
* Process a single node for the Accordion
*
* @param array data
* @param array $options
* @return string $html for node
*/
public function node($data, $options) {
$parentId = $options['id'];
$id = "{$parentId}-{$options['count']}";
$heading = (empty($data['heading']) ? '' : $data['heading']);
$body = (empty($data['body']) ? '' : $data['body']);
$heading = sprintf('<div class="panel-heading"><h4 class="panel-title"><a data-toggle="collapse" data-parent="#%s" href="#%s">%s</a></h4></div>',
$parentId,
$id,
$heading
);
$body = sprintf('<div id="%s" class="panel-collapse collapse %s"><div class="panel-body">%s</div></div>',
$id,
($options['count'] == $options['inCount'] ? 'in' : ''),
$body
);
return sprintf('<div class="panel %s">%s%s</div>',
$options['panelClass'],
$heading,
$body
);
}

/**
* This is a function to return a unique key
*
* @return string $uniqueId
*/
public function uniqueId() {
App::uses('String', 'Utility');
$uniqueId = 'u' . String::uuid();
$uniqueId = preg_replace('#[^a-z0-9_]#', '', $uniqueId);
return $uniqueId;
}
}