I’ve been experimenting with some helper scripts to extract CM-Group Contacts via a CM-Group Name & these work just fine (credit to to Sorvani - sorvani/freepbx-helper-scripts for FreePBX), however, rather than just get the Contacts of a named CM-Group, I would like to adjust the SQL to extract ALL the Contacts from ANY/ALL ‘Private’ CM-Groups associated with a given Owner via their linked ExtnNo.
eg. I start with an Extn No, from that get the Linked User (assuming there is one) & then extract all contacts within any/all ‘Private’ CM-Groups that user has created (ie. that they are the owner of).
I assume this should be possible with SQL JOINS between the various database table/field relationships that tie all that together, however, I don’t know how to expose the DB schema (related Table/Field Names) in order to build the SQL.
Perhaps someone can tell me what the relevant DB tables/fields are called and/or point me to how I can expose that info for myself (alternatively, if you already have & can share the required SQL for this then even better, although I’m happy to do it myself if I can get the info I need).
I can see some of this from the helper scripts, but I’m having to 2nd guess the missing bits;
Extensions Table (devices)
– Extn No (id) <-- Not sure if this is Primary index or whether a separate ExtnId field exists
– Extn Display Name (description)
– Linked User Id/Login Name (???) <-- This might exist here, or equivalent in Users Table
Users Table (???)
– User Id (???) <-- I assume they’ll be a numeric index field for each User Rec
– User Login Name (???)
– User Display Name (???)
– Linked Extn (???) <-- This might exist here, or equivalent in Extns Table
CM-Groups Table (contactmanager_groups)
– Group Id (id)
– Group Name (name)
– Group Type (???) <-- Internal/External/Private etc.
– Group Owner User Id/Login Name (???)
CM-Group Entries Table (contactmanager_group_entries)
– Parent Group Id (groupid)
– Entry Id (id)
– Entry Display Name (displayname)
CM-Group Numbers Table (contactmanager_entry_numbers)
– Parent Entry Id (entryid)
– Number Id (id)
– Number Type (type)
– Number (number)
To summarise, I guess the missing bits for me are;
- How to get the Linked User Id/Login Name from an Extn No
- How to get a List of ‘Private’ CM-Group Ids/Names from a given User Id/Login Name.
I hope I’ve made this clear enough to make sense. Any assistance would be much appreciated.