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'
 ));
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('', + $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; + } +}