Commit d48ab0e0 authored by mattwire's avatar mattwire
Browse files

Add different URLs per grouptype

parent 850930db
......@@ -11,14 +11,29 @@
class CRM_Groupadmin_NavigationMenu {
public static function createOrUpdateGroupAdminMenu() {
private $urls = [];
public function __construct() {
$urlSetting = \Civi::settings()->get('groupadmin_navigationmenu_url');
$urls = preg_split("/\r\n|\n|\r/", $urlSetting);
foreach ($urls as $url) {
list($groupType, $url) = explode(':', $url);
if (empty($url)) {
\Civi::log()->error('groupadmin_navigationmenu_url is not configured correctly.');
continue;
}
$this->urls[$groupType] = $url;
}
}
public function createOrUpdateGroupAdminMenu() {
if (((bool) \Civi::settings()->get('groupadmin_navigationmenu')) === FALSE) {
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_navigation WHERE name LIKE "groupadminmenu%"');
return;
}
// Get list of group admins (so we can get group IDs)
$groupAdminContacts = civicrm_api3('GroupAdminContact', 'get');
$groupAdminContacts = civicrm_api3('GroupAdminContact', 'get', ['options' => ['limit' => 0]]);
$groupList = [];
foreach ($groupAdminContacts as $groupAdminContact) {
$groupList[$groupAdminContact['group_id']] = 1;
......@@ -26,8 +41,9 @@ class CRM_Groupadmin_NavigationMenu {
// Get list of group name/title for all groups which have admins
$groups = civicrm_api3('Group', 'get', [
'return' => ["title", "name"],
'return' => ['id,', 'name', 'title', 'group_type'],
'id' => ['IN' => array_keys($groupList)],
['options' => ['limit' => 0]],
])['values'];
try {
......@@ -47,6 +63,7 @@ class CRM_Groupadmin_NavigationMenu {
$existingMenuItems = civicrm_api3('Navigation', 'get', [
'name' => ['LIKE' => "groupadminmenu_%"],
['options' => ['limit' => 0]]
])['values'];
foreach ($groups as $group) {
......@@ -59,7 +76,7 @@ class CRM_Groupadmin_NavigationMenu {
$newMenuItem['name'] = "groupadminmenu_{$group['name']}";
$newMenuItem['label'] = $group['title'];
$url = \Civi::settings()->get('groupadmin_navigationmenu_url');
$url = $this->getURL($group);
$urlParts = explode('?', $url);
if (isset($urlParts[1])) {
$urlParts[1] = str_replace('%%gid%%', $group['id'], $urlParts[1]);
......@@ -75,6 +92,15 @@ class CRM_Groupadmin_NavigationMenu {
}
\CRM_Core_BAO_Navigation::resetNavigation(CRM_Core_Session::getLoggedInContactID());
}
private function getURL($group) {
foreach ($group['group_type'] as $groupType) {
if (array_key_exists($groupType, $this->urls)) {
return $this->urls[$groupType];
}
}
return $this->urls[0];
}
}
......@@ -29,7 +29,7 @@ View/Download this extension in the [Extension Directory](https://civicrm.org/ex
A navigation menu is created which by default has links to all the groups that the user is a group admin for.
This can be configured at *Administrator->Users and Permissions->Group Admin settings*:
![groupadmin settings]()
![groupadmin settings](images/groupadmin_settings.png)
It defaults to a top-level "Group Admins" menu item but you can move it once created.
......
......@@ -212,9 +212,11 @@ function groupadmin_civicrm_navigationMenu(&$menu) {
}
function groupadmin_civicrm_buildForm($formName, &$form) {
CRM_Groupadmin_NavigationMenu::createOrUpdateGroupAdminMenu();
$navMenu = new CRM_Groupadmin_NavigationMenu();
$navMenu->createOrUpdateGroupAdminMenu();
}
function groupadmin_civicrm_pageRun(&$page) {
CRM_Groupadmin_NavigationMenu::createOrUpdateGroupAdminMenu();
$navMenu = new CRM_Groupadmin_NavigationMenu();
$navMenu->createOrUpdateGroupAdminMenu();
}
......@@ -31,14 +31,16 @@ return [
'groupadmin_navigationmenu_url' => [
'name' => 'groupadmin_navigationmenu_url',
'type' => 'String',
'html_type' => 'text',
'default' => 'civicrm/group/search?force=1&gid=%%gid%%',
'html_type' => 'textarea',
'default' => '0:civicrm/group/search?force=1&gid=%%gid%%',
'is_domain' => 1,
'is_contact' => 0,
'title' => E::ts('URL to link to for group'),
'description' => E::ts('Specify a URL eg. civicrm/group/search?force=1&gid=%%gid%%. %%gid%% will be replaced with the actual group ID. Only supports CiviCRM "relative" URLs currently.'),
'description' => E::ts('Specify a URL eg. 0:civicrm/group/search?force=1&gid=%%gid%%. %%gid%% will be replaced with the actual group ID. Only supports CiviCRM "relative" URLs currently.
You can specify a URL for each group type. You MUST specify the default URL with 0: as the prefix - each grouptype URL should be prefixed with the grouptype ID. To add group types edit the "group_type" option group.'),
'html_attributes' => [
'size' => '80',
'cols' => 60,
'rows' => 4,
],
'settings_pages' => [
'groupadmin' => [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment