Completed
Pull Request — master (#269)
by
unknown
03:00
created

CustomColumn::getHTMLEncodedValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
/**
12
 * A CustomColumn with an value
13
 */
14
class CustomColumn extends Base
15
{
16
    /* @var string|integer the ID of the value */
17
    public $valueID;
18
    /* @var string the (string) representation of the value */
19
    public $value;
20
    /* @var CustomColumnType the custom column that contains the value */
21
    public $customColumnType;
22
    /* @var string the value encoded for HTML displaying */
23
    public $htmlvalue;
24
25
    /**
26
     * CustomColumn constructor.
27
     *
28
     * @param integer $pid id of the chosen value
29
     * @param string $pvalue string representation of the value
30
     * @param CustomColumnType $pcustomColumnType the CustomColumn this value lives in
31
     */
32 7
    public function __construct($pid, $pvalue, $pcustomColumnType)
33
    {
34 7
        $this->valueID = $pid;
35 7
        $this->value = $pvalue;
36 7
        $this->customColumnType = $pcustomColumnType;
37 7
        $this->htmlvalue = $this->customColumnType->encodeHTMLValue($this->value);
38 7
    }
39
40
    /**
41
     * Get the URI to show all books with this value
42
     *
43
     * @return string
44
     */
45
    public function getUri()
46
    {
47
        return $this->customColumnType->getUri($this->valueID);
48
    }
49
50
    /**
51
     * Get the EntryID to show all books with this value
52
     *
53
     * @return string
54
     */
55 4
    public function getEntryId()
56
    {
57 4
        return $this->customColumnType->getEntryId($this->valueID);
58
    }
59
60
    /**
61
     * Get the query to find all books with this value
62
     * the returning array has two values:
63
     *  - first the query (string)
64
     *  - second an array of all PreparedStatement parameters
65
     *
66
     * @return array
67
     */
68 6
    public function getQuery()
69
    {
70 6
        return $this->customColumnType->getQuery($this->valueID);
71
    }
72
73
    /**
74
     * Return the value of this column as an HTML snippet
75
     *
76
     * @return string
77
     */
78 1
    public function getHTMLEncodedValue()
79
    {
80 1
        return $this->htmlvalue;
81
    }
82
83
    /**
84
     * Craete an CustomColumn by CustomColumnID and ValueID
85
     *
86
     * @param integer $customId the id of the customColumn
87
     * @param integer $id the id of the chosen value
88
     * @return CustomColumn|null
89
     */
90 4
    public static function createCustom($customId, $id)
91
    {
92 4
        $columnType = CustomColumnType::createByCustomID($customId);
93
94 4
        return $columnType->getCustom($id);
95
    }
96
}
97
98
/**
99
 * A single calibre custom column
100
 */
101
abstract class CustomColumnType extends Base
102
{
103
    const ALL_CUSTOMS_ID       = "cops:custom";
104
105
    const CUSTOM_TYPE_TEXT      = "text";        // type 1 + 2
106
    const CUSTOM_TYPE_COMMENT   = "comments";    // type 3
107
    const CUSTOM_TYPE_SERIES    = "series";      // type 4
108
    const CUSTOM_TYPE_ENUM      = "enumeration"; // type 5
109
    const CUSTOM_TYPE_DATE      = "datetime";    // type 6
110
    const CUSTOM_TYPE_FLOAT     = "float";       // type 7
111
    const CUSTOM_TYPE_INT       = "int";         // type 8
112
    const CUSTOM_TYPE_RATING    = "rating";      // type 9
113
    const CUSTOM_TYPE_BOOL      = "bool";        // type 10
114
    const CUSTOM_TYPE_COMPOSITE = "composite";   // type 11 + 12
115
116
    /** @var array[integer]CustomColumnType  */
117
    private static $customColumnCacheID = array();
118
119
    /** @var array[string]CustomColumnType  */
120
    private static $customColumnCacheLookup = array();
121
122
    /** @var integer the id of this column */
123
    public $customId;
124
    /** @var string name/title of this column */
125
    public $columnTitle;
126
    /** @var string the datatype of this column (one of the CUSTOM_TYPE_* constant values) */
127
    public $datatype;
128
    /** @var Entry[] */
129
    private $customValues = NULL;
130
131 14
    protected function __construct($pcustomId, $pdatatype)
132
    {
133 14
        $this->columnTitle = self::getTitleByCustomID($pcustomId);
134 14
        $this->customId = $pcustomId;
135 14
        $this->datatype = $pdatatype;
136 14
        $this->customValues = NULL;
0 ignored issues
show
Documentation Bug introduced by
It seems like NULL of type null is incompatible with the declared type array<integer,object<Entry>> of property $customValues.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
137 14
    }
138
139
    /**
140
     * The URI to show all book swith a specific value in this column
141
     *
142
     * @param string|integer $id the id of the value to show
143
     * @return string
144
     */
145 13
    public function getUri($id)
146
    {
147 13
        return "?page=" . parent::PAGE_CUSTOM_DETAIL . "&custom={$this->customId}&id={$id}";
148
    }
149
150
    /**
151
     * The URI to show all the values of this column
152
     *
153
     * @return string
154
     */
155 25
    public function getUriAllCustoms()
156
    {
157 25
        return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$this->customId}";
158
    }
159
160
    /**
161
     * The EntryID to show all book swith a specific value in this column
162
     *
163
     * @param string|integer $id the id of the value to show
164
     * @return string
165
     */
166 17
    public function getEntryId($id)
167
    {
168 17
        return self::ALL_CUSTOMS_ID . ":" . $this->customId . ":" . $id;
169
    }
170
171
    /**
172
     * The EntryID to show all the values of this column
173
     *
174
     * @return string
175
     */
176 37
    public function getAllCustomsId()
177
    {
178 37
        return self::ALL_CUSTOMS_ID . ":" . $this->customId;
179
    }
180
181
    /**
182
     * The title of this column
183
     *
184
     * @return string
185
     */
186 38
    public function getTitle()
187
    {
188 38
        return $this->columnTitle;
189
    }
190
191
    /**
192
     * The description of this column as it is definied in the database
193
     *
194
     * @return string|null
195
     */
196 20
    public function getDatabaseDescription()
197
    {
198 20
        $result = parent::getDb()->prepare('SELECT display FROM custom_columns WHERE id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getDatabaseDescription()). 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...
199 20
        $result->execute(array($this->customId));
200 20
        if ($post = $result->fetchObject()) {
201 20
            $json = json_decode($post->display);
202 20
            return (isset($json->description) && !empty($json->description)) ? $json->description : NULL;
203
        }
204
        return NULL;
205
    }
206
207
    /**
208
     * Get the Entry for this column
209
     * This is used in the initializeContent method to display e.g. the index page
210
     *
211
     * @return Entry
212
     */
213 14
    public function getCount()
214
    {
215 14
        $ptitle = $this->getTitle();
216 14
        $pid = $this->getAllCustomsId();
217 14
        $pcontent = $this->getDescription();
218 14
        $pcontentType = $this->datatype;
219 14
        $plinkArray = array(new LinkNavigation($this->getUriAllCustoms()));
220 14
        $pclass = "";
221 14
        $pcount = $this->getDistinctValueCount();
222
223 14
        return new Entry($ptitle, $pid, $pcontent, $pcontentType, $plinkArray, $pclass, $pcount);
224
    }
225
226
    /**
227
     * Get the amount of distinct values for this column
228
     *
229
     * @return int
230
     */
231 16
    protected function getDistinctValueCount()
232
    {
233 16
        return count($this->getAllCustomValues());
234
    }
235
236
    /**
237
     * Encode a value of this column ready to be displayed in an HTML document
238
     *
239
     * @param integer|string $value
240
     * @return string
241
     */
242 7
    public function encodeHTMLValue($value)
243
    {
244 7
        return htmlspecialchars($value);
245
    }
246
247
    /**
248
     * Get the datatype of a CustomColumn by its customID
249
     *
250
     * @param integer $customId
251
     * @return string|null
252
     */
253 17
    private static function getDatatypeByCustomID($customId)
254
    {
255 17
        $result = parent::getDb()->prepare('SELECT datatype FROM custom_columns WHERE id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getDatatypeByCustomID()). 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...
256 17
        $result->execute(array($customId));
257 17
        if ($post = $result->fetchObject()) {
258 16
            return $post->datatype;
259
        }
260 1
        return NULL;
261
    }
262
263
    /**
264
     * Create a CustomColumnType by CustomID
265
     *
266
     * @param integer $customId the id of the custom column
267
     * @return CustomColumnType|null
268
     * @throws Exception If the $customId is not found or the datatype is unknown
269
     */
270 42
    public static function createByCustomID($customId)
271
    {
272
        // Reuse already created CustomColumns for performance
273 42
        if (array_key_exists($customId, self::$customColumnCacheID))
274 42
            return self::$customColumnCacheID[$customId];
275
276 17
        $datatype = self::getDatatypeByCustomID($customId);
277
278
        switch ($datatype) {
279 17
            case self::CUSTOM_TYPE_TEXT:
280 5
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeText($customId);
281 12
            case self::CUSTOM_TYPE_SERIES:
282 2
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeSeries($customId);
283 10
            case self::CUSTOM_TYPE_ENUM:
284 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeEnumeration($customId);
285 9
            case self::CUSTOM_TYPE_COMMENT:
286 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeComment($customId);
287 8
            case self::CUSTOM_TYPE_DATE:
288 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeDate($customId);
289 7
            case self::CUSTOM_TYPE_FLOAT:
290 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeFloat($customId);
291 6
            case self::CUSTOM_TYPE_INT:
292 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeInteger($customId);
293 5
            case self::CUSTOM_TYPE_RATING:
294 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeRating($customId);
295 4
            case self::CUSTOM_TYPE_BOOL:
296 1
                return self::$customColumnCacheID[$customId] = new CustomColumnTypeBool($customId);
297 3
            case self::CUSTOM_TYPE_COMPOSITE:
298 2
                return NULL; //TODO Currently not supported
299 1
            default:
300 1
                throw new Exception("Unkown column type: " . $datatype);
301 1
        }
302
    }
303
304
    /**
305
     * Create a CustomColumnType by its lookup name
306
     *
307
     * @param string $lookup the lookup-name of the custom column
308
     * @return CustomColumnType|null
309
     */
310 33
    public static function createByLookup($lookup)
311
    {
312
        // Reuse already created CustomColumns for performance
313 33
        if (array_key_exists($lookup, self::$customColumnCacheLookup))
314 33
            return self::$customColumnCacheLookup[$lookup];
315
316 17
        $result = parent::getDb()->prepare('SELECT id FROM custom_columns WHERE label = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of createByLookup()). 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...
317 17
        $result->execute(array($lookup));
318 17
        if ($post = $result->fetchObject()) {
319 16
            return self::$customColumnCacheLookup[$lookup] = self::createByCustomID($post->id);
320
        }
321 1
        return self::$customColumnCacheLookup[$lookup] = NULL;
322
    }
323
324
    /**
325
     * Return an entry array for all possible (in the DB used) values of this column
326
     * These are the values used in the getUriAllCustoms() page
327
     *
328
     * @return Entry[]
329
     */
330 36
    public function getAllCustomValues()
331
    {
332
        // lazy loading
333 36
        if ($this->customValues == NULL)
334 36
            $this->customValues = $this->getAllCustomValuesFromDatabase();
335
336 36
        return $this->customValues;
337
    }
338
339
    /**
340
     * Get the title of a CustomColumn by its customID
341
     *
342
     * @param integer $customId
343
     * @return string|null
344
     */
345 14
    protected static function getTitleByCustomID($customId)
346
    {
347 14
        $result = parent::getDb()->prepare('SELECT name FROM custom_columns WHERE id = ?');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getTitleByCustomID()). 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...
348 14
        $result->execute(array($customId));
349 14
        if ($post = $result->fetchObject()) {
350 14
            return $post->name;
351
        }
352
        return NULL;
353
    }
354
355
    /**
356
     * Get the query to find all books with a specific value of this column
357
     * the returning array has two values:
358
     *  - first the query (string)
359
     *  - second an array of all PreparedStatement parameters
360
     *
361
     * @param string|integer $id the id of the searched value
362
     * @return array
363
     */
364
    abstract public function getQuery($id);
365
366
    /**
367
     * Get a CustomColumn for a specified (by ID) value
368
     *
369
     * @param string|integer $id the id of the searched value
370
     * @return CustomColumn
371
     */
372
    abstract public function getCustom($id);
373
374
    /**
375
     * Return an entry array for all possible (in the DB used) values of this column by querying the database
376
     *
377
     * @return Entry[]
378
     */
379
    abstract protected function getAllCustomValuesFromDatabase();
380
381
    /**
382
     * The description used in the index page
383
     *
384
     * @return string
385
     */
386
    abstract public function getDescription();
387
388
    /**
389
     * Find the value of this column for a specific book
390
     *
391
     * @param Book $book
392
     * @return CustomColumn
393
     */
394
    public abstract function getCustomByBook($book);
395
396
    /**
397
     * Is this column searchable by value
398
     * only searchable columns can be displayed on the index page
399
     *
400
     * @return bool
401
     */
402
    public abstract function isSearchable();
403
}
404
405
class CustomColumnTypeText extends CustomColumnType
406
{
407 5
    protected function __construct($pcustomId)
408
    {
409 5
        parent::__construct($pcustomId, self::CUSTOM_TYPE_TEXT);
410 5
    }
411
412
    /**
413
     * Get the name of the sqlite table for this column
414
     *
415
     * @return string|null
416
     */
417 11
    private function getTableName()
418
    {
419 11
        return "custom_column_{$this->customId}";
420
    }
421
422
    /**
423
     * Get the name of the linking sqlite table for this column
424
     * (or NULL if there is no linktable)
425
     *
426
     * @return string|null
427
     */
428 11
    private function getTableLinkName()
429
    {
430 11
        return "books_custom_column_{$this->customId}_link";
431
    }
432
433
    /**
434
     * Get the name of the linking column in the linktable
435
     *
436
     * @return string|null
437
     */
438 11
    private function getTableLinkColumn()
439
    {
440 11
        return "value";
441
    }
442
443 4
    public function getQuery($id)
444
    {
445 4
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", $this->getTableLinkName(), $this->getTableLinkColumn());
446 4
        return array($query, array($id));
447
    }
448
449 4
    public function getCustom($id)
450
    {
451 4
        $result = parent::getDb()->prepare(str_format("SELECT id, value AS name FROM {0} WHERE id = ?", $this->getTableName()));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustom()). 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...
452 4
        $result->execute(array($id));
453 4
        if ($post = $result->fetchObject()) {
454 4
            return new CustomColumn($id, $post->name, $this);
455
        }
456
        return NULL;
457
    }
458
459 5
    protected function getAllCustomValuesFromDatabase()
460
    {
461 5
        $queryFormat = "SELECT {0}.id AS id, {0}.value AS name, count(*) AS count FROM {0}, {1} WHERE {0}.id = {1}.{2} GROUP BY {0}.id, {0}.value ORDER BY {0}.value";
462 5
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn());
463
464 5
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
465 5
        $entryArray = array();
466 5
        while ($post = $result->fetchObject()) {
467 5
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
468 5
            $entryPLinkArray = array(new LinkNavigation ($this->getUri($post->id)));
469
470 5
            $entry = new Entry($post->name, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
471
472 5
            array_push($entryArray, $entry);
473 5
        }
474 5
        return $entryArray;
475
    }
476
477 9
    public function getDescription()
478
    {
479 9
        $desc = $this->getDatabaseDescription();
480 9
        if ($desc == NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $desc of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
481 9
        return $desc;
482
    }
483
484 2
    public function getCustomByBook($book)
485
    {
486 2
        $queryFormat = "SELECT {0}.id AS id, {1}.{2} AS name FROM {0}, {1} WHERE {0}.id = {1}.{2} AND {1}.book = {3} ORDER BY {0}.value";
487 2
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn(), $book->id);
488
489 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
490 2
        if ($post = $result->fetchObject()) {
491 2
            return new CustomColumn($post->id, $post->name, $this);
492
        }
493
        return new CustomColumn(NULL, "", $this);
494
    }
495
496 9
    public function isSearchable()
497
    {
498 9
        return true;
499
    }
500
}
501
502
class CustomColumnTypeSeries extends CustomColumnType
503
{
504 2
    protected function __construct($pcustomId)
505
    {
506 2
        parent::__construct($pcustomId, self::CUSTOM_TYPE_SERIES);
507 2
    }
508
509
    /**
510
     * Get the name of the sqlite table for this column
511
     *
512
     * @return string|null
513
     */
514 7
    private function getTableName()
515
    {
516 7
        return "custom_column_{$this->customId}";
517
    }
518
519
    /**
520
     * Get the name of the linking sqlite table for this column
521
     * (or NULL if there is no linktable)
522
     *
523
     * @return string|null
524
     */
525 7
    private function getTableLinkName()
526
    {
527 7
        return "books_custom_column_{$this->customId}_link";
528
    }
529
530
    /**
531
     * Get the name of the linking column in the linktable
532
     *
533
     * @return string|null
534
     */
535 7
    private function getTableLinkColumn()
536
    {
537 7
        return "value";
538
    }
539
540 3
    public function getQuery($id)
541
    {
542 3
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", $this->getTableLinkName(), $this->getTableLinkColumn());
543 3
        return array($query, array($id));
544
    }
545
546 3
    public function getCustom($id)
547
    {
548 3
        $result = parent::getDb()->prepare(str_format("SELECT id, value AS name FROM {0} WHERE id = ?", $this->getTableName()));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustom()). 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...
549 3
        $result->execute(array($id));
550 3
        if ($post = $result->fetchObject()) {
551 3
            return new CustomColumn($id, $post->name, $this);
552
        }
553
        return NULL;
554
    }
555
556 2
    protected function getAllCustomValuesFromDatabase()
557
    {
558 2
        $queryFormat = "SELECT {0}.id AS id, {0}.value AS name, count(*) AS count FROM {0}, {1} WHERE {0}.id = {1}.{2} GROUP BY {0}.id, {0}.value ORDER BY {0}.value";
559 2
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn());
560
561 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
562 2
        $entryArray = array();
563 2
        while ($post = $result->fetchObject()) {
564 2
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
565 2
            $entryPLinkArray = array(new LinkNavigation($this->getUri($post->id)));
566
567 2
            $entry = new Entry($post->name, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
568
569 2
            array_push($entryArray, $entry);
570 2
        }
571 2
        return $entryArray;
572
    }
573
574 5
    public function getDescription()
575
    {
576 5
        return str_format(localize("customcolumn.description.series", $this->getDistinctValueCount()), $this->getDistinctValueCount());
577
    }
578
579 2
    public function getCustomByBook($book)
580
    {
581 2
        $queryFormat = "SELECT {0}.id AS id, {1}.{2} AS name, {1}.extra AS extra FROM {0}, {1} WHERE {0}.id = {1}.{2} AND {1}.book = {3}";
582 2
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn(), $book->id);
583
584 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
585 2
        if ($post = $result->fetchObject()) {
586 1
            return new CustomColumn($post->id, $post->name . " [" . $post->extra . "]", $this);
587
        }
588 1
        return new CustomColumn(NULL, "", $this);
589
    }
