84 if (strpos($className,
'\\') === FALSE) {
85 $expectedClassname =
'COUNTER\\'.$className;
86 } elseif (strpos($className,
'\\') === 0) {
87 $expectedClassname = substr($className, 1);
89 $expectedClassname = $className;
91 if (is_null($object)) {
92 throw new \Exception(
'Invalid object. Expected "'.$expectedClassname.
'", got "NULL"');
93 } elseif (is_array($object)) {
96 throw new \Exception(
'Invalid class. Expected "'.$expectedClassname.
'", got unparsable array');
98 } elseif (is_string($object)) {
101 $date = date_create($object);
108 throw new \Exception(
'Invalid class. Expected "'.$expectedClassname.
'", got unparsable string');
109 } elseif ($expectedClassname == get_class($object) || is_subclass_of($object, $expectedClassname)) {
112 throw new \Exception(
'Invalid class. Expected "'.$expectedClassname.
'", got "'.get_class($object).
'"');
124 if (is_array($objects)) {
125 foreach ($objects as $object) {
142 if (empty($objects)) {
157 if (empty($object)) {
171 $intval = intval($int);
172 if (!is_int($intval) || $intval < 0) {
173 throw new \Exception(
'Invalid positive integer: '.gettype($int).
' value '.$int);
185 if (!is_string($string)) {
186 throw new \Exception(
'Invalid string: '.gettype($string));
198 if (is_array($array)) {
199 foreach ($array as $string) {
203 } elseif (is_string($array)) {
204 return array($array);
205 } elseif (!empty($array)) {
206 throw new \Exception(
'Invalid string array: '.gettype($array));
216 return count(array_filter(array_keys($array),
'is_string')) > 0;
227 if (!is_array($array)) {
229 }
else if (self::isAssociative($array)) {
230 return $classname::build($array);
233 foreach ($array as $element) {
234 $elements[] = $classname::build($element);
246 return array(
'Journal',
'Database',
'Platform',
'Book',
'Collection',
'Multimedia',
'Article');
254 return array(
'Online_ISSN',
'Print_ISSN',
'Online_ISBN',
'Print_ISBN',
'DOI',
'Proprietary');
262 return array(
'ORCID',
'ISNI',
'Proprietary');
271 return array(
'PubDate',
'FirstAccessedOnline',
'Proprietary');
280 return array(
'ArticleVersion',
'ArticleType',
'QualificationName',
'QualificationLevel');
288 return array(
'abstract',
'audio',
'data_set',
'ft_epub',
'ft_html',
'ft_html_mobile',
'ft_pdf',
'ft_pdf_mobile',
'ft_ps',
'ft_ps_mobile',
'ft_total',
'image',
'multimedia',
'no_license',
'other',
'podcast',
'record_view',
'reference',
'result_click',
'search_fed',
'search_reg',
'sectioned_html',
'toc',
'turnaway',
'video');
296 return array(
'Requests',
'Searches',
'Access_denied');
306 $doc->formatOutput = TRUE;
307 return $doc->saveXML();
316 throw new Exception(get_class($this).
' does not implement asDOMDocument()');
325 public static function build($array) {
326 throw new \Exception(
'Failed to build '.get_called_class().
' from data '.var_export($array,
true));
339 private $report = array();
357 public static function build($array) {
358 if (is_array($array)) {
359 if (isset($array[
'Report'])) {
361 $reports = parent::buildMultiple(
'COUNTER\Report', $array[
'Report']);
362 return new self($reports);
363 } elseif (!parent::isAssociative($array)) {
365 $reports = parent::buildMultiple(
'COUNTER\Report', $array);
366 return new self($reports);
369 parent::build($array);
387 return $this->report;
395 $doc = new \DOMDocument();
396 $root = $doc->appendChild($doc->createElementNS(self::COUNTER_NAMESPACE,
'Reports'));
397 $xmlns = $doc->createAttributeNS(
'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation');
398 $xmlns->value = self::COUNTER_NAMESPACE.
' http://www.niso.org/schemas/sushi/counter4_1.xsd';
399 $root->appendChild($xmlns);
400 foreach ($this->report as $rep) {
401 $root->appendChild($doc->importNode($rep->asDOMDocument()->documentElement,
true));
410 class Report
extends ReportBuilder {
459 public function __construct($id, $version, $name, $title, $customers, $vendor, $created =
'') {
460 foreach (array(
'id',
'version',
'name',
'title',
'created') as $arg) {
464 $this->created = date(
"Y-m-d\Th:i:sP");
476 public static function build($array) {
477 if (is_array($array)) {
478 if (isset($array[
'ID']) && isset($array[
'Version']) && isset($array[
'Name']) && isset($array[
'Title']) && isset($array[
'Customer']) && isset($array[
'Vendor'])) {
480 $customers = parent::buildMultiple(
'COUNTER\Customer', $array[
'Customer']);
488 isset($array[
'Created']) ? $array[
'Created'] :
''
492 parent::build($array);
500 $doc = new \DOMDocument();
501 $root = $doc->appendChild($doc->createElement(
'Report'));
502 foreach (array(
'Created',
'ID',
'Version',
'Name',
'Title') as $arg) {
503 $lcarg = strtolower($arg);
504 $attrAttr = $doc->createAttribute($arg);
505 $attrAttr->appendChild($doc->createTextNode($this->$lcarg));
506 $root->appendChild($attrAttr);
508 $root->appendChild($doc->importNode($this->vendor->asDOMDocument()->documentElement,
true));
509 foreach ($this->customer as $customer) {
510 $root->appendChild($doc->importNode($customer->asDOMDocument()->documentElement,
true));
519 class Vendor
extends ReportBuilder {
534 private $contact = array();
556 public function __construct($id, $name =
'', $contacts = array(), $webSiteUrl =
'', $logoUrl =
'') {
557 foreach (array(
'id',
'name',
'webSiteUrl',
'logoUrl') as $arg) {
569 public static function build($array) {
570 if (is_array($array)) {
571 if (isset($array[
'ID'])) {
573 $contacts = parent::buildMultiple(
'COUNTER\Contact', isset($array[
'Contact']) ? $array[
'Contact'] : array());
576 isset($array[
'Name']) ? $array[
'Name'] :
'',
578 isset($array[
'WebSiteUrl']) ? $array[
'WebSiteUrl'] :
'',
579 isset($array[
'LogoUrl']) ? $array[
'LogoUrl'] :
''
583 parent::build($array);
591 $doc = new \DOMDocument();
592 $root = $doc->appendChild($doc->createElement(
'Vendor'));
594 $root->appendChild($doc->createElement(
'Name'))->appendChild($doc->createTextNode($this->name));
596 $root->appendChild($doc->createElement(
'ID'))->appendChild($doc->createTextNode($this->id));
597 if ($this->contact) {
598 foreach ($this->contact as $contact) {
599 $root->appendChild($doc->importNode($contact->asDOMDocument()->documentElement,
true));
602 if ($this->webSiteUrl) {
603 $root->appendChild($doc->createElement(
'WebSiteUrl'))->appendChild($doc->createTextNode($this->webSiteUrl));
605 if ($this->logoUrl) {
606 $root->appendChild($doc->createElement(
'LogoUrl'))->appendChild($doc->createTextNode($this->logoUrl));
615 class Contact
extends ReportBuilder {
634 public function __construct($contact =
'', $email =
'') {
635 foreach (array(
'contact',
'email') as $arg) {
646 public static function build($array) {
647 if (is_array($array)) {
648 if (isset($array[
'E-mail'])) {
649 $array[
'Email'] = $array[
'E-mail'];
650 unset($array[
'E-mail']);
652 if (isset($array[
'Contact']) || isset($array[
'Email'])) {
653 return new self($array[
'Contact'] ? $array[
'Contact'] :
'', $array[
'Email'] ? $array[
'Email'] :
'');
654 } elseif (count(array_keys($array)) == 1 && parent::isAssociative($array)) {
656 foreach ($array as $k => $v) {
657 if (filter_var($k, FILTER_VALIDATE_EMAIL)) {
659 return new self($v, $k);
662 return new self($k, $v);
665 } elseif (
count(array_keys($array)) == 1 && !parent::isAssociative($array)) {
667 if (filter_var($k, FILTER_VALIDATE_EMAIL)) {
669 return new self(
'', $array[0]);
672 return new self($array[0]);
675 } elseif (is_string($array)) {
677 if (filter_var($array, FILTER_VALIDATE_EMAIL)) {
679 return new self(
'', $array);
682 return new self($array);
685 parent::build($array);
693 $doc = new \DOMDocument();
694 $root = $doc->appendChild($doc->createElement(
'Contact'));
695 if ($this->contact) {
696 $root->appendChild($doc->createElement(
'Contact'))->appendChild($doc->createTextNode($this->contact));
699 $root->appendChild($doc->createElement(
'E-mail'))->appendChild($doc->createTextNode($this->email));
708 class Customer
extends ReportBuilder {
743 private $institutionalIdentifier;
748 private $reportItems;
763 public function __construct($id, $reportItems, $name =
'', $contacts = array(), $webSiteUrl =
'' , $logoUrl =
'', $consortium = NULL, $institutionalIdentifier = array()) {
764 foreach (array(
'id',
'name',
'webSiteUrl',
'logoUrl') as $arg) {
770 $this->institutionalIdentifier = $this->
validateZeroOrMoreOf($institutionalIdentifier,
'Identifier');
779 public static function build($array) {
780 if (is_array($array)) {
781 if (isset($array[
'ID']) && isset($array[
'ReportItems'])) {
783 $items = parent::buildMultiple(
'COUNTER\ReportItems', $array[
'ReportItems']);
784 $ids = parent::buildMultiple(
'COUNTER\Identifier', isset($array[
'InstitutionalIdentifier']) ? $array[
'InstitutionalIdentifier'] : array());
785 $contacts = parent::buildMultiple(
'COUNTER\Contact', isset($array[
'Contact']) ? $array[
'Contact'] : array());
789 isset($array[
'Name']) ? $array[
'Name'] :
'',
791 isset($array[
'WebSiteUrl']) ? $array[
'WebSiteUrl'] :
'',
792 isset($array[
'LogoUrl']) ? $array[
'LogoUrl'] :
'',
798 parent::build($array);
806 $doc = new \DOMDocument();
807 $root = $doc->appendChild($doc->createElement(
'Customer'));
809 $root->appendChild($doc->createElement(
'Name'))->appendChild($doc->createTextNode($this->name));
811 $root->appendChild($doc->createElement(
'ID'))->appendChild($doc->createTextNode($this->id));
812 if ($this->contact) {
813 foreach ($this->contact as $contact) {
814 $root->appendChild($doc->importNode($contact->asDOMDocument()->documentElement,
true));
817 if ($this->webSiteUrl) {
818 $root->appendChild($doc->createElement(
'WebSiteUrl'))->appendChild($doc->createTextNode($this->webSiteUrl));
820 if ($this->logoUrl) {
821 $root->appendChild($doc->createElement(
'LogoUrl'))->appendChild($doc->createTextNode($this->logoUrl));
823 if ($this->consortium) {
824 $root->appendChild($doc->importNode($this->consortium->asDOMDocument()->documentElement,
true));
826 if ($this->institutionalIdentifier) {
827 foreach ($this->institutionalIdentifier as $id) {
828 $root->appendChild($doc->importNode($id->asDOMDocument()->documentElement,
true));
831 foreach ($this->reportItems as $rep) {
832 $root->appendChild($doc->importNode($rep->asDOMDocument()->documentElement,
true));
841 class Consortium
extends ReportBuilder {
851 private $wellKnownName;
858 public function __construct($wellKnownName, $code =
'') {
859 foreach (array(
'wellKnownName',
'code') as $arg) {
870 public static function build($array) {
871 if (is_array($array)) {
872 if (isset($array[
'WellKnownName'])) {
874 return new self($array[
'WellKnownName'], $array[
'Code'] ? $array[
'Code'] :
'');
875 } elseif (count(array_keys($array)) == 1 && parent::isAssociative($array)) {
877 foreach ($array as $k => $v) {
878 return new self($k, $v);
880 } elseif (
count(array_keys($array)) == 1 && !parent::isAssociative($array)) {
882 return new self($array[0]);
884 } elseif (is_string($array)) {
886 return new self($array);
888 parent::build($array);
896 $doc = new \DOMDocument();
897 $root = $doc->appendChild($doc->createElement(
'Consortium'));
899 $root->appendChild($doc->createElement(
'Code'))->appendChild($doc->createTextNode($this->code));
901 $root->appendChild($doc->createElement(
'WellKnownName'))->appendChild($doc->createTextNode($this->wellKnownName));
909 class ReportItems
extends ReportBuilder {
919 private $itemIdentifier;
924 private $itemContributor;
934 private $itemAttribute;
939 private $itemPlatform;
944 private $itemPublisher;
954 private $itemDataType;
959 private $itemPerformance;
976 public function __construct($itemPlatform, $itemName, $itemDataType, $itemPerformance, $parentItem = NULL, $itemIdentifiers = array(), $itemContributors = array(), $itemDates = array(), $itemAttributes = array(), $itemPublisher =
'') {
977 foreach (array(
'itemPlatform',
'itemPublisher',
'itemName',
'itemDataType') as $arg) {
981 throw new \Exception(
'Invalid item data type: '.$itemDataType);
997 public static function build($array) {
998 if (is_array($array)) {
999 if (isset($array[
'ItemPlatform']) && isset($array[
'ItemName']) && isset($array[
'ItemDataType']) && isset($array[
'ItemPerformance'])) {
1001 $performance = parent::buildMultiple(
'COUNTER\Metric', $array[
'ItemPerformance']);
1002 $ids = parent::buildMultiple(
'COUNTER\Identifier', isset($array[
'ItemIdentifier']) ? $array[
'ItemIdentifier'] : array());
1003 $contributors = parent::buildMultiple(
'COUNTER\ItemContributor', isset($array[
'ItemContributor']) ? $array[
'ItemContributor'] : array());
1004 $dates = parent::buildMultiple(
'COUNTER\ItemDate', isset($array[
'ItemDate']) ? $array[
'ItemDate'] : array());
1005 $attributes = parent::buildMultiple(
'COUNTER\ItemAttribute', isset($array[
'ItemAttribute']) ? $array[
'ItemAttribute'] : array());
1007 $array[
'ItemPlatform'],
1009 $array[
'ItemDataType'],
1016 isset($array[
'ItemPublisher']) ? $array[
'ItemPublisher'] :
''
1020 parent::build($array);
1028 $doc = new \DOMDocument();
1029 $root = $doc->appendChild($doc->createElement(
'ReportItems'));
1030 if ($this->parentItem) {
1031 $root->appendChild($doc->importNode($this->parentItem->asDOMDocument()->documentElement,
true));
1033 if ($this->itemIdentifier) {
1034 foreach ($this->itemIdentifier as $id) {
1035 $root->appendChild($doc->importNode($id->asDOMDocument()->documentElement,
true));
1038 if ($this->itemContributor) {
1039 foreach ($this->itemContributor as $contrib) {
1040 $root->appendChild($doc->importNode($contrib->asDOMDocument()->documentElement,
true));
1043 if ($this->itemDate) {
1044 foreach ($this->itemDate as $date) {
1045 $root->appendChild($doc->importNode($date->asDOMDocument()->documentElement,
true));
1048 if ($this->itemAttribute) {
1049 foreach ($this->itemAttribute as $attrib) {
1050 $root->appendChild($doc->importNode($attrib->asDOMDocument()->documentElement,
true));
1053 $root->appendChild($doc->createElement(
'ItemPlatform'))->appendChild($doc->createTextNode($this->itemPlatform));
1054 if ($this->itemPublisher) {
1055 $root->appendChild($doc->createElement(
'ItemPublisher'))->appendChild($doc->createTextNode($this->itemPublisher));
1057 $root->appendChild($doc->createElement(
'ItemName'))->appendChild($doc->createTextNode($this->itemName));
1058 $root->appendChild($doc->createElement(
'ItemDataType'))->appendChild($doc->createTextNode($this->itemDataType));
1059 foreach ($this->itemPerformance as $perf) {
1060 $root->appendChild($doc->importNode($perf->asDOMDocument()->documentElement,
true));
1069 class ParentItem
extends ReportBuilder {
1074 private $itemIdentifier;
1079 private $itemContributor;
1089 private $itemAttribute;
1094 private $itemPublisher;
1104 private $itemDataType;
1118 public function __construct($itemName, $itemDataType, $itemIdentifiers = array(), $itemContributors = array(), $itemDates = array(), $itemAttributes = array(), $itemPublisher =
'') {
1119 foreach (array(
'itemName',
'itemDataType',
'itemPublisher') as $arg) {
1123 throw new \Exception(
'Invalid type: '.$type);
1137 public static function build($array) {
1138 if (is_array($array)) {
1139 if (isset($array[
'ItemName']) && isset($array[
'ItemDataType'])) {
1141 $ids = parent::buildMultiple(
'COUNTER\Identifier', isset($array[
'ItemIdentifier']) ? $array[
'ItemIdentifier']: array());
1142 $contributors = parent::buildMultiple(
'COUNTER\ItemContributor', isset($array[
'ItemContributor']) ? $array[
'ItemContributor'] : array());
1143 $dates = parent::buildMultiple(
'COUNTER\ItemDate', isset($array[
'ItemDate']) ? $array[
'ItemDate'] : array());
1144 $attributes = parent::buildMultiple(
'COUNTER\ItemAttribute', isset($array[
'ItemAttribute']) ? $array[
'ItemAttribute'] : array());
1147 $array[
'ItemDataType'],
1152 isset($array[
'ItemPublisher']) ? $array[
'ItemPublisher'] :
''
1156 parent::build($array);
1164 $doc = new \DOMDocument();
1165 $root = $doc->appendChild($doc->createElement(
'ParentItem'));
1166 if ($this->itemIdentifier) {
1167 foreach ($this->itemIdentifier as $id) {
1168 $root->appendChild($doc->importNode($id->asDOMDocument()->documentElement,
true));
1171 if ($this->itemContributor) {
1172 foreach ($this->itemContributor as $contrib) {
1173 $root->appendChild($doc->importNode($contrib->asDOMDocument()->documentElement,
true));
1176 if ($this->itemDate) {
1177 foreach ($this->itemDate as $date) {
1178 $root->appendChild($doc->importNode($date->asDOMDocument()->documentElement,
true));
1181 if ($this->itemAttribute) {
1182 foreach ($this->itemAttribute as $attrib) {
1183 $root->appendChild($doc->importNode($attrib->asDOMDocument()->documentElement,
true));
1186 if ($this->itemPublisher) {
1187 $root->appendChild($doc->createElement(
'ItemPublisher'))->appendChild($doc->createTextNode($this->itemPublisher));
1189 $root->appendChild($doc->createElement(
'ItemName'))->appendChild($doc->createTextNode($this->itemName));
1190 $root->appendChild($doc->createElement(
'ItemDataType'))->appendChild($doc->createTextNode($this->itemDataType));
1198 class ItemContributor
extends ReportBuilder {
1203 private $itemContributorId;
1208 private $itemContributorName;
1213 private $itemContributorAffiliation;
1218 private $itemContributorRole;
1229 public function __construct($itemContributorIds = array(), $itemContributorName =
'', $itemContributorAffiliations = array(), $itemContributorRoles = array()) {
1230 $this->itemContributorId = $this->
validateZeroOrMoreOf($itemContributorIds,
'ItemContributorId');
1231 $this->itemContributorName = $this->
validateString($itemContributorName);
1232 $this->itemContributorAffiliation = $this->
validateStrings($itemContributorAffiliations);
1233 $this->itemContributorRole = $this->
validateStrings($itemContributorRoles);
1242 public static function build($array) {
1243 if (is_array($array)) {
1244 if (isset($array[
'ItemContributorID']) || isset($array[
'ItemContributorName']) || isset($array[
'ItemContributorAffiliation']) || isset($array[
'ItemContributorRole'])) {
1246 $ids = parent::buildMultiple(
'COUNTER\ItemContributorId', isset($array[
'ItemContributorID']) ? $array[
'ItemContributorID'] : array());
1249 isset($array[
'ItemContributorName']) ? $array[
'ItemContributorName'] :
'',
1250 isset($array[
'ItemContributorAffiliation']) ? $array[
'ItemContributorAffiliation'] :
'',
1251 isset($array[
'ItemContributorRole']) ? $array[
'ItemContributorRole'] :
''
1255 parent::build($array);
1263 $doc = new \DOMDocument();
1264 $root = $doc->appendChild($doc->createElement(
'ItemContributor'));
1265 if ($this->itemContributorId) {
1266 foreach ($this->itemContributorId as $id) {
1267 $root->appendChild($doc->importNode($id->asDOMDocument()->documentElement,
true));
1270 if ($this->itemContributorName) {
1271 $root->appendChild($doc->createElement(
'ItemContributorName'))->appendChild($doc->createTextNode($this->itemContributorName));
1273 if ($this->itemContributorAffiliation) {
1274 foreach ($this->itemContributorAffiliation as $affiliation) {
1275 $root->appendChild($doc->createElement(
'ItemContributorAffiliation', $affiliation));
1278 if ($this->itemContributorRole) {
1279 foreach ($this->itemContributorRole as $role) {
1280 $root->appendChild($doc->createElement(
'ItemContributorRole', $role));
1290 class ItemContributorId
extends ReportBuilder {
1310 foreach (array(
'type',
'value') as $arg) {
1314 throw new \Exception(
'Invalid type: '.$type);
1325 if (is_array($array)) {
1326 if (isset($array[
'Type']) && isset($array[
'Value'])) {
1328 return new self($array[
'Type'], $array[
'Value']);
1329 } elseif (count(array_keys($array)) == 1 && parent::isAssociative($array)) {
1331 foreach ($array as $k => $v) {
1332 return new self($k, $v);
1336 parent::build($array);
1344 $doc = new \DOMDocument();
1345 $root = $doc->appendChild($doc->createElement(
'ItemContributorID'));
1346 $root->appendChild($doc->createElement(
'Type'))->appendChild($doc->createTextNode($this->type));
1347 $root->appendChild($doc->createElement(
'Value'))->appendChild($doc->createTextNode($this->value));
1355 class Identifier
extends ReportBuilder {
1375 foreach (array(
'type',
'value') as $arg) {
1379 throw new \Exception(
'Invalid type: '.$type);
1389 public static function build($array) {
1390 if (is_array($array)) {
1391 if (isset($array[
'Type']) && isset($array[
'Value'])) {
1393 return new self($array[
'Type'], $array[
'Value']);
1394 } elseif (
count(array_keys($array)) == 1 && parent::isAssociative($array)) {
1396 foreach ($array as $k => $v) {
1397 return new self($k, $v);
1401 parent::build($array);
1409 $doc = new \DOMDocument();
1410 $root = $doc->appendChild($doc->createElement(
'ItemIdentifier'));
1411 $root->appendChild($doc->createElement(
'Type'))->appendChild($doc->createTextNode($this->type));
1412 $root->appendChild($doc->createElement(
'Value'))->appendChild($doc->createTextNode($this->value));
1420 class ItemDate
extends ReportBuilder{
1442 throw new \Exception(
'Invalid type: '.$type);
1454 if (is_array($array)) {
1455 if (isset($array[
'Type']) && isset($array[
'Value'])) {
1457 return new self($array[
'Type'], $array[
'Value']);
1458 } elseif (count(array_keys($array)) == 1 && parent::isAssociative($array)) {
1460 foreach ($array as $k => $v) {
1461 return new self($k, $v);
1465 parent::build($array);
1473 $doc = new \DOMDocument();
1474 $root = $doc->appendChild($doc->createElement(
'ItemDate'));
1475 $root->appendChild($doc->createElement(
'Type'))->appendChild($doc->createTextNode($this->type));
1476 $root->appendChild($doc->createElement(
'Value'))->appendChild($doc->createTextNode(date_format($this->value,
'Y-m-d')));
1484 class ItemAttribute
extends ReportBuilder {
1504 foreach (array(
'type',
'value') as $arg) {
1508 throw new \Exception(
'Invalid type: '.$type);
1518 public static function build($array) {
1519 if (is_array($array)) {
1520 if (isset($array[
'Type']) && isset($array[
'Value'])) {
1522 return new self($array[
'Type'], $array[
'Value']);
1523 } elseif (count(array_keys($array)) == 1 && parent::isAssociative($array)) {
1525 foreach ($array as $k => $v) {
1526 return new self($k, $v);
1530 parent::build($array);
1538 $doc = new \DOMDocument();
1539 $root = $doc->appendChild($doc->createElement(
'ItemAttribute'));
1540 $root->appendChild($doc->createElement(
'Type'))->appendChild($doc->createTextNode($this->type));
1541 $root->appendChild($doc->createElement(
'Value'))->appendChild($doc->createTextNode($this->value));
1549 class Metric
extends ReportBuilder {
1592 public function __construct($period, $category, $instances, $pubYrFrom = NULL, $pubYrTo = NULL, $pubYr = NULL) {
1596 throw new \Exception(
'Invalid category: '.$category);
1616 public static function build($array) {
1617 if (is_array($array)) {
1618 if (isset($array[
'Period']) && isset($array[
'Instance']) && isset($array[
'Category'])) {
1620 $instances = parent::buildMultiple(
'COUNTER\PerformanceCounter', $array[
'Instance']);
1625 isset($array[
'PubYrFrom']) ? $array[
'PubYrFrom']: NULL,
1626 isset($array[
'PubYrTo']) ? $array[
'PubYrTo'] : NULL,
1627 isset($array[
'PubYr']) ? $array[
'PubYr'] : NULL
1631 parent::build($array);
1639 $doc = new \DOMDocument();
1640 $root = $doc->appendChild($doc->createElement(
'ItemPerformance'));
1641 if ($this->period) {
1642 $root->appendChild($doc->importNode($this->period->asDOMDocument()->documentElement,
true));
1644 if ($this->category) {
1645 $root->appendChild($doc->createElement(
'Category'))->appendChild($doc->createTextNode($this->category));
1647 foreach ($this->instance as $instance) {
1648 $root->appendChild($doc->importNode($instance->asDOMDocument()->documentElement,
true));
1650 foreach (array(
'pubYr',
'pubYrFrom',
'pubYrTo') as $pubYrKey) {
1651 if ($this->$pubYrKey) {
1652 $root->appendChild($doc->createElement(ucfirst($pubYrKey)))->appendChild($doc->createTextNode($this->$pubYrKey));
1653 $attr = $doc->createAttribute(ucfirst($pubYrKey));
1654 $attr->value = $this->$pubYrKey;
1655 $root->appendChild($attr);
1666 class DateRange
extends ReportBuilder {
1696 public static function build($array) {
1697 if (is_array($array)) {
1698 if (isset($array[
'Begin']) && isset($array[
'End'])) {
1700 return new self($array[
'Begin'], $array[
'End']);
1701 } elseif (count(array_keys($array)) == 2 && !parent::isAssociative($array)) {
1703 return new self($array[0], $array[1]);
1706 parent::build($array);
1714 $doc = new \DOMDocument();
1715 $root = $doc->appendChild($doc->createElement(
'Period'));
1716 $root->appendChild($doc->createElement(
'Begin'))->appendChild($doc->createTextNode(date_format($this->begin,
'Y-m-d')));
1717 $root->appendChild($doc->createElement(
'End'))->appendChild($doc->createTextNode(date_format($this->end,
'Y-m-d')));
1725 class PerformanceCounter
extends ReportBuilder {
1730 private $metricType;
1744 public function __construct($metricType, $count) {
1747 throw new \Exception(
'Invalid metric type: '.$metricType);
1758 public static function build($array) {
1759 if (is_array($array)) {
1760 if (isset($array[
'MetricType']) && isset($array[
'Count'])) {
1762 return new self($array[
'MetricType'], $array[
'Count']);
1763 } elseif (
count(array_keys($array)) == 1 && parent::isAssociative($array)) {
1765 foreach ($array as $k => $v) {
1766 return new self($k, $v);
1770 parent::build($array);
1778 $doc = new \DOMDocument();
1779 $root = $doc->appendChild($doc->createElement(
'Instance'));
1780 $root->appendChild($doc->createElement(
'MetricType'))->appendChild($doc->createTextNode($this->metricType));
1781 $root->appendChild($doc->createElement(
'Count'))->appendChild($doc->createTextNode($this->count));