Connecting with multiple resources in PHRETS

667 Views Asked by At

I have to retrieve the data from multiple resources by using the Rets server. Is there any way to do so?

For example, I have resources and classes like:

  1. Property(Resource), Listing(Class)
  2. Media(Resource), Media(Class)

Some data should be fetched from the first and a little bit from the second.

I am using the Phrets to retrieve the data from the Rets server.

I am using the source code:

<?php

date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));


$config = new \PHRETS\Configuration;
$config->setLoginUrl('Url to connect with')
    ->setUsername('Username to login')
    ->setPassword('Password to login');
     ->setRetsVersion('1.5')

$rets = new \PHRETS\Session($config);
$rets->setLogger($log);

$connect = $rets->Login();



$resource     = 'Property';
$class        = 'Listing';
$query        = "(Acres=0+)";

$options      = array(
'Count'         => 1,
'Format'        => 'COMPACT-DECODED',
'Limit'         => 50,
'StandardNames' => 0,
     'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);
$results = $rets->Search($resource,$class,$query,$options);
       foreach($results as $record){
echo "<table>";
    echo "<tr>";
          echo "<td>".$record['Acres']."</td>&nbsp";
          echo "<td>".$record['City']."</td>";
          echo "<td>".$record['ClosePrice']."</td>";
          echo "<td>".$record['BathsFull']."</td>";
          echo "<td>".$record['BathsHalf']."</td>";

         echo "<td>".$record['VirtualTourLink']."</td>";

    echo "</tr>";
echo "</table>";
}

?>

Thanks in advance!

2

There are 2 best solutions below

0
On

Fetch your records from the first class and then fetch your records from the second class using the second classes dependent id. Media classes are always dependent on the property classes, so it will have some id that corresponds to the main id of the property class (usually the mls # of the listing). Without seeing your RETS server's metadata I won't be able to tell you the names of the fields you need to pull from. Also, your version is more than likely 1.7.2, AFAIK no one really uses 1.5 anymore.

0
On

You can fetch by using loop of class name.

$resource     = 'Property';
$classes        = array('Listing','Media');
$query        = "(Acres=0+)";

$options      = array(
    'Count'         => 1,
    'Format'        => 'COMPACT-DECODED',
    'Limit'         => 50,
    'StandardNames' => 0,
    'Select'=>'Acres,City,ClosePrice,BathsFull,BathsHalf,PhotoCount,VirtualTourLink'
);


foreach($classes as $class){
    $results[$class] = $rets->Search($resource,$class,$query,$options);
}