Plugin Directory

Changeset 785018


Ignore:
Timestamp:
10/09/2013 03:49:08 AM (12 years ago)
Author:
WebsiteBakery
Message:

1.1 release

Location:
woot-library
Files:
7 added
10 edited

Legend:

Unmodified
Added
Removed
  • woot-library/branches/1.x/aliases.php

    r784792 r785018  
    11<?php
     2/**
     3 * Determines if tickets for the current or specified event have sold out.
     4 *
     5 * Note that an event that does not have any associated ticket products will
     6 * return false, since it is not available for sale in any case.
     7 *
     8 * @param mixed $event int|object = null
     9 * @return bool
     10 */
     11function woot_has_soldout($event = null) {
     12    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     13    return (Woot_Library::has_sold_out($event) && woot_has_tickets($event));
     14}
     15
     16/**
     17 * Checks if the current or specified events ticket stock levels are below or
     18 * equal to the threshold level (defaults to 10).
     19 *
     20 * @param int $threshold = 10
     21 * @param mixed $event int|object = null
     22 * @return bool
     23 */
     24function woot_low_stock($threshold = 10, $event = null) {
     25    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     26    $levels = Woot_Library::total_inventory_for_event($event);
     27    return ($levels <= $threshold && woot_has_tickets($event));
     28}
     29
     30/**
     31 * Determines if any tickets are associated with the current (or specified)
     32 * event ... this does not necessarily mean they are available for sale,
     33 * however, as they may have sold out or be outwith the sale dates.
     34 *
     35 * The same test can be performed, but counting only those ticket products
     36 * within sale dates, using woot_currently_has_tickets().
     37 *
     38 * @param mixed $event int|object = null
     39 * @return false
     40 */
     41function woot_has_tickets($event = null) {
     42    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     43    $tickets = woot_get_products(true, $event);
     44    return (false === $tickets) ? false : (1 <= count($tickets));
     45}
     46
     47/**
     48 * Determines if any tickets are associated with the current (or specified)
     49 * event and are within the sale dates (start/end sale) ... this does not
     50 * necessarily mean they are actually available for sale, however, as they
     51 * may have sold out.
     52 *
     53 * @param mixed $event int|object = null
     54 * @return false
     55 */
     56function woot_currently_has_tickets($event = null) {
     57    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     58    $tickets = woot_get_products(false, $event);
     59    return (false === $tickets) ? false : (1 <= count($tickets));
     60}
     61
    262/**
    363 * Returns the event associated with the current product (this can explicitly
     
    1373    if (null === $product) $product = get_the_ID();
    1474    return Woot_Library::get_event_from_product($product);
     75}
     76
     77/**
     78 * Returns ticket products associated with the current event (this can
     79 * explicitly be specified as either a post ID or object or else not be
     80 * supplied, and the current post in the loop will be assumed).
     81 *
     82 * Alias for woot_get_products().
     83 *
     84 * @param bool $onsale = true
     85 * @param mixed $event = null int|object
     86 * @return bool|array
     87 * @see woot_get_products()
     88 */
     89function woot_get_tickets($onsale = true, $event = null) {
     90    return woot_get_products($onsale, $event);
    1591}
    1692
     
    36112    else return Woot_Library::get_products_from_event($event);
    37113}
     114
  • woot-library/branches/1.x/library.php

    r784792 r785018  
    6666        self::$events[$product->id] = $event;
    6767        return $event;
     68    }
     69
     70
     71    /**
     72     * If the event has associated tickets that ought to be available for sale, but have
     73     * run out of inventory, this function returns true.
     74     *
     75     * It does not assess tickets that are not currently onsale (ie we are outwith their
     76     * selling date range). Note also that a negative result does not guarantee that there
     77     * are indeed any associated products.
     78     *
     79     * @param $event
     80     * @return bool
     81     */
     82    public static function has_sold_out($event) {
     83        $inventory = self::total_inventory_for_event($event);
     84        return (0 == $inventory);
     85    }
     86
     87
     88    /**
     89     * Returns the ticket inventory for the specified event. Note that an event with no
     90     * associated ticket products will return 0, as will an event that *does* have associated
     91     * ticket products but has simply sold out.
     92     *
     93     * @param $event
     94     * @return int
     95     */
     96    public static function total_inventory_for_event($event) {
     97        // We need to load products as products here, but can temporarily change the setting to suit
     98        $load_as_products_setting = self::$load_products_as_products;
     99        self::$load_products_as_products = true;
     100
     101        // Load the products!
     102        $products = self::get_onsale_products_from_event($event);
     103        if (false === $products) return 0;
     104
     105        // Check our inventory levels
     106        $inventory = 0;
     107        foreach ($products as $product) $inventory += $product->get_stock_quantity();
     108
     109        // Restore the load products as products setting then return inventory level
     110        self::$load_products_as_products = $load_as_products_setting;
     111        return absint($inventory);
    68112    }
    69113
  • woot-library/branches/1.x/readme.txt

    r784792 r785018  
    66Requires at least: 3.6
    77Tested up to: 3.6.1
    8 Stable tag: 1.0
     8Stable tag: 1.1
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
  • woot-library/branches/1.x/woot-library.php

    r784792 r785018  
    55 * Description: Simple helper library - to help you build customizations relating to your WooCommerce Tickets powered website.
    66 * Author: Barry Hughes
    7  * Version: 1.0
     7 * Version: 1.1
    88 * Author URI: http://codingkills.me
    99 */
  • woot-library/trunk/aliases.php

    r784792 r785018  
    11<?php
     2/**
     3 * Determines if tickets for the current or specified event have sold out.
     4 *
     5 * Note that an event that does not have any associated ticket products will
     6 * return false, since it is not available for sale in any case.
     7 *
     8 * @param mixed $event int|object = null
     9 * @return bool
     10 */
     11function woot_has_soldout($event = null) {
     12    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     13    return (Woot_Library::has_sold_out($event) && woot_has_tickets($event));
     14}
     15
     16/**
     17 * Checks if the current or specified events ticket stock levels are below or
     18 * equal to the threshold level (defaults to 10).
     19 *
     20 * @param int $threshold = 10
     21 * @param mixed $event int|object = null
     22 * @return bool
     23 */
     24function woot_low_stock($threshold = 10, $event = null) {
     25    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     26    $levels = Woot_Library::total_inventory_for_event($event);
     27    return ($levels <= $threshold && woot_has_tickets($event));
     28}
     29
     30/**
     31 * Determines if any tickets are associated with the current (or specified)
     32 * event ... this does not necessarily mean they are available for sale,
     33 * however, as they may have sold out or be outwith the sale dates.
     34 *
     35 * The same test can be performed, but counting only those ticket products
     36 * within sale dates, using woot_currently_has_tickets().
     37 *
     38 * @param mixed $event int|object = null
     39 * @return false
     40 */
     41function woot_has_tickets($event = null) {
     42    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     43    $tickets = woot_get_products(true, $event);
     44    return (false === $tickets) ? false : (1 <= count($tickets));
     45}
     46
     47/**
     48 * Determines if any tickets are associated with the current (or specified)
     49 * event and are within the sale dates (start/end sale) ... this does not
     50 * necessarily mean they are actually available for sale, however, as they
     51 * may have sold out.
     52 *
     53 * @param mixed $event int|object = null
     54 * @return false
     55 */
     56function woot_currently_has_tickets($event = null) {
     57    if (null === $event) $event = TribeEvents::instance()->postIdHelper();
     58    $tickets = woot_get_products(false, $event);
     59    return (false === $tickets) ? false : (1 <= count($tickets));
     60}
     61
    262/**
    363 * Returns the event associated with the current product (this can explicitly
     
    1373    if (null === $product) $product = get_the_ID();
    1474    return Woot_Library::get_event_from_product($product);
     75}
     76
     77/**
     78 * Returns ticket products associated with the current event (this can
     79 * explicitly be specified as either a post ID or object or else not be
     80 * supplied, and the current post in the loop will be assumed).
     81 *
     82 * Alias for woot_get_products().
     83 *
     84 * @param bool $onsale = true
     85 * @param mixed $event = null int|object
     86 * @return bool|array
     87 * @see woot_get_products()
     88 */
     89function woot_get_tickets($onsale = true, $event = null) {
     90    return woot_get_products($onsale, $event);
    1591}
    1692
     
    36112    else return Woot_Library::get_products_from_event($event);
    37113}
     114
  • woot-library/trunk/library.php

    r784792 r785018  
    6666        self::$events[$product->id] = $event;
    6767        return $event;
     68    }
     69
     70
     71    /**
     72     * If the event has associated tickets that ought to be available for sale, but have
     73     * run out of inventory, this function returns true.
     74     *
     75     * It does not assess tickets that are not currently onsale (ie we are outwith their
     76     * selling date range). Note also that a negative result does not guarantee that there
     77     * are indeed any associated products.
     78     *
     79     * @param $event
     80     * @return bool
     81     */
     82    public static function has_sold_out($event) {
     83        $inventory = self::total_inventory_for_event($event);
     84        return (0 == $inventory);
     85    }
     86
     87
     88    /**
     89     * Returns the ticket inventory for the specified event. Note that an event with no
     90     * associated ticket products will return 0, as will an event that *does* have associated
     91     * ticket products but has simply sold out.
     92     *
     93     * @param $event
     94     * @return int
     95     */
     96    public static function total_inventory_for_event($event) {
     97        // We need to load products as products here, but can temporarily change the setting to suit
     98        $load_as_products_setting = self::$load_products_as_products;
     99        self::$load_products_as_products = true;
     100
     101        // Load the products!
     102        $products = self::get_onsale_products_from_event($event);
     103        if (false === $products) return 0;
     104
     105        // Check our inventory levels
     106        $inventory = 0;
     107        foreach ($products as $product) $inventory += $product->get_stock_quantity();
     108
     109        // Restore the load products as products setting then return inventory level
     110        self::$load_products_as_products = $load_as_products_setting;
     111        return absint($inventory);
    68112    }
    69113
  • woot-library/trunk/readme.txt

    r784792 r785018  
    66Requires at least: 3.6
    77Tested up to: 3.6.1
    8 Stable tag: 1.0
     8Stable tag: 1.1
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
  • woot-library/trunk/woot-library.php

    r784792 r785018  
    55 * Description: Simple helper library - to help you build customizations relating to your WooCommerce Tickets powered website.
    66 * Author: Barry Hughes
    7  * Version: 1.0
     7 * Version: 1.1
    88 * Author URI: http://codingkills.me
    99 */
Note: See TracChangeset for help on using the changeset viewer.