AutoPatrol, Bureaucrats, Administrators
683
edits
(Created page with "This script recursively collects values of custom attribute '''contacts''' from all node parents. Collected values concatenated into single string and separated by semicolons....") |
|||
Line 2: | Line 2: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
global contacts = ""; | global contacts = ""; // concatenated values will be stored here | ||
global | global presence = %{ }; // value presence indicator (hash map) | ||
// walk through each parent object for current node | |||
foreach(o : GetObjectParents($node)) | foreach(o : GetObjectParents($node)) | ||
{ | { | ||
Line 10: | Line 11: | ||
} | } | ||
// Concatenated result is in "contacts" global variable | |||
println "Contacts: " . contacts; | println "Contacts: " . contacts; | ||
/** | |||
* Recursively add contacts from object and it's parents | |||
*/ | |||
sub add_contacts(curr) | sub add_contacts(curr) | ||
{ | { | ||
c = GetCustomAttribute(curr, "contacts"); | c = GetCustomAttribute(curr, "contacts"); | ||
if ((c != null) && ( | if ((c != null) && (presence[c] == null)) | ||
{ | { | ||
if (length(contacts) > 0) | if (length(contacts) > 0) | ||
Line 21: | Line 26: | ||
else | else | ||
contacts = c; | contacts = c; | ||
presence[c] = true; | |||
} | } | ||