function __construct($directed, $items) { $this->ctype = $directed; $this->column_id = sprintf('p2p-%s-%s', $this->ctype->get_direction(), $this->ctype->name); $extra_qv = array('p2p:per_page' => -1, 'p2p:context' => 'admin_column'); $connected = $this->ctype->get_connected($items, $extra_qv, 'abstract'); $this->connected = p2p_triage_connected($connected->items); $screen = get_current_screen(); add_filter("manage_{$screen->id}_columns", array($this, 'add_column')); }
/** * Given a list of objects and another list of connected items, * distribute each connected item to it's respective counterpart. * * @param array List of objects * @param array List of connected objects * @param string Name of connected array property */ function p2p_distribute_connected($items, $connected, $prop_name) { $indexed_list = array(); foreach ($items as $item) { $item->{$prop_name} = array(); $indexed_list[$item->ID] = $item; } $groups = p2p_triage_connected($connected); foreach ($groups as $outer_item_id => $connected_items) { $indexed_list[$outer_item_id]->{$prop_name} = $connected_items; } }