<commit_before><?php
require_once('Autoload.php');

class TicketSystemSettings extends Singleton
{
    protected $cache;
    protected $datatable;

    protected function __construct()
    {
        $this->cache = array();
        $dataset = DataSetFactory::get_data_set('tickets');
        $this->datatable = $dataset['Variables'];
    }

    public function getVariable($var_name, $default=false)
    {
        if(isset($this->cache[$var_name]))
        {
            return $this->cache[$var_name];
        }
        $vars = $this->datatable->read(new \Data\Filter("name eq '$var_name'"));
        if($vars === false || !isset($vars))
        {
            return $default;
        }
        $this->cache[$var_name] = $vars[0]['value'];
        return $this->cache[$var_name];
    }

    public function setVariable($var_name, $value)
    {
        $this->cache[$var_name] = $value;
        return $this->datatable->update(new \Data\Filter("name eq '$var_name'"), array('value'=>$value));
    }

    public function isTestMode()
    {
        return $this->getVariable('test_mode') === '1';
    }
}
?><commit_msg>Add support for creating and deleting variables<commit_after><?php
require_once('Autoload.php');

class TicketSystemSettings extends Singleton
{
    protected $cache;
    protected $datatable;

    protected function __construct()
    {
        $this->cache = array();
        $dataset = DataSetFactory::get_data_set('tickets');
        $this->datatable = $dataset['Variables'];
    }

    public function getVariable($var_name, $default=false)
    {
        if(isset($this->cache[$var_name]))
        {
            return $this->cache[$var_name];
        }
        $vars = $this->datatable->read(new \Data\Filter("name eq '$var_name'"));
        if($vars === false || !isset($vars))
        {
            return $default;
        }
        $this->cache[$var_name] = $vars[0]['value'];
        return $this->cache[$var_name];
    }

    public function setVariable($var_name, $value)
    {
        $this->cache[$var_name] = $value;
        return $this->datatable->update(new \Data\Filter("name eq '$var_name'"), array('value'=>$value));
    }

    public function createVariable($var_name, $value)
    {
        $this->cache[$var_name] = $value;
        return $this->datatable->create(array('name'=>$var_name, 'value'=>$value));
    }

    public function deleteVariable($var_name)
    {
        unset($this->cache[$var_name]);
        return $this->datatable->delete(new \Data\Filter("name eq '$var_name'"));
    }

    public function isTestMode()
    {
        return $this->getVariable('test_mode') === '1';
    }

    public function toArray()
    {
        $vars = $this->datatable->read();
        $count = count($vars);
        for($i = 0; $i < $count; $i++)
        {
            $this->cache[$vars[$i]['name']] = $vars[$i]['value'];
        }
        return $this->cache;
    }
}
?>
{'fraction_non_alphanumeric': 0.17560137457044672, 'fraction_numerical': 0.001718213058419244, 'mean_word_length': 2.620646766169154, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714075', 'n_tokens_mistral': 897, 'n_tokens_neox': 886, 'n_words': 156}