590
591 5
    public function isSearchable()
592
    {
593 5
        return true;
594
    }
595
}
596
597
class CustomColumnTypeEnumeration extends CustomColumnType
598
{
599 1
    protected function __construct($pcustomId)
600
    {
601 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_ENUM);
602 1
    }
603
604
    /**
605
     * Get the name of the sqlite table for this column
606
     *
607
     * @return string|null
608
     */
609 5
    private function getTableName()
610
    {
611 5
        return "custom_column_{$this->customId}";
612
    }
613
614
    /**
615
     * Get the name of the linking sqlite table for this column
616
     * (or NULL if there is no linktable)
617
     *
618
     * @return string|null
619
     */
620 5
    private function getTableLinkName()
621
    {
622 5
        return "books_custom_column_{$this->customId}_link";
623
    }
624
625
    /**
626
     * Get the name of the linking column in the linktable
627
     *
628
     * @return string|null
629
     */
630 5
    private function getTableLinkColumn()
631
    {
632 5
        return "value";
633
    }
634
635 2
    public function getQuery($id)
636
    {
637 2
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", $this->getTableLinkName(), $this->getTableLinkColumn());
638 2
        return array($query, array($id));
639
    }
640
641 2
    public function getCustom($id)
642
    {
643 2
        $result = parent::getDb()->prepare(str_format("SELECT id, value AS name FROM {0} WHERE id = ?", $this->getTableName()));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustom()). 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...
644 2
        $result->execute(array($id));
645 2
        if ($post = $result->fetchObject()) {
646 2
            return new CustomColumn ($id, $post->name, $this);
647
        }
648
        return NULL;
649
    }
650
651 1
    protected function getAllCustomValuesFromDatabase()
652
    {
653 1
        $queryFormat = "SELECT {0}.id AS id, {0}.value AS name, count(*) AS count FROM {0}, {1} WHERE {0}.id = {1}.{2} GROUP BY {0}.id, {0}.value ORDER BY {0}.value";
654 1
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn());
655
656 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
657 1
        $entryArray = array();
658 1
        while ($post = $result->fetchObject()) {
659 1
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
660 1
            $entryPLinkArray = array(new LinkNavigation ($this->getUri($post->id)));
661
662 1
            $entry = new Entry ($post->name, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
663
664 1
            array_push($entryArray, $entry);
665 1
        }
666 1
        return $entryArray;
667
    }
668
669 3
    public function getDescription()
670
    {
671 3
        return str_format(localize("customcolumn.description.enum", $this->getDistinctValueCount()), $this->getDistinctValueCount());
672
    }
673
674 2
    public function getCustomByBook($book)
675
    {
676 2
        $queryFormat = "SELECT {0}.id AS id, {1}.{2} AS name FROM {0}, {1} WHERE {0}.id = {1}.{2} AND {1}.book = {3}";
677 2
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn(), $book->id);
678
679 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
680 2
        if ($post = $result->fetchObject()) {
681 2
            return new CustomColumn($post->id, $post->name, $this);
682
        }
683
        return new CustomColumn(NULL, localize("customcolumn.enum.unknown"), $this);
684
    }
685
686 3
    public function isSearchable()
687
    {
688 3
        return true;
689
    }
690
}
691
692
class CustomColumnTypeDate extends CustomColumnType
693
{
694 1
    protected function __construct($pcustomId)
695
    {
696 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_DATE);
697 1
    }
698
699
    /**
700
     * Get the name of the sqlite table for this column
701
     *
702
     * @return string|null
703
     */
704 5
    private function getTableName()
705
    {
706 5
        return "custom_column_{$this->customId}";
707
    }
708
709 2
    public function getQuery($id)
710
    {
711 2
        $date = new DateTime($id);
712 2
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DATE, "{0}", "{1}", $this->getTableName());
713 2
        return array($query, array($date->format("Y-m-d")));
714
    }
715
716 2
    public function getCustom($id)
717
    {
718 2
        $date = new DateTime($id);
719
720 2
        return new CustomColumn($id, $date->format(localize("customcolumn.date.format")), $this);
721
    }
722
723 1
    protected function getAllCustomValuesFromDatabase()
724
    {
725 1
        $queryFormat = "SELECT date(value) AS datevalue, count(*) AS count FROM {0} GROUP BY datevalue";
726 1
        $query = str_format($queryFormat, $this->getTableName());
727 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
728
729 1
        $entryArray = array();
730 1
        while ($post = $result->fetchObject()) {
731 1
            $date = new DateTimeImmutable($post->datevalue);
732 1
            $id = $date->format("Y-m-d");
733
734 1
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
735 1
            $entryPLinkArray = array(new LinkNavigation ($this->getUri($id)));
736
737 1
            $entry = new Entry($date->format(localize("customcolumn.date.format")), $this->getEntryId($id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
738
739 1
            array_push($entryArray, $entry);
740 1
        }
741
742 1
        return $entryArray;
743
    }
744
745 3
    public function getDescription()
746
    {
747 3
        $desc = $this->getDatabaseDescription();
748 3
        if ($desc == NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $desc of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
749 3
        return $desc;
750
    }
751
752 2
    public function getCustomByBook($book)
753
    {
754 2
        $queryFormat = "SELECT date({0}.value) AS datevalue FROM {0} WHERE {0}.book = {1}";
755 2
        $query = str_format($queryFormat, $this->getTableName(), $book->id);
756
757 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
758 2
        if ($post = $result->fetchObject()) {
759 1
            $date = new DateTimeImmutable($post->datevalue);
760
761 1
            return new CustomColumn($date->format("Y-m-d"), $date->format(localize("customcolumn.date.format")), $this);
762
        }
763 1
        return new CustomColumn(NULL, localize("customcolumn.date.unknown"), $this);
764
    }
765
766 3
    public function isSearchable()
767
    {
768 3
        return true;
769
    }
770
}
771
772
class CustomColumnTypeRating extends CustomColumnType
773
{
774 1
    protected function __construct($pcustomId)
775
    {
776 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_RATING);
777 1
    }
778
779
    /**
780
     * Get the name of the sqlite table for this column
781
     *
782
     * @return string|null
783
     */
784 5
    private function getTableName()
785
    {
786 5
        return "custom_column_{$this->customId}";
787
    }
788
789
    /**
790
     * Get the name of the linking sqlite table for this column
791
     * (or NULL if there is no linktable)
792
     *
793
     * @return string|null
794
     */
795 5
    private function getTableLinkName()
796
    {
797 5
        return "books_custom_column_{$this->customId}_link";
798
    }
799
800
    /**
801
     * Get the name of the linking column in the linktable
802
     *
803
     * @return string|null
804
     */
805 4
    private function getTableLinkColumn()
806
    {
807 4
        return "value";
808
    }
809
810 2
    public function getQuery($id)
811
    {
812 2
        if ($id == 0) {
813 2
            $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_RATING_NULL, "{0}", "{1}", $this->getTableLinkName(), $this->getTableName(), $this->getTableLinkColumn());
814 2
            return array($query, array());
815
        } else {
816 2
            $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_RATING, "{0}", "{1}", $this->getTableLinkName(), $this->getTableName(), $this->getTableLinkColumn());
817 2
            return array($query, array($id));
818
        }
819
    }
