Forked from steveheinsch/gist:287edd5ce26e608b06b20af384f4cc1e
Created
April 7, 2022 11:35
-
-
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+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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