Elgg\Database\RelationshipsTable::removeAll PHP Method

removeAll() public method

Removes all relationships originating from a particular entity
public removeAll ( integer $guid, string $relationship = "", boolean $inverse_relationship = false, string $type = '' ) : true
$guid integer GUID of the subject or target entity (see $inverse)
$relationship string Type of the relationship (optional, default is all relationships)
$inverse_relationship boolean Is $guid the target of the deleted relationships? By default, $guid is the subject of the relationships.
$type string The type of entity related to $guid (defaults to all)
return true
    public function removeAll($guid, $relationship = "", $inverse_relationship = false, $type = '')
    {
        $guid = (int) $guid;
        $params = [];
        if (!empty($relationship)) {
            $where = "AND er.relationship = :relationship";
            $params[':relationship'] = $relationship;
        } else {
            $where = "";
        }
        if (!empty($type)) {
            if (!$inverse_relationship) {
                $join = "JOIN {$this->db->prefix}entities e ON e.guid = er.guid_two";
            } else {
                $join = "JOIN {$this->db->prefix}entities e ON e.guid = er.guid_one";
                $where .= " AND ";
            }
            $where .= " AND e.type = :type";
            $params[':type'] = $type;
        } else {
            $join = "";
        }
        $guid_col = $inverse_relationship ? "guid_two" : "guid_one";
        $this->db->deleteData("\n\t\t\tDELETE er FROM {$this->db->prefix}entity_relationships AS er\n\t\t\t{$join}\n\t\t\tWHERE {$guid_col} = {$guid}\n\t\t\t{$where}\n\t\t", $params);
        return true;
    }