Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Model.php « LanguagesManager « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0d5dffdbd151b62d412eb69a6ec90731aea6cac (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 *
 */
namespace Piwik\Plugins\LanguagesManager;

use Piwik\Common;
use Piwik\Db;
use Piwik\DbHelper;

class Model
{
    private static $rawPrefix = 'user_language';
    private $table;

    public function __construct()
    {
        $this->table = Common::prefixTable(self::$rawPrefix);
    }

    public function deleteUserLanguage($userLogin)
    {
        Db::query('DELETE FROM ' . $this->table . ' WHERE login = ?', $userLogin);
    }

    /**
     * Returns the language for the user
     *
     * @param string $userLogin
     * @return string
     */
    public function getLanguageForUser($userLogin)
    {
        return Db::fetchOne('SELECT language FROM ' . $this->table .
                            ' WHERE login = ? ', array($userLogin));
    }

    /**
     * Sets the language for the user
     *
     * @param string $login
     * @param string $languageCode
     * @return bool
     */
    public function setLanguageForUser($login, $languageCode)
    {
        $query = 'INSERT INTO ' . $this->table .
                 ' (login, language) VALUES (?,?) ON DUPLICATE KEY UPDATE language=?';
        $bind  = array($login, $languageCode, $languageCode);
        Db::query($query, $bind);

        return true;
    }

    /**
     * Returns whether the given user has chosen to use 12 hour clock
     *
     * @param $userLogin
     * @return bool
     * @throws \Exception
     */
    public function uses12HourClock($userLogin)
    {
        return (bool) Db::fetchOne('SELECT use_12_hour_clock FROM ' . $this->table .
            ' WHERE login = ? ', array($userLogin));
    }

    /**
     * Sets whether the given user wants to use 12 hout clock
     *
     * @param string $login
     * @param string $use12HourClock
     * @return bool
     */
    public function set12HourClock($login, $use12HourClock)
    {
        $query = 'INSERT INTO ' . $this->table .
            ' (login, use_12_hour_clock) VALUES (?,?) ON DUPLICATE KEY UPDATE use_12_hour_clock=?';
        $bind  = array($login, $use12HourClock, $use12HourClock);
        Db::query($query, $bind);

        return true;
    }

    public static function install()
    {
        $userLanguage = "login VARCHAR( 100 ) NOT NULL ,
					     language VARCHAR( 10 ) NOT NULL ,
					     use_12_hour_clock TINYINT(1) NOT NULL DEFAULT 0 ,
					     PRIMARY KEY ( login )";
        DbHelper::createTable(self::$rawPrefix, $userLanguage);
    }

    public static function uninstall()
    {
        Db::dropTables(Common::prefixTable(self::$rawPrefix));
    }
}