Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 
<?php
namespace Apptus\ESales\Connector;
use Apptus\ESales\Connector\Time\TimePoint;

/**
 * Represents a single element in a result having the ad format.
 *
 */
class Ad implements \IteratorAggregate {
    private $ticket;
    private $attributes;
    private $products;

    /**
     * @internal
     * @param string|null $ticket
     * @param array $attributes
     * @param array $products
     */
    public function __construct($ticket = null, array $attributes = array (), Products $products = null) {
        $this->ticket = $ticket;
        $this->attributes = $attributes;
        $this->products = $products;
    }

    /**
     * Get the attribute with the specified name or <b>null</b> if no such attribute exists for this ad.
     *
     * @param string
     *            The name of the attribute to get.
     * @return Attribute|null
     *            The attribute with the specified name or <b>null</b>.
     */
    public function getAttribute($name) {
        if (isset($this->attributes[$name])) {
            return $this->attributes[$name];
        }
        return null;
    }

    private static function timeOrNull($time) {
        if ($time === null) {
            return null;
        }
        try {
            return TimePoint::parse($time, new \DateTimeZone('UTC'));
        } catch (\InvalidArgumentException $iae) {
            return null;
        }
    }

    /**
     * Get the start time or <b>null</b> if no such attribute exists for this ad.
     *
     * @return TimePoint|null
     *           The start time or <b>null</b>.
     */
    public function getStartTime() {
        return self::timeOrNull($this->getValue('start_time'));
    }

    /**
     * Get the end time or <b>null</b> if no such attribute exists for this ad.
     *
     * @return TimePoint|null
     *            The end time or <b>null</b>.
     */
    public function getEndTime() {
        return self::timeOrNull($this->getValue('end_time'));
    }

    /**
     * Get the "included" attribute or <b>null</b> if no such attribute exists for this ad.
     *
     * @return Filter|null
     *            The included filter or <b>null</b>.
     */
    public function getIncluded() {
        $included = $this->getValue('included');
        if ($included === null) {
            return null;
        }
        return FilterBuilder::fromString($included);
    }

    /**
     * Get the "related" attribute or <b>null</b> if no such attribute exists for this ad.
     *
     * @return Filter|null
     *            The related filter or <b>null</b>.
     */
    public function getRelated() {
        $related = $this->getValue('related');
        if ($related === null) {
            return null;
        }
        return FilterBuilder::fromString($related);
    }

    /**
     * Get the campaign key of this ad.
     *
     * @return string
     *            The campaign key of this ad.
     */
    public function campaignKey() {
        return $this->getValue('campaign_key');
    }

    /**
     * Get the key of this ad
     *
     * @return string
     *            The key of this ad.
     */
    public function key() {
        return $this->getValue('ad_key');
    }

    /**
     * Get the value of the attribute with the specified <code>attributeName</code>. The specified <code>defaultValue</code>
     * will be returned if no such attribute exists (defaults to <b>null</b>).
     *
     * @param string
     *            The name of the attribute whose value to retrieve.
     * @param mixed
     *            The value to return if this ad doesn't have an attribute with the specified <code>attributeName</code>.
     * @return string|mixed
     *            The attribute value of attribute with the specified <code>attributeName</code>. The supplied <code>defaultValue</code> will be returned
     *            if this ad has no attribute matching the name.
     */
    public function getValue($attributeName, $defaultValue = null) {
        $a = $this->getAttribute($attributeName);
        return $a === null ? $defaultValue : $a->getValue();
    }

    public function getIterator() {
        return new \ArrayIterator($this->attributes);
    }

    /**
     * Get the notification ticket of this ad.
     *
     * @return string
     *            The ticket.
     */
    public function getTicket() {
        return $this->ticket;
    }

    /**
     * Get the products in this ad.
     *
     * @return Products
     *            The products in this ad.
     */
    public function getProducts() {
        return $this->products;
    }

    public function __toString() {
        if (isset($this->attributes['ad_key'])) {
            return (string) $this->attributes['ad_key'];
        }
        return (string) $this->attributes;
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen