开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 921

张健(peter)/IBOS

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
标签 (6)
master
develop
4.2
3.9
3.8
3.5
v3.5
3.3
master
分支 (2)
标签 (6)
master
develop
4.2
3.9
3.8
3.5
v3.5
3.3
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
标签 (6)
master
develop
4.2
3.9
3.8
3.5
v3.5
3.3
IBOS
/
library
/
web
/
CArrayDataProvider.php
IBOS
/
library
/
web
/
CArrayDataProvider.php
CArrayDataProvider.php 5.93 KB
一键复制 编辑 原始数据 按行查看 历史
seekArt 提交于 2015年07月21日 17:24 +08:00 . 提交初始版本
<?php
/**
* CArrayDataProvider class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* CArrayDataProvider implements a data provider based on a raw data array.
*
* The {@link rawData} property contains all data that may be sorted and/or paginated.
* CArrayDataProvider will supply the data after sorting and/or pagination.
* You may configure the {@link sort} and {@link pagination} properties to
* customize sorting and pagination behaviors.
*
* Elements in the raw data array may be either objects (e.g. model objects)
* or associative arrays (e.g. query results of DAO).
* Make sure to set the {@link keyField} property to the name of the field that uniquely
* identifies a data record or false if you do not have such a field.
*
* CArrayDataProvider may be used in the following way:
* <pre>
* $rawData=Yii::app()->db->createCommand('SELECT * FROM tbl_user')->queryAll();
* // or using: $rawData=User::model()->findAll();
* $dataProvider=new CArrayDataProvider($rawData, array(
* 'id'=>'user',
* 'sort'=>array(
* 'attributes'=>array(
* 'id', 'username', 'email',
* ),
* ),
* 'pagination'=>array(
* 'pageSize'=>10,
* ),
* ));
* // $dataProvider->getData() will return a list of arrays.
* </pre>
*
* Note: if you want to use the sorting feature, you must configure {@link sort} property
* so that the provider knows which columns can be sorted.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.web
* @since 1.1.4
*/
class CArrayDataProvider extends CDataProvider
{
/**
* @var string the name of the key field. This is a field that uniquely identifies a
* data record. In database this would be the primary key.
* Defaults to 'id'. If it's set to false, keys of {@link rawData} array are used.
*/
public $keyField='id';
/**
* @var array the data that is not paginated or sorted. When pagination is enabled,
* this property usually contains more elements than {@link data}.
* The array elements must use zero-based integer keys.
*/
public $rawData=array();
/**
* @var boolean controls how sorting works. True value means that case will be
* taken into account. False value will lead to the case insensitive sort. Default
* value is true.
* @since 1.1.13
*/
public $caseSensitiveSort=true;
/**
* Constructor.
* @param array $rawData the data that is not paginated or sorted. The array elements must use zero-based integer keys.
* @param array $config configuration (name=>value) to be applied as the initial property values of this class.
*/
public function __construct($rawData,$config=array())
{
$this->rawData=$rawData;
foreach($config as $key=>$value)
$this->$key=$value;
}
/**
* Fetches the data from the persistent data storage.
* @return array list of data items
*/
protected function fetchData()
{
if(($sort=$this->getSort())!==false && ($order=$sort->getOrderBy())!='')
$this->sortData($this->getSortDirections($order));
if(($pagination=$this->getPagination())!==false)
{
$pagination->setItemCount($this->getTotalItemCount());
return array_slice($this->rawData, $pagination->getOffset(), $pagination->getLimit());
}
else
return $this->rawData;
}
/**
* Fetches the data item keys from the persistent data storage.
* @return array list of data item keys.
*/
protected function fetchKeys()
{
if($this->keyField===false)
return array_keys($this->rawData);
$keys=array();
foreach($this->getData() as $i=>$data)
$keys[$i]=is_object($data) ? $data->{$this->keyField} : $data[$this->keyField];
return $keys;
}
/**
* Calculates the total number of data items.
* This method simply returns the number of elements in {@link rawData}.
* @return integer the total number of data items.
*/
protected function calculateTotalItemCount()
{
return count($this->rawData);
}
/**
* Sorts the raw data according to the specified sorting instructions.
* After calling this method, {@link rawData} will be modified.
* @param array $directions the sorting directions (field name => whether it is descending sort)
*/
protected function sortData($directions)
{
if(empty($directions))
return;
$args=array();
$dummy=array();
foreach($directions as $name=>$descending)
{
$column=array();
$fields_array=preg_split('/\.+/',$name,-1,PREG_SPLIT_NO_EMPTY);
foreach($this->rawData as $index=>$data)
$column[$index]=$this->getSortingFieldValue($data, $fields_array);
$args[]=&$column;
$dummy[]=&$column;
unset($column);
$direction=$descending ? SORT_DESC : SORT_ASC;
$args[]=&$direction;
$dummy[]=&$direction;
unset($direction);
}
$args[]=&$this->rawData;
call_user_func_array('array_multisort', $args);
}
/**
* Get field for sorting, using dot like delimiter in query.
* @param mixed $data array or object
* @param array $fields sorting fields in $data
* @return mixed $data sorting field value
*/
protected function getSortingFieldValue($data, $fields)
{
if(is_object($data))
{
foreach($fields as $field)
$data=isset($data->$field) ? $data->$field : null;
}
else
{
foreach($fields as $field)
$data=isset($data[$field]) ? $data[$field] : null;
}
return $this->caseSensitiveSort ? $data : mb_strtolower($data,Yii::app()->charset);
}
/**
* Converts the "ORDER BY" clause into an array representing the sorting directions.
* @param string $order the "ORDER BY" clause.
* @return array the sorting directions (field name => whether it is descending sort)
*/
protected function getSortDirections($order)
{
$segs=explode(',',$order);
$directions=array();
foreach($segs as $seg)
{
if(preg_match('/(.*?)(\s+(desc|asc))?$/i',trim($seg),$matches))
$directions[$matches[1]]=isset($matches[3]) && !strcasecmp($matches[3],'desc');
else
$directions[trim($seg)]=false;
}
return $directions;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

基于Yii和bootstrap的开源OA/协同办公平台,连接全平台覆盖的酷办公客户端(Win,IOS,Android,Mac,Linux),支撑您的企业管理二次开发--作为国内首家开源OA,有的不只是颜值
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/case-code/IBOS.git
git@gitee.com:case-code/IBOS.git
case-code
IBOS
IBOS
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /