Skip to content

Commit

Permalink
add info and change typo
Browse files Browse the repository at this point in the history
  • Loading branch information
steevenz committed Jan 16, 2018
1 parent 4f74e8b commit 9603059
Show file tree
Hide file tree
Showing 3 changed files with 674 additions and 560 deletions.
16 changes: 16 additions & 0 deletions src/DataObjects/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// ------------------------------------------------------------------------

use O2System\Database\DataObjects\Result\Info;
use O2System\Database\DataObjects\Result\Row;
use O2System\Spl\Datastructures\Traits\ArrayConversionTrait;

Expand Down Expand Up @@ -470,4 +471,19 @@ public function jsonSerialize()
{
return $this->rows;
}

// ------------------------------------------------------------------------

/**
* Result::getInfo
*
* @return \O2System\Database\DataObjects\Result\Info
*/
public function getInfo()
{
return new Info([
'rows' => $this->countAll(),
'founds' => $this->count()
]);
}
}
92 changes: 92 additions & 0 deletions src/DataObjects/Result/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* This file is part of the O2System PHP Framework package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Steeve Andrian Salim
* @copyright Copyright (c) Steeve Andrian Salim
*/

// ------------------------------------------------------------------------

namespace O2System\Database\DataObjects\Result;

// ------------------------------------------------------------------------

use O2System\Spl\Datastructures\SplArrayObject;

/**
* Class Info
* @package O2System\Database\DataObjects\Result
*/
class Info
{
protected $entries = 5;
protected $total;
protected $numbering;

// ------------------------------------------------------------------------

/**
* Info::__construct
*
* @param array $total
*/
public function __construct( array $total )
{
$this->total = new SplArrayObject(array_merge([
'rows' => 0,
'founds' => 0,
'pages' => 0,
], $total));
}

// ------------------------------------------------------------------------

/**
* Info::setEntries
*
* @param int $entries
*
* @return static
*/
public function setEntries( $entries )
{
$this->entries = (int) $entries;

return $this;
}

// ------------------------------------------------------------------------

/**
* Info::getTotal
*
* @return \O2System\Spl\Datastructures\SplArrayObject
*/
public function getTotal()
{
$this->total->pages = round( $this->total->rows / $this->entries );

return $this->total;
}

// ------------------------------------------------------------------------

/**
* Info::getNumbering
*
* @return \O2System\Spl\Datastructures\SplArrayObject
*/
public function getNumbering()
{
$activePage = (input()->get('page') ? input()->get('page') : 1);

return new SplArrayObject([
'start' => $start = ($activePage == 1 ? 1 : $activePage * $this->entries + 1),
'end' => $start + $this->entries
]);
}
}
Loading

0 comments on commit 9603059

Please sign in to comment.