Example #1
0
/**
 * Returns meta data assigned to an object.
 *
 * @api
 * @since 1.2
 *
 * @param int $id (optional) of the meta entry, or object id of the object the Shopp meta is attached to
 * @param string $context (optional) the object type that the object id refers to.
 * @param string $name (optional) the name of the meta data
 * @param string $type (optional default: meta) the data type of meta data (examples meta, spec, download, image, yourdatatype )
 * @return array of stdClass Object meta values, with parent, type, name, and value properties
 *
 * Usage Examples:
 * shopp_meta(<id>) - meta record by id
 * shopp_meta([id], [context], [name], [type]) - pick one or more, id is the id of the parent contextual object if context is specified
 *
 * shopp_meta(1) loads meta record 1
 * shopp_meta(5,'product','Producer','spec') loads spec named Producer of product id 5
 * shopp_meta(false, 'product','mydownload.zip','downloads') load the meta record for mydownload.zip product download
 * shopp_meta(5, 'product', false, 'downloads') load all product download meta records for product id 5
 * shopp_meta(false, 'price') loads all meta data associated with variants
 *
 **/
function shopp_meta($id = false, $context = false, $name = false, $type = 'meta')
{
    $values = array();
    if (!($id || $context || $name)) {
        shopp_debug(__FUNCTION__ . ' failed: No parameters specified.');
        return;
    }
    // Load meta by id
    if ($id && false === $context) {
        $meta = new ShoppMetaObject();
        $meta->load($id);
        if (empty($meta->id)) {
            shopp_debug(__FUNCTION__ . " failed: No such meta with id {$id} or missing context.");
        }
        return $meta->value;
    }
    // Load one or more meta
    $loading = array();
    if ($id && $context) {
        $loading['parent'] = $id;
    }
    // if context is specified, id will always be parent object
    if ($context) {
        $loading['context'] = $context;
    }
    if ($type) {
        $loading['type'] = $type;
    }
    if ($name) {
        $loading['name'] = $name;
    }
    $Meta = new ObjectMeta();
    $Meta->load($loading);
    if (empty($Meta->meta)) {
        return array();
    }
    foreach ($Meta->meta as $meta) {
        if (!isset($values[$meta->id])) {
            $values[$meta->id] = new stdClass();
        }
        $values[$meta->id]->parent = $meta->parent;
        $values[$meta->id]->type = $meta->type;
        $values[$meta->id]->name = $meta->name;
        if (empty($meta->value) && $meta->numeral > 0) {
            $meta->value = $meta->numeral;
        }
        $values[$meta->id]->value = $meta->value;
    }
    if ($id && $context && $type && $name and 1 == count($values)) {
        return reset($values)->value;
    }
    return $values;
}
Example #2
0
 public function get_tickets_references($event_id)
 {
     if (is_object($event_id)) {
         $event_id = $event_id->ID;
     }
     $meta_query = new ObjectMeta();
     $meta_query->load(array('context' => 'product', 'type' => 'meta', 'name' => $this->event_key, 'value' => $event_id));
     return (array) $meta_query->meta;
 }