当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiBase::makeErrorResult方法代码示例

本文整理汇总了PHP中ApiBase::makeErrorResult方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiBase::makeErrorResult方法的具体用法?PHP ApiBase::makeErrorResult怎么用?PHP ApiBase::makeErrorResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiBase的用法示例。


在下文中一共展示了ApiBase::makeErrorResult方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 function run($constraints)
 {
     #set limit
     list($limit, $w) = ApiBase::setLimit($_GET['limit']);
     $warning = isset($w) ? $w : null;
     #set offset
     list($offset, $w) = ApiBase::setOffset($_GET['offset']);
     $warning = isset($w) ? $warning . $w : $warning;
     #set view
     list($target_table, $w) = self::setView($_GET['view']);
     $warning = isset($w) ? $warning . $w : $warning;
     #load list of parameters to select
     list($select, $w) = self::setSelect($_GET['show']);
     $warning = isset($w) ? $warning . $w : $warning;
     #load constraints
     #isset($_GET['muni']) ? $constraints['muni'] = $_GET['muni'] : null;
     #isset($_GET['county']) ? $constraints['county'] = $_GET['county'] : null;
     #construct query
     $query = '
             SELECT SQL_CALC_FOUND_ROWS ' . $select . '
             FROM `' . mysql_real_escape_string($target_table) . '`
             ';
     $query = isset($constraints) ? ApiBase::addConstraints($query . 'WHERE ', $constraints) : $query;
     $query .= 'LIMIT ' . mysql_real_escape_string($offset) . ', ' . mysql_real_escape_string($limit) . '
             ';
     #run query
     try {
         $response = ApiBase::doQuery($query);
         $hits = ApiBase::doQuery('SELECT FOUND_ROWS()');
     } catch (Exception $e) {
         return ApiBase::makeErrorResult('610', 'Select Failed. ' . 'Probably wrong name supplied.[' . $e->getMessage() . ']', $warning);
     }
     $body = array();
     foreach ($response as $r) {
         array_push($body, array('hit' => ApiBase::sanitizeBit1($r)));
     }
     # so that xml plays nice
     #Did we get all?
     $hits = $hits[0]['FOUND_ROWS()'];
     $head = array('hits' => $offset . '–' . ($offset + count($body)) . ' of ' . $hits, 'limit' => $limit);
     if ($hits > $offset + $limit) {
         $head['continue'] = $offset + $limit;
     }
     if (!empty($warning)) {
         $head['warning'] = $warning;
     }
     //~ $head = Array(
     //~ 'hits' => $hits,
     //~ 'limit' => $limit,
     //~ 'warning' => $warning
     //~ );
     $results = ApiBase::makeSuccessResultHead($head, $body);
     return $results;
 }
开发者ID:Abbe98,项目名称:ODOK,代码行数:54,代码来源:ApiGet.php

示例2: run

 function run($constraints)
 {
     /*
      * use options to choose a query generating function
      * then
      */
     $table = isset($_GET['table']) ? strtolower($_GET['table']) : null;
     $column = isset($_GET['column']) ? strtolower($_GET['column']) : null;
     $split = isset($_GET['split']) ? strtolower($_GET['split']) : null;
     #choose function based on given parameters
     try {
         if (isset($table) and isset($column)) {
             $warning = 'You cannot specify both table and column; ignoring table parameter. ';
             list($response, $warning) = self::splitSelector($split, 'main', $column, $constraints, $warning);
         } elseif (isset($table)) {
             list($response, $warning) = self::splitSelector($split, $table, NULL, $constraints, $warning);
         } elseif (isset($column)) {
             list($response, $warning) = self::splitSelector($split, 'main', $column, $constraints, $warning);
         } elseif (isset($split)) {
             #only split is set
             $warning = 'No table specified for split; assuming table = "main". ';
             list($response, $warning) = self::splitSelector($split, 'main', NULL, $constraints, $warning);
         } else {
             $warning = 'Neither column, table nor split parameter defined; assuming table = "all". ';
             $response = self::countTable('all', $constraints);
         }
     } catch (Exception $e) {
         return ApiBase::makeErrorResult('620', 'Count Failed. ' . 'Probably wrong parameter name supplied. [' . $e->getMessage() . ']', $warning);
     }
     return ApiBase::makeSuccessResult($warning, $response);
 }
开发者ID:Abbe98,项目名称:ODOK,代码行数:31,代码来源:ApiStats.php

