PHPGeocache Class

This class is contained in the file PHPGeocache.inc.php and encapsulates most functions. It uses the Geocache.inc.php and Waypoint.inc.php internally which itself use the OCFParser.inc.php and db-mysql.inc.php internally.

1. General Cache Functions

getCacheByID

Context: PHPGeocache

Retrieves a Geocache object from the database by the cacheID given
This method retrieves the dataset from the database, creates a Geocache object and returns that object.

Return value
Geocache object or FALSE

$cacheID is the content of the field "cache_id" in the database table "caches".
This is mapped internally to the srcid attribute of the GeoCache object.

Usage
$phpgc->getCacheByID($cacheID)
Example
<?php
    $cache
=$phpgc->getCacheByID(1);
    echo
$cache->name." ".$cache->title;
?>


GCVXFF Haardliner


getCacheByName

Context: PHPGeocache

Retrieves a Geocache object from the database by the cache name given
This method retrieves the dataset from the database, creates a Geocache object and returns that object.

Return value
Geocache object or FALSE

$cacheName is the content of the field "name" in the database table "caches".
This is mapped internally to the name attribute of the GeoCache object.

Usage
$phpgc->getCacheByName($cacheName)
Example
<?php
    $cache
=$phpgc->getCacheByName("GCVXFF");
    echo
$cache->name." ".$cache->title;
?>


GCVXFF Haardliner


findCaches

Context: PHPGeocache

Searches in the fields name and description for any cache containing the string given
This method retrieves the datasets from the database, creates Geocache objects and returns them as an array.

Return value
Array of Geocache objects or FALSE

$searchString is the text to be found.

Usage
$phpgc->findCaches($searchString)
Example
<?php
    
if($caches=$phpgc->findCaches("h")) {
        for(
$i=0; $i<sizeof($caches); $i++)
        {
            echo
"(".$i.") ".$cache->name." ".$cache->title."<br>";
        }
    }
?>


(0) GCVXFF Haardliner
(1) CSRHEB Rheinelbe X-1
(2) CS7673 A small multi-cache!
(3) CS7673 A small multi-cache!


getCachesByDistance

Context: PHPGeocache

Retrieves a specific maximum number of geocaches around the coordinates given sorted by distance
Please note that depending on the number of geocaches in your database this query might take some time as the distance calculation is quite time consuming.

Return value
Array of Geocache objects or FALSE

$long and $lat define the center of the radius.
$maxCount is the maximum number of results to be returned.
$radius defines the radius to be used in kilometers.
$onlyActive only returns entries which have the status 'RUN' in the database.
$withWaypoints returns all waypoints as well. As this is not always needed this defaults to false.
$getOnlyTheseFields defines the fields to be retrieved. If not given, "SELECT *" is used.

Usage
$phpgc->getCachesByDistance($long, $lat, $maxCount [, $radius=9999, $onlyActive=true, $withWaypoints=false, $getOnlyTheseFields=array()])
Example
<?php
    
// Get a maximum of 10 geocaches
    
if($caches=$phpgc->getCachesByDistance(7.11382, 51.49648, 10)) {
        for(
$i=0; $i<sizeof($caches); $i++)
        {
            echo
"(".$i.") ".$caches[$i]->name." ".$caches[$i]->title." (".round($caches[$i]->targetDistance,2)." km)<br>";
        }
    }
?>


(0) CSRHEB Rheinelbe X-1 (0.76 km)
(1) GCVXFF Haardliner (23.9 km)
(2) CS7673 A small multi-cache! (6324.95 km)
(3) CS7673 A small multi-cache! (6324.95 km)


AddCacheToDB

Context: PHPGeocache

Adds the cache given to the database
The given cache (reference to a Geocache object) is inserted into the database table "caches". All waypoints are also added to the table "waypoints" automatically and referenced to the cache_id of the caches table.

Return value
TRUE or FALSE

$geocache is a Geocache object.
$userID can be given to indicate the userID (integer value) of the user this cache belongs to. Only useful if the application using PHPGeocache has its own user management.
$initialStatus is the initial status of the cache in the database table "caches". Can be one of 'RUN', 'PENDING', 'HOLD', 'ARCHIVED', 'DELETE'

Usage
$phpgc->addCacheToDB(&$geocache [, $userID=0, $initialStatus="RUN"])
Example
<?php
    $gc
=&new PHPGeocache();
    
$geocache=&new Geocache();
    if(
$geocache->loadCacheFromOCF("demo/ocf-multicache.xml")) {
        
// Unset the original srcid or the import will fail
        
$geocache->srcid=null;
        
$gc->addCacheToDB($geocache, 24, "RUN");
    }
?>




PHPGeocache  -  Geocaching  with  PHP