Search code examples
elgg

Trying to customise an Elgg database query


I've been trying to customise the block user plugin in order to create a 2 way block, however, I am running into a problem when trying to tweak the lib/functions.php in event manager.

I am essentially just getting the list of blocked users and then trying to put a "NOT EXISTS" clause in before the event list is returned via the $entities_options query array. I'm farily new to the DB querying side of things in Elgg so could use some help in getting this right.

// GET ARRAY OF BLOCKED USERS

$users = lee_framework_get_options(elgg_get_plugin_user_setting('blockuser_get', lee_loggedin_user_guid, 'blockuser'));
$blocked_user_array = array();
foreach($users as $user)

{
    $blocked_guid = get_user_by_username($user)->guid; 
    $blocked_user_array[] = $blocked_guid;

    $entities_options['owner_guids'] != $blocked_guid; // This is just to indicate what I am trying to achieve!

}

I believe I need to use the JOINS / WHERES clauses, as used in the rest of the page but am struggling to find and use the correct field names. eg.

$entities_options['joins'][] = "JOIN " . elgg_get_config("dbprefix") . "entity_relationships e_ra ON e.guid = e_ra.guid_one";
$entities_options['wheres'][] = "(e_ra.guid_two IN (" . implode(", ", $friends_guids) . "))";

Any advice on this would be very much appreciated :)


Solution

  • For anyone interested, this was solved using the following code placed in the functions.php file of event manager:

    // GET ARRAY OF BLOCKED USERS
    
    $blocked_users = lee_framework_get_options(elgg_get_plugin_user_setting('blockuser_get', lee_loggedin_user_guid, 'blockuser'));
    $blocked_user_array = array();
    
    foreach($blocked_users as $user) {
    
    $blocked_user_array[] = get_user_by_username($user)->guid;
    
    $entities_options['joins'][] = "JOIN " . elgg_get_config("dbprefix") . "metadata md on e.guid = md.entity_guid";
    $entities_options['wheres'][] = "md.owner_guid != " . get_user_by_username($user)->guid;
    
    }