本文整理汇总了PHP中Arr::listToHash方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::listToHash方法的具体用法?PHP Arr::listToHash怎么用?PHP Arr::listToHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::listToHash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxChangeStatusAction
public function ajaxChangeStatusAction()
{
$applyId = Request::getPOST('apply-id');
$op = Request::getPOST('op');
if (!in_array($op, array(1, 2)) || empty($applyId)) {
$this->renderError('参数错误!');
}
$applyInfo = OjContestApplyInterface::getById(array('id' => $applyId));
if (empty($applyInfo)) {
$this->renderError('报名信息不存在!');
}
// 只能处理自己竞赛下的报名
$where = array(array('user_id', '=', $this->loginUserInfo['id']), array('is_diy', '=', 1));
$contestHash = OjContestInterface::getList(array('where' => $where));
$contestHash = Arr::listToHash('id', $contestHash);
$contestIds = array_keys($contestHash);
if (!in_array($applyInfo['contest_id'], $contestIds)) {
$this->renderError('你没有权限操作!');
}
if ($op == 1 && $applyInfo['status'] == ContestVars::APPLY_ACCEPTED || $op == 2 && $applyInfo['status'] == ContestVars::APPLY_REJECTED) {
$msg = $op == 1 ? '已经通过!' : '已经拒绝!';
$this->renderError($msg);
}
if ($op == 1) {
OjContestApplyInterface::accept(array('id' => $applyId));
} else {
OjContestApplyInterface::reject(array('id' => $applyId));
}
$this->setNotice(FrameworkVars::NOTICE_SUCCESS, '操作成功!');
$this->renderAjax(0);
}
示例2: defaultAction
public function defaultAction()
{
list($rankHash, $mat, $userHash) = OjContestInterface::getRankBoard(array('id' => $this->contestInfo['id']));
// 如果是报名,获取报名列表
$applyHash = array();
if ($this->contestInfo['type'] == ContestVars::TYPE_APPLY) {
$where = array(array('contest_id', '=', $this->contestInfo['id']));
$applyHash = OjContestApplyInterface::getList(array('where' => $where));
$applyHash = Arr::listToHash('user_id', $applyHash);
}
$this->renderFramework(array('rankHash' => $rankHash, 'mat' => $mat, 'userHash' => $userHash, 'applyHash' => $applyHash), 'rank/list.php');
}
示例3: ajaxLoadProblemAction
public function ajaxLoadProblemAction()
{
require_once INCLUDE_PATH . '/remote/RemoteProblemApi.class.php';
$remote = (int) Request::getPOST('remote');
$number = (int) Request::getPOST('number');
if (empty($number)) {
$this->renderError('参数错误1!');
}
if (!array_key_exists($remote, StatusVars::$REMOTE_SCHOOL) || $remote == StatusVars::REMOTE_HQU) {
$this->renderError('参数错误2!');
}
// 获取各个OJ下题号
$where = array('group_by' => 'remote');
$problemList = OjProblemInterface::getList(array('field' => 'remote, max(problem_code) AS max_id', 'where' => $where));
if (false === $problemList) {
$this->renderError('查询失败!');
}
$remoteHash = Arr::listToHash('remote', $problemList);
foreach ($problemList as $problemInfo) {
$remoteHash[$problemInfo['remote']] = $problemInfo['max_id'];
}
$hduFromId = (int) Arr::get(StatusVars::REMOTE_HDU, $remoteHash, 999) + 1;
$pojFromId = (int) Arr::get(StatusVars::REMOTE_POJ, $remoteHash, 999) + 1;
$zojFromId = (int) Arr::get(StatusVars::REMOTE_POJ, $remoteHash, 1000) + 1;
$loadProblemList = array();
if ($remote == StatusVars::REMOTE_HDU) {
$loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_HDU, $hduFromId, $number);
} else {
if ($remote == StatusVars::REMOTE_POJ) {
$loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_POJ, $pojFromId, $number);
} else {
if ($remote == StatusVars::REMOTE_ZOJ) {
$loadProblemList = RemoteProblemApi::getProblemList(StatusVars::REMOTE_ZOJ, $zojFromId, $number);
}
}
}
foreach ($loadProblemList as &$problemInfo) {
$problemInfo['remote'] = $remote;
$problemInfo['remote_format'] = StatusVars::$REMOTE_SCHOOL[$remote];
}
$this->renderAjax(0, 'Success!', array('problemList' => $loadProblemList));
}
示例4: defaultAction
public function defaultAction()
{
$pageSize = 20;
$page = Pager::get();
$loginName = Request::getGET('login-name', '');
$path = Request::getGET('path', '');
$includePath = Request::getGET('include-path', '');
// 路径非法提示
if (!empty($path)) {
if (!RootPermissionInterface::isValidPath(array('path' => $path))) {
$this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$path}格式不正确!");
$url = Url::getCurrentUrl(array('path' => null));
Url::redirect($url);
}
}
// 路径非法提示
if (!empty($includePath)) {
if (!RootPermissionInterface::isValidPath(array('path' => $includePath))) {
$this->setNotice(FrameworkVars::NOTICE_ERROR, "路径{$includePath}格式不正确!");
$url = Url::getCurrentUrl(array('include-path' => null));
Url::redirect($url);
}
}
// 用户不存在提示
if (!empty($loginName)) {
$userInfo = UserCommonInterface::getByLoginName(array('login_name' => $loginName));
if (empty($userInfo)) {
$this->setNotice(FrameworkVars::NOTICE_ERROR, '用户不存在!');
$url = Url::getCurrentUrl(array('login-name' => null));
Url::redirect($url);
}
}
// 构建where
$where = array();
if (!empty($userInfo)) {
$where[] = array('user_id', '=', $userInfo['id']);
}
if (!empty($path)) {
$managerIds = RootManagerInterface::getAllowedManagerIds(array('path' => $path));
$where[] = array('id', 'IN', $managerIds);
}
if (!empty($includePath)) {
$managerIds = RootManagerInterface::getIncludeManagerIds(array('path' => $includePath));
$where[] = array('id', 'IN', $managerIds);
}
$offset = ($page - 1) * $pageSize;
$managerList = RootManagerInterface::getList(array('where' => $where, 'limit' => $pageSize, 'offset' => $offset));
$allCount = RootManagerInterface::getCount($where);
$userList = array();
$pathHash = array();
if (!empty($managerList)) {
$userIds = array_column($managerList, 'user_id');
$userList = UserCommonInterface::getById(array('id' => $userIds));
$userList = Arr::listToHash('id', $userList);
// 获取权限列表
$managerIds = array_column($managerList, 'id');
$pathHash = RootManagerInterface::getPaths(array('id' => $managerIds));
}
// 找出invalid path
$invalidHash = array();
foreach ($pathHash as $id => $pathSet) {
foreach ($pathSet as $tmpPath) {
if (array_key_exists($tmpPath, $invalidHash)) {
continue;
}
$invalidHash[$tmpPath] = RootPermissionInterface::findPath(array('path' => $tmpPath)) ? 0 : 1;
}
}
// 缓存部分的html
$html = array();
$html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 8), 'widget/pager.php');
$this->renderFramework(array('html' => $html, 'managerList' => $managerList, 'userList' => $userList, 'pathHash' => $pathHash, 'invalidHash' => $invalidHash), 'manager/list.php');
}
示例5: getById
/**
* 如果id是一个数字,返回对应的一行;如果id是数组,返回一个关联列表;
*
* @param int|array $id
* @return array null|一行, array()|关联列表
* @throws LibraryException
*/
public function getById($id)
{
// 校验参数
if (is_numeric($id) && intval($id) == $id && $id > 0 || is_array($id)) {
} else {
throw new LibraryException('参数错误:$id');
}
if (empty($id)) {
return array();
}
// 校验字段id是否存在
if (!array_key_exists('id', $this->fieldTypes)) {
throw new LibraryException("数据表`{$this->dbName}`.`{$this->tableName}`或者Model中不存在字段id!");
}
// 获取缓存,如果处在事务,那么不使用缓存
$staticCache = array();
if (!$this->isTransModel && isset(self::$rowCache[$this->dbName][$this->tableName]['id']['eq'])) {
$staticCache = self::$rowCache[$this->dbName][$this->tableName]['id']['eq'];
}
if (is_array($id)) {
$queryIds = $id;
if (!empty($staticCache)) {
// 如果缓存不为空,排除已经处在缓存中的id
foreach ($queryIds as $i => $k) {
if (array_key_exists($k, $staticCache)) {
unset($queryIds[$i]);
}
}
}
// 查询
$retList = array();
if (!empty($queryIds)) {
$where = array();
if (count($queryIds) == 1) {
$where[] = array('id', '=', current($queryIds));
} else {
$where[] = array('id', 'IN', $queryIds);
}
$retList = $this->getList('*', $where);
$retList = Arr::listToHash('id', $retList);
}
// 合并结果
$ret = array();
foreach ($id as $k) {
$row = array();
if (array_key_exists($k, $staticCache)) {
$row = $staticCache[$k];
} else {
if (array_key_exists($k, $retList)) {
$row = $retList[$k];
}
}
// 不在事务中才能更新静态缓存
if (!$this->isTransModel) {
self::$rowCache[$this->dbName][$this->tableName]['id']['eq'][$k] = $row;
}
$ret[$k] = $row;
}
return $ret;
} else {
// 在缓存中,返回
if (array_key_exists($id, $staticCache)) {
return $staticCache[$id];
}
// 查询
$where = array(array('id', '=', $id));
$rowInfo = $this->getRow('*', $where);
// 不在事务中才能更新静态缓存
if (!$this->isTransModel) {
self::$rowCache[$this->dbName][$this->tableName]['id']['eq'][$id] = $rowInfo;
}
return $rowInfo;
}
}