From 2eea4cd3ba14b546b38981fd36c2e0c0958c153b Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Mon, 17 Dec 2018 22:13:15 +0100 Subject: [PATCH] improves for Blocks --- bl-kernel/admin/views/blocks.php | 15 ++++++---- bl-kernel/block.class.php | 49 ++++++++++++++++++++++++++++++++ bl-kernel/blocks.class.php | 16 +++++++++-- bl-kernel/boot/init.php | 1 + bl-themes/alternative/blocks.php | 6 ++-- 5 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 bl-kernel/block.class.php diff --git a/bl-kernel/admin/views/blocks.php b/bl-kernel/admin/views/blocks.php index 4b7c08ed..fdf3973e 100644 --- a/bl-kernel/admin/views/blocks.php +++ b/bl-kernel/admin/views/blocks.php @@ -17,14 +17,17 @@ '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( 'name'=>'key[]', 'label'=>$L->g('Key'), - 'value'=>$blockKey, + 'value'=>$block->key(), 'class'=>'', 'placeholder'=>'', 'tip'=>'', @@ -34,7 +37,7 @@ echo Bootstrap::formInputText(array( 'name'=>'title[]', 'label'=>$L->g('title'), - 'value'=>$blockData['title'], + 'value'=>$block->title(), 'class'=>'', 'placeholder'=>'', 'tip'=>'' @@ -43,7 +46,7 @@ echo Bootstrap::formTextarea(array( 'name'=>'value[]', 'label'=>$L->g('Value'), - 'value'=>$blockData['value'], + 'value'=>$block->value(), 'class'=>'', 'placeholder'=>'', 'tip'=>'', diff --git a/bl-kernel/block.class.php b/bl-kernel/block.class.php new file mode 100644 index 00000000..e3ddd122 --- /dev/null +++ b/bl-kernel/block.class.php @@ -0,0 +1,49 @@ +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'); + } +} \ No newline at end of file diff --git a/bl-kernel/blocks.class.php b/bl-kernel/blocks.class.php index c05c9f51..6a9cd1a9 100644 --- a/bl-kernel/blocks.class.php +++ b/bl-kernel/blocks.class.php @@ -5,7 +5,8 @@ class Blocks extends dbJSON // Fields allowed for a row in the database private $dbFields = array( 'title'=>'', - 'value'=>'' + 'value'=>'', + 'description'=>'' ); function __construct() @@ -13,9 +14,20 @@ class Blocks extends dbJSON parent::__construct(DB_BLOCKS); } + // Get a particular Block-Object by his 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 diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index e4fb7c61..5ca54db6 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -83,6 +83,7 @@ include(PATH_ABSTRACT.'plugin.class.php'); // Inclde Classes include(PATH_KERNEL.'blocks.class.php'); +include(PATH_KERNEL.'block.class.php'); include(PATH_KERNEL.'pages.class.php'); include(PATH_KERNEL.'users.class.php'); include(PATH_KERNEL.'tags.class.php'); diff --git a/bl-themes/alternative/blocks.php b/bl-themes/alternative/blocks.php index d731acf5..1e8aea1e 100644 --- a/bl-themes/alternative/blocks.php +++ b/bl-themes/alternative/blocks.php @@ -2,12 +2,14 @@ $blocks->add(array( 'key'=>'google-analitycs', 'title'=>'Google Analytics', - 'value'=>'' + 'value'=>'', + 'description'=>'Insert the code for Google Analytics' )); $blocks->add(array( 'key'=>'level', 'title'=>'Level', - 'value'=>'' + 'value'=>'', + 'description'=>'' )); ?> \ No newline at end of file