Completed
Push — master ( 75c398...3c71f0 )
by Thierry
01:47
created

Paginator::setProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
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\Request\Factory\CallableObject;
16
17
use Jaxon\Request\Support\CallableObject;
18
19
class Paginator
20
{
21
    /**
22
     * The callable object this factory is attached to
23
     *
24
     * @var CallableObject
25
     */
26
    private $xCallable;
27
28
    /**
29
     * The total number of items
30
     *
31
     * @var integer
32
     */
33
    private $nItemsTotal = 0;
34
35
    /**
36
     * The number of items per page
37
     *
38
     * @var integer
39
     */
40
    private $nItemsPerPage = 0;
41
42
    /**
43
     * The current page
44
     *
45
     * @var integer
46
     */
47
    private $nCurrentPage = 0;
48
49
    /**
50
     * The class constructor
51
     *
52
     * @param CallableObject        $xCallable
53
     */
54
    public function __construct(CallableObject $xCallable)
55
    {
56
        $this->xCallable = $xCallable;
57
    }
58
59
    /**
60
     * Set the paginator properties
61
     *
62
     * @param integer $nItemsTotal the total number of items
63
     * @param integer $nItemsPerPage the number of items per page
64
     * @param integer $nCurrentPage the current page
65
     *
66
     * @return Paginator
67
     */
68
    public function setProperties($nItemsTotal, $nItemsPerPage, $nCurrentPage)
69
    {
70
        $this->nItemsTotal = $nItemsTotal;
71
        $this->nItemsPerPage = $nItemsPerPage;
72
        $this->nCurrentPage = $nCurrentPage;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Generate the corresponding javascript code for a call to any method
79
     *
80
     * @return string
81
     */
82
    public function __call($sMethod, $aArguments)
83
    {
84
        // Add the paginator options to the method arguments
85
        $aPgArgs = [$this->nItemsTotal, $this->nItemsPerPage, $this->nCurrentPage, $sMethod];
86
        $aArguments = array_merge($aPgArgs, $aArguments);
87
88
        // Make the request
89
        $factory = rq()->setCallable($this->xCallable);
90
        return call_user_func_array([$factory, 'paginate'], $aArguments);
91
    }
92
}
93