public function arrayToWhereClause(array $data, $and = true) {
        $out = array();
        $adapter = $this->getAdapter();
        foreach ($data as $key => $value) {
            $quotedKey = $adapter->quoteIdentifier($key);
            $quotedValue = $adapter->quote($value);

            if (is_null($value)) {
                $out[] = "$quotedKey IS NULL";
            } elseif (is_array($value)) {
                $out[] = "$quotedKey IN ($quotedValue)";
            } else {
                $out[] = "$quotedKey = $quotedValue";
            }
        }
        $glue = $and ? 'AND' : 'OR';
        $out = implode(" $glue ", $out);
        return $out;
    }