Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
01b6a7cf
Commit
01b6a7cf
authored
Jul 08, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added DataProvider and IDataProvider.
parent
e00346e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
11 deletions
+160
-11
DataProvider.php
framework/yii/data/DataProvider.php
+100
-0
IDataProvider.php
framework/yii/data/IDataProvider.php
+59
-0
Pagination.php
framework/yii/data/Pagination.php
+1
-11
No files found.
framework/yii/data/DataProvider.php
0 → 100644
View file @
01b6a7cf
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\data
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\InvalidParamException
;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
abstract
class
DataProvider
extends
Component
implements
IDataProvider
{
private
$_sort
;
private
$_pagination
;
/**
* @return Pagination the pagination object. If this is false, it means the pagination is disabled.
*/
public
function
getPagination
()
{
if
(
$this
->
_pagination
===
null
)
{
$this
->
_pagination
=
new
Pagination
;
}
return
$this
->
_pagination
;
}
/**
* Sets the pagination for this data provider.
* @param array|Pagination|boolean $value the pagination to be used by this data provider.
* This can be one of the following:
*
* - a configuration array for creating the pagination object. The "class" element defaults
* to 'yii\data\Pagination'
* - an instance of [[Pagination]] or its subclass
* - false, if pagination needs to be disabled.
*
* @throws InvalidParamException
*/
public
function
setPagination
(
$value
)
{
if
(
is_array
(
$value
))
{
$this
->
_pagination
=
Yii
::
createObject
(
array_merge
(
array
(
'class'
=>
'yii\data\Pagination'
),
$value
));
}
elseif
(
$value
instanceof
Pagination
||
$value
===
false
)
{
$this
->
_pagination
=
$value
;
}
else
{
throw
new
InvalidParamException
(
'Only Pagination instance, configuration array or false is allowed.'
);
}
}
/**
* @return Sort the sorting object. If this is false, it means the sorting is disabled.
*/
public
function
getSort
()
{
if
(
$this
->
_sort
===
null
)
{
$this
->
_sort
=
new
Sort
;
}
return
$this
->
_sort
;
}
/**
* Sets the sort definition for this data provider.
* @param array|Sort|boolean $value the sort definition to be used by this data provider.
* This can be one of the following:
*
* - a configuration array for creating the sort definition object. The "class" element defaults
* to 'yii\data\Sort'
* - an instance of [[Sort]] or its subclass
* - false, if sorting needs to be disabled.
*
* @throws InvalidParamException
*/
public
function
setSort
(
$value
)
{
if
(
is_array
(
$value
))
{
$this
->
_sort
=
Yii
::
createObject
(
array_merge
(
array
(
'class'
=>
'yii\data\Sort'
),
$value
));
}
elseif
(
$value
instanceof
Sort
||
$value
===
false
)
{
$this
->
_sort
=
$value
;
}
else
{
throw
new
InvalidParamException
(
'Only Sort instance, configuration array or false is allowed.'
);
}
}
/**
* Returns the number of data items in the current page.
* @return integer the number of data items in the current page.
*/
public
function
getItemCount
()
{
return
count
(
$this
->
getItems
());
}
}
framework/yii/data/IDataProvider.php
0 → 100644
View file @
01b6a7cf
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\data
;
/**
* IDataProvider is the interface that must be implemented by data provider classes.
*
* Data providers are components that can provide data that are sorted and paginated.
* Data providers are often used with widgets, such as [[GridView]], [[ListView]]
* that display data and support sorting and pagination.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
interface
IDataProvider
{
/**
* Returns the number of data items in the current page.
* This is equivalent to `count($provider->getItems())`.
* When [[pagination]] is false, this is the same as [[totalItemCount]].
* @return integer the number of data items in the current page.
*/
public
function
getItemCount
();
/**
* Returns the total number of data items.
* When [[pagination]] is false, this is the same as [[itemCount]].
* @return integer total number of possible data items.
*/
public
function
getTotalItemCount
();
/**
* Returns the data items in the current page.
* @return array the list of data items in the current page.
*/
public
function
getItems
();
/**
* Returns the key values associated with the data items.
* @return array the list of key values corresponding to [[items]]. Each data item in [[items]]
* is uniquely identified by the corresponding key value in this array.
*/
public
function
getKeys
();
/**
* @return Sort the sorting object. If this is false, it means the sorting is disabled.
*/
public
function
getSort
();
/**
* @return Pagination the pagination object. If this is false, it means the pagination is disabled.
*/
public
function
getPagination
();
}
framework/yii/data/Pagination.php
View file @
01b6a7cf
...
...
@@ -104,18 +104,8 @@ class Pagination extends Object
/**
* @var integer total number of items.
*/
public
$itemCount
;
public
$itemCount
=
0
;
/**
* Constructor.
* @param integer $itemCount total number of items.
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public
function
__construct
(
$itemCount
,
$config
=
array
())
{
$this
->
itemCount
=
$itemCount
;
parent
::
__construct
(
$config
);
}
/**
* @return integer number of pages
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment