ModelToolUpload::getTotalUploads()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
c 0
b 0
f 0
nc 16
nop 0
dl 0
loc 28
rs 9.5555
1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ModelToolUpload extends \Divine\Engine\Core\Model
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    public function addUpload($name, $filename)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        $code = sha1(uniqid(mt_rand(), true));
28
29
        $this->db->query("
30
			INSERT INTO `upload` 
31
			SET `name` = '" . $this->db->escape($name) . "', 
32
				`filename` = '" . $this->db->escape($filename) . "', 
33
				`code` = '" . $this->db->escape($code) . "', 
34
				`date_added` = NOW()
35
		");
36
37
        return $code;
38
    }
39
        
40
    public function deleteUpload($upload_id)
41
    {
42
        $this->db->query("
43
			DELETE 
44
			FROM upload 
45
			WHERE upload_id = '" . (int)$upload_id . "'
46
		");
47
    }
48
49
    public function getUpload($upload_id)
50
    {
51
        $query = $this->db->query("
52
			SELECT * 
53
			FROM `upload` 
54
			WHERE upload_id = '" . (int)$upload_id . "'
55
		");
56
57
        return $query->row;
58
    }
59
60
    public function getUploadByCode($code)
61
    {
62
        $query = $this->db->query("
63
			SELECT * 
64
			FROM upload 
65
			WHERE code = '" . $this->db->escape($code) . "'
66
		");
67
68
        return $query->row;
69
    }
70
71
    public function getUploads($data = array())
72
    {
73
        $sql = "
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT * \... FROM upload\n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
74
			SELECT * 
75
			FROM upload
76
		";
77
78
        $implode = array();
79
80
        if (!empty($data['filter_name'])) {
81
            $implode[] = "name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
82
        }
83
84
        if (!empty($data['filter_filename'])) {
85
            $implode[] = "filename LIKE '" . $this->db->escape($data['filter_filename']) . "%'";
86
        }
87
88
        if (!empty($data['filter_date_added'])) {
89
            $implode[] = "date_added = '" . $this->db->escape($data['filter_date_added']) . "%'";
90
        }
91
92
        if ($implode) {
93
            $sql .= " WHERE " . implode(" AND ", $implode);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal WHERE does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal AND does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
94
        }
95
96
        $sort_data = array(
97
            'name',
98
            'filename',
99
            'date_added'
100
        );
101
102
        if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
103
            $sql .= " ORDER BY " . $data['sort'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
104
        } else {
105
            $sql .= " ORDER BY date_added";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY date_added does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
106
        }
107
108
        if (isset($data['order']) && ($data['order'] == 'DESC')) {
109
            $sql .= " DESC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal DESC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
110
        } else {
111
            $sql .= " ASC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ASC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
112
        }
113
114
        if (isset($data['start']) || isset($data['limit'])) {
115
            if ($data['start'] < 0) {
116
                $data['start'] = 0;
117
            }
118
119
            if ($data['limit'] < 1) {
120
                $data['limit'] = 20;
121
            }
122
123
            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal LIMIT does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal , does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
124
        }
125
126
        $query = $this->db->query($sql);
127
128
        return $query->rows;
129
    }
130
131
    public function getTotalUploads()
132
    {
133
        $sql = "
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT COU... FROM upload\n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
134
			SELECT COUNT(*) AS total 
135
			FROM upload
136
		";
137
138
        $implode = array();
139
140
        if (!empty($data['filter_name'])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to never exist and therefore empty should always be true.
Loading history...
141
            $implode[] = "name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
142
        }
143
144
        if (!empty($data['filter_filename'])) {
145
            $implode[] = "filename LIKE '" . $this->db->escape($data['filter_filename']) . "%'";
146
        }
147
148
        if (!empty($data['filter_date_added'])) {
149
            $implode[] = "date_added = '" . $this->db->escape($data['filter_date_added']) . "'";
150
        }
151
152
        if ($implode) {
153
            $sql .= " WHERE " . implode(" AND ", $implode);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal WHERE does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal AND does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
154
        }
155
156
        $query = $this->db->query($sql);
157
158
        return $query->row['total'];
159
    }
160
}
161