/** * Get a list of staff members who have enabled this notification (i.e. have permission to AND have chosen to or are defaulted to). * * @param ID_TEXT Notification code * @param ?SHORT_TEXT The category within the notification code (NULL: none) * @param ?array List of member IDs we are restricting to (NULL: no restriction). This effectively works as a intersection set operator against those who have enabled. * @param integer Start position (for pagination) * @param integer Maximum (for pagination) * @return array A pair: Map of members to their notification setting, and whether there may be more */ function _all_staff_who_have_enabled($only_if_enabled_on__notification_code, $only_if_enabled_on__category, $to_member_ids, $start, $max) { $initial_setting = $this->get_initial_setting($only_if_enabled_on__notification_code, $only_if_enabled_on__category); $db = substr($only_if_enabled_on__notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']; $admin_groups = array_merge($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), collapse_1d_complexity('group_id', $db->query_select('gsp', array('group_id'), array('specific_permission' => 'may_enable_staff_notifications')))); $rows = $GLOBALS['FORUM_DRIVER']->member_group_query($admin_groups, $max, $start); $possibly_has_more = count($rows) >= $max; if (!is_null($to_member_ids)) { $new_rows = array(); foreach ($rows as $row) { if (in_array($GLOBALS['FORUM_DRIVER']->pname_id($row), $to_member_ids)) { $new_rows[] = $row; } } $rows = $new_rows; } $new_rows = array(); foreach ($rows as $row) { $test = notifications_setting($only_if_enabled_on__notification_code, $only_if_enabled_on__category, $GLOBALS['FORUM_DRIVER']->pname_id($row)); if ($test != A_NA) { $new_rows[$GLOBALS['FORUM_DRIVER']->pname_id($row)] = $test; } } return array($new_rows, $possibly_has_more); }
/** * Build a tree UI for all categories available. * * @param array Notification types * @param ID_TEXT The notification code to work with * @param object Notificiation hook object * @param ?ID_TEXT Category we're looking under (NULL: root) * @param integer Recursion depth * @return tempcode UI */ function _notifications_build_category_tree($_notification_types, $notification_code, $ob, $id, $depth = 0) { static $done_get_change = false; $_notification_categories = $ob->create_category_tree($notification_code, $id); $statistical_notification_type = _find_member_statistical_notification_type(get_member()); $notification_categories = array(); foreach ($_notification_categories as $c) { $notification_category = is_integer($c['id']) ? strval($c['id']) : $c['id']; $current_setting = notifications_setting($notification_code, $notification_category); if ($current_setting == A__STATISTICAL) { $current_setting = _find_member_statistical_notification_type(get_member()); } $notification_types = array(); foreach ($_notification_types as $possible => $ntype) { $current_setting = notifications_setting($notification_code, $notification_category); if ($current_setting == A__STATISTICAL) { $current_setting = $statistical_notification_type; } $allowed_setting = $ob->allowed_settings($notification_code); $available = ($possible & $allowed_setting) != 0; if (count($_POST) != 0) { $checked = post_param_integer('notification_' . $notification_category . '_' . $ntype, 0); } else { $checked = ($possible & $current_setting) != 0 ? 1 : 0; } $notification_types[] = array('NTYPE' => $ntype, 'LABEL' => do_lang_tempcode('ENABLE_NOTIFICATIONS_' . $ntype), 'CHECKED' => $checked == 1, 'RAW' => strval($possible), 'AVAILABLE' => $available, 'SCOPE' => $notification_category); } if (!array_key_exists('num_children', $c) && array_key_exists('child_count', $c)) { $c['num_children'] = $c['child_count']; } if (!array_key_exists('num_children', $c) && array_key_exists('children', $c)) { $c['num_children'] = count($c['children']); } $children = new ocp_tempcode(); if (array_key_exists('num_children', $c) && $c['num_children'] != 0) { $children = _notifications_build_category_tree($_notification_types, $notification_code, $ob, $notification_category, $depth + 1); } $notification_categories[] = array('NUM_CHILDREN' => strval(array_key_exists('num_children', $c) ? $c['num_children'] : 0), 'DEPTH' => strval($depth), 'NOTIFICATION_CATEGORY' => $notification_category, 'NOTIFICATION_TYPES' => $notification_types, 'CATEGORY_TITLE' => $c['title'], 'CHECKED' => notifications_enabled($notification_code, $notification_category), 'CHILDREN' => $children); } $tree = do_template('NOTIFICATIONS_TREE', array('NOTIFICATION_CODE' => $notification_code, 'NOTIFICATION_CATEGORIES' => $notification_categories)); return $tree; }