820
821 2
    public function getCustom($id)
822
    {
823 2
        return new CustomColumn ($id, str_format(localize("customcolumn.stars", $id / 2), $id / 2), $this);
824
    }
825
826 1
    protected function getAllCustomValuesFromDatabase()
827
    {
828 1
        $queryFormat = "SELECT coalesce({0}.value, 0) AS value, count(*) AS count FROM books  LEFT JOIN {1} ON  books.id = {1}.book LEFT JOIN {0} ON {0}.id = {1}.value GROUP BY coalesce({0}.value, -1)";
829 1
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName());
830 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
831
832 1
        $countArray = array(0 => 0, 2 => 0, 4 => 0, 6 => 0, 8 => 0, 10 => 0);
833 1
        while ($row = $result->fetchObject()) {
834 1
            $countArray[$row->value] = $row->count;
835 1
        }
836
837 1
        $entryArray = array();
838
839 1
        for ($i = 0; $i <= 5; $i++) {
840 1
            $count = $countArray[$i * 2];
841 1
            $name = str_format(localize("customcolumn.stars", $i), $i);
842 1
            $entryid = $this->getEntryId($i * 2);
843 1
            $content = str_format(localize("bookword", $count), $count);
844 1
            $linkarray = array(new LinkNavigation($this->getUri($i * 2)));
845 1
            $entry = new Entry($name, $entryid, $content, $this->datatype, $linkarray, "", $count);
846 1
            array_push($entryArray, $entry);
847 1
        }
848
849 1
        return $entryArray;
850
    }
851
852 3
    public function getDescription()
853
    {
854 3
        return localize("customcolumn.description.rating");
855
    }
856
857 2
    public function getCustomByBook($book)
858
    {
859 2
        $queryFormat = "SELECT {0}.value AS value FROM {0}, {1} WHERE {0}.id = {1}.{2} AND {1}.book = {3}";
860 2
        $query = str_format($queryFormat, $this->getTableName(), $this->getTableLinkName(), $this->getTableLinkColumn(), $book->id);
861
862 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
863 2
        if ($post = $result->fetchObject()) {
864 1
            return new CustomColumn($post->value, str_format(localize("customcolumn.stars", $post->value / 2), $post->value / 2), $this);
865
        }
866 1
        return new CustomColumn(NULL, localize("customcolumn.rating.unknown"), $this);
867
    }
868
869 3
    public function isSearchable()
870
    {
871 3
        return true;
872
    }
873
}
874
875
class CustomColumnTypeBool extends CustomColumnType
876
{
877
    // PHP pre 5.6 does not support const arrays
878
    private $BOOLEAN_NAMES = array(
879
        -1 => "customcolumn.boolean.unknown", // localize("customcolumn.boolean.unknown")
880
        00 => "customcolumn.boolean.no",      // localize("customcolumn.boolean.no")
881
        +1 => "customcolumn.boolean.yes",     // localize("customcolumn.boolean.yes")
882
    );
883
884 1
    protected function __construct($pcustomId)
885
    {
886 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_BOOL);
887 1
    }
