/** * Setup the table. */ public function setup_table() { if (!Dispatch::is_current_view('list')) { return; } $query = new Releases($this->generate_query_args()); $releases = $query->get_results(); $total = $query->get_total_items(); $products = itelic_get_products_with_licensing_enabled(); $this->table = new Table($this->prepare_data($releases), $total, $products); }
/** * Render the view for this controller. * * @return void */ public function render() { wp_enqueue_script('itelic-admin-licenses-new'); wp_enqueue_style('itelic-admin-licenses-new'); $view = new Add_New_View(itelic_get_products_with_licensing_enabled()); $view->begin(); $view->title(); if (!empty($this->message)) { $view->notice(reset($this->message), key($this->message)); } $view->tabs('licenses'); $view->render(); $view->end(); }
/** * Get all products with licensing enabled. * * ## Options * * [--<field>=<value>] * : Pass additional parameters to products query. * * [--fields=<fields>] * : Only return certain fields. * * [--format=<format>] * : Accepted values: table, json, csv. Default: table * * [--raw] * : Return raw values. IDs instead of human readable names. * * @param $args * @param $assoc_args * * @subcommand list */ public function list_($args, $assoc_args) { $products = itelic_get_products_with_licensing_enabled($assoc_args); $items = array(); foreach ($products as $product) { $items[] = $this->get_fields_for_object($product, \WP_CLI\Utils\get_flag_value($assoc_args, 'raw', false)); } $formatter = $this->get_formatter($assoc_args); $formatter->display_items($items); }
/** * Generate license keys. * * ## Options * * [--count=<count>] * : Number of keys to generate. Default 500. Max 750. * * [--product=<product>] * : Only generate keys for a certain product. * * [--activations] * : Generate activations for license keys. * * @param $args * @param $assoc_args */ public function generate($args, $assoc_args) { if ($product = \WP_CLI\Utils\get_flag_value($assoc_args, 'product')) { $product = itelic_get_product($product); if (!$product) { WP_CLI::error("Invalid product."); } $products = array($product->ID); } else { $products = wp_list_pluck(itelic_get_products_with_licensing_enabled(), 'ID'); } $count = \WP_CLI\Utils\get_flag_value($assoc_args, 'count', 500); $notify = \WP_CLI\Utils\make_progress_bar("Generating keys", $count); for ($i = 0; $i < $count; $i++) { $product = $this->get_product($products); $customer = $this->get_random_customer(); $min_date = max(strtotime($product->post_date), strtotime($customer->wp_user->user_registered)); $date = $this->faker->dateTimeBetween("@{$min_date}"); $key_args = array('product' => $product->ID, 'customer' => $customer->id, 'date' => $date->format('Y-m-d H:i:s'), 'status' => $this->get_status(), 'paid' => $product->get_feature('base-price')); $key = itelic_create_key($key_args); if (is_wp_error($key)) { WP_CLI::error($key); } if (\WP_CLI\Utils\get_flag_value($assoc_args, 'activations')) { $this->create_activations_for_key($key); } if ($key->get_status() == \ITELIC\Key::EXPIRED) { $key->expire($key->get_expires()); } $notify->tick(); } $notify->finish(); }
/** * Setup the table. */ public function setup_table() { if (!Dispatch::is_current_view('list')) { return; } try { $msg = $this->process_bulk_actions(); if ($msg) { $this->message[View::NOTICE_SUCCESS] = $msg; } } catch (\Exception $e) { $this->message[View::NOTICE_ERROR] = $e->getMessage(); } $query = new Keys($this->generate_get_key_args()); $keys = $query->get_results(); $total = $query->get_total_items(); $products = itelic_get_products_with_licensing_enabled(); $this->table = new Table($this->prepare_data($keys), $total, $products); if (isset($_GET['s'])) { $key = itelic_get_key($_GET['s']); if ($key) { wp_redirect(itelic_get_admin_edit_key_link($key->get_key())); die; } } }
/** * Render the product select dropdown. * * @since 1.0 * * @param int $selected */ protected function render_product_select($selected = 0) { $products = itelic_get_products_with_licensing_enabled(); ?> <label for="product"><?php _e("Select a Product", Plugin::SLUG); ?> </label> <select id="product" name="product"> <option value="">– <?php _e("Select", Plugin::SLUG); ?> –</option> <?php foreach ($products as $product) { ?> <?php $version = $product->get_feature('licensing', array('field' => 'version')); ?> <option value="<?php echo $product->ID; ?> " data-version="<?php echo esc_attr($version); ?> " <?php selected($selected, $product->ID); ?> > <?php echo $product->post_title; ?> </option> <?php } ?> </select> <?php }
/** * Generate releases. * * @param $args * @param $assoc_args */ public function generate($args, $assoc_args) { $products = itelic_get_products_with_licensing_enabled(); $notify = \WP_CLI\Utils\make_progress_bar('Generating Releases', count($products)); $now = new DateTime(); foreach ($products as $product) { $major = get_post_meta($product->ID, '_itelic_first_release', true); $major = itelic_get_release($major); $minor_releases = rand(3, 9); $last = $major; while ($last->get_start_date() < $now) { for ($i = 0; $i < $minor_releases; $i++) { // this exponentially spaces out minor releases $days = rand($i ^ 2, $i + 1 ^ 2); $start = $last->get_start_date()->add(new DateInterval("P{$days}D")); // we don't want to create any releases in the future if ($start > $now) { break 2; } $last = $this->generate_minor_release($last); $last->activate($start); } // between 3 and 7 weeks after a minor release to a major release $days_before_major = rand(3 * 7, 7 * 7); $start = $last->get_start_date()->add(new DateInterval("P{$days_before_major}D")); if ($start > $now) { break; } $last = $this->generate_major_release($last); $last->activate($start); } $notify->tick(); } $notify->finish(); }
/** * Render the view. * * @since 1.0 */ public function render() { if (!$this->report) { return; } $selected_type = isset($_GET['date_type']) ? $_GET['date_type'] : 'this_year'; $selected_product = isset($_GET['product']) ? absint($_GET['product']) : 0; $chart = $this->report->get_chart($selected_type, $selected_product); $show_button = false; ?> <form method="GET" class="filter-form"> <input type="hidden" name="page" value="<?php echo $_GET['page']; ?> "> <input type="hidden" name="tab" value="<?php echo $_GET['tab']; ?> "> <input type="hidden" name="view" value="<?php echo $_GET['view']; ?> "> <input type="hidden" name="report" value="<?php echo $_GET['report']; ?> "> <?php if ($this->report instanceof Date_Filterable) { ?> <label for="date-type" class="screen-reader-text"> <?php _e("Select a date range.", Plugin::SLUG); ?> </label> <select name="date_type" id="date-type"> <?php foreach ($this->report->get_date_types() as $type => $label) { ?> <option value="<?php echo $type; ?> " <?php selected($type, $selected_type); ?> > <?php echo $label; ?> </option> <?php } ?> </select> <?php $show_button = true; ?> <?php } ?> <?php if ($this->report instanceof Product_Filterable) { ?> <label for="product" class="screen-reader-text"> <?php _e("Select a product.", Plugin::SLUG); ?> </label> <select name="product" id="product"> <option value=""> <?php if ($this->report->is_product_required()) { ?> <?php _e("Select a Product", Plugin::SLUG); ?> <?php } else { ?> <?php _e("All Products", Plugin::SLUG); ?> <?php } ?> </option> <?php foreach (itelic_get_products_with_licensing_enabled() as $product) { ?> <option value="<?php echo $product->ID; ?> " <?php selected($product->ID, $selected_product); ?> > <?php echo $product->post_title; ?> </option> <?php } ?> </select> <?php $show_button = true; ?> <?php } ?> <?php if ($show_button) { ?> <?php submit_button(__("Filter", Plugin::SLUG), 'button', 'submit', false); ?> <?php } ?> </form> <?php if (!$chart && $this->report instanceof Product_Filterable && $this->report->is_product_required() && !$selected_product) { ?> <?php $this->notice(__("You must select a product to view this report.", Plugin::SLUG), View::NOTICE_INFO); ?> <?php return; ?> <?php } ?> <?php if (!$chart || !$chart->get_total_items()) { ?> <?php $this->notice(__("No data exists for this combination.", Plugin::SLUG), View::NOTICE_WARNING); ?> <?php return; ?> <?php } ?> <?php /** * Fires before the single report screen. * * @since 1.0 * * @param Report $report */ do_action('itelic_report_single_screen_before', $this->report); ?> <div class="report report-<?php echo $this->report->get_slug(); ?> "> <?php /** * Fires in the single report screen before the report has been rendered. * * @since 1.0 * * @param Report $report */ do_action('itelic_report_single_screen_begin', $this->report); ?> <h3><?php echo $this->report->get_title(); ?> </h3> <p class="description"> <?php echo $this->report->get_description(); ?> </p> <div class="chart"> <?php $chart->graph(); ?> </div> <div id="legend-<?php echo $this->report->get_slug(); ?> " class="chart-js-legend"></div> <?php /** * Fires in the single report screen after the report has been rendered. * * @since 1.0 * * @param Report $report */ do_action('itelic_report_single_screen_end', $this->report); ?> </div> <?php /** * Fires after the single report screen. * * @since 1.0 * * @param Report $report */ do_action('itelic_report_single_screen_after', $this->report); ?> <?php }