當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Arr::listToHash方法代碼示例

本文整理匯總了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);
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:31,代碼來源:ApplyListController.class.php

示例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');
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:12,代碼來源:ListController.class.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));
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:42,代碼來源:AddController.class.php

示例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');
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:73,代碼來源:ListController.class.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;
     }
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:81,代碼來源:BaseModel.class.php


注:本文中的Arr::listToHash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。