Example #1
0
 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;
 }
Example #2
0
 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);
 }
Example #3
0
 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;
 }