private static function get_visible_directions($post_type, $ctype, $show_ui)
 {
     $direction = $ctype->find_direction($post_type, false);
     if (!$direction) {
         return array();
     }
     if ($ctype->indeterminate && !$ctype->reciprocal) {
         return _p2p_expand_direction($show_ui);
     }
     if ('any' == $show_ui || $direction == $show_ui) {
         return array($direction);
     }
     return array();
 }
Esempio n. 2
0
/**
 * Retrieve connections.
 *
 * @param string $p2p_type A valid connection type.
 * @param array $args Query args:
 *
 * - 'direction': Can be 'from', 'to' or 'any'
 * - 'from': Object id. The first end of the connection. (optional)
 * - 'to': Object id. The second end of the connection. (optional)
 * - 'fields': Which field of the connection to return. Can be:
 * 		'all', 'object_id', 'p2p_from', 'p2p_to', 'p2p_id' or 'count'
 *
 * @return array
 */
function p2p_get_connections($p2p_type, $args = array())
{
    extract(wp_parse_args($args, array('direction' => 'from', 'from' => 'any', 'to' => 'any', 'fields' => 'all')), EXTR_SKIP);
    $r = array();
    foreach (_p2p_expand_direction($direction) as $direction) {
        $args = array($from, $to);
        if ('to' == $direction) {
            $args = array_reverse($args);
        }
        if ('object_id' == $fields) {
            $field = 'to' == $direction ? 'p2p_from' : 'p2p_to';
        } else {
            $field = $fields;
        }
        $r = array_merge($r, _p2p_get_connections($p2p_type, array('from' => $args[0], 'to' => $args[1], 'fields' => $field)));
    }
    if ('count' == $fields) {
        return array_sum($r);
    }
    return $r;
}
Esempio n. 3
0
 function _directions_for_admin($direction, $show_ui)
 {
     return array_intersect(_p2p_expand_direction($show_ui), _p2p_expand_direction($direction));
 }
Esempio n. 4
0
/**
 * Retrieve connections.
 *
 * @param string $p2p_type A valid connection type.
 * @param array $args Query args:
 *
 * - 'direction': Can be 'from', 'to' or 'any'
 * - 'from': Object id. The first end of the connection. (optional)
 * - 'to': Object id. The second end of the connection. (optional)
 * - 'fields': Which field of the connection to return. Can be:
 * 		'all', 'object_id', 'p2p_from', 'p2p_to', 'p2p_id' or 'count'
 *
 * @return array
 */
function p2p_get_connections($p2p_type, $args = array())
{
    $args = wp_parse_args($args, array('direction' => 'from', 'from' => 'any', 'to' => 'any', 'fields' => 'all'));
    $r = array();
    foreach (_p2p_expand_direction($args['direction']) as $direction) {
        $dirs = array($args['from'], $args['to']);
        if ('to' == $direction) {
            $dirs = array_reverse($dirs);
        }
        if ('object_id' == $args['fields']) {
            $fields = 'to' == $direction ? 'p2p_from' : 'p2p_to';
        } else {
            $fields = $args['fields'];
        }
        $r = array_merge($r, _p2p_get_connections($p2p_type, array('from' => $dirs[0], 'to' => $dirs[1], 'fields' => $fields)));
    }
    if ('count' == $args['fields']) {
        return array_sum($r);
    }
    return $r;
}
 function directions_for_admin($_, $show_ui)
 {
     return array_intersect(_p2p_expand_direction($show_ui), _p2p_expand_direction('any'));
 }