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:
<?php
namespace Apptus\ESales\Connector;
/**
* A common abstraction for the CategoryNode and CategoryData classes.
*/
abstract class Category implements \IteratorAggregate {
private $key;
private $ticket;
private $parentKey;
private $attributes = array();
private $displayName;
private $locale;
private $productCount = -1;
/**
* @internal
* @param $key
* @param $ticket
* @param $parentKey
*/
public function __construct($key, $ticket, $parentKey) {
$this->key = $key;
$this->ticket = $ticket;
$this->parentKey = $parentKey;
}
/**
* @internal
* @param string $name
* @param string $value
*/
public function addAttribute($name, $value) {
$attribute = new Attribute($name, $value);
$this->attributes[$name] = $attribute;
}
public function addSpecialAttribute($name, $value) {
switch ($name) {
case "display_name":
$this->displayName = $value;
break;
case "locale":
$this->locale = $value;
break;
case "product_count":
$this->productCount = PanelParser::parseInt($value);
break;
}
}
/**
* Get the attribute with the specified name or <b>null</b> if no such attribute exists for this category.
*
* @param name
* 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;
}
/**
* Return the key of this category.
*
* @return string the key
* The key of this category.
*/
public function key() {
return $this->key;
}
/**
* Get the value of the attribute with the specified $attributeName. The specified $defaultValue
* will be returned if no such attribute exists (defaults to null).
*
* @param string
* The name of the attribute whose value to retrieve.
* @param mixed
* The value to return if this category does not have an attribute with the specified $attributeName, defaults to null.
* @return string|mixed
* The attribute value of attribute with the specified $attributeName, or the supplied $defaultValue
* if this category has no attribute matching the name.
*/
public function getValue($attributeName, $defaultValue = null) {
$a = $this->getAttribute($attributeName);
return ($a === null) ? $defaultValue : $a->getValue();
}
public function __toString() {
return (string) $this->key;
}
/**
* Get the notification ticket of this category.
*
* @return string
*/
public function getTicket() {
return $this->ticket;
}
/**
*
* Get the display name of this category.
*
* @return string the display name
*/
public function getDisplayName() {
return $this->displayName;
}
/**
* Get the parent key of this category.
*
* @return string the parent key
*/
public function getParentKey() {
return $this->parentKey;
}
/**
* Get the locale of this category.
*
* @return string the locale
*/
public function getLocale() {
return $this->locale;
}
/**
* Get the total number of products contained in this category. Will be -1 if not supported by the requested panel.
*
* @return int the product count
*
*/
public function getProductCount() {
return $this->productCount;
}
public function getIterator() {
return new \ArrayIterator($this->attributes);
}
}