blob: a00d0b7e7e9f8176f2457241b27e1eb190312e3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?php
namespace Model;
use \SimpleValidator\Validator;
use \SimpleValidator\Validators;
class Config extends Base
{
const TABLE = 'config';
public function getTimezones()
{
$timezones = \timezone_identifiers_list();
return array_combine(array_values($timezones), $timezones);
}
public function getLanguages()
{
$languages = array(
'en_US' => t('English'),
'fr_FR' => t('French'),
'pl_PL' => t('Polish'),
);
asort($languages);
return $languages;
}
public function get($name, $default_value = '')
{
if (! isset($_SESSION['config'][$name])) {
$_SESSION['config'] = $this->getAll();
}
if (isset($_SESSION['config'][$name])) {
return $_SESSION['config'][$name];
}
return $default_value;
}
public function getAll()
{
return $this->db->table(self::TABLE)->findOne();
}
public function save(array $values)
{
$_SESSION['config'] = $values;
return $this->db->table(self::TABLE)->update($values);
}
public function reload()
{
$_SESSION['config'] = $this->getAll();
$language = $this->get('language', 'en_US');
if ($language !== 'en_US') \Translator\load($language);
}
public function validateModification(array $values)
{
$v = new Validator($values, array(
new Validators\Required('language', t('The language is required')),
));
return array(
$v->execute(),
$v->getErrors()
);
}
public function optimizeDatabase()
{
$this->db->getconnection()->exec("VACUUM");
}
public function downloadDatabase()
{
return gzencode(file_get_contents(self::DB_FILENAME));
}
public function getDatabaseSize()
{
return filesize(self::DB_FILENAME);
}
}
|