Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCHR-3376: Update T&A Administer Menu Items #325

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public function upgrade_1032() {
'return' => ['id'],
'name' => ['IN' => ['Probation', 'Activity_Custom_Fields']],
]);

foreach ($result['values'] as $value) {
civicrm_api3('CustomGroup', 'create', [
'id' => $value['id'],
Expand All @@ -734,6 +734,30 @@ public function upgrade_1032() {
return TRUE;
}

/**
* Update permissions and set the weight for the "Tasks" menu item.
*
* @return bool
*/
public function upgrade_1033() {
$params = ['return' => 'id', 'name' => 'tasksassignments_administer'];
$parentId = (int) civicrm_api3('Navigation', 'getvalue', $params);
$params = ['return' => 'id', 'name' => 'ta_settings'];
$taSettingsId = (int) civicrm_api3('Navigation', 'getvalue', $params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just call the Navigation API once to get the ids of the menu's rather than twice?

$permission = 'administer CiviCase';

// Update permissions
foreach ([$parentId, $taSettingsId] as $navId) {
$params = ['permission' => $permission, 'id' => $navId];
civicrm_api3('Navigation', 'create', $params);
}

// Update parent weight
civicrm_api3('Navigation', 'create', ['id' => $parentId, 'weight' => -97]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually update permission and weight of the parentID in one call and the permission of taSettingsId in another call, which means we will call the API two times rather than three.
We can have a function do this that will optionally update the permission or not if present


return TRUE;
}

public function uninstall() {
CRM_Core_DAO::executeQuery("DELETE FROM `civicrm_navigation` WHERE name IN ('tasksassignments', 'ta_dashboard_tasks', 'ta_dashboard_documents', 'ta_dashboard_calendar', 'ta_dashboard_keydates', 'tasksassignments_administer', 'ta_settings')");
CRM_Core_BAO_Navigation::resetNavigation();
Expand Down
18 changes: 12 additions & 6 deletions uk.co.compucorp.civicrm.tasksassignments/tasksassignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,18 @@ function tasksassignments_civicrm_navigationMenu(&$params) {
*/
function _tasksassignments_moveCiviCaseAdminSubMenuItemsUnderTaskAdminSubMenu(&$params) {
$administerMenuItems = &_tasksassignments_getAdministerMenuItems($params);
$menuItemsToClone = _tasksassignments_filterMenuItemsOfAdministerSubMenu($administerMenuItems, 'CiviCase', ['Case Types', 'Case Statuses']);
$menuItemsToClone = _tasksassignments_filterMenuItemsOfAdministerSubMenu(
$administerMenuItems,
'CiviCase',
['Case Types']
);

_tasksassignments_cloneMenuItemsInAdministerSubMenuAndChangeLabels($administerMenuItems, $menuItemsToClone, 'tasksassignments_administer', [
'Case Types' => 'Workflows',
'Case Statuses' => 'Workflows Status'
]);
_tasksassignments_cloneMenuItemsInAdministerSubMenuAndChangeLabels(
$administerMenuItems,
$menuItemsToClone,
'tasksassignments_administer',
['Case Types' => 'Workflows',]
);

_tasksassignments_deleteAdministerSubMenu($administerMenuItems, 'CiviCase');
}
Expand Down Expand Up @@ -323,7 +329,7 @@ function _tasksassignments_filterMenuItemsOfAdministerSubMenu($administerMenuIte
*
* @param array $administerMenuItems
* @param array $menuItems
* @param array $subMenuName
* @param string $subMenuName
* @param array $labelsMapping
*/
function _tasksassignments_cloneMenuItemsInAdministerSubMenuAndChangeLabels(&$administerMenuItems, $menuItems, $subMenuName, $labelsMapping) {
Expand Down