Ejemplo n.º 1
0
/**
 * Retrieve data for a package.
 *
 * @since	1.4
 * @param	int|obj	$package	The package WP_Post object, or post ID.
 * @return	arr
 */
function mdjm_get_package_data($package)
{
    $package_id = is_object($package) ? $package->ID : $package;
    $events = mdjm_get_package_event_types($package_id);
    $users = mdjm_get_employees_with_package($package_id);
    $items = mdjm_get_package_addons($package_id);
    $cats = get_the_terms($package_id, 'package-category');
    $employees = array();
    $months = array();
    $addons = array();
    $categories = array();
    if (!mdjm_package_is_restricted_by_date($package_id)) {
        $months[] = __('Always', 'mobile-dj-manager');
    } else {
        $availability = mdjm_get_package_months_available($package_id);
        if (!$availability) {
            $months[] = __('Always', 'mobile-dj-manager');
        } else {
            $i = 0;
            foreach ($availability as $month) {
                $months[] = mdjm_month_num_to_name($availability[$i]);
                $i++;
            }
        }
    }
    if (in_array('all', $users)) {
        $employees[] = __('All Employees', 'mobile-dj-manager');
    } else {
        foreach ($users as $employee_id) {
            if ('all' == $employee_id) {
                continue;
            }
            $employees[] = array($employee_id => mdjm_get_employee_display_name($employee_id));
        }
    }
    if (in_array('all', $events)) {
        $event_types = sprintf(__('All %s Types', 'mobile-dj-manager'), mdjm_get_label_singular());
    } else {
        foreach ($events as $event) {
            $term = get_term($event, 'event-types');
            if (!empty($term)) {
                $event_types[] = $term->name;
            }
        }
    }
    if (mdjm_package_has_variable_prices($package_id)) {
        $range = mdjm_get_package_price_range($package_id);
        $price = mdjm_get_currency() . ' ' . mdjm_format_amount($range['low']) . ' — ' . mdjm_format_amount($range['high']);
    } else {
        $price = mdjm_get_currency() . ' ' . mdjm_format_amount(mdjm_get_package_price($package_id));
    }
    if ($items) {
        foreach ($items as $addon_id) {
            $addons[] = array($addon_id => mdjm_get_addon_name($addon_id));
        }
    }
    if ($cats) {
        foreach ($cats as $cat) {
            $categories[] = $cat->name;
        }
    }
    $package_data = array('name' => mdjm_get_package_name($package_id), 'categories' => get_the_term_list($package_id, 'package-category', '', ', ', ''), 'availability' => array('months' => $months, 'employees' => $employees, 'event_types' => $event_types), 'price' => $price, 'items' => $addons, 'usage' => array('events' => mdjm_count_events_with_package($package_id)));
    return apply_filters('mdjm_get_package_data', $package_data);
}
Ejemplo n.º 2
0
/**
 * Define the data to be displayed in each of the custom columns for the Package post types
 *
 * @since	1.4
 * @param	str		$column_name	The name of the column to display
 * @param	int		$post_id		The current post ID
 * @return
 */
function mdjm_package_posts_custom_column($column_name, $post_id)
{
    global $post;
    switch ($column_name) {
        // Items
        case 'items':
            $items = mdjm_get_package_addons($post_id);
            if ($items) {
                $i = 0;
                foreach ($items as $item) {
                    echo '<a href="' . admin_url("post.php?post={$item}&action=edit") . '">' . mdjm_get_addon_name($item) . '</a>';
                    $i++;
                    if ($i < count($items)) {
                        echo '<br />';
                    }
                }
            }
            break;
            // Category
        // Category
        case 'package_category':
            echo get_the_term_list($post_id, 'package-category', '', ', ', '');
            break;
            // Availability
        // Availability
        case 'availability':
            $output = array();
            if (!mdjm_package_is_restricted_by_date($post_id)) {
                $output[] = __('Always', 'mobile-dj-manager');
            } else {
                $availability = mdjm_get_package_months_available($post_id);
                if (!$availability) {
                    $output[] = __('Always', 'mobile-dj-manager');
                } else {
                    $i = 0;
                    foreach ($availability as $month) {
                        $output[] = mdjm_month_num_to_name($availability[$i]);
                        $i++;
                    }
                }
            }
            echo implode(', ', $output);
            break;
            // Event Types
        // Event Types
        case 'event_types':
            $output = array();
            $event_label = mdjm_get_label_singular();
            $event_types = mdjm_get_package_event_types($post_id);
            if (in_array('all', $event_types)) {
                $output[] = sprintf(__('All %s Types', 'mobile-dj-manager'), $event_label);
            } else {
                foreach ($event_types as $event_type) {
                    $term = get_term($event_type, 'event-types');
                    if (!empty($term)) {
                        $output[] = $term->name;
                    }
                }
            }
            echo implode(', ', $output);
            break;
            // Employees
        // Employees
        case 'employees':
            $employees = mdjm_get_employees_with_package($post_id);
            $output = array();
            if (in_array('all', $employees)) {
                $output[] .= __('All Employees', 'mobile-dj-manager');
            } else {
                foreach ($employees as $employee) {
                    if ('all' == $employee) {
                        continue;
                    }
                    $output[] = '<a href="' . get_edit_user_link($employee) . '">' . mdjm_get_employee_display_name($employee) . '</a>';
                }
            }
            echo implode('<br />', $output);
            break;
            // Price
        // Price
        case 'price':
            if (mdjm_package_has_variable_prices($post_id)) {
                $range = mdjm_get_package_price_range($post_id);
                echo mdjm_currency_filter(mdjm_format_amount($range['low']));
                echo ' &mdash; ';
                echo mdjm_currency_filter(mdjm_format_amount($range['high']));
            } else {
                echo mdjm_currency_filter(mdjm_format_amount(mdjm_get_package_price($post_id)));
            }
            break;
        case 'usage':
            $count = mdjm_count_events_with_package($post_id);
            echo $count . ' ' . _n(mdjm_get_label_singular(), mdjm_get_label_plural(), $count, 'mobile-dj-manager');
            break;
    }
    // switch
}