888
889
    /**
890
     * Get the name of the sqlite table for this column
891
     *
892
     * @return string|null
893
     */
894 5
    private function getTableName()
895
    {
896 5
        return "custom_column_{$this->customId}";
897
    }
898
899 3
    public function getQuery($id)
900
    {
901 3
        if ($id == -1) {
902 2
            $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_NULL, "{0}", "{1}", $this->getTableName());
903 2
            return array($query, array());
904 3
        } else if ($id == 0) {
905 3
            $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_FALSE, "{0}", "{1}", $this->getTableName());
906 3
            return array($query, array());
907 2
        } else if ($id == 1) {
908 2
            $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_BOOL_TRUE, "{0}", "{1}", $this->getTableName());
909 2
            return array($query, array());
910
        } else {
911
            return NULL;
912
        }
913
    }
914
915 3
    public function getCustom($id)
916
    {
917 3
        return new CustomColumn($id, localize($this->BOOLEAN_NAMES[$id]), $this);
918
    }
919
920 1
    protected function getAllCustomValuesFromDatabase()
921
    {
922 1
        $queryFormat = "SELECT coalesce({0}.value, -1) AS id, count(*) AS count FROM books LEFT JOIN {0} ON  books.id = {0}.book GROUP BY {0}.value ORDER BY {0}.value";
923 1
        $query = str_format($queryFormat, $this->getTableName());
924 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
925
926 1
        $entryArray = array();
927 1
        while ($post = $result->fetchObject()) {
928 1
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
929 1
            $entryPLinkArray = array(new LinkNavigation ($this->getUri($post->id)));
930
931 1
            $entry = new Entry(localize($this->BOOLEAN_NAMES[$post->id]), $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
932
933 1
            array_push($entryArray, $entry);
934 1
        }
935 1
        return $entryArray;
936
    }
937
938 3
    public function getDescription()
939
    {
940 3
        return localize("customcolumn.description.bool");
941
    }
942
943 2
    public function getCustomByBook($book)
944
    {
945 2
        $queryFormat = "SELECT {0}.value AS boolvalue FROM {0} WHERE {0}.book = {1}";
946 2
        $query = str_format($queryFormat, $this->getTableName(), $book->id);
947
948 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
949 2
        if ($post = $result->fetchObject()) {
950 2
            return new CustomColumn($post->boolvalue, localize($this->BOOLEAN_NAMES[$post->boolvalue]), $this);
951
        } else {
952
            return new CustomColumn(-1, localize($this->BOOLEAN_NAMES[-1]), $this);
953
        }
954
    }
955
956 3
    public function isSearchable()
957
    {
958 3
        return true;
959
    }
960
}
961
962
class CustomColumnTypeInteger extends CustomColumnType
963
{
964 1
    protected function __construct($pcustomId)
965
    {
966 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_INT);
967 1
    }
968
969
    /**
970
     * Get the name of the sqlite table for this column
971
     *
972
     * @return string|null
973
     */
974 5
    private function getTableName()
975
    {
976 5
        return "custom_column_{$this->customId}";
977
    }
978
979 2
    public function getQuery($id)
980
    {
981 2
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DIRECT, "{0}", "{1}", $this->getTableName());
982 2
        return array($query, array($id));
983
    }
984
985 2
    public function getCustom($id)
986
    {
987 2
        return new CustomColumn($id, $id, $this);
988
    }
989
990 1
    protected function getAllCustomValuesFromDatabase()
991
    {
992 1
        $queryFormat = "SELECT value AS id, count(*) AS count FROM {0} GROUP BY value";
993 1
        $query = str_format($queryFormat, $this->getTableName());
994
995 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
996 1
        $entryArray = array();
997 1
        while ($post = $result->fetchObject()) {
998 1
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
999 1
            $entryPLinkArray = array(new LinkNavigation($this->getUri($post->id)));
1000
1001 1
            $entry = new Entry($post->id, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
1002
1003 1
            array_push($entryArray, $entry);
1004 1
        }
1005 1
        return $entryArray;
1006
    }
1007
1008 3
    public function getDescription()
1009
    {
1010 3
        $desc = $this->getDatabaseDescription();
1011 3
        if ($desc == NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $desc of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
1012 3
        return $desc;
1013
    }
1014
1015 2
    public function getCustomByBook($book)
1016
    {
1017 2
        $queryFormat = "SELECT {0}.value AS value FROM {0} WHERE {0}.book = {1}";
1018 2
        $query = str_format($queryFormat, $this->getTableName(), $book->id);
1019
1020 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
1021 2
        if ($post = $result->fetchObject()) {
1022 1
            return new CustomColumn($post->value, $post->value, $this);
1023
        }
1024 1
        return new CustomColumn(NULL, localize("customcolumn.int.unknown"), $this);
1025
    }
1026
1027 3
    public function isSearchable()
1028
    {
1029 3
        return true;
1030
    }
1031
}
1032
1033
class CustomColumnTypeFloat extends CustomColumnType
1034
{
1035 1
    protected function __construct($pcustomId)
1036
    {
1037 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_FLOAT);
1038 1
    }
1039
1040
    /**
1041
     * Get the name of the sqlite table for this column
1042
     *
1043
     * @return string|null
1044
     */
1045 5
    private function getTableName()
1046
    {
1047 5
        return "custom_column_{$this->customId}";
1048
    }
1049
1050 2
    public function getQuery($id)
1051
    {
1052 2
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DIRECT, "{0}", "{1}", $this->getTableName());
1053 2
        return array($query, array($id));
1054
    }
