BP_Document::get_scope_folder_query_sql( mixed $scope = false, array $r = array() )

Get the SQL for the ‘scope’ param in BP_Document::get().

Description

A scope is a predetermined set of document arguments. This method is used to grab these document arguments and override any existing args if needed. Can handle multiple scopes.

Parameters

$scope

(Optional) The document scope. Accepts string or array of scopes.

Default value: false

$r

(Optional) Current activity arguments. Same as those of BP_document::get(), but merged with defaults.

Default value: array()

Return

(false|array) 'sql' WHERE SQL string and 'override' document args.

Source

File: bp-document/classes/class-bp-document.php

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
public static function get_scope_folder_query_sql( $scope = false, $r = array() ) {
 
    // Define arrays for future use.
    $query_args = array();
    $override   = array();
    $retval     = array();
 
    // Check for array of scopes.
    if ( is_array( $scope ) ) {
        $scopes = $scope;
 
        // Explode a comma separated string of scopes.
    } elseif ( is_string( $scope ) ) {
        $scopes = explode( ',', $scope );
    }
 
    // Bail if no scope passed.
    if ( empty( $scopes ) ) {
        return false;
    }
 
    // Helper to easily grab the 'user_id'.
    if ( ! empty( $r['filter']['user_id'] ) ) {
        $r['user_id'] = $r['filter']['user_id'];
    }
 
    // Parse each scope; yes! we handle multiples!
    foreach ( $scopes as $scope ) {
        $scope_args = array();
 
        /**
         * Plugins can hook here to set their document arguments for custom scopes.
         * This is a dynamic filter based on the document scope. eg:
         *   - 'bp_document_set_groups_scope_args'
         *   - 'bp_document_set_friends_scope_args'
         * To see how this filter is used, plugin devs should check out:
         *   - bp_groups_filter_document_scope() - used for 'groups' scope
         *   - bp_friends_filter_document_scope() - used for 'friends' scope
         *
         * @param array {
         *                        Document query clauses.
         *
         * @type array {
         *         Document arguments for your custom scope.
         *         See {@link BP_Document_Query::_construct()} for more details.
         *     }
         * @type array  $override Optional. Override existing document arguments passed by $r.
         *     }
         * }
         *
         * @param array $r        Current activity arguments passed in BP_Document::get().
         *
         * @since BuddyBoss 1.4.0
         */
        $scope_args = apply_filters( "bp_document_set_folder_{$scope}_scope_args", array(), $r );
 
        if ( ! empty( $scope_args ) ) {
            // Merge override properties from other scopes
            // this might be a problem...
            if ( ! empty( $scope_args['override'] ) ) {
                $override = array_merge( $override, $scope_args['override'] );
                unset( $scope_args['override'] );
            }
 
            // Save scope args.
            if ( ! empty( $scope_args ) ) {
                $query_args[] = $scope_args;
            }
        }
    }
 
    if ( ! empty( $query_args ) ) {
        // Set relation to OR.
        $query_args['relation'] = 'OR';
 
        $query = new BP_Document_Query( $query_args );
        $sql   = $query->get_sql_folder();
        if ( ! empty( $sql ) ) {
            $retval['sql'] = $sql;
        }
    }
 
    if ( ! empty( $override ) ) {
        $retval['override'] = $override;
    }
 
    return $retval;
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.