示例3: run

 function run($constraints)
 {
     #set limit
     list($limit, $w) = ApiBase::setLimit($_GET['limit']);
     $warning = isset($w) ? $w : null;
     #set offset
     list($offset, $w) = ApiBase::setOffset($_GET['offset']);
     $warning .= isset($w) ? $w : '';
     try {
         switch (strtolower($_GET['function'])) {
             case strtolower('diff'):
                 list($response, $hits) = self::getChanges($limit, $offset, $constraints);
                 break;
             case strtolower('lists'):
                 list($response, $hits) = self::getLists();
                 break;
             case strtolower('objectlessArtist'):
                 #list of artists that have no objects
                 list($response, $hits) = self::getObjectlessArtist($limit, $offset);
                 break;
             case strtolower('yearlessArtist'):
                 list($response, $hits) = self::getYearlessArtist($limit, $offset);
                 break;
             case strtolower('artistlessObject'):
                 list($response, $hits) = self::getArtistlessObject($limit, $offset);
                 break;
             case 'info':
                 #e.g. funtion=info&table=source&id=4
                 #Displays all known info for a given id of a given table
                 $table = $_GET['table'];
                 $id = $_GET['id'];
                 if (isset($table) and isset($id)) {
                     $response = self::getInfo($table, $id);
                 } else {
                     return ApiBase::makeErrorResult('631', 'Admin Failed. ' . 'Function "info" must be used together with a "table" and "id" parameter.', $warning);
                 }
                 break;
             default:
                 return ApiBase::makeErrorResult('632', 'Admin Failed. ' . 'Sorry but [' . $_GET['function'] . '] is not a valid function for the "admin" action.', $warning);
                 break;
         }
     } catch (Exception $e) {
         return ApiBase::makeErrorResult('630', 'Admin Failed. ' . 'Probably error in one of the constraints. [' . $e->getMessage() . ']', $warning);
     }
     $head = array();
     if (isset($hits)) {
         $hits = $hits[0]['FOUND_ROWS()'];
         $head['hits'] = $offset . '–' . ($offset + count($response)) . ' of ' . $hits;
         $head['limit'] = $limit;
         if ($hits > $offset + $limit) {
             $head['continue'] = $offset + $limit;
         }
     }
     if (!empty($warning)) {
         $head['warning'] = $warning;
     }
     return ApiBase::makeSuccessResultHead($head, $response);
 }
开发者ID:Abbe98,项目名称:ODOK,代码行数:58,代码来源:ApiAdmin.php

