vendor/bundles/Pagerfanta/Adapter/MandangoAdapter.php
changeset 15 99ad73ef7385
equal deleted inserted replaced
14:fc78844c8a76 15:99ad73ef7385
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Pagerfanta package.
       
     5  *
       
     6  * (c) Pablo Díez <pablodip@gmail.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Pagerfanta\Adapter;
       
    13 
       
    14 use Mandango\Query;
       
    15 
       
    16 /**
       
    17  * MandangoAdapter.
       
    18  *
       
    19  * @author Pablo Díez <pablodip@gmail.com>
       
    20  *
       
    21  * @api
       
    22  */
       
    23 class MandangoAdapter implements AdapterInterface
       
    24 {
       
    25     private $query;
       
    26 
       
    27     /**
       
    28      * Constructor.
       
    29      *
       
    30      * @param Query $query The query.
       
    31      *
       
    32      * @api
       
    33      */
       
    34     public function __construct(Query $query)
       
    35     {
       
    36         $this->query = $query;
       
    37     }
       
    38 
       
    39     /**
       
    40      * Returns the query.
       
    41      *
       
    42      * @return Query The query.
       
    43      *
       
    44      * @api
       
    45      */
       
    46     public function getQuery()
       
    47     {
       
    48         return $this->query;
       
    49     }
       
    50 
       
    51     /**
       
    52      * {@inheritdoc}
       
    53      */
       
    54     public function getNbResults()
       
    55     {
       
    56         return $this->query->count();
       
    57     }
       
    58 
       
    59     /**
       
    60      * {@inheritdoc}
       
    61      */
       
    62     public function getSlice($offset, $length)
       
    63     {
       
    64         return $this->query->limit($length)->skip($offset)->all();
       
    65     }
       
    66 }