From 26cfe38a5686cdf6b931e7bd59579588b346fbce Mon Sep 17 00:00:00 2001 From: alan bount Date: Wed, 29 Jan 2014 18:09:41 -0500 Subject: [PATCH 1/2] added BoostCakeAccordionHelper --- View/Helper/BoostCakeAccordionHelper.php | 107 +++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 View/Helper/BoostCakeAccordionHelper.php diff --git a/View/Helper/BoostCakeAccordionHelper.php b/View/Helper/BoostCakeAccordionHelper.php new file mode 100644 index 0000000..0a64438 --- /dev/null +++ b/View/Helper/BoostCakeAccordionHelper.php @@ -0,0 +1,107 @@ + 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('
%s
', $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('

%s

', + $parentId, + $id, + $heading + ); + $body = sprintf('
%s
', + $id, + ($options['count'] == $options['inCount'] ? 'in' : ''), + $body + ); + return sprintf('
%s%s
', + $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; + } +} From 87a2f98fa600c47d432576ead891bc4aa7be74f7 Mon Sep 17 00:00:00 2001 From: Benjamin Stout Date: Tue, 26 Feb 2019 10:48:21 -0800 Subject: [PATCH 2/2] CTU-82 Resolve CakePHP Session -> Flash deprecations --- Controller/BoostCakeController.php | 42 +++++++++++++++++++---------- View/BoostCake/bootstrap2.ctp | 6 ++--- View/BoostCake/bootstrap3.ctp | 8 +++--- View/Elements/bootstrap2/alerts.ctp | 11 +++++--- View/Elements/bootstrap3/alerts.ctp | 14 ++++++---- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Controller/BoostCakeController.php b/Controller/BoostCakeController.php index ea09f06..1af900f 100644 --- a/Controller/BoostCakeController.php +++ b/Controller/BoostCakeController.php @@ -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'); + ]); } /** @@ -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'); + ]); } } diff --git a/View/BoostCake/bootstrap2.ctp b/View/BoostCake/bootstrap2.ctp index eae510c..e5a5fc0 100644 --- a/View/BoostCake/bootstrap2.ctp +++ b/View/BoostCake/bootstrap2.ctp @@ -151,9 +151,9 @@

Alerts

- Session->flash('notice'); ?> - Session->flash('success'); ?> - Session->flash('error'); ?> + Flash->render('notice'); ?> + Flash->render('success'); ?> + Flash->render('error'); ?>
Alerts
 			
 
-			Session->flash('success'); ?>
-			Session->flash('info'); ?>
-			Session->flash('warning'); ?>
-			Session->flash('danger'); ?>
+			Flash->render('success'); ?>
+			Flash->render('info'); ?>
+			Flash->render('warning'); ?>
+			Flash->render('danger'); ?>
 
 			
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'
 ));
diff --git a/View/Elements/bootstrap3/alerts.ctp b/View/Elements/bootstrap3/alerts.ctp
index 247145c..ade996f 100644
--- a/View/Elements/bootstrap3/alerts.ctp
+++ b/View/Elements/bootstrap3/alerts.ctp
@@ -1,24 +1,28 @@
 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'
 ));