Passed
Push — master ( 806287...909ea5 )
by Lydia
02:52
created

Tag::findPopular()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lyco\Tag;
4
5
use Anax\DatabaseActiveRecord\ActiveRecordModel;
6
7
/**
8
 * A database driven model using the Active Record design pattern.
9
 */
10
class Tag extends ActiveRecordModel
11
{
12
    /**
13
     * @var string $tableName name of the database table.
14
     */
15
     protected $tableName = "Tag";
16
     protected $tableIdColumn = "tagId";
17
18
19
20
    /**
21
     * Columns in the table.
22
     *
23
     * @var integer $id primary key auto incremented.
24
     */
25
     public $tagId;
26
     public $tag;
27
     public $postId;
28
29
    public function findAllTagsWhere($where, $value)
30
    {
31
        $this->checkDb();
32
        $params = is_array($value) ? $value : [$value];
33
        return $this->db->connect()
34
                        ->select()
35
                        ->from($this->tableName)
36
                        ->where($where . " = ?")
37
                        ->join("post", "tag.postId = post.postId")
38
                        ->execute($params)
39
                        ->fetchAllClass(get_class($this));
40
    }
41
42
    public function findPopular()
43
    {
44
        $this->checkDb();
45
        return $this->db->connect()
46
                        ->select("tag")
47
                        ->from($this->tableName)
48
                        ->groupBy("tag.tag")
49
                        ->limit(5)
50
                        ->execute()
51
                        ->fetchAllClass(get_class($this));
52
    }
53
}
54