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: 
<?php
namespace Apptus\ESales\Connector\Report;

use Apptus\ESales\Connector\Time\IsoDateTime;

/**
 * A class that contains attribute information for an ad.
 */
class Ad {

    private $key;
    private $attributeMap = array ();

    /**
     * @internal
     * @param string
     * @throws \InvalidArgumentException
     */
    public function __construct($key) {
        $key = (string) $key;
        if (strlen(trim($key)) === 0) {
            throw new \InvalidArgumentException('Illegal value for argument key.');
        }

        $this->key = $key;
    }

    /**
     * Adds an attribute to the ad.
     *
     * @internal
     * @param string
     *            The name of the attribute.
     * @param string
     *            The value for the attribute.
     * @throws \InvalidArgumentException
     */
    public function addAttribute($name, $value) {
        if ($value === null) {
            throw new \InvalidArgumentException('Attribute value can not be null.');
        }
        $this->attributeMap[$name] = new Attribute((string) $name, (string) $value);
    }

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

    /**
     * @return IsoDateTime|null
     *            The start time for the ad or null if a start time has not been set for the ad.
     */
    public function startTime() {
        if (isset($this->attributeMap['start_time'])) {
            return IsoDateTime::parse($this->attributeMap['start_time']->value());
        }
        return null;
    }

    /**
     * @return IsoDateTime|null
     *            The end time for the ad or null if an end time has not been set for the ad.
     */
    public function endTime() {
        if (isset($this->attributeMap['end_time'])) {
            return IsoDateTime::parse($this->attributeMap['end_time']->value());
        }
        return null;
    }

    /**
     * @return Attribute[]
     *            An indexed array of {@see Attribute} objects for this ad. Sorted alphabetically by name.
     */
    public function attributes() {
        asort($this->attributeMap);
        return array_values($this->attributeMap);
    }

    /**
     * @param string
     *            The name for the attribute to get.
     * @return Attribute
     *            The attribute with the specified name, or null if there is no attribute with that name.
     */
    public function attribute($name) {
        if (isset($this->attributeMap[$name])) {
            return $this->attributeMap[$name];
        }
        return null;
    }

    public function __toString() {
        $s = 'Ad{key=\'' . $this->key . '\', attributes=[';
        $separator = '';
        foreach ($this->attributes() as $entry) {
            $s .= $separator . (string) $entry;
            $separator = ', ';
        }
        $s .= ']}';
        return $s;
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen