/** * Renders a dropdown list of equipment add-ons. * * @since 1.3.7 * @param arr $args @see $default * @return str */ public function addons_dropdown($args = array()) { $defaults = array('name' => 'event_addons', 'id' => '', 'class' => '', 'selected' => '', 'show_option_none' => __('No Addons', 'mobile-dj-manager'), 'show_option_all' => false, 'chosen' => false, 'employee' => false, 'event_type' => false, 'event_date' => false, 'placeholder' => null, 'multiple' => true, 'package' => '', 'cost' => true, 'desc' => false, 'titles' => false, 'options_only' => false, 'blank_first' => false, 'data' => array()); $args = wp_parse_args($args, $defaults); $options = array(); $titles = array(); $addons = mdjm_get_addons(); if ($addons) { foreach ($addons as $addon) { if (!empty($args['package'])) { if (is_numeric($args['package'])) { $package = mdjm_get_package($args['package']); } else { $package = mdjm_get_package_by('slug', $args['package']); } if ($package) { $package_items = mdjm_get_package_addons($package->ID); } if (!empty($package_items) && in_array($addon->ID, $package_items)) { continue; } } if (!empty($args['employee'])) { if (!mdjm_employee_has_addon($addon->ID, $args['employee'])) { continue; } } if ($args['event_type']) { if (!mdjm_addon_is_available_for_event_type($addon->ID, $args['event_type'])) { continue; } } if ($args['event_date']) { if (!mdjm_addon_is_available_for_event_date($addon->ID, $args['event_date'])) { continue; } } else { $args['event_date'] = NULL; } $price = ''; if ($args['cost'] == true) { $price .= ' - ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_addon_price($addon->ID, $args['event_date']))); } $desc = ''; if ($args['desc']) { $desc .= ' - ' . mdjm_get_addon_excerpt($addon->ID, $args['desc']); } $term = ''; $terms = get_the_terms($addon->ID, 'addon-category'); if (!empty($terms)) { $term = esc_html($terms[0]->name); } $args['options']['groups'][$term][] = array($addon->ID => $addon->post_title . $price . $desc); if ($args['titles']) { $titles[$addon->ID] = mdjm_get_addon_excerpt($addon->ID); } } } if (!empty($args['options']['groups'])) { ksort($args['options']['groups']); } if (!empty($titles)) { $args['titles'] = $titles; } $output = $this->select($args); return $output; }
function get_available_addons($employee = '', $package = '', $event_id = '') { _deprecated_function(__FUNCTION__, '1.4', 'mdjm_get_available_addons()'); $addons = array(); $_addons = mdjm_get_available_addons(array('employee' => $employee, 'event_id' => $event_id, 'package' => $package)); if ($_addons) { foreach ($_addons as $addon) { $terms = get_the_terms($addon->ID, 'addon-category'); $addons[$addon->post_name]['cat'] = $terms[0]; $addons[$addon->post_name]['slug'] = $addon->post_name; $addons[$addon->post_name]['name'] = $addon->post_title; $addons[$addon->post_name]['cost'] = mdjm_get_addon_price($addon->ID); $addons[$addon->post_name]['desc'] = mdjm_get_addon_excerpt($addon->ID); } } return $addons; }
/** * Renders the HTML code for an Addons checkbox list * * @since 1.0 * @param arr $args See @defaultsSettings for the dropdown * @return HTML output for checkboxes */ function mdjm_addons_checkboxes($args = array()) { global $current_user; $defaults = array('name' => 'event_addons', 'id' => '', 'class' => '', 'current' => array(), 'employee' => is_user_logged_in() && !current_user_can('client') ? $current_user->ID : '', 'package' => '', 'event_type' => false, 'event_date' => false, 'title' => true, 'cost' => false); $args = wp_parse_args($args, $defaults); $output = ''; $options = array(); $addons = mdjm_get_addons(); if (empty($args['id'])) { $args['id'] = $args['name']; } // For backwards compatibility if (isset($args['dj'])) { $args['employee'] = $args['dj']; } if ($addons) { foreach ($addons as $addon) { if (!empty($args['package'])) { if (is_numeric($args['package'])) { $package = mdjm_get_package($args['package']); } else { $package = mdjm_get_package_by('slug', $args['package']); } if ($package) { $package_items = mdjm_get_package_addons($package->ID); } if (!empty($package_items) && in_array($addon->ID, $package_items)) { continue; } } if (!empty($args['employee'])) { if (!mdjm_employee_has_addon($addon->ID, $args['employee'])) { continue; } } if ($args['event_type']) { if (!mdjm_addon_is_available_for_event_type($addon->ID, $args['event_type'])) { continue; } } if ($args['event_date']) { if (!mdjm_addon_is_available_for_event_date($addon->ID, $args['event_date'])) { continue; } } else { $args['event_date'] = NULL; } $price = ''; if ($args['cost'] == true) { $price .= ' - ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_addon_price($addon->ID, $args['event_date']))); } $term = ''; $terms = get_the_terms($addon->ID, 'addon-category'); if (!empty($terms)) { $term = esc_html($terms[0]->name); } $options[$term][] = array($addon->ID => $addon->post_title . $price); } } if (!empty($options)) { ksort($options); $i = 0; foreach ($options as $term => $addons) { if ($i == 0) { $output .= '<strong>' . $term . '</strong><br />' . "\n"; } foreach ($addons as $items) { foreach ($items as $item_id => $item) { $output .= sprintf('<input type="checkbox" name="%1$s[]" id="%1$s-%2$d" class="%3$s" value="%2$d" %4$s />', esc_attr($args['name']), $item_id, sanitize_html_class($args['class']), checked(in_array($item_id, $args['current']), true, false)); $output .= '<label for="' . esc_attr($args['name']) . '-' . $item_id . '" title="' . mdjm_get_addon_excerpt($item_id) . '">'; $output .= esc_html($item); $output .= '</label>'; $output .= '<br />'; $i++; if ($i >= count($items)) { $i = 0; } } } } } else { $output .= __('No add-ons are available', 'mobile-dj-manager'); } return $output; }
/** * Addons List Shortcode. * * @param arr $atts Shortcode attributes. See $atts. * @param str|int $filter_value The value to which to filter $filter_by. Default false (all). * @param str $list List type to display. li for bulleted. Default p. * @param bool $cost Whether or not display the price. Default false. * * */ function mdjm_shortcode_addons_list($atts) { global $post; $atts = shortcode_atts(array('filter_by' => false, 'filter_value' => false, 'list' => 'p', 'desc' => false, 'desc_length' => mdjm_get_option('package_excerpt_length', 55), 'cost' => false, 'addon_class' => false, 'cost_class' => false, 'desc_class' => false), $atts, 'mdjm-addons'); ob_start(); $output = ''; if (!empty($post) && 'mdjm-package' == get_post_type($post->ID)) { $package_addons = mdjm_get_package_addons($post->ID); $addons = array(); foreach ($package_addons as $package) { $addons[] = mdjm_get_addon($package); } } elseif (!empty($atts['filter_by']) && !empty($atts['filter_value']) && $atts['filter_by'] != 'false' && $atts['filter_value'] != 'false') { // Filter addons by user if ($atts['filter_by'] == 'category') { $addons = mdjm_get_addons_in_category($atts['filter_value']); } elseif ($atts['filter_by'] == 'package') { if (!is_numeric($atts['filter_value'])) { // For backwards compatibility $package = mdjm_get_package_by('slug', $atts['filter_value']); if ($package) { $atts['filter_value'] = $package->ID; } } $package_addons = mdjm_get_package_addons($atts['filter_value']); $addons = array(); foreach ($package_addons as $package) { $addons[] = mdjm_get_addon($package); } } elseif ($atts['filter_by'] == 'user') { $addons = mdjm_get_addons_by_employee($atts['filter_value']); } } else { $addons = mdjm_get_addons(); } /** * Output the results */ if (!$addons) { $output .= '<p>' . __('No addons available', 'mobile-dj-manager') . '</p>'; } else { // Check to start bullet list if ($atts['list'] == 'li') { $output .= '<ul>'; } foreach ($addons as $addon) { // Output the remaining addons if (!empty($atts['list'])) { $output .= '<' . $atts['list'] . '>'; } if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') { $output = '<span class="' . $atts['addon_class'] . '">'; } $output .= $addon->post_title; if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') { $output = '</span>'; } $cost = mdjm_get_addon_price($addon->ID); if (!empty($atts['cost']) && $atts['cost'] != 'false' && !empty($cost)) { if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') { $output = '<span class="' . $atts['cost_class'] . '">'; } $output .= ' – ' . mdjm_currency_filter(mdjm_format_amount($cost)); if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') { $output = '</span>'; } } $desc = mdjm_get_addon_excerpt($addon->ID, $atts['desc_length']); if (!empty($atts['desc']) && $atts['desc'] != 'false' && !empty($desc)) { $output .= '<br />'; if (!empty($atts['desc_class']) && $atts['desc_class'] != 'false') { $output = '<span class="' . $atts['desc_class'] . '">'; } else { $output .= '<span style="font-style: italic; font-size: smaller;">'; } $output .= $desc; $output .= '</span>'; } if (!empty($atts['list'])) { $output .= '</' . $atts['list'] . '>'; } } // Check to end bullet list if ($atts['list'] == 'li') { $output .= '</ul>'; } } echo apply_filters('mdjm_shortcode_addons_list', $output); return ob_get_clean(); }