more generalisation of commonly used code constructs
This commit is contained in:
parent
c92bb6176a
commit
cc0cd0b292
@ -266,25 +266,11 @@ function hubloc_mark_as_down($posturl) {
|
|||||||
|
|
||||||
function locations_by_netid($netid) {
|
function locations_by_netid($netid) {
|
||||||
|
|
||||||
$strloc = '';
|
|
||||||
|
|
||||||
$locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0",
|
$locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0",
|
||||||
dbesc($netid)
|
dbesc($netid)
|
||||||
);
|
);
|
||||||
|
|
||||||
if($locs) {
|
return array_elm_to_str($locs,'location',', ');
|
||||||
foreach($locs as $l) {
|
|
||||||
if(!($l['location']))
|
|
||||||
continue;
|
|
||||||
if(strpos($strloc,$l['location']) !== false)
|
|
||||||
continue;
|
|
||||||
if(strlen($strloc))
|
|
||||||
$strloc .= ', ';
|
|
||||||
$strloc .= $l['location'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $strloc;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3261,3 +3261,31 @@ function purify_filename($s) {
|
|||||||
return '';
|
return '';
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief array_elm_to_str($arr,$elm,$delim = ',') extract unique individual elements from an array of arrays and return them as a string separated by a delimiter
|
||||||
|
*
|
||||||
|
* empty elements (evaluated after trim()) are ignored.
|
||||||
|
* @param $arr array
|
||||||
|
* @param $elm array key to extract from sub-array
|
||||||
|
* @param $delim string default ','
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
|
||||||
|
function array_elm_to_str($arr,$elm,$delim = ',') {
|
||||||
|
|
||||||
|
$tmp = [];
|
||||||
|
if($arr && is_array($arr)) {
|
||||||
|
foreach($arr as $x) {
|
||||||
|
if(is_array($x) && array_key_exists($elm,$x)) {
|
||||||
|
$z = trim($x[$elm]);
|
||||||
|
if(($z) && (! in_array($z,$tmp))) {
|
||||||
|
$tmp[] = $z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode($tmp,$delim);
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user