Completed
Pull Request — develop (#716)
by Agel_Nash
11:45 queued 04:51
created

ModuleCategoriesManager::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php namespace EvolutionCMS\Legacy;
2
3
class ModuleCategoriesManager extends Categories
0 ignored issues
show
Coding Style introduced by
The property $new_translations is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
4
{
5
    /**
6
     * @var array
7
     */
8
    public $params = array();
9
    /**
10
     * @var array
11
     */
12
    public $translations = array();
13
    /**
14
     * @var array
15
     */
16
    public $new_translations = array();
17
18
19
    /**
20
     * Set a paramter key and its value
21
     *
22
     * @return null
23
     * @param string $key paramter key
24
     * @param mixed $value parameter value - could be mixed value-types
25
     */
26
    public function set($key, $value)
27
    {
28
        $this->params[$key] = $value;
29
30
        return null;
31
    }
32
33
34
    /**
35
     * Get a parameter value
36
     *
37
     * @return  string           return the parameter value if exists, otherwise false
38
     * @param   string $key Paramter-key
39
     */
40
    public function get($key)
41
    {
42
        $modx = evolutionCMS();
43
44
        if (isset($this->params[$key])) {
45
            return $this->params[$key];
46
        } elseif (isset($modx->config[$key])) {
47
            return $modx->config[$key];
48
        } elseif (isset($modx->event->params[$key])) {
49
            return $modx->event->params[$key];
50
        }
51
52
        return false;
53
    }
54
55
56
    /**
57
     * @param string $message
58
     * @param string $namespace
59
     */
60
    public function addMessage($message, $namespace = 'default')
61
    {
62
        $this->params['messages'][$namespace][] = $message;
63
    }
64
65
66
    /**
67
     * @param string $namespace
68
     * @return bool
69
     */
70
    public function getMessages($namespace = 'default')
71
    {
72
        if (isset($this->params['messages'][$namespace])) {
73
            return $this->params['messages'][$namespace];
74
        }
75
76
        return false;
77
    }
78
79
80
    /**
81
     * @param string $view_name
82
     * @param array $data
83
     */
84
    public function renderView($view_name, $data = array())
0 ignored issues
show
Coding Style Naming introduced by
The parameter $view_name is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
85
    {
86
        global $_lang, $_style;
87
88
        $filename = trim($view_name) . '.tpl.phtml';
89
        $file = self::get('views_dir') . $filename;
90
        $view = &$this;
91
92
        if (is_file($file)
93
            && is_readable($file)) {
94
            include $file;
95
        } else {
96
            echo sprintf(
97
                'View "%s<strong>%s</strong>" not found.',
98
                self::get('views_dir'),
99
                $filename
100
            );
101
        }
102
    }
103
104
    /**
105
     * @param string $element
106
     * @param int $element_id
107
     * @param int $category_id
108
     * @return bool
109
     */
110
    public function updateElement($element, $element_id, $category_id)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $element_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $category_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
111
    {
112
113
        $_update = array(
114
            'id'       => (int)$element_id,
115
            'category' => (int)$category_id
116
        );
117
118
        $this->db->update(
119
            $_update,
120
            $this->db_tbl[$element],
121
            "`id` = '" . (int)$element_id . "'"
122
        );
123
124
        return $this->db->getAffectedRows() === 1;
125
    }
126
127
128
    /**
129
     * @param string $txt
130
     * @return string
131
     */
132
    public function txt($txt)
133
    {
134
        global $_lang;
135
        if (isset($_lang[$txt])) {
136
            return $_lang[$txt];
137
        }
138
139
        return $txt;
140
    }
141
}
142