searchService = $parameters->get('searchServiceUrl'); $this->cache = \JCache :: getInstance(); $this->http = new \JHttp(); } /** * Returns a message for display * @param integer $pk Primary key of the "message item", currently unused * @return object Message object */ public function getItem($pk= null): object { $item = new \stdClass(); $item->message = "Hello there!";// Text::_('com_openaire_MSG_GREETING'); return $item; } // Retrieve a single project by identifier using caching if enabled. // $id the project identifier // $locale the locale to use // return a project (object) or NULL if no such project exists public function getProject($id, $locale) { if ($this->cache->getCaching()) { $cacheId = self::PROJECT_CACHE_ID . '.' . $id . '.' . $locale; $project = $this->cache->get($cacheId, self::CACHE_GROUP); if ($project === FALSE) { $project = $this->_getProject($id, $locale); if ($project !== NULL) $this->cache->store($project, $cacheId, self::CACHE_GROUP); } } else $project = $this->_getProject($id, $locale); return $project; } // Retrieve a single project by identifier. // $id the project identifier // $locale the locale to use // return a project (object) or NULL if no such project exists private function _getProject($id, $locale) { try { $time = microtime(TRUE); $query = self::PROJECT_QUERY . ' and (' . self::PROJECT_ID . ' exact "' . $id . '")'; \JLog :: add('Generated query is \'' . $query . '\'', \JLog :: INFO, self::LOG); if (($response = $this->performGet('search?action=search&sTransformer=projects_openaire&query=' . urlencode($query) . '&locale=' . str_replace('-', '_', $locale))) == NULL) throw new \Exception('no HTTP response'); if ($response->code != self::HTTP_OK) throw new \Exception('HTTP response code ' . $response->code); $document = new \DOMDocument(); $document->recover = TRUE; if ($document->loadXML($response->body) == FALSE) throw new \Exception('invalid XML response'); $xpath = new \DOMXPath($document); $project = $this->parseProject($xpath); \JLog :: add('Retrieved project in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', \JLog :: INFO, self::LOG); return $project; } catch (Exception $e) { \JLog :: add('Error retrieving project (id: ' . $id . ', locale: ' . $locale . '): ' . $e->getMessage(), \JLog :: ERROR, self::LOG); return NULL; } } // Perform an HTTP GET request. // $request the relative URL to connect to // return the HTTP response (object) private function performGet($request) { $request = $this->searchService . $request; \JLog :: add('Requesting ' . $request, \JLog :: INFO, self::LOG); $time = microtime(TRUE); $response = $this->http->get($request); \JLog :: add('Received response in ' . (microtime(TRUE) - $time) . ' s', \JLog :: INFO, self::LOG); return $response; } // Parse a single project from a search service XML response. // xpath the DOMXPath to parse // return project (object) private function parseProject($xpath) { if ((($resultsNodes = $xpath->query('/response/results/result')) == FALSE) || (($resultNode = $resultsNodes->item(0)) == NULL)) { //print_r($resultsNodes, true); throw new \Exception('error parsing project'); } if (($idNodes = $xpath->query('./field[@name = "projectId"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing projects'); if (($acronymNodes = $xpath->query('./field[@name = "name"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($titleNodes = $xpath->query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($funderNodes = $xpath->query('./field[@name = "funder"]/field[@name = "fundershortname"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($fundingStreamNodes = $xpath->query('./field[@name = "funding_level_0"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($scientificAreaNodes = $xpath->query('./field[@name = "funding_level_1"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($fundingStreamLevel2Nodes = $xpath->query('./field[@name = "funding_level_2"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($callNodes = $xpath->query('./field[@name = "call_identifier"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($codeNodes = $xpath->query('./field[@name = "code"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($startYearNodes = $xpath->query('./field[@name = "startyear"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($startDateNodes = $xpath->query('./field[@name = "startdate"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($endYearNodes = $xpath->query('./field[@name = "endyear"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($endDateNodes = $xpath->query('./field[@name = "enddate"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($sc39Nodes = $xpath->query('./field[@name = "ec_sc39"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($oaMandateNodes = $xpath->query('./field[@name = "oamandatepublications"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($datapilotNodes = $xpath->query('./field[@name = "ecarticle29_3"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($funding0Nodes = $xpath->query('./field[@name = "funding_level_0"]', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($funding1Nodes = $xpath->query('./field[@name = "funding_level_1"]', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($funding2Nodes = $xpath->query('./field[@name = "funding_level_2"]', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($organizationNodes = $xpath->query('./field[@name = "organization"]', $resultNode)) == FALSE) throw new \Exception('error parsing project'); if (($urlNodes = $xpath->query('./field[@name = "websiteurl"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasources'); $project = new \stdClass(); $project->projectId = (($idNode = $idNodes->item(0)) == NULL) ? NULL : trim($idNode->nodeValue); $project->acronym = (($acronymNode = $acronymNodes->item(0)) == NULL) ? NULL : ((trim($acronymNode->nodeValue) == self::UNKNOWN) ? NULL : trim($acronymNode->nodeValue)); $project->title = (($titleNode = $titleNodes->item(0)) == NULL) ? NULL : trim($titleNode->nodeValue); $project->funder = (($funderNode = $funderNodes->item(0)) == NULL) ? NULL : trim($funderNode->nodeValue); $project->fundingStream = (($fundingStreamNode = $fundingStreamNodes->item(0)) == NULL) ? NULL : trim($fundingStreamNode->nodeValue); $project->scientificArea = (($scientificAreaNode = $scientificAreaNodes->item(0)) == NULL) ? NULL : trim($scientificAreaNode->nodeValue); $project->fundingStreamLevel2 = (($fundingStreamLevel2Node = $fundingStreamLevel2Nodes->item(0)) == NULL) ? NULL : trim($fundingStreamLevel2Node->nodeValue); $project->call = (($callNode = $callNodes->item(0)) == NULL) ? NULL : trim($callNode->nodeValue); $project->code = (($codeNode = $codeNodes->item(0)) == NULL) ? NULL : trim($codeNode->nodeValue); $project->startYear = (($startYearNode = $startYearNodes->item(0)) == NULL) ? NULL : intval(trim($startYearNode->nodeValue)); $project->startDate = (($startDateNode = $startDateNodes->item(0)) == NULL) ? NULL : strtotime(trim($startDateNode->nodeValue)); $project->endYear = (($endYearNode = $endYearNodes->item(0)) == NULL) ? NULL : intval(trim($endYearNode->nodeValue)); $project->endDate = (($endDateNode = $endDateNodes->item(0)) == NULL) ? NULL : strtotime(trim($endDateNode->nodeValue)); $project->sc39 = (($sc39Node = $sc39Nodes->item(0)) == NULL) ? NULL : trim($sc39Node->nodeValue); switch ($project->sc39) { case 'true': $project->sc39 = TRUE; break; case 'false': $project->sc39 = FALSE; break; default: $project->sc39 = NULL; } $project->oaMandate = (($oaMandateNode = $oaMandateNodes->item(0)) == NULL) ? NULL : trim($oaMandateNode->nodeValue); switch ($project->oaMandate) { case 'true': $project->oaMandate = TRUE; break; case 'false': $project->oaMandate = FALSE; break; default: $project->oaMandate = NULL; } $project->dataPilot = (($datapilotNode = $datapilotNodes->item(0)) == NULL) ? NULL : trim($datapilotNode->nodeValue); switch ($project->dataPilot) { case 'true': $project->dataPilot = TRUE; break; case 'false': $project->dataPilot = FALSE; break; default: $project->dataPilot = NULL; } $project->url = (($urlNode = $urlNodes->item(0)) == NULL) ? NULL : trim($urlNode->nodeValue); $project->funding = new \stdClass(); $project->funding->funding_level_0 = NULL; $project->funding->funding_level_1 = NULL; $project->funding->funding_level_2 = NULL; if (($funding0Node = $funding0Nodes->item(0)) == NULL) ; else { if (($funding0NameNodes = $xpath->query('./field[@name = "fundingname"]/@value', $funding0Node)) == FALSE) throw new \Exception('error parsing publication test'); $project->funding->funding_level_0 = (($funding0NameNode = $funding0NameNodes->item(0)) == NULL) ? NULL : trim($funding0NameNode->nodeValue); } if (($funding1Node = $funding1Nodes->item(0)) == NULL) ; else { if (($funding1NameNodes = $xpath->query('./field[@name = "fundingname"]/@value', $funding1Node)) == FALSE) throw new \Exception('error parsing publication test'); $project->funding->funding_level_1 = (($funding1NameNode = $funding1NameNodes->item(0)) == NULL) ? NULL : trim($funding1NameNode->nodeValue); } if (($funding2Node = $funding2Nodes->item(0)) == NULL) ; else { if (($funding2NameNodes = $xpath->query('./field[@name = "fundingname"]/@value', $funding2Node)) == FALSE) throw new \Exception('error parsing publication test'); $project->funding->funding_level_2 = (($funding2NameNode = $funding2NameNodes->item(0)) == NULL) ? NULL : trim($funding2NameNode->nodeValue); } $project->organizations = array(); foreach ($organizationNodes as $organizationNode) { if (($idNodes = $xpath->query('./field[@name = "organizationid"]/@value', $organizationNode)) == FALSE) throw new \Exception('error parsing project'); if (($shortNameNodes = $xpath->query('./field[@name = "legalshortname"]/@value', $organizationNode)) == FALSE) throw new \Exception('error parsing project'); if (($nameNodes = $xpath->query('./field[@name = "legalname"]/@value', $organizationNode)) == FALSE) throw new \Exception('error parsing project'); $organization = new \stdClass(); $organization->id = (($idNode = $idNodes->item(0)) == NULL) ? NULL : trim($idNode->nodeValue); $organization->shortName = (($shortNameNode = $shortNameNodes->item(0)) == NULL) ? NULL : trim($shortNameNode->nodeValue); $organization->name = (($nameNode = $nameNodes->item(0)) == NULL) ? NULL : trim($nameNode->nodeValue); if (($organization->id != NULL) || ($organization->shortName != NULL) || ($organization->name != NULL)) $project->organizations[] = $organization; } // \JLog :: add('project: '. print_r($project, true), \JLog :: DEBUG, self::LOG); return $project; } // Retrieve projects by identifier using caching if enabled. // $ids the project identifiers // $locale the locale to use // return an array of project (object) or NULL if no such projects exists public function getProjectByCodeId($id, $funder, $locale) { if ($this->cache->getCaching()) { $cacheId = self::PROJECT_CACHE_ID . '.' . $id . '.' . $funder . '.' . $locale; $projects = $this->cache->get($cacheId, self::CACHE_GROUP); if ($projects === FALSE) { $projects = $this->_getProjectByCodeId($id, $funder, $locale); if ($projects !== NULL) $this->cache->store($projects, $cacheId, self::CACHE_GROUP); } } else $projects = $this->_getProjectByCodeId($id, $funder, $locale); return $projects; } // Retrieve projects by code id. // $id the project grant agreement code // $locale the locale to use // return projects or NULL if no such project exists private function _getProjectByCodeId($id, $funder, $locale) { try { $time = microtime(TRUE); $query = self::PROJECT_QUERY . ' and '; // (oaftype=project) and (projectcode_nt exact 731011) $query.=' ( projectcode_nt exact "' . $id . '") and '; $query.=' ( funderid exact "' . $funder . '")'; //and (funderid exact "ec__________::EC")' \JLog :: add('Generated query is \'' . $query . '\'', \JLog :: INFO, self::LOG); if (($response = $this->performGet('search?action=search&sTransformer=projects_openaire&query=' . urlencode($query) . '&locale=' . str_replace('-', '_', $locale))) == NULL) throw new \Exception('no HTTP response'); if ($response->code != self::HTTP_OK) throw new \Exception('HTTP response code ' . $response->code); $document = new \DOMDocument(); $document->recover = TRUE; if ($document->loadXML($response->body) == FALSE) throw new \Exception('invalid XML response'); $xpath = new \DOMXPath($document); $projects = $this->parseProject($xpath, $locale); \JLog :: add('Retrieved projects in ' . (microtime(TRUE) - $time) . ' s (id: ' .$id . ', locale: ' . $locale . ')', \JLog :: INFO, self::LOG); return $projects; } catch (Exception $e) { \JLog :: add('Error retrieving projects (id: ' .$id. ', locale: ' . $locale . '): ' . $e->getMessage(), \JLog :: ERROR, self::LOG); return NULL; } } // Perform a browse for datasets using cache if enabled. // $type the ID of the dataset type to use as filter or NULL for no dataset type filtering // $language the ID of the language to use as filter or NULL for no language filtering // $funder the ID of the funder to use as filter or NULL for no funder filtering // $fundingStream the ID of the funding stream to use as filter or NULL for no funding stream filtering // $scientificArea the ID of the scientific area to use as filter or NULL for no scientific area filtering // $year the year of publication to use as filter or NULL for no year filtering // $accessMode the ID of the access mode to use as filter or NULL for no access mode filtering // $datasource the ID of the datasource to use as filter or NULL for no datasource filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // $project the ID of the project to use as filter or NULL for no project filtering // $author the ID of the author to use as filter or NULL for no author filtering // return a result (object) containing datasets and statistics public function searchResults($type, $page, $size, $project) { if ($this->cache->getCaching()) { $cacheId = self::SEARCH_RESULTS_CACHE_ID . '.' . $type . '.' . $project; $result = $this->cache->get($cacheId, self::CACHE_GROUP); if ($result === FALSE) { $result = $this->_searchResults($type, $page, $size, $project); if ($result !== NULL) $this->cache->store($result, $cacheId, self::CACHE_GROUP); } } else $result = $this->_searchResults($type, $page, $size, $project); return $result; } // Perform a browse for datasets. // $type the ID of the dataset type to use as filter or NULL for no dataset type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // $project the ID of the project to use as filter or NULL for no project filtering // return a result (object) containing datasets and statistics private function _searchResults($type, $page, $size, $project) { try { $time = microtime(TRUE); $query = self::RESULT_QUERY; $query .= ($type == NULL) ? '' : (' and (' . self::RESULT_TYPE . ' exact "' . $type . '")'); // $query .= ($project == NULL) ? '' : (' and (' . self::DATASET_PROJECT . ' exact "' . $project . '")'); $project_id_array = explode("||", $project); if(sizeof($project_id_array) > 1 ){ $query .= ($project == NULL) ? '' : (' and (' . self::RESULT_PROJECT . ' exact "' . $project . '")'); }else{ $query .= ($project == NULL) ? '' : (' and (' . self::RESULT_PROJECT_ID . ' exact "' . $project . '")'); } \JLog :: add('Generated query is \'' . $query . '\'', \JLog :: INFO, self::LOG); $completeQuery='search?action=search&sTransformer=results_openaire&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size ; if (($response = $this->performGet($completeQuery)) == NULL) throw new \Exception('no HTTP response'); if ($response->code != self::HTTP_OK) throw new \Exception('HTTP response code ' . $response->code); $document = new \DOMDocument(); $document->recover = TRUE; if ($document->loadXML($response->body) == FALSE) throw new \Exception('invalid XML response'); $xpath = new \DOMXPath($document); $result = new \stdClass(); $result->totalDatasets = $this->parseTotalResults($xpath); $result->datasets = $this->parseResults($xpath); \JLog :: add('Search retrieved ' . count($result->datasets) . ' results in ' . (microtime(TRUE) - $time) . ' s (type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size .', project: ' . (($project == NULL) ? 'null' : $project) . ')', \JLog :: INFO, self::LOG); return $result; } catch (Exception $e) { \JLog :: add('Error performing dataset browse (type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', project: ' . (($project == NULL) ? 'null' : $project) . '): ' . $e->getMessage(), \JLog :: ERROR, self::LOG); return NULL; } } // Parse datasets from a search service XML response. // xpath the DOMXPath to parse // return datasets (array) private function parseResults($xpath) { if (($resultNodes = $xpath->query('/response/results/result')) == FALSE) throw new \Exception('error parsing datasets'); $datasets = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath->query('./field[@name = "resultId"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($datasourceNodes = $xpath->query('./field[@name = "datasource"]', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($titleNodes = $xpath->query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($authorNodes = $xpath->query('./field[@name = "hasAuthor"]', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($publisherNodes = $xpath->query('./field[@name = "publisher"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($yearNodes = $xpath->query('./field[@name = "dateofacceptance"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($languageNodes = $xpath->query('./field[@name = "language"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($projectNodes = $xpath->query('./field[@name = "project"]', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($embargoEndDateNodes = $xpath->query('./field[@name = "embargoenddate"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($descriptionNodes = $xpath->query('./field[@name = "description"]/@value', $resultNode)) == FALSE) throw new \Exception('error parsing datasets'); $dataset = new \stdClass(); $dataset->id = (($idNode = $idNodes->item(0)) == NULL) ? NULL : trim($idNode->nodeValue); $dataset->source = 'openaire'; $dataset->url = NULL; $dataset->accessMode = NULL; $dataset->datasources = array(); $dataset->title = (($titleNode = $titleNodes->item(0)) == NULL) ? NULL : trim($titleNode->nodeValue); $dataset->authors = array(); $dataset->publisher = (($publisherNode = $publisherNodes->item(0)) == NULL) ? NULL : trim($publisherNode->nodeValue); $dataset->year = (($yearNode = $yearNodes->item(0)) == NULL) ? NULL : intval(trim($yearNode->nodeValue)); $dataset->language = (($languageNode = $languageNodes->item(0)) == NULL) ? NULL : trim($languageNode->nodeValue); $dataset->projects = array(); $dataset->embargoEndDate = (($embargoEndDateNode = $embargoEndDateNodes->item(0)) == NULL) ? NULL : strtotime(trim($embargoEndDateNode->nodeValue)); $dataset->description = (($descriptionNode = $descriptionNodes->item(0)) == NULL) ? NULL : trim($descriptionNode->nodeValue); foreach ($datasourceNodes as $datasourceNode) { if (($urlNodes = $xpath->query('./field[@name = "url"]/@value', $datasourceNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($accessModeNodes = $xpath->query('./field[@name = "accessrightid"]/@value', $datasourceNode)) == FALSE) throw new \Exception('error parsing datasets'); $datasource = new \stdClass(); $datasource->url = (($urlNode = $urlNodes->item(0)) == NULL) ? NULL : trim($urlNode->nodeValue); $datasource->accessMode = (($accessModeNode = $accessModeNodes->item(0)) == NULL) ? NULL : trim($accessModeNode->nodeValue); if (($datasource->url != NULL) && ((($datasource->accessMode == self::DATASOURCE_ACCESS_OPEN) && (($dataset->accessMode == NULL) || ($dataset->accessMode == self::UNKNOWN) || ($dataset->accessMode == self::DATASOURCE_ACCESS_CLOSED) || ($dataset->accessMode == self::DATASOURCE_ACCESS_RESTRICTED) || ($dataset->accessMode == self::DATASOURCE_ACCESS_EMBARGO))) || (($datasource->accessMode == self::DATASOURCE_ACCESS_EMBARGO) && (($dataset->accessMode == NULL) || ($dataset->accessMode == self::UNKNOWN) || ($dataset->accessMode == self::DATASOURCE_ACCESS_CLOSED) || ($dataset->accessMode == self::DATASOURCE_ACCESS_RESTRICTED))) || (($datasource->accessMode == self::DATASOURCE_ACCESS_RESTRICTED) && (($dataset->accessMode == NULL) || ($dataset->accessMode == self::UNKNOWN) || ($dataset->accessMode == self::DATASOURCE_ACCESS_CLOSED))) || (($datasource->accessMode == self::DATASOURCE_ACCESS_CLOSED) && (($dataset->accessMode == NULL) || ($dataset->accessMode == self::UNKNOWN))) || (($datasource->accessMode == self::UNKNOWN) && ($dataset->accessMode == NULL)) || ((($datasource->accessMode == NULL) && ($dataset->accessMode == NULL) && ($dataset->url == NULL))))) { $dataset->accessMode = $datasource->accessMode; $dataset->url = $datasource->url; } if (($datasource->url != NULL) || ($datasource->accessMode != NULL)) $dataset->datasources[] = $datasource; } foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath->query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($fullNameNodes = $xpath->query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($rankingNodes = $xpath->query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new \Exception('error parsing datasets'); $author = new \stdClass(); $author->id = (($idNode = $idNodes->item(0)) == NULL) ? NULL : trim($idNode->nodeValue); $author->lastName = NULL; $author->firstName = NULL; $author->fullName = (($fullNameNode = $fullNameNodes->item(0)) == NULL) ? NULL : trim($fullNameNode->nodeValue); $author->ranking = (($rankingNode = $rankingNodes->item(0)) == NULL) ? 0 : intval(trim($rankingNode->nodeValue)); if (($author->id != NULL) || ($author->lastName != NULL) || ($author->firstName != NULL) || ($author->fullName != NULL)) $dataset->authors[] = $author; usort($dataset->authors, function ($author1, $author2) { return $author1->ranking - $author2->ranking; }); } foreach ($projectNodes as $projectNode) { if (($idNodes = $xpath->query('./field[@name = "projectId"]/@value', $projectNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($acronymNodes = $xpath->query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($titleNodes = $xpath->query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($codeNodes = $xpath->query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new \Exception('error parsing datasets'); if (($fundingNodes = $xpath->query('./field[@name = "funding"]', $projectNode)) == FALSE) throw new \Exception('error parsing datasets'); $project = new \stdClass(); $project->id = (($idNode = $idNodes->item(0)) == NULL) ? NULL : trim($idNode->nodeValue); $project->acronym = (($acronymNode = $acronymNodes->item(0)) == NULL) ? NULL : ((trim($acronymNode->nodeValue) == self::UNKNOWN) ? NULL : trim($acronymNode->nodeValue)); $project->title = (($titleNode = $titleNodes->item(0)) == NULL) ? NULL : trim($titleNode->nodeValue); $project->code = (($codeNode = $codeNodes->item(0)) == NULL) ? NULL : trim($codeNode->nodeValue); if (($project->id != NULL) || ($project->acronym != NULL) || ($project->title != NULL) || ($project->code != NULL)) $dataset->projects[] = $project; $project -> funder = NULL; if (($fundingNode = $fundingNodes->item(0)) == NULL) ; else { if (($funderNodes = $xpath->query('./field[@name = "funder"]/@value', $fundingNode)) == FALSE) throw new \Exception('error parsing datasets'); $project -> funder = (($funderNode = $funderNodes->item(0)) == NULL) ? NULL : trim($funderNode->nodeValue); if (($funderShortNameNodes = $xpath->query('./field[@name = "fundershortname"]/@value', $fundingNode)) == FALSE) throw new \Exception('error parsing datasets'); $project -> funderShortName = (($funderShortNameNode = $funderShortNameNodes->item(0)) == NULL) ? NULL : trim($funderShortNameNode->nodeValue); } } if (($dataset->id != NULL) || ($dataset->source != NULL) || ($dataset->url != NULL) || ($dataset->accessMode != NULL) || ($dataset->datasources != NULL) || ($dataset->title != NULL) || ($dataset->authors != NULL) || ($dataset->publisher != NULL) || ($dataset->year != NULL) || ($dataset->language != NULL) || ($dataset->projects != NULL) || ($dataset->embargoEndDate != NULL) || ($dataset->description != NULL)) $datasets[] = $dataset; } return $datasets; } // Parse total results from a search service XML response. // xpath the DOMXPath to parse // return total results (integer) private function parseTotalResults($xpath) { if ((($totalNodes = $xpath->query('/response/header/total')) == FALSE) || (($totalNode = $totalNodes->item(0)) == NULL)) throw new Exception('error parsing total results'); return intval(trim($totalNode->nodeValue)); } }