/** * Retrieve a single package by ID, name, or slug. * * @since 1.4 * @return void */ public function get_package() { $response = array(); if (!isset($this->request['package'])) { $this->missing_params('package'); } do_action('mdjm_before_api_get_package', $this); if (!is_numeric($this->request['package'])) { // Using name or slug $package = mdjm_get_package_by('name', $this->request['package']); } else { $package = mdjm_get_package($this->request['package']); } if (!$package) { $error = array(); $error['error'] = __('Package does not exist.', 'mobile-dj-manager'); $this->data = $error; $this->output(); } $response['package'] = mdjm_get_package_data($package); $response['package'] = array_merge(array('id' => $package->ID), $response['package']); $this->data = array_merge($this->data, $response); do_action('mdjm_after_api_get_package', $this); $this->output(); }
/** * 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; }
/** * 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; }