Completed
Pull Request — master (#233)
by
unknown
10:59
created

customcolumn.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * COPS (Calibre OPDS PHP Server) class file
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     S�bastien Lucas <[email protected]>
7
 */
8
9
require_once('base.php');
10
11
class CustomColumn extends Base {
12
    const ALL_CUSTOMS_ID = "cops:custom";
13
14
    public $id;
15
    public $name;
16
    public $customId;
17
18 6
    public function __construct($pid, $pname, $pcustomId) {
19 6
        $this->id = $pid;
20 6
        $this->name = $pname;
21 6
        $this->customId = $pcustomId;
22 6
    }
23
24 3
    public function getUri () {
25 3
        return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}";
26
    }
27
28 6
    public function getEntryId () {
29 6
        return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id;
30
    }
31
32 10
    public static function getTableName ($customId) {
33 10
        return "custom_column_{$customId}";
34
    }
35
36 6
    public static function getTableLinkName ($customId) {
37 6
        return "books_custom_column_{$customId}_link";
38
    }
39
40 6
    public static function getTableLinkColumn ($customId) {
41 6
        return "value";
42
    }
43
44 7
    public static function getAllCustomsId ($customId) {
45 7
        return self::ALL_CUSTOMS_ID . ":" . $customId;
46
    }
47
48 4
    public static function getUriAllCustoms ($customId) {
49 4
        return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}";
50
    }
51
52 7
    public static function getAllTitle ($customId) {
53 7
        $result = parent::getDb ()->prepare('select name from custom_columns where id = ?');
54 7
        $result->execute (array ($customId));
55 7
        $post = $result->fetchObject ();
56 7
        return $post->name;
57
    }
58
59 4
    public static function getCustomId ($lookup) {
60 4
        $result = parent::getDb ()->prepare('select id from custom_columns where label = ?');
61 4
        $result->execute (array ($lookup));
62 4
        if ($post = $result->fetchObject ()) {
63 4
            return $post->id;
64
        }
65
        return NULL;
66
    }
67
68 4
    public static function getCount($customId) {
69 4
        $nCustoms = parent::executeQuerySingle ('select count(*) from ' . self::getTableName ($customId));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuerySingle() instead of getCount()). Are you sure this is correct? If so, you might want to change this to $this->executeQuerySingle().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
70 4
        $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId),
71 4
            str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text",
72 4
            array ( new LinkNavigation (self::getUriAllCustoms ($customId))), "", $nCustoms);
73 4
        return $entry;
74
    }
75
76 3
    public static function getCustomById ($customId, $id) {
77 3
        $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?');
78 3
        $result->execute (array ($id));
79 3
        if ($post = $result->fetchObject ()) {
80 3
            return new CustomColumn ($post->id, $post->name, $customId);
81
        }
82
        return NULL;
83
    }
84
85 3
    public static function getAllCustoms($customId) {
86 3
        $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustoms()). Are you sure this is correct? If so, you might want to change this to $this->getDb().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
87
from {0}, {1}
88
where {0}.id = {1}.{2}
89
group by {0}.id, {0}.value
90 3
order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($customId), self::getTableLinkColumn ($customId)));
91 3
        $entryArray = array();
92 3
        while ($post = $result->fetchObject ())
93
        {
94 3
            $customColumn = new CustomColumn ($post->id, $post->name, $customId);
95 3
            array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (),
96 3
                str_format (localize("bookword", $post->count), $post->count), "text",
97 3
                array ( new LinkNavigation ($customColumn->getUri ())), "", $post->count));
98 3
        }
99 3
        return $entryArray;
100
    }
101
}
102