if (CRM_Core_Permission::checkActionPermission('delete', array('entity' => 'contact'))) { // User is allowed to delete contacts // Add code to delete the contact here } else { // User does not have permission to delete contacts // Add code to display an error message here }
if (CRM_Core_Permission::checkActionPermission('view', array('entity' => 'event', 'id' => $event_id))) { // User is allowed to view the specified event // Add code to display the event details here } else { // User does not have permission to view the specified event // Add code to display an error message here }In this example, the checkActionPermission function is used to determine whether the current user has permission to view a specific event within CiviCRM. The function takes an additional parameter, "id", which specifies the ID of the event being accessed. If the user has permission to view the event, the code within the if statement will be executed, which could include code to display the event details. If the user does not have permission, an error message will be displayed. The CRM_Core_Permission class is part of the CiviCRM Core package, which provides a wide range of functionality for managing contacts, events, contributions, and more within a CRM environment.