public static function getThing($type_or_qp, $version = 0)
 {
     $thingNames = array_flip(HVRawConnector::$things);
     $typeId = '';
     if ($type_or_qp instanceof Query) {
         $typeId = $type_or_qp->top()->find('type-id')->text();
     } elseif (is_string($type_or_qp)) {
         $typeId = HealthRecordItemFactory::getTypeId($type_or_qp);
         $template = __DIR__ . '/HealthRecordItem/XmlTemplates/' . $typeId . '.xml';
         if (is_readable($template)) {
             $type_or_qp = qp(file_get_contents($template), NULL, array('use_parser' => 'xml'));
         }
     } else {
         throw new HVClientException('ThingFactory::getThing must be called with a valid thing name or type id or a QueryPath object representing a thing.');
     }
     if ($typeId) {
         if ($type_or_qp instanceof Query) {
             if ($className = HealthRecordItemFactory::convertThingNameToClassName($thingNames[$typeId])) {
                 return new $className($type_or_qp);
             } else {
                 throw new HVClientException('Things of that type id are not supported yet: ' . $typeId);
             }
         } else {
             throw new HVClientException('Creation of new empty things of that type id is not supported yet: ' . $typeId);
         }
     } else {
         throw new HVClientException('Unable to detect type id.');
     }
 }
Пример #2
0
 public function getThings($thingNameOrTypeId, $recordId, $options = array())
 {
     if ($this->connector) {
         $typeId = HealthRecordItemFactory::getTypeId($thingNameOrTypeId);
         $options += array('group max' => 30);
         $this->connector->authenticatedWcRequest('GetThings', '3', '<group max="' . $options['group max'] . '"><filter><type-id>' . $typeId . '</type-id></filter><format><section>core</section><xml/></format></group>', array('record-id' => $recordId));
         $things = array();
         $qp = $this->connector->getQueryPathResponse();
         $qpThings = $qp->branch()->find('thing');
         foreach ($qpThings as $qpThing) {
             $things[] = HealthRecordItemFactory::getThing(qp('<?xml version="1.0"?>' . $qpThing->xml(), NULL, array('use_parser' => 'xml')));
         }
         return $things;
     } else {
         throw new HVClientNotConnectedException();
     }
 }