MyActiveRecord   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 159
c 0
b 0
f 0
ccs 68
cts 68
cp 1
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A joinConcatOrder() 0 11 1
A joinWhere() 0 11 2
A findAllWhereOrder() 0 11 2
A count() 0 8 1
A findAllGroupOrder() 0 11 1
A joinWhereConcatOrder() 0 13 2
A findAllOrder() 0 10 1
1
<?php
2
3
namespace Pamo\MyActiveRecord;
4
5
use Anax\DatabaseActiveRecord\Exception\ActiveRecordException;
6
use Anax\DatabaseActiveRecord\ActiveRecordModel;
7
use Anax\DatabaseQueryBuilder\DatabaseQueryBuilder;
8
9
/**
10
 * An implementation of the Active Record pattern to be used as
11
 * base class for database driven models.
12
 */
13
class MyActiveRecord extends ActiveRecordModel
14
{
15
    /**
16
     *
17
     * @param string $where to use in where statement.
18
     * @param mixed  $value to use in where statement.
19
     * @param mixed  $orderBy.
20
     *
21
     * @return array of object of this class
22
     */
23 7
    public function findAllWhereOrder($where, $value, $orderBy)
24
    {
25 7
        $this->checkDb();
26 7
        $params = is_array($value) ? $value : [$value];
27 7
        return $this->db->connect()
28 7
                        ->select()
29 7
                        ->from($this->tableName)
30 7
                        ->where($where)
31 7
                        ->orderBy($orderBy)
32 7
                        ->execute($params)
33 7
                        ->fetchAllClass(get_class($this));
34
    }
35
36
37
    /**
38
     *
39
     * @param mixed  $orderBy.
40
     *
41
     * @return array of object of this class
42
     */
43 1
    public function findAllOrder($orderBy, $limit = 1000)
44
    {
45 1
        $this->checkDb();
46 1
        return $this->db->connect()
47 1
                        ->select()
48 1
                        ->from($this->tableName)
49 1
                        ->orderBy($orderBy)
50 1
                        ->limit($limit)
51 1
                        ->execute()
52 1
                        ->fetchAllClass(get_class($this));
53
    }
54
55
56
    /**
57
     *
58
     * @param string $select.
59
     * @param string  $groupBy.
60
     * @param string  $orderBy.
61
     * @param int  $limit.
62
     *
63
     * @return array of object of this class
64
     */
65 1
    public function findAllGroupOrder($select, $groupBy, $orderBy, $limit = 1000)
66
    {
67 1
        $this->checkDb();
68 1
        return $this->db->connect()
69 1
                        ->select($select)
70 1
                        ->from($this->tableName)
71 1
                        ->groupBy($groupBy)
72 1
                        ->orderBy($orderBy)
73 1
                        ->limit($limit)
74 1
                        ->execute()
75 1
                        ->fetchAllClass(get_class($this));
76
    }
77
78
79
    /**
80
     *
81
     * @param string $count.
82
     *
83
     * @return object
84
     */
85 1
    public function count($count = "*")
86
    {
87 1
        $this->checkDb();
88 1
        return $this->db->connect()
89 1
                        ->select("COUNT ($count) AS count")
90 1
                        ->from($this->tableName)
91 1
                        ->execute()
92 1
                        ->fetch();
93
    }
94
95
96
97
    /**
98
     *
99
     * @param string $table.
100
     * @param string  $condition.
101
     * @param string $groupConcat.
102
     * @param string  $groupBy.
103
     * @param string  $sortBy.
104
     *
105
     * @return array of object of this class
106
     */
107 1
    public function joinConcatOrder($table, $condition, $groupConcat, $groupBy, $sortBy)
108
    {
109 1
        $this->checkDb();
110 1
        return $this->db->connect()
111 1
                        ->select("*, " . $groupConcat)
112 1
                        ->from($this->tableName)
113 1
                        ->join($table, $condition)
114 1
                        ->groupBy($groupBy)
115 1
                        ->orderBy($sortBy)
116 1
                        ->execute()
117 1
                        ->fetchAllClass(get_class($this));
118
    }
119
120
121
122
    /**
123
     *
124
     * @param string $where.
125
     * @param string  $value.
126
     * @param string $table.
127
     * @param string  $condition.
128
     * @param string  $select.
129
     *
130
     * @return array of object of this class
131
     */
132 2
    public function joinWhere($where, $value, $table, $condition, $select = "*")
133
    {
134 2
        $this->checkDb();
135 2
        $params = is_array($value) ? $value : [$value];
136 2
        return $this->db->connect()
137 2
                        ->select($select)
138 2
                        ->from($this->tableName)
139 2
                        ->where($where)
140 2
                        ->join($table, $condition)
141 2
                        ->execute($params)
142 2
                        ->fetchAllClass(get_class($this));
143
    }
144
145
146
147
    /**
148
     *
149
     * @param string  $where.
150
     * @param string  $value.
151
     * @param string $table.
152
     * @param string  $condition.
153
     * @param string $groupConcat.
154
     * @param string  $groupBy.
155
     * @param string  $orderBy.
156
     *
157
     * @return array of object of this class
158
     */
159 1
    public function joinWhereConcatOrder($where, $value, $table, $condition, $groupConcat, $groupBy, $orderBy)
160
    {
161 1
        $this->checkDb();
162 1
        $params = is_array($value) ? $value : [$value];
163 1
        return $this->db->connect()
164 1
                        ->select("*, " . $groupConcat)
165 1
                        ->from($this->tableName)
166 1
                        ->where($where)
167 1
                        ->join($table, $condition)
168 1
                        ->groupBy($groupBy)
169 1
                        ->orderBy($orderBy)
170 1
                        ->execute($params)
171 1
                        ->fetchAllClass(get_class($this));
172
    }
173
}
174