Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save randy-johnson/1d71ad3d71034847b96f7071b50665a6 to your computer and use it in GitHub Desktop.
Save randy-johnson/1d71ad3d71034847b96f7071b50665a6 to your computer and use it in GitHub Desktop.
Function to retrieve all lookup key/values for a Resource/Class in PHRETS 2+
<?php
// Note: $this->server is a "logged in" PHRETS $session
public function getLookupValues($resourceName, $className)
{
$results = array();
// Get Table Metadata for this resource/class
$tableMeta = $this->server->GetTableMetadata($resourceName, $className);
// Retrieve "Lookup" fields from the collection
$lookups = $tableMeta->where('Interpretation', 'Lookup');
// Retrieve "LookupMulti" fields from the collection
$lookupMultis = $tableMeta->where('Interpretation', 'LookupMulti');
// Merge the two
$lookups->merge($lookupMultis);
// Cycle through the fields
foreach ($lookups as $lookup) {
// Grab the SystemName for this field
$systemName = $lookup['SystemName'];
// Grab the table metadata for this field
$metaField = $tableMeta->get($systemName);
// Grab the lookup keys/values for this field
foreach ($metaField->getLookupValues() as $lookupData) {
$key = $lookupData->getValue();
$value = $lookupData->getLongValue();
$results[$systemName][] = array('key' => $key, 'value' => $value);
}
}
return $results;
}
// Example:
$lookups = getLookupValues('Property', 'A');
foreach ($lookups as $SystemName => $FieldData) {
echo "SystemName: <strong>$SystemName</strong><br>";
foreach ($FieldData as $Key => $Value) {
echo "[$Key] = $Value<br>";
}
}
?>
// Example Output:
*LIST_9*
[OV61GOJW9K1] = Single Family - Detached
[REOUGLCC8LS] = Loft Style
[REOUGL63WUT] = Modular/Pre-Fab
[REOUGL2PCRN] = Mfg/Mobile Housing
[REOUGL0AYUJ] = Gemini/Twin Home
[REOUGKX5LJD] = Apartment Style/Flat
[REOUGKU9XO7] = Townhouse
[REOUGKR3XWN] = Patio Home
*LIST_15*
[OV61GOJ13C0] = Active
[OV61GOJ0PPY] = Temp Off Market
[OV61GOJ0PL2] = Pending
[OV61GOJ0PNN] = Expired
[OV61GOJ0SGR] = Deleted
[OV61GOJ0PIK] = Closed
[OV61GOJ0SEH] = Cancelled
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment