MoreFilesHandler::getMoreFilesCriteria()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate;
2
3
use 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       XOOPS Project (https://xoops.org)
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
 * @version         $Id: morefiles.php 13080 2015-06-12 10:12:32Z timgno $
26
 */
27
//include __DIR__.'/autoload.php';
28
29
/**
30
 *  @Class MoreFilesHandler
31
 *  @extends \XoopsPersistableObjectHandler
32
 */
33
class MoreFilesHandler extends \XoopsPersistableObjectHandler
34
{
35
    /**
36
     *  @public function constructor class
37
     *
38
     * @param null|\XoopsDatabase|\XoopsMySQLDatabase $db
39
     */
40
    public function __construct(\XoopsDatabase $db)
41
    {
42
        parent::__construct($db, 'tdmcreate_morefiles', MoreFiles::class, 'file_id', 'file_name');
43
    }
44
45
    /**
46
     * @param bool $isNew
47
     *
48
     * @return \XoopsObject
49
     */
50
    public function create($isNew = true)
51
    {
52
        return parent::create($isNew);
53
    }
54
55
    /**
56
     * retrieve a field.
57
     *
58
     * @param int  $i      field id
59
     * @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...
60
     *
61
     * @return mixed reference to the <a href='psi_element://Fields'>Fields</a> object
62
     *               object
63
     */
64
    public function get($i = null, $fields = null)
65
    {
66
        return parent::get($i, $fields);
67
    }
68
69
    /**
70
     * get inserted id.
71
     *
72
     * @param null
73
     *
74
     * @return int reference to the {@link Tables} object
75
     */
76
    public function getInsertId()
77
    {
78
        return $this->db->getInsertId();
79
    }
80
81
    /**
82
     * Get Count MoreFiles.
83
     *
84
     * @param int    $start
85
     * @param int    $limit
86
     * @param string $sort
87
     * @param string $order
88
     *
89
     * @return int
90
     */
91
    public function getCountMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
92
    {
93
        $crMoreFilesCount = new \CriteriaCompo();
94
        $crMoreFilesCount = $this->getMoreFilesCriteria($crMoreFilesCount, $start, $limit, $sort, $order);
95
96
        return $this->getCount($crMoreFilesCount);
97
    }
98
99
    /**
100
     * Get All MoreFiles.
101
     *
102
     * @param int    $start
103
     * @param int    $limit
104
     * @param string $sort
105
     * @param string $order
106
     *
107
     * @return array
108
     */
109
    public function getAllMoreFiles($start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
110
    {
111
        $crMoreFilesAdd = new \CriteriaCompo();
112
        $crMoreFilesAdd = $this->getMoreFilesCriteria($crMoreFilesAdd, $start, $limit, $sort, $order);
113
114
        return $this->getAll($crMoreFilesAdd);
115
    }
116
117
    /**
118
     * Get All MoreFiles By Module Id.
119
     *
120
     * @param        $modId
121
     * @param int    $start
122
     * @param int    $limit
123
     * @param string $sort
124
     * @param string $order
125
     *
126
     * @return array
127
     */
128
    public function getAllMoreFilesByModuleId($modId, $start = 0, $limit = 0, $sort = 'file_id ASC, file_name', $order = 'ASC')
129
    {
130
        $crMoreFilesByModuleId = new \CriteriaCompo();
131
        $crMoreFilesByModuleId->add(new \Criteria('file_mid', $modId));
132
        $crMoreFilesByModuleId = $this->getMoreFilesCriteria($crMoreFilesByModuleId, $start, $limit, $sort, $order);
133
134
        return $this->getAll($crMoreFilesByModuleId);
135
    }
136
137
    /**
138
     * Get MoreFiles Criteria.
139
     *
140
     * @param $crMoreFiles
141
     * @param $start
142
     * @param $limit
143
     * @param $sort
144
     * @param $order
145
     *
146
     * @return mixed
147
     */
148
    private function getMoreFilesCriteria($crMoreFiles, $start, $limit, $sort, $order)
149
    {
150
        $crMoreFiles->setStart($start);
151
        $crMoreFiles->setLimit($limit);
152
        $crMoreFiles->setSort($sort);
153
        $crMoreFiles->setOrder($order);
154
155
        return $crMoreFiles;
156
    }
157
}
158