1. Go to this page and download the library: Download troydavisson/phrets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
troydavisson / phrets example snippets
date_default_timezone_set('America/New_York');
nUrl('rets login url here')
->setUsername('rets username here')
->setPassword('rets password here')
->setRetsVersion('1.7.2');
$rets = new \PHRETS\Session($config);
// If you're using Monolog already for logging, you can pass that logging instance to PHRETS for some additional
// insight into what PHRETS is doing.
//
// $log = new \Monolog\Logger('PHRETS');
// $log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
// $rets->setLogger($log);
$connect = $rets->Login();
$system = $rets->GetSystemMetadata();
var_dump($system);
$resources = $system->getResources();
$classes = $resources->first()->getClasses();
var_dump($classes);
$classes = $rets->GetClassesMetadata('Property');
var_dump($classes->first());
$objects = $rets->GetObject('Property', 'Photo', '00-1669', '*', 1);
var_dump($objects);
$fields = $rets->GetTableMetadata('Property', 'A');
var_dump($fields[0]);
$results = $rets->Search('Property', 'A', '*', ['Limit' => 3, 'Select' => 'LIST_1,LIST_105,LIST_15,LIST_22,LIST_87,LIST_133,LIST_134']);
foreach ($results as $r) {
var_dump($r);
}
$config = new \PHRETS\Configuration;
$config->setLoginUrl($rets_login_url);
$config->setUsername($rets_username);
$config->setPassword($rets_password);
// optional. value shown below are the defaults used when not overridden
$config->setRetsVersion('1.7.2'); // see constants from \PHRETS\Versions\RETSVersion
$config->setUserAgent('PHRETS/2.0');
$config->setUserAgentPassword($rets_user_agent_password); // string password, if given
$config->setHttpAuthenticationMethod('digest'); // or 'basic' if
$config = Configuration::load([
see above for what to give here
]);
$rets = new \PHRETS\Session($config);
$bulletin = $rets->Login();
$results = $rets->Search($resource, $class, $query);
// or with the additional options (with defaults shown)
$results = $rets->Search(
$resource,
$class,
$query,
[
'QueryType' => 'DMQL2',
'Count' => 1, // count and records
'Format' => 'COMPACT-DECODED',
'Limit' => 99999999,
'StandardNames' => 0, // give system names
]
);
$results = $rets->Search( see above for what to give here );
foreach ($results as $record) {
echo $record['Address'] . "\n";
// is the same as:
echo $record->get('Address') . "\n";
}
// return an array of the field names to expect with each record
$results->getHeaders();
// return the total number of results found (reported by the RETS server)
$results->getTotalResultsCount();
// return the count of results actually retrieved by PHRETS
$results->getReturnedResultsCount(); // same as: count($results)
// make a RETS GetMetadata call for the metadata for this RETS Resource and Class
$results->getMetadata();
// return whether or not the RETS server has more results to give
$results->isMaxRowsReached();
// return the string of characters to expect as the value of a field the RETS server blocked
$results->getRestrictedIndicator();
// return the first record in the set
$results->first();
// return the last record in the set
$results->last();
// returns an array representing the collected values from the identified field
$all_ids = $results->lists('ListingID');
// export the results in CSV format
$results->toCSV();
// export the results in JSON format
$results->toJSON();
// export the results in a simple array format
$results->toArray();
$record->isRestricted('Address'); // determine if the RETS server blocked this value
$record->getFields(); // return an array of the field names associated with this record
$record->toArray(); // returns a true PHP array of the given record
$record->toJson(); // returns a JSON encoded string representing the record
$record->getResource(); // returns the RETS Resource responsible for this record
$record->getClass(); // returns the RETS Class responsible for this record
$objects = $rets->GetObject($rets_resource, $object_type, $object_keys);
// grab the first object of the set
$objects->first();
// grab the last object of the set
$objects->last();
// throw out everything but the first 10 objects
$objects = $objects->slice(0, 10);
$objects = $rets->GetObject( see above documentation );
foreach ($objects as $object) {
// does this represent some kind of error
$object->isError();
$object->getError(); // returns a \PHRETS\Models\RETSError
// get the record ID associated with this object
$object->getContentId();
// get the sequence number of this object relative to the others with the same ContentId
$object->getObjectId();
// get the object's Content-Type value
$object->getContentType();
// get the description of the object
$object->getContentDescription();
// get the sub-description of the object
$object->getContentSubDescription();
// get the object's binary data
$object->getContent();
// get the size of the object's data
$object->getSize();
// does this object represent the primary object in the set
$object->isPreferred();
// when requesting URLs, access the URL given back
$object->getLocation();
// use the given URL and make it look like the RETS server gave the object directly
$object->setContent(file_get_contents($object->getLocation()));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.