Skip to content
Troy Davisson edited this page Mar 5, 2016 · 4 revisions

Note: This page documents capabilities available in the older 1.x version. Please see this repository's README file for the new 2.x version documentation.

GetObject

GetObject ( string $resource, string $type, string $id [, string $object-id [, string $location ]] )

Parameters

$resource - RETS Resource for requested object
$type - RETS GetObject type. See GetMetadataObjects for available types.
$id - ID of Object. This is the value of the KeyName field within the Resource for your record (typically the MLS#). This is NOT the full ID as described in the RETS specification.
$object-id - Optional. Requested object ID. Typically represents the photo order. Possible Values: 0, 1, 2, 3, etc., or * (asterisk) to request all objects. Default is *
$location - Optional. Used to return URLs rather than image data. Not always supported by the server. 1 is True (get URLs), 0 is False (get binary image data). Default is 0

Return Value

Array

Each item in this array represents a single image that was returned. If multiple images requested, multiple array keys exist and the server may return these in any order.

Possible item contents:

Success - Boolean. True if the specific response is successful. False if not.
Content-ID - Content-ID for this specific object.
Object-ID - Object-ID for this specific object (typically represents the display order)
Content-Type - Content-Type for this specific object.
MIME-Version - MIME-Version of this object.
Content-Description - Text description of this object.
Location - Returned if Location is True and server supports. Contains URL to object
Length - Size of data response
Data - Contains the response. If requested Location as False, this is raw image data.
ReplyCode - If Success is False, this contains the RETS ReplyCode returned.
ReplyText - If Success is False, this contains the RETS ReplyText returned.

Changelog

1.0 - Added more intelligent support for multiple id's or object-id's

Usage Examples

Pulls all photos for 12345

<?php
$photos = $rets->GetObject("Property", "Photo", "12345");
foreach ($photos as $photo) {
        $listing = $photo['Content-ID'];
        $number = $photo['Object-ID'];

        if ($photo['Success'] == true) {
                file_put_contents("image-{$listing}-{$number}.jpg", $photo['Data']);
        }
        else {
                echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
        }
}

Pulls all photo URLs for 12345

<?php
$photos = $rets->GetObject("Property", "Photo", "12345", "*", 1);
foreach ($photos as $photo) {
        $listing = $photo['Content-ID'];
        $number = $photo['Object-ID'];

        if ($photo['Success'] == true) {
                echo "{$listing}'s #{$number} photo is at {$photo['Location']}\n";
        }
        else {
                echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
        }
}

Pull URL for 12345's #2 photo

<?php
$photos = $rets->GetObject("Property", "Photo", "12345", "2", 1);
foreach ($photos as $photo) {
        $listing = $photo['Content-ID'];
        $number = $photo['Object-ID'];

        if ($photo['Success'] == true) {
                echo "{$listing}'s #{$number} photo is at {$photo['Location']}\n";
        }
        else {
                echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
        }
}

Pull URLs for 12345, 12346 and 12347's 3rd, 4th and 5th photos each

<?php
$photos = $rets->GetObject("Property", "Photo", "12345,12346,12347", "3,4,5", 1);
foreach ($photos as $photo) {
        $listing = $photo['Content-ID'];
        $number = $photo['Object-ID'];

        if ($photo['Success'] == true) {
                echo "{$listing}'s #{$number} photo is at {$photo['Location']}\n";
        }
        else {
                echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
        }
}

Pulls all photos for 12345, encodes image data, and outputs to browser

<?php
$photos = $rets->GetObject("Property", "Photo", "12345", "*", 0);
foreach ($photos as $photo) {
        $listing = $photo['Content-ID'];
        $number = $photo['Object-ID'];

    if ($photo['Success'] == true) {
        $contentType = $photo['Content-Type'];
        $base64 = base64_encode($photo['Data']); 
		echo "<img src='data:{$contentType};base64,{$base64}' />";
    }
    else {
        echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
    }
}
Related To

AddHeader, SetParam, Disconnect