示例4: search

 function search()
 {
     # Database info (including username+pass) in external file
     if (file_exists('/home/andre/config.php')) {
         require_once '/home/andre/config.php';
     } elseif (file_exists('config.php')) {
         require_once 'config.php';
     } else {
         die('Couldn\'t find config file ');
     }
     include 'Format.php';
     #formats the output
     include 'ApiBase.php';
     #functions used by multiple modules
     include 'ApiGet.php';
     #standard sql query stuff
     include 'ApiStats.php';
     #stats about the database
     include 'ApiAdmin.php';
     #various functions that the average user wouldn't care about
     include 'ApiArtist.php';
     #hook into the artist_table
     #include('ApiHelp.php');     #help file/documentation
     global $helpurl;
     /*
      * Trying to connect to mysql server and database
      * Output Temporary error if unable to.
      */
     if (!@mysql_connect($dbServer, $dbUser, $dbPassword)) {
         $results = ApiBase::makeErrorResult('500', 'Temporary Error. ' . 'Our server might be down, please try again later.[' . mysql_error() . ']', null);
         $errors = 1;
     }
     if (!@mysql_select_db($dbDatabase)) {
         $results = ApiBase::makeErrorResult('500', 'Temporary Error. ' . 'Our server might be down, please try again later.[' . mysql_error() . ']', null);
         $errors = 1;
     }
     /*
      * Set up jsonp compatibility
      */
     if (strtolower($_GET['format']) == 'jsonp') {
         if (!isset($_GET['callback'])) {
             $results = ApiBase::makeErrorResult('640', 'JSONP Error. ' . 'Cannot request JSONP without a callback', null);
             $errors = 1;
         }
     }
     /*
      * If no errors were found during connection
      * let's proceed with our queries
      */
     if (!$errors) {
         mysql_query("SET CHARACTER SET utf8");
         #deal with general constraints
         try {
             $constraints = ApiBase::readConstraints();
         } catch (ValueLimitException $e) {
             $results = ApiBase::makeErrorResult('602', $e->getMessage(), null);
             $errors = 1;
         } catch (CharacterLimitException $e) {
             $results = ApiBase::makeErrorResult('603', $e->getMessage(), null);
             $errors = 1;
         } catch (Exception $e) {
             $results = ApiBase::makeErrorResult('600', $e->getMessage(), null);
             $errors = 1;
         }
         #if kml/geojson output format then make sure has_coords is set
         if (($_GET['format'] == 'kml' or $_GET['format'] == 'geojson') and !isset($_GET['has_coords'])) {
             $constraints['coords'] = ApiBase::requireCoords();
         }
     }
     if (!$errors) {
         #switch by action; return results array
         switch (strtolower($_GET['action'])) {
             case 'get':
                 $results = ApiGet::run($constraints);
                 break;
             case 'artist':
                 $results = ApiArtist::run($constraints);
                 break;
             case 'statistics':
                 /*
                  * Outputs counts per table/muni/county/artist/withCoords/withPics
                  */
                 $results = ApiStats::run($constraints);
                 break;
             case 'admin':
                 /*
                  * should generate a file with changes (since a certain date) and/or
                  * list all entries (with changes) from a given source which has ugc=1.
                  * Possibly use this to create an rss feed?
                  */
                 $results = ApiAdmin::run($constraints);
                 break;
             case 'help':
                 header('Location: ' . $helpurl);
                 break;
             default:
                 $results = ApiBase::makeErrorResult('601', 'Action Failed. ' . 'Sorry but "' . $_GET['action'] . '" is not a valid action for this api.', $warning);
                 break;
         }
     }
//.........这里部分代码省略.........
开发者ID:Abbe98,项目名称:ODOK,代码行数:101,代码来源:ApiMain.php

示例5: run

 function run($constraints)
 {
     #either look up on artwork_id or one of the others
     $prefix = null;
     $w = null;
     $otherSelectors = array('wiki', 'id', 'first_name', 'last_name', 'name', 'birth_year', 'death_year', 'is_dead', 'lifespan');
     if (isset($_GET['artwork'])) {
         $prefix = 'at';
         if (count(array_intersect($otherSelectors, array_keys($_GET))) > 0) {
             # if any of $otherSelectors were provided
             $w = 'The artwork parameter cannot be combined with any other selectors, these are therefore disregarded. ';
         }
     }
     $warning = isset($w) ? $w : null;
     #set limit
     list($limit, $w) = ApiBase::setLimit($_GET['limit']);
     $warning = isset($w) ? $warning . $w : $warning;
     #set offset
     list($offset, $w) = ApiBase::setOffset($_GET['offset']);
     $warning = isset($w) ? $warning . $w : $warning;
     #load list of parameters to select
     list($select, $getWorks, $w) = self::setSelect($_GET['show'], $prefix);
     $warning = isset($w) ? $warning . $w : $warning;
     #Needs support for
     # name, first_name, last_name as well (with name=Concatenate(first, ' ', last))
     # as a constraint
     # Look up on artwork_id or other
     $query = null;
     if (isset($_GET['artwork'])) {
         $query = '
             SELECT SQL_CALC_FOUND_ROWS ' . $select . '
             FROM `artist_table` at
             INNER JOIN `artist_links` al ON al.`artist` = at.`id`
             WHERE al.`object` in (
             "' . implode('", "', array_map('mysql_real_escape_string', explode('|', $_GET['artwork']))) . '"
             )
             ';
     } else {
         #add available constraints
         $query = '
             SELECT SQL_CALC_FOUND_ROWS ' . $select . '
             FROM `artist_table`
             ';
         $query = isset($constraints) ? ApiBase::addConstraints($query . 'WHERE ', $constraints) : $query;
     }
     # add limit
     $query .= 'LIMIT ' . mysql_real_escape_string($offset) . ', ' . mysql_real_escape_string($limit) . '
             ';
     #run query
     try {
         $response = ApiBase::doQuery($query);
         $hits = ApiBase::doQuery('SELECT FOUND_ROWS()');
     } catch (Exception $e) {
         return ApiBase::makeErrorResult('610', 'Select Failed. ' . 'Probably wrong name supplied.[' . $e->getMessage() . ']', $warning);
     }
     # look up works for each artist
     $works = null;
     if ($getWorks) {
         $artists = array();
         foreach ($response as $r) {
             array_push($artists, $r['id']);
         }
         list($works, $w) = self::getWorks($artists, $warning);
         $warning = isset($w) ? $warning . $w : $warning;
     }
     #collect results
     $body = array();
     foreach ($response as $r) {
         if ($getWorks) {
             $r['works'] = array();
             if (isset($works[$r['id']])) {
                 foreach ($works[$r['id']] as $work) {
                     array_push($r['works'], array('work' => $work));
                     # so that xml plays nice
                 }
             }
         }
         array_push($body, array('hit' => ApiBase::sanitizeBit1($r)));
         # so that xml plays nice
     }
     #Did we get all?
     $hits = $hits[0]['FOUND_ROWS()'];
     $head = array('hits' => $offset . '–' . ($offset + count($body)) . ' of ' . $hits, 'limit' => $limit);
     if ($hits > $offset + $limit) {
         $head['continue'] = $offset + $limit;
     }
     if (!empty($warning)) {
         $head['warning'] = $warning;
     }
     $results = ApiBase::makeSuccessResultHead($head, $body);
     return $results;
 }
开发者ID:Abbe98,项目名称:ODOK,代码行数:92,代码来源:ApiArtist.php


注:本文中的ApiBase::makeErrorResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。