_elgg_get_access_where_sql is missing in elgg 3.X

Hi everyone,

I am still upgrading some plugins from 2.X to 3.X.

The following function does not exist anymore in 3.X 

_elgg_get_access_where_sql

What's the name of the new function in 3.X ?

regards,

 

  • There is no specific function in Elgg 3 for it. I could help you if you explain exactly what you're trying to do.

  • Thanks a lot.

    I use the _elgg_get_access_where_sql to get a where clause to retrieve the data that a user has permission to read.

    My code for elgg 2.X looks  as followed.

    public function pessek_count(array $options = []) {
    
    
    $recipient_guid = elgg_extract('recipient_guid', $options);
    
    $status = elgg_extract('status', $options);
    
    
    $access_sql = _elgg_get_access_where_sql([
    
    'table_alias' => 'pessek',
    
    'owner_guid_column' => 'access_owner_guid',
    
    'guid_column' => 'access_guid',
    
    'use_enabled_clause' => false,
    
    ]);
    
    
    switch ($status) {
    
    default :
    
    $status_sql = '1=1';
    
    break;
    
    case 'read' :
    
    $status_sql = 'pessek.time_read IS NOT NULL';
    
    break;
    
    case 'unread' :
    
    $status_sql = 'pessek.time_read IS NULL or pessek.time_read = 0';
    
    break;
    
    case 'seen' :
    
    $status_sql = 'pessek.time_seen IS NOT NULL';
    
    break;
    
    case 'unseen' :
    
    $status_sql = 'pessek.time_seen IS NULL or pessek.time_seen = 0';
    
    break;
    
    }
    
    
    $query = "
    
    SELECT COUNT(DISTINCT pessek.id) as total
    
    FROM {$this->table} pessek
    
    WHERE pessek.recipient_guid = :recipient_guid
    
    AND ($status_sql)
    
    AND $access_sql
    
    ";
    
    
    $params = [':recipient_guid' => (int) $recipient_guid];
    
    
    $row = get_data_row($query, null, $params);
    
    if ($row) {
    
    return (int) $row->total;
    
    }
    
    return 0;
    
    }
     
    How can I implement the above code in elgg 3.X without using _elgg_get_access_where_sql
     
    regards,
  • You should use \Elgg\Database\Clauses\AccessWhereClause

    Never tried but you can do it:

    function (QueryBuilder $qb, $main_alias) use ('pessek') {
        $wheres = [];
        $wheres[] = $qb->compare("{$main_alias}.owner_guid", '=', 'access_owner_guid', ELGG_VALUE_GUID);
        $wheres[] = $qb->compare("{$main_alias}.guid", '=', 'access_guid', ELGG_VALUE_GUID);
    
        return $qb->merge($wheres, 'AND');
    };

     

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking