improves for Blocks

This commit is contained in:
Diego Najar 2018-12-17 22:13:15 +01:00
parent f58c4d7f69
commit 2eea4cd3ba
5 changed files with 77 additions and 10 deletions

View File

@ -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'=>'',

49
bl-kernel/block.class.php Normal file
View File

@ -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');
}
}

View File

@ -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

View File

@ -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');

View File

@ -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'=>''
));
?>