1055
1056 2
    public function getCustom($id)
1057
    {
1058 2
        return new CustomColumn($id, $id, $this);
1059
    }
1060
1061 1
    protected function getAllCustomValuesFromDatabase()
1062
    {
1063 1
        $queryFormat = "SELECT value AS id, count(*) AS count FROM {0} GROUP BY value";
1064 1
        $query = str_format($queryFormat, $this->getTableName());
1065
1066 1
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getAllCustomValuesFromDatabase()). 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...
1067 1
        $entryArray = array();
1068 1
        while ($post = $result->fetchObject()) {
1069 1
            $entryPContent = str_format(localize("bookword", $post->count), $post->count);
1070 1
            $entryPLinkArray = array(new LinkNavigation($this->getUri($post->id)));
1071
1072 1
            $entry = new Entry($post->id, $this->getEntryId($post->id), $entryPContent, $this->datatype, $entryPLinkArray, "", $post->count);
1073
1074 1
            array_push($entryArray, $entry);
1075 1
        }
1076 1
        return $entryArray;
1077
    }
1078
1079 3
    public function getDescription()
1080
    {
1081 3
        $desc = $this->getDatabaseDescription();
1082 3
        if ($desc == NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $desc of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
1083 3
        return $desc;
1084
    }
1085
1086 2
    public function getCustomByBook($book)
1087
    {
1088 2
        $queryFormat = "SELECT {0}.value AS value FROM {0} WHERE {0}.book = {1}";
1089 2
        $query = str_format($queryFormat, $this->getTableName(), $book->id);
1090
1091 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
1092 2
        if ($post = $result->fetchObject()) {
1093 2
            return new CustomColumn($post->value, $post->value, $this);
1094
        }
1095
        return new CustomColumn(NULL, localize("customcolumn.float.unknown"), $this);
1096
    }
1097
1098 3
    public function isSearchable()
1099
    {
1100 3
        return true;
1101
    }
1102
}
1103
1104
class CustomColumnTypeComment extends CustomColumnType
1105
{
1106 1
    protected function __construct($pcustomId)
1107
    {
1108 1
        parent::__construct($pcustomId, self::CUSTOM_TYPE_COMMENT);
1109 1
    }
1110
1111
    /**
1112
     * Get the name of the sqlite table for this column
1113
     *
1114
     * @return string|null
1115
     */
1116 4
    private function getTableName()
1117
    {
1118 4
        return "custom_column_{$this->customId}";
1119
    }
1120
1121 2
    public function getQuery($id)
1122
    {
1123 2
        $query = str_format(Book::SQL_BOOKS_BY_CUSTOM_DIRECT_ID, "{0}", "{1}", $this->getTableName());
1124 2
        return array($query, array($id));
1125
    }
1126
1127 2
    public function getCustom($id)
1128
    {
1129 2
        return new CustomColumn($id, $id, $this);
1130
    }
1131
1132 4
    public function encodeHTMLValue($value)
1133
    {
1134 4
        return "<div>" . $value . "</div>"; // no htmlspecialchars, this is already HTML
1135
    }
1136
1137
    protected function getAllCustomValuesFromDatabase()
1138
    {
1139
        return NULL;
1140
    }
1141
1142 1
    public function getDescription()
1143
    {
1144 1
        $desc = $this->getDatabaseDescription();
1145 1
        if ($desc == NULL || empty($desc)) $desc = str_format(localize("customcolumn.description"), $this->getTitle());
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $desc of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
1146 1
        return $desc;
1147
    }
1148
1149 2
    public function getCustomByBook($book)
1150
    {
1151 2
        $queryFormat = "SELECT {0}.id AS id, {0}.value AS value FROM {0} WHERE {0}.book = {1}";
1152 2
        $query = str_format($queryFormat, $this->getTableName(), $book->id);
1153
1154 2
        $result = parent::getDb()->query($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDb() instead of getCustomByBook()). 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...
1155 2
        if ($post = $result->fetchObject()) {
1156 1
            return new CustomColumn($post->id, $post->value, $this);
1157
        }
1158 1
        return new CustomColumn(NULL, localize("customcolumn.float.unknown"), $this);
1159
    }
1160
1161 3
    public function isSearchable()
1162
    {
1163 3
        return false;
1164
    }
1165
}
1166