I have been trying to retrieve the correct images for each listing. I
have been using many of the scripts found on the PHRETS website and
stuck with no solution.
The listings data comes over no problem and clearly identified with
the correct PictureId, however, when either retrieving the image and
url, it is something completely different.
I also tried VieleRets and experienced the same issue.
Secondly, when the MLSNUM (MLS#) is retrieved, the leading 0's are
removed. Could this be the cause?
Our instructions from Filogix:
RETRIEVING DATA/OBJECTS:
========================
For kicks, this will return a list mls numbers and PictureIds of
active residential listings:
-IF you want to play, change Field list in the 'Select' parameter. Use
"SystemName" fields from the Table Metadata
(do not use the RETS StandardNames )
http://rets.filogixdms.com:8080/rets2/rets/search?Class=RES&Query=(STATUS=STACT)&QueryType=DMQL2&Format=COMPACT&SearchType=Property&Count=1&StandardNames=0&Select=MLSNUM,PictureId
You Can then grab Photos associated to a given PictureId:
http://rets.filogixdms.com:8080/rets2/rets/getObject?Resource=Property&Type=Photo&ID=xxxxxx:y
where:
xxxxxx is PictureId
y is 0 - default photo
1 to n - other associated photos
NOTE: Replace 'Type=Photo' with 'Type=Thumbnail'....to get
thumbnails :)
Basically the code is pulling back the data for all the listings and
then appending it to a csv. Then it grabs the images and records them
into a separate csv and posts the image to a directory. I also tried
just grabbing the URL but that was wrong too.
Here is my code:
$rets_login_url = "
http://rets.filogixdms.com:8080/rets2/rets/login";
$rets_username = "xxx";
$rets_password = "xxx";
// use
http://retsmd.com to help determine the SystemName of the
DateTime field which
// designates when a record was last modified
$rets_modtimestamp_field = "LastModDate";
// use
http://retsmd.com to help determine the names of the classes
you want to pull.
// these might be something like RE_1, RES, RESI, 1, etc.
//$property_classes =
array("COM","MUL","ALL","FRM","RES","OPEN","ACTAGT","OFFICE","AGT","ALLAGT");
$property_classes = array("RES");
// DateTime which is used to determine how far back to retrieve
records.
// using a really old date so we can get everything
$previous_start_time = "2010-01-01T00:00:00";
//////////////////////////////
require_once("phrets.php");
// start rets connection
$rets = new phRETS;
// only enable this if you know the server supports the optional RETS
feature called 'Offset'
$rets->SetParam("offset_support", false);
echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username,
$rets_password);
if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}
foreach ($property_classes as $class) {
echo "+ Property:{$class}<br>\n";
$file_name = strtolower("property_{$class}.csv");
$fh = fopen($file_name, "w+");
$fields_order = array();
$query = "({$rets_modtimestamp_field}={$previous_start_time}
+)";
// run RETS search
echo " + Resource: Property Class: {$class} Query:
{$query}<br>\n";
$search = $rets->SearchQuery("Property", $class, $query,
array("Format" => "COMPACT", "STATUS" => "STACT", "QueryType" =>
"DMQL2", "Limit" => 1000));
if ($rets->NumRows($search) > 0) {
// print filename headers as first line
$fields_order = $rets->SearchGetFields($search);
fputcsv($fh, $fields_order);
// process results
while ($record = $rets->FetchRow($search)) {
$this_record = array();
foreach ($fields_order as $fo) {
$this_record[] = $record[$fo];
}
fputcsv($fh, $this_record);
}
}
echo " + Total found: {$rets->TotalRecordsFound($search)}
<br>\n";
$rets->FreeResult($search);
fclose($fh);
echo " - done<br>\n";
/* Get Pictures Now*/
// Fetch all the images for each property we just retrieved.
echo "Fetching all images for $class...\n";
// CSV into array
$fullData = csvArray(strtolower("property_{$class}.csv"));
// Listing IDs into array
//$list = getColumn($fullData, "ListingRid");
$list = getColumn($fullData, "MLSNUM");
// Open CSV for storing image data
$file_name = strtolower("property_{$class}_images.csv");
$fh = fopen($file_name, "w+");
//$colHeaders = array("ListingRid", "INDEX", "PATH",
"LOCATION");
$colHeaders = array("MLSNUM", "INDEX", "PATH", "LOCATION");
fputcsv($fh, $colHeaders);
$count = 0;
$batches = create_batch_list($list);
foreach ($batches as $batch) {
$photos = $rets->GetObject("Property", "Photo", $batch);
foreach ($photos as $photo) {
$listing = $photo['Content-ID'];
$index = $photo['Object-ID'];
$imgURL = "/home/freddy/public_html/rets/
phrets/{$listing}_{$index}.jpg";
$location =
$photo['Location'];
if($index <= 25 && $photo['Success'] == true)
{
file_put_contents($imgURL,
$photo['Data']);
$this_image = array("$listing",
"$index", "$imgURL", "$location");
fputcsv($fh, $this_image);
$count++;
}
}
}
echo " + $count images downloaded.\n";
fclose($fh);
}
echo "+ Disconnecting<br>\n";
$rets->Disconnect();
?>