AddFilesHandler   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 131
rs 10
c 1
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getInsertId() 0 3 1
A getAllAddFiles() 0 6 1
A getAddFilesCriteria() 0 8 1
A get() 0 3 1
A getAllAddFilesByModuleId() 0 7 1
A insert() 0 7 2
A __construct() 0 3 1
A create() 0 3 1
A getCountAddFiles() 0 6 1
1
<?php
2
3
namespace XoopsModules\Tdmcreate;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * morefiles class.
17
 *
18
 * @copyright       The XOOPS Project http:sourceforge.net/projects/xoops/
19
 * @license         GNU GPL 2 (http:www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.7
22
 *
23
 * @author          Txmod Xoops <[email protected]> - <http:www.txmodxoops.org/>
24
 *
25
 */
26
//include __DIR__.'/autoload.php';
27
28
/**
29
 * Class MoreFilesHandler.
30
 */
31
class AddFilesHandler extends \XoopsPersistableObjectHandler
32
{
33
    /**
34
     * @public function constructor class
35
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
36
     */
37
    public function __construct(\XoopsDatabase $db)
38
    {
39
        parent::__construct($db, 'tdmcreate_addfiles', AddFiles::class, 'file_id', 'file_name');
40
    }
41
42
    /**
43
     * @param bool $isNew
44
     *
45
     * @return \XoopsObject
46
     */
47
    public function create($isNew = true)
48
    {
49
        return parent::create($isNew);
50
    }
51
52
    /**
53
     * retrieve a field.
54
     *
55
     * @param int  $i field id
56
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
57
     *
58
     * @return mixed reference to the <a href='psi_element:Fields'>Fields</a> object
59
     *               object
60
     */
61
    public function &get($i = null, $fields = null)
62
    {
63
        return parent::get($i, $fields);
64
    }
65
66
    /**
67
     * get inserted id.
68
     *
69
     * @param null
70
     *
71
     * @return int reference to the {@link Tables} object
72
     */
73
    public function &getInsertId()
74
    {
75
        return $this->db->getInsertId();
76
    }
77
78
    /**
79
     * insert a new field in the database.
80
     *
81
     * @param \XoopsObject $field reference to the {@link Fields} object
82
     * @param bool         $force
83
     *
84
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
85
     */
86
    public function insert(\XoopsObject $field, $force = false)
87
    {
88
        if (!parent::insert($field, $force)) {
89
            return false;
90
        }
91
92
        return true;
93
    }
94
95
    /**
96
     * Get Count AddFiles.
97
     * @param int    $start
98
     * @param int    $limit
99
     * @param string $sort
100
     * @param string $order
101
     * @return int
102
     */
103
    public function getCountAddFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
104
    {
105
        $criteriaAddFilesCount = new \CriteriaCompo();
106
        $criteriaAddFilesCount = $this->getAddFilesCriteria($criteriaAddFilesCount, $start, $limit, $sort, $order);
107
108
        return $this->getCount($criteriaAddFilesCount);
109
    }
110
111
    /**
112
     * Get All AddFiles.
113
     * @param int    $start
114
     * @param int    $limit
115
     * @param string $sort
116
     * @param string $order
117
     * @return array
118
     */
119
    public function getAllAddFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
120
    {
121
        $criteriaAddFilesAdd = new \CriteriaCompo();
122
        $criteriaAddFilesAdd = $this->getAddFilesCriteria($criteriaAddFilesAdd, $start, $limit, $sort, $order);
123
124
        return $this->getAll($criteriaAddFilesAdd);
125
    }
126
127
    /**
128
     * Get All AddFiles By Module Id.
129
     * @param        $modId
130
     * @param int    $start
131
     * @param int    $limit
132
     * @param string $sort
133
     * @param string $order
134
     * @return array
135
     */
136
    public function getAllAddFilesByModuleId($modId, $start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
137
    {
138
        $criteriaAddFilesByModuleId = new \CriteriaCompo();
139
        $criteriaAddFilesByModuleId->add(new \Criteria('file_mid', $modId));
140
        $criteriaAddFilesByModuleId = $this->getAddFilesCriteria($criteriaAddFilesByModuleId, $start, $limit, $sort, $order);
141
142
        return $this->getAll($criteriaAddFilesByModuleId);
143
    }
144
145
    /**
146
     * Get AddFiles Criteria.
147
     * @param $criteriaAddFiles
148
     * @param $start
149
     * @param $limit
150
     * @param $sort
151
     * @param $order
152
     * @return mixed
153
     */
154
    private function getAddFilesCriteria($criteriaAddFiles, $start, $limit, $sort, $order)
155
    {
156
        $criteriaAddFiles->setStart($start);
157
        $criteriaAddFiles->setLimit($limit);
158
        $criteriaAddFiles->setSort($sort);
159
        $criteriaAddFiles->setOrder($order);
160
161
        return $criteriaAddFiles;
162
    }
163
}
164