Completed
Push — master ( fd24d6...d99eda )
by Thierry
02:33
created

Paginator::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Paginator.php - Jaxon Request Factory
5
 *
6
 * Create pagination links to a given class.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Factory\CallableObject;
16
17
use Jaxon\DI\Container;
18
use Jaxon\Request\Support\CallableObject;
19
20
class Paginator
21
{
22
    /**
23
     * The callable object this factory is attached to
24
     *
25
     * @var CallableObject
26
     */
27
    private $xCallable;
28
29
    /**
30
     * The total number of items
31
     *
32
     * @var integer
33
     */
34
    private $nItemsTotal = 0;
35
36
    /**
37
     * The number of items per page
38
     *
39
     * @var integer
40
     */
41
    private $nItemsPerPage = 0;
42
43
    /**
44
     * The current page
45
     *
46
     * @var integer
47
     */
48
    private $nCurrentPage = 0;
49
50
    /**
51
     * Create a new Factory instance.
52
     *
53
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
54
     */
55
    public function __construct(CallableObject $xCallable)
56
    {
57
        $this->xCallable = $xCallable;
58
    }
59
60
    /**
61
     * Set the paginator properties
62
     *
63
     * @param integer $nItemsTotal the total number of items
64
     * @param integer $nItemsPerPage the number of items per page
65
     * @param integer $nCurrentPage the current page
66
     *
67
     * @return Paginator
68
     */
69
    public function setProperties($nItemsTotal, $nItemsPerPage, $nCurrentPage)
70
    {
71
        $this->nItemsTotal = $nItemsTotal;
72
        $this->nItemsPerPage = $nItemsPerPage;
73
        $this->nCurrentPage = $nCurrentPage;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Generate the corresponding javascript code for a call to any method
80
     *
81
     * @return string
82
     */
83
    public function __call($sMethod, $aArguments)
84
    {
85
        // Add the paginator options to the method arguments
86
        $aPgArgs = [$this->nItemsTotal, $this->nItemsPerPage, $this->nCurrentPage, $sMethod];
87
        $aArguments = array_merge($aPgArgs, $aArguments);
88
89
        // Make the request
90
        $factory = Container::getInstance()->getRequestFactory()->setCallable($this->xCallable);
91
        return call_user_func_array([$factory, 'paginate'], $aArguments);
92
    }
93
}
94