Elgg\Database\RelationshipsTable::getEntityRelationshipWhereSql PHP Method

getEntityRelationshipWhereSql() public method

Returns SQL appropriate for relationship joins and wheres
public getEntityRelationshipWhereSql ( string $column, string $relationship = null, integer $relationship_guid = null, boolean $inverse_relationship = false ) : mixed
$column string Column name the GUID should be checked against. Provide in table.column format.
$relationship string Type of the relationship
$relationship_guid integer Entity GUID to check
$inverse_relationship boolean Is $relationship_guid the target of the relationship?
return mixed
    public function getEntityRelationshipWhereSql($column, $relationship = null, $relationship_guid = null, $inverse_relationship = false)
    {
        if ($relationship == null && $relationship_guid == null) {
            return '';
        }
        $wheres = array();
        $joins = array();
        $group_by = '';
        if ($inverse_relationship) {
            $joins[] = "JOIN {$this->db->prefix}entity_relationships r on r.guid_one = {$column}";
        } else {
            $joins[] = "JOIN {$this->db->prefix}entity_relationships r on r.guid_two = {$column}";
        }
        if ($relationship) {
            $wheres[] = "r.relationship = '" . $this->db->sanitizeString($relationship) . "'";
        }
        if ($relationship_guid) {
            if ($inverse_relationship) {
                $wheres[] = "r.guid_two = '{$relationship_guid}'";
            } else {
                $wheres[] = "r.guid_one = '{$relationship_guid}'";
            }
        } else {
            // See #5775. Queries that do not include a relationship_guid must be grouped by entity table alias,
            // otherwise the result set is not unique
            $group_by = $column;
        }
        if ($where_str = implode(' AND ', $wheres)) {
            return array('wheres' => array("({$where_str})"), 'joins' => $joins, 'group_by' => $group_by);
        }
        return '';
    }