Commit 74fe2016 authored by Christian Wach's avatar Christian Wach
Browse files

Switch to bracket notation for arrays

parent e97c20af
......@@ -23,9 +23,9 @@ class CRM_CiviNetworkGroups_ExtensionUtil {
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
public static function ts($text, $params = []) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
$params['domain'] = [self::LONG_NAME, NULL];
}
return ts($text, $params);
}
......
......@@ -35,7 +35,7 @@ class CiviCRM_Network_Groups_CLE {
$this->plugin = $plugin;
// Initialise when plugin is loaded.
add_action( 'civicrm_network_groups_loaded', array( $this, 'initialise' ) );
add_action( 'civicrm_network_groups_loaded', [ $this, 'initialise' ] );
}
......@@ -49,11 +49,11 @@ class CiviCRM_Network_Groups_CLE {
public function initialise() {
// Register directories.
add_action( 'civicrm_config', array( $this, 'register_php_directory' ), 10, 1 );
add_action( 'civicrm_config', array( $this, 'register_template_directory' ), 10, 1 );
add_action( 'civicrm_config', [ $this, 'register_php_directory' ], 10, 1 );
add_action( 'civicrm_config', [ $this, 'register_template_directory' ], 10, 1 );
// Register hooks.
add_action( 'civicrm_config', array( $this, 'register_hooks' ), 10, 1 );
add_action( 'civicrm_config', [ $this, 'register_hooks' ], 10, 1 );
}
......@@ -130,21 +130,21 @@ class CiviCRM_Network_Groups_CLE {
// Add callback for CiviCRM postProcess hook.
Civi::service('dispatcher')->addListener(
'hook_civicrm_postProcess',
array( $this, 'block_register' ),
[ $this, 'block_register' ],
-100 // Default priority.
);
// Add callback for CiviCRM pageRun hook.
Civi::service('dispatcher')->addListener(
'hook_civicrm_pageRun',
array( $this, 'block_add_to_screen' ),
[ $this, 'block_add_to_screen' ],
-100 // Default priority.
);
// Add callback for Contact Layout Editor extension contactSummaryBlocks hook.
Civi::service('dispatcher')->addListener(
'hook_civicrm_contactSummaryBlocks',
array( $this, 'block_add_to_editor' ),
[ $this, 'block_add_to_editor' ],
-100 // Default priority.
);
......
......@@ -58,7 +58,7 @@ class CRM_CiviNetworkGroups_Form_Inline_CiviNetworkGroups extends CRM_Contact_Fo
$groupOptions = CRM_CiviNetworkGroups_Utils_CiviNetworkGroups::groupOptions();
// Build network groups elements.
$groups = array();
$groups = [];
foreach ($groupOptions as $name => $label) {
$group = $this->createElement('advcheckbox', $name, NULL, $label);
$groups[] = $group;
......@@ -68,7 +68,7 @@ class CRM_CiviNetworkGroups_Form_Inline_CiviNetworkGroups extends CRM_Contact_Fo
$this->addGroup($groups, 'network_groups', civicrm_network_groups_title(), '&nbsp;<br/>');
// Build form elements.
$wrapper = array();
$wrapper = [];
$wrapper['network_groups'] = $groupOptions;
// Export form elements.
......@@ -100,7 +100,7 @@ class CRM_CiviNetworkGroups_Form_Inline_CiviNetworkGroups extends CRM_Contact_Fo
if (count($values['network_groups']) > 0) {
// Init error checker.
$errors = array();
$errors = [];
// If the flag is set to switch to main site.
$switch = civicrm_network_groups()->admin->setting_get( 'main' );
......
......@@ -17,7 +17,7 @@ class CRM_CiviNetworkGroups_Utils_CiviNetworkGroups {
public static function groupOptions() {
// Init return array.
$return = array();
$return = [];
// Get synced groups.
$synced_groups = civicrm_network_groups()->civicrm->groups_with_sync_get();
......@@ -56,7 +56,7 @@ class CRM_CiviNetworkGroups_Utils_CiviNetworkGroups {
);
// Build defaults for network groups.
$groups = array();
$groups = [];
foreach ($groupOptions as $id => $label) {
$isMember = 0;
if (in_array(absint($id), $userGroups)) {
......
......@@ -43,7 +43,7 @@ class CiviCRM_Network_Groups_Admin {
* @access public
* @var array $settings The plugin settings data.
*/
public $settings = array();
public $settings = [];
......@@ -60,7 +60,7 @@ class CiviCRM_Network_Groups_Admin {
$this->plugin = $plugin;
// Initialise when plugin is loaded.
add_action( 'civicrm_network_groups_loaded', array( $this, 'initialise' ) );
add_action( 'civicrm_network_groups_loaded', [ $this, 'initialise' ] );
}
......@@ -157,7 +157,7 @@ class CiviCRM_Network_Groups_Admin {
public function register_hooks() {
// Add menu item to Network Admin Settings submenu.
add_action( 'network_admin_menu', array( $this, 'admin_menu' ) );
add_action( 'network_admin_menu', [ $this, 'admin_menu' ] );
}
......@@ -194,15 +194,15 @@ class CiviCRM_Network_Groups_Admin {
__( 'CiviCRM Network Groups', 'civicrm-network-groups' ), // Menu title.
'manage_options', // Required cap.
'civicrm_network_groups', // Slug name.
array( $this, 'page_settings' ) // Callback.
[ $this, 'page_settings' ] // Callback.
);
// Add utilities.
add_action( 'admin_head-' . $this->settings_page, array( $this, 'admin_head' ), 50 );
add_action( 'admin_head-' . $this->settings_page, [ $this, 'admin_head' ], 50 );
// Add scripts and styles.
add_action( 'admin_print_styles-' . $this->settings_page, array( $this, 'admin_css' ) );
add_action( 'admin_print_scripts-' . $this->settings_page, array( $this, 'admin_js' ) );
add_action( 'admin_print_styles-' . $this->settings_page, [ $this, 'admin_css' ] );
add_action( 'admin_print_scripts-' . $this->settings_page, [ $this, 'admin_js' ] );
}
......@@ -244,11 +244,11 @@ class CiviCRM_Network_Groups_Admin {
}
// Add a tab - we can add more later.
$screen->add_help_tab( array(
$screen->add_help_tab( [
'id' => 'civicrm_ng',
'title' => __( 'CiviCRM Network Groups', 'civicrm-network-groups' ),
'content' => $this->admin_help_text(),
));
] );
// --<
return $screen;
......@@ -307,7 +307,7 @@ class CiviCRM_Network_Groups_Admin {
wp_enqueue_script(
'civicrm_network_groups_js',
plugins_url( 'assets/js/civicrm-network-groups-settings.js', CIVICRM_NETWORK_GROUPS_FILE ),
array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ),
[ 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ],
CIVICRM_NETWORK_GROUPS_VERSION // Version.
);
......@@ -404,8 +404,8 @@ class CiviCRM_Network_Groups_Admin {
}
// Init groups and checkbox arrays.
$groups = array();
$checkboxes = array();
$groups = [];
$checkboxes = [];
// Parse synced groups and order by precedence array.
foreach( $network_groups AS $ordered_group_id ) {
......@@ -508,7 +508,7 @@ class CiviCRM_Network_Groups_Admin {
public function settings_get_defaults() {
// Init return.
$settings = array();
$settings = [];
// Set default title.
$settings['title'] = __( 'Network Groups', 'civicrm-network-groups' );
......@@ -520,7 +520,7 @@ class CiviCRM_Network_Groups_Admin {
$settings['main'] = 'n';
// Set default precedence if defined.
$settings['precedence'] = array();
$settings['precedence'] = [];
if ( defined( 'CIVICRM_NETWORK_GROUPS_PRECEDENCE' ) ) {
$settings['precedence'] = CIVICRM_NETWORK_GROUPS_PRECEDENCE;
}
......
......@@ -33,7 +33,7 @@ class CiviCRM_Network_Groups_CiviCRM {
$this->plugin = $plugin;
// Initialise when plugin is loaded.
add_action( 'civicrm_network_groups_loaded', array( $this, 'initialise' ) );
add_action( 'civicrm_network_groups_loaded', [ $this, 'initialise' ] );
}
......@@ -71,7 +71,7 @@ class CiviCRM_Network_Groups_CiviCRM {
public function groups_with_sync_get() {
// Init return.
$groups = array();
$groups = [];
// Bail if no CiviCRM.
if ( ! $this->plugin->is_civicrm_initialised() ) {
......@@ -79,7 +79,7 @@ class CiviCRM_Network_Groups_CiviCRM {
}
// Get all groups with a "synced-group" source.
$result = civicrm_api( 'Group', 'get', array(
$result = civicrm_api( 'Group', 'get', [
'version' => 3,
'sequential' => 1,
'source' => array( 'LIKE' => '%synced-group%' ),
......@@ -87,7 +87,7 @@ class CiviCRM_Network_Groups_CiviCRM {
'options' => array(
'limit' => '0'
),
));
] );
// Bail if we get an error.
if ( isset( $result['is_error'] ) AND $result['is_error'] == '1' ) {
......@@ -131,7 +131,7 @@ class CiviCRM_Network_Groups_CiviCRM {
public function groups_get_for_contact( $contact_id ) {
// Init groups.
$groups = array();
$groups = [];
// Bail if no CiviCRM.
if ( ! $this->plugin->is_civicrm_initialised() ) {
......@@ -139,14 +139,14 @@ class CiviCRM_Network_Groups_CiviCRM {
}
// Get groups that the user is in.
$user_groups = civicrm_api( 'GroupContact', 'get', array(
$user_groups = civicrm_api( 'GroupContact', 'get', [
'version' => 3,
'sequential' => 1,
'contact_id' => $contact_id,
'options' => array(
'limit' => '0'
),
));
] );
// Sanity check.
if ( $user_groups['is_error'] == '0' AND absint( $user_groups['count'] ) > 0 ) {
......@@ -176,7 +176,7 @@ class CiviCRM_Network_Groups_CiviCRM {
public function group_ids_get_for_contact( $contact_id ) {
// Init groups.
$groups = array();
$groups = [];
// Get groups that the user is in.
$user_groups = $this->groups_get_for_contact( $contact_id );
......@@ -219,21 +219,21 @@ class CiviCRM_Network_Groups_CiviCRM {
}
// Call API.
$result = civicrm_api( 'GroupContact', 'create', array(
$result = civicrm_api( 'GroupContact', 'create', [
'version' => 3,
'group_id' => $group_id,
'contact_id' => $contact_id,
'status' => 'Added',
));
] );
// Add log entry on failure.
if ( isset( $result['is_error'] ) AND $result['is_error'] == '1' ) {
error_log( print_r( array(
error_log( print_r( [
'method' => __METHOD__,
'group_id' => $group_id,
'contact_id' => $contact_id,
'result' => $result,
), true ) );
], true ) );
return false;
}
......@@ -256,21 +256,21 @@ class CiviCRM_Network_Groups_CiviCRM {
public function group_contact_delete( $contact_id, $group_id ) {
// Call API.
$result = civicrm_api( 'GroupContact', 'create', array(
$result = civicrm_api( 'GroupContact', 'create', [
'version' => 3,
'group_id' => $group_id,
'contact_id' => $contact_id,
'status' => 'Removed',
));
] );
// Add log entry on failure.
if ( isset( $result['is_error'] ) AND $result['is_error'] == '1' ) {
error_log( print_r( array(
error_log( print_r( [
'method' => __METHOD__,
'group_id' => $group_id,
'contact_id' => $contact_id,
'result' => $result,
), true ) );
], true ) );
return false;
}
......@@ -351,10 +351,10 @@ class CiviCRM_Network_Groups_CiviCRM {
}
// Get domain org info.
$contact = civicrm_api( 'contact', 'getsingle', array(
$contact = civicrm_api( 'contact', 'getsingle', [
'version' => 3,
'id' => $contact_id,
));
] );
// Bail if there's an error.
if ( ! empty( $contact['is_error'] ) AND $contact['is_error'] == 1 ) {
......
......@@ -47,7 +47,7 @@ class CiviCRM_Network_Groups_Hooks {
$this->plugin = $plugin;
// Initialise when plugin is loaded.
add_action( 'civicrm_network_groups_loaded', array( $this, 'initialise' ) );
add_action( 'civicrm_network_groups_loaded', [ $this, 'initialise' ] );
}
......@@ -75,22 +75,22 @@ class CiviCRM_Network_Groups_Hooks {
public function filters_add() {
// Switch to the main site.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'switch_to_main_site' ), 10 );
add_filter( 'civicrm_network_groups_synced_groups', [ $this, 'switch_to_main_site' ], 10 );
// Filter groups to keep only those on the main site.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_main_site_groups' ), 20 );
add_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_main_site_groups' ], 20 );
// Filter groups to keep only those defined in our settings.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_defined_groups' ), 30 );
add_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_defined_groups' ], 30 );
// Filter groups by logged-in user precedence.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_precedence' ), 40 );
add_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_precedence' ], 40 );
// Switch to original site.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'switch_back' ), 50 );
add_filter( 'civicrm_network_groups_synced_groups', [ $this, 'switch_back' ], 50 );
// Filter capability level.
add_filter( 'civicrm_network_groups_edit_own', array( $this, 'capability_level' ), 10, 2 );
add_filter( 'civicrm_network_groups_edit_own', [ $this, 'capability_level' ], 10, 2 );
}
......@@ -104,12 +104,12 @@ class CiviCRM_Network_Groups_Hooks {
public function filters_remove() {
// Remove all filters.
remove_filter( 'civicrm_network_groups_synced_groups', array( $this, 'switch_to_main_site' ), 10 );
remove_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_main_site_groups' ), 20 );
remove_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_defined_groups' ), 30 );
remove_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_precedence' ), 40 );
remove_filter( 'civicrm_network_groups_synced_groups', array( $this, 'switch_back' ), 50 );
remove_filter( 'civicrm_network_groups_edit_own', array( $this, 'capability_level' ), 10, 2 );
remove_filter( 'civicrm_network_groups_synced_groups', [ $this, 'switch_to_main_site' ], 10 );
remove_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_main_site_groups' ], 20 );
remove_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_defined_groups' ], 30 );
remove_filter( 'civicrm_network_groups_synced_groups', [ $this, 'filter_by_precedence' ], 40 );
remove_filter( 'civicrm_network_groups_synced_groups', [ $this, 'switch_back' ], 50 );
remove_filter( 'civicrm_network_groups_edit_own', [ $this, 'capability_level' ], 10, 2 );
}
......@@ -135,7 +135,7 @@ class CiviCRM_Network_Groups_Hooks {
}
// Init return.
$groups = array();
$groups = [];
// Filter by existence of corresponding "Groups" group.
foreach( $civicrm_groups AS $group ) {
......@@ -177,7 +177,7 @@ class CiviCRM_Network_Groups_Hooks {
}
// Init return.
$groups = array();
$groups = [];
// Parse defined groups ordered by descending precedence.
foreach( $network_groups AS $defined_group_id ) {
......@@ -229,7 +229,7 @@ class CiviCRM_Network_Groups_Hooks {
}
// Init "Groups" groups visible to the user/contact.
$groups = array();
$groups = [];
// Get current user data.
$user = wp_get_current_user();
......
......@@ -33,7 +33,7 @@ class CiviCRM_Network_Groups_WordPress {
$this->plugin = $plugin;
// Initialise when plugin is loaded.
add_action( 'civicrm_network_groups_loaded', array( $this, 'initialise' ) );
add_action( 'civicrm_network_groups_loaded', [ $this, 'initialise' ] );
}
......@@ -47,11 +47,11 @@ class CiviCRM_Network_Groups_WordPress {
public function initialise() {
// Add section to the 'user-edit.php' page.
add_action( 'personal_options', array( $this, 'profile_extras' ), 50 );
add_action( 'personal_options', [ $this, 'profile_extras' ], 50 );
// Save data when user is updated.
add_action( 'personal_options_update', array( $this, 'profile_update_self' ) );
add_action( 'edit_user_profile_update', array( $this, 'profile_update_other' ) );
add_action( 'personal_options_update', [ $this, 'profile_update_self' ] );
add_action( 'edit_user_profile_update', [ $this, 'profile_update_other' ] );
}
......@@ -96,7 +96,7 @@ class CiviCRM_Network_Groups_WordPress {
}
// Init checkboxes and markup.
$checkboxes = array();
$checkboxes = [];
$groups_markup = '';
// Build checkboxes.
......@@ -153,7 +153,7 @@ class CiviCRM_Network_Groups_WordPress {
}
// Retrieve user groups.
$chosen_user_groups = array();
$chosen_user_groups = [];
if ( isset( $_POST['cng_user_groups'] ) AND is_array( $_POST['cng_user_groups'] ) ) {
$chosen_user_groups = $_POST['cng_user_groups'];
}
......@@ -268,7 +268,7 @@ class CiviCRM_Network_Groups_WordPress {
public function group_ids_get_for_user( $user_id ) {
// Init user groups.
$groups = array();
$groups = [];
// Get "Groups" groups for this user.
$user_groups = $this->groups_get_for_user( $user_id );
......
Supports Markdown
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