2017-12-18 23:49:53 +01:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class Category {
|
|
|
|
|
2019-01-26 12:50:48 +01:00
|
|
|
protected $vars;
|
2017-12-18 23:49:53 +01:00
|
|
|
|
|
|
|
function __construct($key)
|
|
|
|
{
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
|
|
|
if (isset($categories->db[$key])) {
|
|
|
|
$this->vars['name'] = $categories->db[$key]['name'];
|
|
|
|
$this->vars['template'] = $categories->db[$key]['template'];
|
|
|
|
$this->vars['description'] = $categories->db[$key]['description'];
|
2017-12-18 23:49:53 +01:00
|
|
|
$this->vars['key'] = $key;
|
|
|
|
$this->vars['permalink'] = DOMAIN_CATEGORIES . $key;
|
2018-08-02 22:33:53 +02:00
|
|
|
$this->vars['list'] = $categories->db[$key]['list'];
|
2018-08-02 17:06:53 +02:00
|
|
|
} else {
|
|
|
|
$errorMessage = 'Category not found in database by key ['.$key.']';
|
|
|
|
Log::set(__METHOD__.LOG_SEP.$errorMessage);
|
|
|
|
throw new Exception($errorMessage);
|
2017-12-18 23:49:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValue($field)
|
|
|
|
{
|
|
|
|
if (isset($this->vars[$field])) {
|
|
|
|
return $this->vars[$field];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function key()
|
|
|
|
{
|
|
|
|
return $this->getValue('key');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->getValue('name');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function permalink()
|
|
|
|
{
|
|
|
|
return $this->getValue('permalink');
|
|
|
|
}
|
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
public function template()
|
|
|
|
{
|
|
|
|
return $this->getValue('template');
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:06:53 +02:00
|
|
|
public function description()
|
|
|
|
{
|
|
|
|
return $this->getValue('description');
|
|
|
|
}
|
|
|
|
|
2017-12-18 23:49:53 +01:00
|
|
|
// Returns an array with the keys of pages linked to the category
|
|
|
|
public function pages()
|
|
|
|
{
|
|
|
|
return $this->getValue('list');
|
|
|
|
}
|
2019-05-12 12:32:12 +02:00
|
|
|
|
|
|
|
// Returns an array in json format with all the data of the tag
|
|
|
|
public function json($returnsArray=false)
|
|
|
|
{
|
|
|
|
$tmp['key'] = $this->key();
|
|
|
|
$tmp['name'] = $this->name();
|
|
|
|
$tmp['description'] = $this->description();
|
|
|
|
$tmp['permalink'] = $this->permalink();
|
|
|
|
$tmp['pages'] = $this->pages();
|
|
|
|
|
|
|
|
if ($returnsArray) {
|
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_encode($tmp);
|
|
|
|
}
|
|
|
|
}
|