Exemple #1
0
/** @internal */
function _p2p_get_connections($p2p_type, $args = array())
{
    global $wpdb;
    extract($args, EXTR_SKIP);
    $where = $wpdb->prepare('WHERE p2p_type = %s', $p2p_type);
    foreach (array('from', 'to') as $key) {
        if ('any' == ${$key}) {
            continue;
        }
        if (empty(${$key})) {
            return array();
        }
        $value = scbUtil::array_to_sql(_p2p_normalize(${$key}));
        $where .= " AND p2p_{$key} IN ({$value})";
    }
    switch ($fields) {
        case 'p2p_id':
        case 'p2p_from':
        case 'p2p_to':
            $sql_field = $fields;
            break;
        case 'count':
            $sql_field = 'COUNT(*)';
            break;
        default:
            $sql_field = '*';
    }
    $query = "SELECT {$sql_field} FROM {$wpdb->p2p} {$where}";
    if ('*' == $sql_field) {
        return $wpdb->get_results($query);
    } else {
        return $wpdb->get_col($query);
    }
}