/** * 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 ' — '; 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 }
/** * Whether or not an employee has the package. * * @since 1.4 * @param int $package_id The package ID. * @param int $employee_id The employee ID to check. * @return bool True if the employee has the package, or false if not. */ function mdjm_employee_has_package($package_id, $employee_id = 0) { $employees = mdjm_get_employees_with_package($package_id); if (empty($employee_id)) { $employee_id = get_current_user_id(); } if ($employees) { if (in_array('all', $employees) || in_array($employee_id, $employees)) { return true; } } return false; }
/** * Output the package availability employee_row * * @since 1.4 * @param int $post The WP_Post object. * @return str */ function mdjm_package_metabox_availability_employee_row($post) { $employees_with = mdjm_get_employees_with_package($post->ID); $event_types = mdjm_get_package_event_types($post->ID); $event_label = mdjm_get_label_singular(true); ?> <div class="mdjm_field_wrap mdjm_form_fields"> <?php if (mdjm_is_employer()) { ?> <div id="package-employee-select" class="mdjm_col col2"> <p><label for="_package_employees"><?php _e('Employees with this package', 'mobile-dj-manager'); ?> </label><br /> <?php echo MDJM()->html->employee_dropdown(array('name' => '_package_employees', 'selected' => !empty($employees_with) ? $employees_with : array('all'), 'show_option_none' => false, 'show_option_all' => __('All Employees', 'mobile-dj-manager'), 'group' => true, 'chosen' => true, 'multiple' => true, 'placeholder' => __('Click to select employees', 'mobile-dj-manager'))); ?> </p> </div> <?php } else { ?> <input type="hidden" name="_package_employees" value="all" /> <?php } ?> <div id="package-event-type" class="mdjm_col col2"> <p><label for="_package_event_types"><?php printf(__('Available for %s types', 'mobile-dj-manager'), $event_label); ?> </label><br /> <?php echo MDJM()->html->event_type_dropdown(array('name' => '_package_event_types', 'selected' => !empty($event_types) ? $event_types : array('all'), 'show_option_none' => false, 'show_option_all' => sprintf(__('All %s Types', 'mobile-dj-manager'), ucfirst($event_label)), 'multiple' => true, 'chosen' => true, 'placeholder' => sprintf(__('Click to select %s types', 'mobile-dj-manager'), $event_label))); ?> </p> </div> </div> <?php }