Browse Source

improves for Blocks

Diego Najar 6 years ago
parent
commit
2eea4cd3ba

+ 9 - 6
bl-kernel/admin/views/blocks.php

@@ -17,14 +17,17 @@
 		'value'=>$security->getTokenCSRF()
 		'value'=>$security->getTokenCSRF()
 	));
 	));
 
 
-	$list = $blocks->getDB();
-	foreach ($list as $blockKey => $blockData) {
-		echo Bootstrap::formTitle(array('title'=>$blockData['title']));
+	foreach ($blocks->getAll() as $block) {
+		echo Bootstrap::formTitle(array('title'=>$block->title()));
+
+		if (Text::isNotEmpty( $block->description() )) {
+			echo Bootstrap::alert(array('class'=>'alert-primary', 'text'=>$block->description()));
+		}
 
 
 		echo Bootstrap::formInputText(array(
 		echo Bootstrap::formInputText(array(
 			'name'=>'key[]',
 			'name'=>'key[]',
 			'label'=>$L->g('Key'),
 			'label'=>$L->g('Key'),
-			'value'=>$blockKey,
+			'value'=>$block->key(),
 			'class'=>'',
 			'class'=>'',
 			'placeholder'=>'',
 			'placeholder'=>'',
 			'tip'=>'',
 			'tip'=>'',
@@ -34,7 +37,7 @@
 		echo Bootstrap::formInputText(array(
 		echo Bootstrap::formInputText(array(
 			'name'=>'title[]',
 			'name'=>'title[]',
 			'label'=>$L->g('title'),
 			'label'=>$L->g('title'),
-			'value'=>$blockData['title'],
+			'value'=>$block->title(),
 			'class'=>'',
 			'class'=>'',
 			'placeholder'=>'',
 			'placeholder'=>'',
 			'tip'=>''
 			'tip'=>''
@@ -43,7 +46,7 @@
 		echo Bootstrap::formTextarea(array(
 		echo Bootstrap::formTextarea(array(
 			'name'=>'value[]',
 			'name'=>'value[]',
 			'label'=>$L->g('Value'),
 			'label'=>$L->g('Value'),
-			'value'=>$blockData['value'],
+			'value'=>$block->value(),
 			'class'=>'',
 			'class'=>'',
 			'placeholder'=>'',
 			'placeholder'=>'',
 			'tip'=>'',
 			'tip'=>'',

+ 49 - 0
bl-kernel/block.class.php

@@ -0,0 +1,49 @@
+<?php defined('BLUDIT') or die('Bludit CMS.');
+
+class Block {
+
+	private $vars;
+
+	function __construct($key)
+	{
+		global $blocks;
+		if (isset($blocks->db[$key])) {
+			$this->vars['title'] 		= $blocks->db[$key]['title'];
+			$this->vars['value'] 		= $blocks->db[$key]['value'];
+			$this->vars['description'] 	= $blocks->db[$key]['description'];
+			$this->vars['key'] 		= $key;
+		} else {
+			$errorMessage = 'Block not found in database by key ['.$key.']';
+			Log::set(__METHOD__.LOG_SEP.$errorMessage);
+			throw new Exception($errorMessage);
+		}
+	}
+
+	public function getValue($field)
+	{
+		if (isset($this->vars[$field])) {
+			return $this->vars[$field];
+		}
+		return false;
+	}
+
+	public function title()
+	{
+		return $this->getValue('title');
+	}
+
+	public function value()
+	{
+		return $this->getValue('value');
+	}
+
+	public function description()
+	{
+		return $this->getValue('description');
+	}
+
+	public function key()
+	{
+		return $this->getValue('key');
+	}
+}

+ 14 - 2
bl-kernel/blocks.class.php

@@ -5,7 +5,8 @@ class Blocks extends dbJSON
 	// Fields allowed for a row in the database
 	// Fields allowed for a row in the database
 	private $dbFields = array(
 	private $dbFields = array(
 		'title'=>'',
 		'title'=>'',
-		'value'=>''
+		'value'=>'',
+		'description'=>''
 	);
 	);
 
 
 	function __construct()
 	function __construct()
@@ -13,9 +14,20 @@ class Blocks extends dbJSON
 		parent::__construct(DB_BLOCKS);
 		parent::__construct(DB_BLOCKS);
 	}
 	}
 
 
+	// Get a particular Block-Object by his key
 	public function get($key)
 	public function get($key)
 	{
 	{
-		return $this->db[$key];
+		return new Block($key);
+	}
+
+	// Get an array with all the Block-Object
+	public function getAll()
+	{
+		$all = array();
+		foreach ($this->db as $key=>$fields) {
+			$all[$key] = new Block($key);
+		}
+		return $all;
 	}
 	}
 
 
 	// Add a row to the database
 	// Add a row to the database

+ 1 - 0
bl-kernel/boot/init.php

@@ -83,6 +83,7 @@ include(PATH_ABSTRACT.'plugin.class.php');
 
 
 // Inclde Classes
 // Inclde Classes
 include(PATH_KERNEL.'blocks.class.php');
 include(PATH_KERNEL.'blocks.class.php');
+include(PATH_KERNEL.'block.class.php');
 include(PATH_KERNEL.'pages.class.php');
 include(PATH_KERNEL.'pages.class.php');
 include(PATH_KERNEL.'users.class.php');
 include(PATH_KERNEL.'users.class.php');
 include(PATH_KERNEL.'tags.class.php');
 include(PATH_KERNEL.'tags.class.php');

+ 4 - 2
bl-themes/alternative/blocks.php

@@ -2,12 +2,14 @@
 $blocks->add(array(
 $blocks->add(array(
 	'key'=>'google-analitycs',
 	'key'=>'google-analitycs',
 	'title'=>'Google Analytics',
 	'title'=>'Google Analytics',
-	'value'=>''
+	'value'=>'',
+	'description'=>'Insert the code for Google Analytics'
 ));
 ));
 
 
 $blocks->add(array(
 $blocks->add(array(
 	'key'=>'level',
 	'key'=>'level',
 	'title'=>'Level',
 	'title'=>'Level',
-	'value'=>''
+	'value'=>'',
+	'description'=>''
 ));
 ));
 ?>
 ?>