Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active January 4, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgaetz/8626154 to your computer and use it in GitHub Desktop.
Save lgaetz/8626154 to your computer and use it in GitHub Desktop.
PHP function for use with FreePBX that accepts a DAHDI group as an argument, and returns an array of DAHDI channels (if any) for that goup
<?php
// This function works within FreePBX or with FreePBX 2.9+ bootstrap loader
// $astman (phpagi class) already declared
function group2chan($groupid) {
global $astman;
// strip non-digits and assume the remaining number is the group number
$groupid = preg_replace("/[^0-9]*/", "", $groupid);
// use phpagi class to query channels in dahdi group
$data = $astman->command("dahdi show channels group $groupid");
foreach(explode("\n", $data['data']) as $line) {
// catch the leading digits of each line and ignore the rest of the line
preg_match("~^.*?(\d+?) .*~",$line,$foo);
if (trim($foo[1]) != "") {
$channels[] = trim($foo[1]);
}
}
if (isset($channels)) {
return $channels;
}
else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment