remove Blocks classes

This commit is contained in:
Diego Najar 2019-02-03 20:05:32 +01:00
parent 19d9493c83
commit 56eb4a3a93
2 changed files with 0 additions and 130 deletions

View File

@ -1,49 +0,0 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Block {
protected $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

@ -1,81 +0,0 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Blocks extends dbJSON
{
// Fields allowed for a row in the database
protected $dbFields = array(
'title'=>'',
'value'=>'',
'description'=>''
);
function __construct()
{
parent::__construct(DB_BLOCKS);
}
// Get a particular Block-Object by his key
public function get($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
public function add($args)
{
$key = $this->generateKey($args['key']);
if (Text::isEmpty($key)) {
Log::set(__METHOD__.LOG_SEP.'Invalid key for the Block.', LOG_TYPE_ERROR);
return false;
}
$row = array();
foreach ($this->dbFields as $field=>$defaultValue) {
if (isset($args[$field])) {
// Sanitize if will be stored on database
$value = Sanitize::html($args[$field]);
settype($value, gettype($defaultValue));
$row[$field] = $value;
}
}
// Insert the row in the database
$this->db[$key] = $row;
// Save the database
return $this->save();
}
// Delete a row from the database
public function delete($key)
{
if (!$this->exists($key)) {
Log::set(__METHOD__.LOG_SEP.'The Block does not exist. Key: '.$key, LOG_TYPE_ERROR);
}
// Remove from database
unset($this->db[$key]);
// Save the database
return $this->save();
}
// Check if a row exists
public function exists($key)
{
return isset ($this->db[$key]);
}
private function generateKey($text)
{
return Text::cleanUrl($text);
}
}