Ejemplo n.º 1
0
/**
 * Convert an array of features in GeoJSON format.
 * 
 * @param array $features The array of features to convert.
 * @param stdClass $context The context object.
 * @param int $treasurehuntid The identifier of the treasure hunt instance.
 * @param int $groupid The identifier of the group or 0 if is individually.
 * @return array
 */
function treasurehunt_features_to_geojson($features, $context, $treasurehuntid, $groupid = 0)
{
    $featuresarray = array();
    foreach ($features as $feature) {
        $geometry = treasurehunt_wkt_to_object($feature->geometry);
        if (isset($feature->cluetext)) {
            $cluetext = file_rewrite_pluginfile_urls($feature->cluetext, 'pluginfile.php', $context->id, 'mod_treasurehunt', 'cluetext', $feature->stageid ? $feature->stageid : $feature->id);
        } else {
            $cluetext = null;
        }
        $attr = array('roadid' => intval($feature->roadid), 'stageposition' => intval($feature->position), 'name' => $feature->name, 'treasurehuntid' => $treasurehuntid, 'clue' => $cluetext);
        if (property_exists($feature, 'geometrysolved') && property_exists($feature, 'success')) {
            $attr['geometrysolved'] = intval($feature->geometrysolved);
            // The type of attempt is modified to location for the next function.
            $feature->type = "location";
            $attr['info'] = treasurehunt_set_string_attempt($feature, $groupid);
        }
        $feature = new Feature($feature->id ? intval($feature->id) : 0, $geometry, $attr);
        array_push($featuresarray, $feature);
    }
    $featurecollection = new FeatureCollection($featuresarray);
    $geojson = $featurecollection->getGeoInterface();
    return $geojson;
}