"UNKNOWN")'; const DATASOURCE_QUERY_COMPATIBILITY = '(oaftype exact datasource)'; const DATASOURCE_TYPE = 'datasourcetypeuiid'; const DATASOURCE_LANGUAGE = 'datasourceodlanguages'; const DATASOURCE_CONTENT = 'datasourceodcontenttypes'; const DATASOURCE_COMPATIBILITY = 'datasourcecompatibilityid'; const DATASOURCE_NAME = 'datasourceofficialname'; const DATASOURCE_ENGLISH_NAME = 'datasourceenglishname'; const DATASOURCE_SUBJECT = 'datasourceodsubjects'; const DATASOURCE_ORGANIZATION = 'relorganizationid'; const DATASOURCE_ID = 'objIdentifier'; const DATASOURCE_COMPATIBILITY_NOT_COMPATIBLE = 'notCompatible'; const DATASOURCE_ACCESS_OPEN = 'OPEN'; const DATASOURCE_ACCESS_EMBARGO = 'EMBARGO'; const DATASOURCE_ACCESS_RESTRICTED = 'RESTRICTED'; const DATASOURCE_ACCESS_CLOSED = 'CLOSED'; const UNKNOWN = 'UNKNOWN'; const UNDETERMINED = 'Undetermined'; const PUBLICATION = 'publication'; const DATASET = 'dataset'; const HTTP_OK = 200; private $searchService; private $publicationStatisticsExistUrl; private $publicationStatisticsChartUrl; private $datasourceStatisticsExistUrl; private $datasourceStatisticsChartUrl; private $projectStatisticsChartUrl; private $cache; private $http; // Construct a new OpenAireModelSearch. // $configuration the configuration to use public function __construct($configuration = array()) { parent :: __construct($configuration); $parameters = JComponentHelper :: getParams('com_openaire'); $this -> searchService = $parameters -> get('searchServiceUrl'); $this -> publicationStatisticsExistUrl = $parameters -> get('statisticsDocumentExistUrl'); $this -> publicationStatisticsChartUrl = $parameters -> get('statisticsDocumentChartUrl'); $this -> datasourceStatisticsExistUrl = $parameters -> get('statisticsRepositoryExistUrl'); $this -> datasourceStatisticsChartUrl = $parameters -> get('statisticsRepositoryChartUrl'); $this -> projectStatisticsChartUrl = $parameters -> get('statisticsProjectChartUrl'); $this -> cache = JCache :: getInstance(); $this -> http = new JHttp(); } // Retrieve the statistics exist URL for a publication. // return the URL to use in order to check whether statistics exist for a publication public function getPublicationStatisticsExistUrl() { return $this -> publicationStatisticsExistUrl; } // Retrieve the statistics chart URL for a publication. // return the URL to use in order to retrieve statistics chart for a publication public function getPublicationStatisticsChartUrl() { return $this -> publicationStatisticsChartUrl; } // Retrieve the statistics exist URL for a datasource. // return the URL to use in order to check whether statistics exist for a datasource public function getDatasourceStatisticsExistUrl() { return $this -> datasourceStatisticsExistUrl; } // Retrieve the statistics chart URL for a datasource. // return the URL to use in order to retrieve statistics chart for a datasource public function getDatasourceStatisticsChartUrl() { return $this -> datasourceStatisticsChartUrl; } // Retrieve the statistics chart URL for a project. // return the URL to use in order to retrieve statistics chart for a project public function getProjectStatisticsChartUrl() { return $this -> projectStatisticsChartUrl; } // Retrieve publication statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getPublicationStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PUBLICATION_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getPublicationStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getPublicationStatistics($locale); return $statistics; } // Retrieve dataset statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getDatasetStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: DATASET_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getDatasetStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getDatasetStatistics($locale); return $statistics; } // Retrieve project statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getProjectStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PROJECT_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getProjectStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getProjectStatistics($locale); return $statistics; } // Retrieve people statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getPeopleStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PEOPLE_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getPeopleStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getPeopleStatistics($locale); return $statistics; } // Retrieve organization statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getOrganizationStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ORGANIZATION_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getOrganizationStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getOrganizationStatistics($locale); return $statistics; } // Retrieve datasource statistics using cache if enabled. // $locale the locale to use // return statistics (object) public function getDatasourceStatistics($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: DATASOURCE_STATISTICS_CACHE_ID . '.' . $locale; $statistics = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($statistics === FALSE) { $statistics = $this -> _getDatasourceStatistics($locale); if ($statistics !== NULL) $this -> cache -> store($statistics, $cacheId, self :: CACHE_GROUP); } } else $statistics = $this -> _getDatasourceStatistics($locale); return $statistics; } // Perform a simple search for publications using cache if enabled. // $keyword the keyword to search for // $articles flag to limit searching on articles; if all flags are FALSE no limits apply // $books flag to limit searching on books; if all flags are FALSE no limits apply // $theses flag to limit searching on books; if all flags are FALSE no limits apply // $reports flag to limit searching on reports; if all flags are FALSE no limits apply // $type the ID of the publication type to use as filter or NULL for no publication 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 a filter or NULL for no access mode filtering // $datasource the ID of the datasource to use as filter or NULL for no datasource filtering // $community the ID of the community to use as filter or NULL for no community filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing publications and statistics public function searchPublications($keyword, $articles, $books, $theses, $reports, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_PUBLICATIONS_CACHE_ID . '.' . $keyword . '.' . $articles . '.' . $books . '.' . $theses . '.' . $reports . '.' . $type . '.' . $language . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $year . '.' . $accessMode . '.' . $datasource . '.' . $community . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchPublications($keyword, $articles, $books, $theses, $reports, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchPublications($keyword, $articles, $books, $theses, $reports, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale); return $result; } // Perform a simple search for datasets using cache if enabled. // $keyword the keyword to search for // $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 a 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 // return a result (object) containing datasets and statistics public function searchDatasets($keyword, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_DATASETS_CACHE_ID . '.' . $keyword . '.' . $type . '.' . $language . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $year . '.' . $accessMode . '.' . $datasource . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchDatasets($keyword, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchDatasets($keyword, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale); return $result; } // Perform a simple search for projects using cache if enabled. // $keyword the keyword to search for // $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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to suse as filter or NULL for no end year filtering // $sc39 the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics public function searchProjects($keyword, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_PROJECTS_CACHE_ID . '.' . $keyword . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $startYear . '.' . $endYear . '.' . (($sc39 === NULL) ? '' : (($sc39) ? 'true' : 'false')) . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchProjects($keyword, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchProjects($keyword, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); return $result; } // Perform a simple search for people using cache if enabled. // $keyword the keyword to search for // $country the ID of the country to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics public function searchPeople($keyword, $country, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_PEOPLE_CACHE_ID . '.' . $keyword . '.' . $country . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchPeople($keyword, $country, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchPeople($keyword, $country, $page, $size, $locale); return $result; } // Perform a simple search for organizations using cache if enabled. // $keyword the keyword to search for // $country the ID of the country to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing organizations and statistics public function searchOrganizations($keyword, $country, $type, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_ORGANIZATIONS_CACHE_ID . '.' . $keyword . '.' . $country . '.' . $type . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchOrganizations($keyword, $country, $type, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchOrganizations($keyword, $country, $type, $page, $size, $locale); return $result; } // Perform a simple search for datasources using cache if enabled. // $keyword the keyword to search for // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no project filtering // $compatibility the ID of the compatibility level to use as filter or NULL for no compatibility level filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics public function searchDatasources($keyword, $type, $language, $content, $compatibility, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: SEARCH_DATASOURCES_CACHE_ID . '.' . $keyword . '.' . $type . '.' . $language . '.' . $content . '.' . $compatibility . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _searchDatasources($keyword, $type, $language, $content, $compatibility, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _searchDatasources($keyword, $type, $language, $content, $compatibility, $page, $size, $locale); return $result; } // Perform a browse for publications using cache if enabled. // $type the ID of the publication type to use as filter or NULL for no publication 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 // $community the ID of the community 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 publications and statistics public function browsePublications($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale, $project, $author) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_PUBLICATIONS_CACHE_ID . '.' . $type . '.' . $language . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $year . '.' . $accessMode . '.' . $datasource . '.' . $community . '.' . $page . '.' . $size . '.' . $locale . '.' . $project . '.' . $author; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browsePublications($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale, $project, $author); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browsePublications($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale, $project, $author); return $result; } // 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 browseDatasets($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale, $project, $author) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_DATASETS_CACHE_ID . '.' . $type . '.' . $language . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $year . '.' . $accessMode . '.' . $datasource . '.' . $page . '.' . $size . '.' . $locale . '.' . $project . '.' . $author; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browseDatasets($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale, $project, $author); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browseDatasets($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale, $project, $author); return $result; } // Perform a browse for projects using cache if enabled. // $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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to use as filter or NULL for no end year filtering // $sc39 the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics public function browseProjects($funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_PROJECTS_CACHE_ID . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $startYear . '.' . '.' . $endYear . '.' . $sc39 . '.' .$page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browseProjects($funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browseProjects($funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); return $result; } // Perform a browse for people using cache if enabled. // $country the ID of the country to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics public function browsePeople($country, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_PEOPLE_CACHE_ID . '.' . $country . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browsePeople($country, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browsePeople($country, $page, $size, $locale); return $result; } // Perform a browse for organizations using cache if enabled. // $country the ID of the country to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing organizations and statistics public function browseOrganizations($country, $type, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_ORGANIZATIONS_CACHE_ID . '.' . $country . '.' . $type . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browseOrganizations($country, $type, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browseOrganizations($country, $type, $page, $size, $locale); return $result; } // Perform a browse for datasources using cache if enabled. // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language the ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no content filtering // $compatibility the ID of the compatibility level to use as filter or NULL for no compatibility status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics public function browseDatasources($type, $language, $content, $compatibility, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: BROWSE_DATASOURCES_CACHE_ID . '.' . $type . '.' . $language . '.' . $content . '.' . $compatibility . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _browseDatasources($type, $language, $content, $compatibility, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _browseDatasources($type, $language, $content, $compatibility, $page, $size, $locale); return $result; } // Perform an advanced search for publications using cache if enabled. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are TITLE, AUTHOR, PUBLISHER and SUBJECT) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $types the IDs of the publication types to search for // $languages the IDs of the publication languages to search for // $funders the IDs of the funders to search for // $fundingStreams the IDs of the funding streams to search for // $scientificAreas the IDs of the scientific areas to search for // $date the publication date range to search for expressed in months before current date (if -1 search for any publication date, if 0 search explicitly using $fromMonth, $fromYear, $toMonth and $toYear) // $fromMonth start month of the publication date range to search for if $date has value 0 // $fromYear start year of the publication date range to search for if $date has value 0 // $toMonth end month of the publication date range to search for if $date has value 0 // $toYear end year of the publication date range to search for if $date has value 0 // $accessModes the IDs of the access modes to search for // $datasources the IDs of the datasources to search for // $type the ID of the publication type to use as filter or NULL for no publication type filtering // $language the ID of the publication language to use as filter or NULL for no publication 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 publication year to use as filter or NULL for no publication 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 // return a result (object) containing publications and statistics public function advancedSearchPublications($keywords, $fields, $constraints, $types, $languages, $funders, $fundingStreams, $scientificAreas, $date, $fromMonth, $fromYear, $toMonth, $toYear, $accessModes, $datasources, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ADVANCED_SEARCH_PUBLICATIONS_CACHE_ID . '.' . implode('.', $keywords) . '.' . implode('.', $fields) . '.' . implode('.', $constraints) . '.' . implode('.', $types) . '.' . implode('.', $languages) . '.' . implode('.', $funders) . '.' . implode('.', $fundingStreams) . '.' . implode('.', $scientificAreas) . '.' . $date . '.' . $fromMonth . '.' . $fromYear . '.' . $toMonth . '.' . $toYear . '.' . implode('.', $accessModes) . '.' . implode('.', $datasources) . '.' . $type . '.' . $language . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $year . '.' . $accessMode . '.' . $datasource . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _advancedSearchPublications($keywords, $fields, $constraints, $types, $languages, $funders, $fundingStreams, $scientificAreas, $date, $fromMonth, $fromYear, $toMonth, $toYear, $accessModes, $datasources, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _advancedSearchPublications($keywords, $fields, $constraints, $types, $languages, $funders, $fundingStreams, $scientificAreas, $date, $fromMonth, $fromYear, $toMonth, $toYear, $accessModes, $datasources, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale); return $result; } // Perform an advanced search for projects using cache if enabled. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are ACRONYM, TITLE and KEYWORDS) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $funders the IDs of the funders to search for // $fundingStreams the IDs of the funding streams to search for // $scientificAreas the IDs of the scientific areas to search for // $startDate the start date range to search for expressed in months before current date (if -1 search for any start date, if 0 search explicitly using $startFromMonth, $startFromYear, $startToMonth and $startToYear) // $startFromMonth start month of the start date range to search for if $startDate has value 0 // $startFromYear start year of the start date range to search for if $startDate has value 0 // $startToMonth end month of the start date range to search for if $startDate has value 0 // $startToYear end year of the start date range to search for if $startDate has value 0 // $endDate the end date range to search for expressed in months before current date (if -1 search for any end date, if 0 search explicitly using $endFromMonth, $endFromYear, $endToMonth and $endToYear) // $endFromMonth start month of the end date range to search for if $endDate has value 0 // $endFromYear start year of the end date range to search for if $endDate has value 0 // $endToMonth end month of the end date range to search for if $endDate has value 0 // $endToYear end year of the end date range to search for if $endDate has value 0 // $sc39 the SC-39 statuses to search for // $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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to use as filter or NULL for no end year filtering // $accessMode the ID of the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics public function advancedSearchProjects($keywords, $fields, $constraints, $funders, $fundingStreams, $scientificAreas, $startDate, $startFromMonth, $startFromYear, $startToMonth, $startToYear, $endDate, $endFromMonth, $endFromYear, $endToMonth, $endToYear, $sc39s, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ADVANCED_SEARCH_PROJECTS_CACHE_ID . '.' . implode('.', $keywords) . '.' . implode('.', $fields) . '.' . implode('.', $constraints) . '.' . implode('.', $funders) . '.' . implode('.', $fundingStreams) . '.' . implode('.', $scientificAreas) . '.' . $startDate . '.' . $startFromMonth . '.' . $startFromYear . '.' . $startToMonth . '.' . $startToYear . '.' . $endDate . '.' . $endFromMonth . '.' . $endFromYear . '.' . $endToMonth . '.' . $endToYear . '.' . implode('.', array_map(function ($sc39) {return $sc39 ? 'true' : 'false';}, $sc39s)) . '.' . $funder . '.' . $fundingStream . '.' . $scientificArea . '.' . $startYear . '.' . $endYear . '.' . (($sc39 === NULL) ? '' : ($sc39 ? 'true' : 'false')) . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _advancedSearchProjects($keywords, $fields, $constraints, $funders, $fundingStreams, $scientificAreas, $startDate, $startFromMonth, $startFromYear, $startToMonth, $startToYear, $endDate, $endFromMonth, $endFromYear, $endToMonth, $endToYear, $sc39s, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _advancedSearchProjects($keywords, $fields, $constraints, $funders, $fundingStreams, $scientificAreas, $startDate, $startFromMonth, $startFromYear, $startToMonth, $startToYear, $endDate, $endFromMonth, $endFromYear, $endToMonth, $endToYear, $sc39s, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale); return $result; } // Perform an advanced search for people using cache if enabled. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are LAST_NAME, FIRST_NAME and FULL_NAME) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $countries the IDs of the countries to search for // $country the ID of the coutnry to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics public function advancedSearchPeople($keywords, $fields, $constraints, $countries, $country, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ADVANCED_SEARCH_PEOPLE_CACHE_ID . '.' . implode('.', $keywords) . '.' . implode('.', $fields) . '.' . implode('.', $constraints) . '.' . implode('.', $countries) . '.' . $country . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _advancedSearchPeople($keywords, $fields, $constraints, $countries, $country, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _advancedSearchPeople($keywords, $fields, $constraints, $countries, $country, $page, $size, $locale); return $result; } // Perform an advanced search for organizations using cache if enabled. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are NAME and SHORT_NAME) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $countries the IDs of the countries to search for // $types the IDs of the organization types to search for // $country the ID of the country to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics public function advancedSearchOrganizations($keywords, $fields, $constraints, $countries, $types, $country, $type, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ADVANCED_SEARCH_ORGANIZATIONS_CACHE_ID . '.' . implode('.', $keywords) . '.' . implode('.', $fields) . '.' . implode('.', $constraints) . '.' . implode('.', $countries) . '.' . implode('.', $types) . $country . '.' . $type . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _advancedSearchOrganizations($keywords, $fields, $constraints, $countries, $types, $country, $type, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _advancedSearchOrganizations($keywords, $fields, $constraints, $countries, $types, $country, $type, $page, $size, $locale); return $result; } // Perform an advanced search for datasources using cache if enabled. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are NAME, ENGLISH_NAME and SUBJECT) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $types the IDs of the datasource types to search for // $languages the IDs of the datasource languages to search for // $contents the IDs of the contents to search for // $compatibilities the IDs of the compatibilities to search for // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language the ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no content filtering // $compatibility the ID of the compatibility to use as filter or NULL for no compatibility filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics public function advancedSearchDatasources($keywords, $fields, $constraints, $types, $languages, $contents, $compatibilities, $type, $language, $content, $compatibility, $page, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ADVANCED_SEARCH_DATASOURCES_CACHE_ID . '.' . implode('.', $keywords) . '.' . implode('.', $fields) . '.' . implode('.', $constraints) . '.' . implode('.', $types) . '.' . implode('.', $languages) . '.' . implode('.', $contents) . '.' . implode('.', $compatibilities) . '.' . $type . '.' . $language . '.' . $content . '.' . $compatibility . '.' . $page . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _advancedSearchDatasources($keywords, $fields, $constraints, $types, $languages, $contents, $compatibilities, $type, $language, $content, $compatibility, $page, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _advancedSearchDatasources($keywords, $fields, $constraints, $types, $languages, $contents, $compatibilities, $type, $language, $content, $compatibility, $page, $size, $locale); return $result; } // Retrieve a single publication by identifier using caching if enabled. // $id the publication identifier // $locale the locale to use // return a publication (object) or NULL if no such publication exists public function getPublication($id, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PUBLICATION_CACHE_ID . '.' . $id . '.' . $locale; $publication = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($publication === FALSE) { $publication = $this -> _getPublication($id, $locale); if ($publication !== NULL) $this -> cache -> store($publication, $cacheId, self :: CACHE_GROUP); } } else $publication = $this -> _getPublication($id, $locale); return $publication; } // Retrieve a single publication by identifier using caching if enabled. // $ids the publication identifiers // $locale the locale to use // return a publication (object) or NULL if no such publication exists public function getResults($ids, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: RESULTS_CACHE_ID . '.' . join(",",$ids) . '.' . $locale; $results = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($results === FALSE) { $results = $this -> _getResults($ids, $locale); if ($results !== NULL) $this -> cache -> store($results, $cacheId, self :: CACHE_GROUP); } } else $results = $this -> _getResults($ids, $locale); return $results; } // Retrieve a single publication by identifier using caching if enabled. // $ids the publication identifiers // $locale the locale to use // return a publication (object) or NULL if no such publication exists public function getPublications($ids, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PUBLICATION_CACHE_ID . '.' . join(",",$ids) . '.' . $locale; $publications = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($publications === FALSE) { $publications = $this -> _getPublications($ids, $locale); if ($publications !== NULL) $this -> cache -> store($publications, $cacheId, self :: CACHE_GROUP); } } else $publications = $this -> _getPublications($ids, $locale); return $publications; } // Retrieve a single dataset by identifier using caching if enabled. // $ids the dataset identifiers // $locale the locale to use // return a publication (object) or NULL if no such publication exists public function getDatasets($ids, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: DATASET_CACHE_ID . '.' . join(",",$ids) . '.' . $locale; $datasets = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($datasets === FALSE) { $datasets = $this -> _getDatasets($ids, $locale); if ($datasets !== NULL) $this -> cache -> store($datasets, $cacheId, self :: CACHE_GROUP); } } else $publications = $this -> _getDatasets($ids, $locale); return $publications; } // 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 getProjects($ids, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PROJECT_CACHE_ID . '.' . join(",",$ids) . '.' . $locale; $projects = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($projects === FALSE) { $projects = $this -> _getProjects($ids, $locale); if ($projects !== NULL) $this -> cache -> store($projects, $cacheId, self :: CACHE_GROUP); } } else $projects = $this -> _getProjects($ids, $locale); return $projects; } // Retrieve a single dataset by identifier using caching if enabled. // $id the dataset identifier // $locale the locale to use // return a dataset (object) or NULL if no such dataset exists public function getDataset($id, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: DATASET_CACHE_ID . '.' . $id . '.' . $locale; $dataset = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($dataset === FALSE) { $dataset = $this -> _getDataset($id, $locale); if ($dataset !== NULL) $this -> cache -> store($dataset, $cacheId, self :: CACHE_GROUP); } } else $dataset = $this -> _getDataset($id, $locale); return $dataset; } // 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 person by identifier using caching if enabled. // $id the person identifier // $locale the locale to use // return a person (object) or NULL if no such person exists public function getPerson($id, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: PERSON_CACHE_ID . '.' . $id . '.' . $locale; $person = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($person === FALSE) { $person = $this -> _getPerson($id, $locale); if ($person !== NULL) $this -> cache -> store($person, $cacheId, self :: CACHE_GROUP); } } else $person = $this -> _getPerson($id, $locale); return $person; } // Retreive a single organization by identifier using cache if enabled. // $id the organization identifier // $locale the locale to use // return an organization (object) or NULL if no such organization exists public function getOrganization($id, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ORGANIZATION_CACHE_ID . '.' . $id . '.' . $locale; $organization = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($organization === FALSE) { $organization = $this -> _getOrganization($id, $locale); if ($organization !== NULL) $this -> cache -> store($organization, $cacheId, self :: CACHE_GROUP); } } else $organization = $this -> _getOrganization($id, $locale); return $organization; } // Retrieve the datasources of an organization using caching if enabled. // $id the organization identifier // $size the maximum number of organizations to retrieve // $locale the locale to use // return a result (object) containing datasources and total public function getOrganizationDatasources($id, $size, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: ORGANIZATION_DATASOURCES_CACHE_ID . '.' . $id . '.' . $size . '.' . $locale; $result = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($result === FALSE) { $result = $this -> _getOrganizationDatasources($id, $size, $locale); if ($result !== NULL) $this -> cache -> store($result, $cacheId, self :: CACHE_GROUP); } } else $result = $this -> _getOrganizationDatasources($id, $size, $locale); return $result; } // Retrieve a single datasource by identifier using cache if enabled. // $id the datasource identifier // $locale the locale to use // return a datasource (object) or NULL if no such datasource exists public function getDatasource($id, $locale, $compatibility = false) { if ($this -> cache -> getCaching()) { $cacheId = self :: DATASOURCE_CACHE_ID . '.' . $id . '.' . $locale . "." . $compatibility; $datasource = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($datasource === FALSE) { $datasource = $this -> _getDatasource($id, $locale, $compatibility); if ($datasource !== NULL) $this -> cache -> store($datasource, $cacheId, self :: CACHE_GROUP); } } else $datasource = $this -> _getDatasource($id, $locale, $compatibility); return $datasource; } // Retrieve all the OpenAIRE compatible datasources using cache if enabled. // $locale the locale to use // return the datasources (array) or NULL if any errors occur public function getCompatibleDatasources($locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: COMPATIBLE_DATASOURCES_CACHE_ID . '.' . $locale; $datasources = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($datasources === FALSE) { $datasources = $this -> _getCompatibleDatasources($locale); if ($datasources !== NULL) $this -> cache -> store($datasources, $cacheId, self :: CACHE_GROUP); } } else $datasources = $this -> _getCompatibleDatasources($locale); return $datasources; } // Perform a quick search for projects, searching only by acronym, title or code and funder and using cahce if enabled. // $keyword the keyword to search for // $funder the funder to search for // $limit the maximum number of results to retrieve // $locale the locale to use // return projects (array) or NULL if any errors occur public function quickSearchProjects($keyword, $funder, $limit, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: QUICK_SEARCH_PROJECTS_CACHE_ID . '.' . $keyword . '.' . $funder . '.' . $limit . '.' . $locale; $projects = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($projects === FALSE) { $projects = $this -> _quickSearchProjects($keyword, $funder, $limit, $locale); if ($projects !== NULL) $this -> cache -> store($projects, $cacheId, self :: CACHE_GROUP); } } else $projects = $this -> _quickSearchProjects($keyword, $funder, $limit, $locale); return $projects; } // Perform a quick search for organizations, searching only by name or short name and using cache if enabled. // $keyword the keyword to search for // $limit the maximum number of results to retrieve // $locale the locale to use // return organizations (array) or NULL if any errors occur public function quickSearchOrganizations($keyword, $limit, $locale) { if ($this -> cache -> getCaching()) { $cacheId = self :: QUICK_SEARCH_ORGANIZATIONS_CACHE_ID . '.' . $keyword . '.' . $limit . '.' . $locale; $organizations = $this -> cache -> get($cacheId, self :: CACHE_GROUP); if ($organizations === FALSE) { $organizations = $this -> _quickSearchOrganizations($keyword, $limit, $locale); if ($organizations !== NULL) $this -> cache -> store($organizations, $cacheId, self :: CACHE_GROUP); } } else $organizations = $this -> _quickSearchOrganizations($keyword, $limit, $locale); return $organizations; } // Retrieve publication statistics. // $locale the locale to use // return statistics (object) private function _getPublicationStatistics($locale) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: PUBLICATION_TYPE . '&fields=' . self :: PUBLICATION_LANGUAGE . '&fields=' . self :: PUBLICATION_CONTEXT . '&fields=' . self :: PUBLICATION_FUNDER . '&fields=' . self :: PUBLICATION_FUNDING_STREAM . '&fields=' . self :: PUBLICATION_SCIENTIFIC_AREA . '&fields=' . self :: PUBLICATION_YEAR . '&fields=' . self :: PUBLICATION_ACCESS_MODE . '&fields=' . self :: PUBLICATION_DATASOURCE .'&fields=' . self :: PUBLICATION_CONTEXT . '&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); $statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource', 'community'), array('DOCUMENT_TYPE', 'DOCUMENT_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE', 'CONTEXT'), array('NO_DOCUMENT_TYPE_STATISTICS_FOUND', 'NO_DOCUMENT_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_PUBLICATION_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND', 'NO_CONTEXT_STATISTICS_FOUND'), array(self :: PUBLICATION_TYPE, self :: PUBLICATION_LANGUAGE, self :: PUBLICATION_FUNDER, self :: PUBLICATION_FUNDING_STREAM, self :: PUBLICATION_SCIENTIFIC_AREA, self :: PUBLICATION_YEAR, self :: PUBLICATION_ACCESS_MODE, self :: PUBLICATION_DATASOURCE, self :: PUBLICATION_CONTEXT)); JLog :: add('Retrieved publication statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving publication statistics (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve dataset statistics. // $locale the locale to use // return statistics (object) private function _getDatasetStatistics($locale) { try { $time = microtime(TRUE); $query = self :: DATASET_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: DATASET_TYPE . '&fields=' . self :: DATASET_LANGUAGE . '&fields=' . self :: DATASET_FUNDER . '&fields=' . self :: DATASET_FUNDING_STREAM . '&fields=' . self :: DATASET_SCIENTIFIC_AREA . '&fields=' . self :: DATASET_YEAR . '&fields=' . self :: DATASET_ACCESS_MODE . '&fields=' . self :: DATASET_DATASOURCE . '&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); $statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource'), array('DATASET_TYPE', 'DATASET_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE'), array('NO_DATASET_TYPE_STATISTICS_FOUND', 'NO_DATASET_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_PUBLICATION_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: DATASET_TYPE, self :: DATASET_LANGUAGE, self :: DATASET_FUNDER, self :: DATASET_FUNDING_STREAM, self :: DATASET_SCIENTIFIC_AREA, self :: DATASET_YEAR, self :: DATASET_ACCESS_MODE, self :: DATASET_DATASOURCE)); JLog :: add('Retrieved dataset statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving dataset statistics (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve project statistics. // $locale the locale to use // return statistics (object) private function _getProjectStatistics($locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: PROJECT_FUNDER . '&fields=' . self :: PROJECT_FUNDING_STREAM . '&fields=' . self :: PROJECT_SCIENTIFIC_AREA . '&fields=' . self :: PROJECT_START_YEAR . '&fields=' . self :: PROJECT_END_YEAR . '&fields=' . self :: PROJECT_SC39 . '&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); $statistics = $this -> createStatistics($xpath, array('funder', 'fundingStream', 'scientificArea', 'startYear', 'endYear', 'sc39'), array('FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'START_YEAR', 'END_YEAR', 'SPECIAL_CLAUSE_39'), array('NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_START_YEAR_STATISTICS_FOUND', 'NO_END_YEAR_STATISTICS_FOUND', 'NO_SPECIAL_CLAUSE_39_STATISTICS_FOUND'), array(self :: PROJECT_FUNDER, self :: PROJECT_FUNDING_STREAM, self :: PROJECT_SCIENTIFIC_AREA, self :: PROJECT_START_YEAR, self :: PROJECT_END_YEAR, self :: PROJECT_SC39)); JLog :: add('Retrieved project statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving project statistics (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve people statistics. // $locale the locale to use // return statistics (object) private function _getPeopleStatistics($locale) { try { $time = microtime(TRUE); $query = self :: PERSON_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: PERSON_COUNTRY . '&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); $statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: PERSON_COUNTRY)); JLog :: add('Retrieved people statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving people statistics (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve organization statistics. // $locale the locale to use // return statistics (object) private function _getOrganizationStatistics($locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: ORGANIZATION_COUNTRY . '&fields=' . self :: ORGANIZATION_LEGAL_BODY . '&fields=' . self :: ORGANIZATION_LEGAL_PERSON . '&fields=' . self :: ORGANIZATION_NON_PROFIT . '&fields=' . self :: ORGANIZATION_RESEARCH . '&fields=' . self :: ORGANIZATION_EU_INTERESTS . '&fields=' . self :: ORGANIZATION_INTERNATIONAL . '&fields=' . self :: ORGANIZATION_ENTERPRISE . '&fields=' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . '&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); $statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: ORGANIZATION_COUNTRY)); $statistics['type'] = new JObject(); $statistics['type'] -> id = 'type'; $statistics['type'] -> title = JText :: _('ORGANIZATION_TYPE'); $statistics['type'] -> error = JText :: _('NO_ORGANIZATION_TYPE_STATISTICS_FOUND'); $statistics['type'] -> data = array(); $legalBody = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_BODY); if (($legalBody != NULL) && array_key_exists('true', $legalBody)) { $statistics['type'] -> data['legalBody'] = new JObject(); $statistics['type'] -> data['legalBody'] -> id = 'legalBody'; $statistics['type'] -> data['legalBody'] -> name = JText :: _('LEGAL_BODY'); $statistics['type'] -> data['legalBody'] -> count = $legalBody['true'] -> count; } $legalPerson = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_PERSON); if (($legalPerson != NULL) && array_key_exists('true', $legalPerson)) { $statistics['type'] -> data['legalPerson'] = new JObject(); $statistics['type'] -> data['legalPerson'] -> id = 'legalPerson'; $statistics['type'] -> data['legalPerson'] -> name = JText :: _('LEGAL_PERSON'); $statistics['type'] -> data['legalPerson'] -> count = $legalPerson['true'] -> count; } $nonProfit = $this -> parseStatistics($xpath, self :: ORGANIZATION_NON_PROFIT); if (($nonProfit != NULL) && array_key_exists('true', $nonProfit)) { $statistics['type'] -> data['nonProfit'] = new JObject(); $statistics['type'] -> data['nonProfit'] -> id = 'nonProfit'; $statistics['type'] -> data['nonProfit'] -> name = JText :: _('NON_PROFIT_ORGANIZATION'); $statistics['type'] -> data['nonProfit'] -> count = $nonProfit['true'] -> count; } $research = $this -> parseStatistics($xpath, self :: ORGANIZATION_RESEARCH); if (($research != NULL) && array_key_exists('true', $research)) { $statistics['type'] -> data['research'] = new JObject(); $statistics['type'] -> data['research'] -> id = 'research'; $statistics['type'] -> data['research'] -> name = JText :: _('RESEARCH_ORGANIZATION'); $statistics['type'] -> data['research'] -> count = $research['true'] -> count; } $euInterests = $this -> parseStatistics($xpath, self :: ORGANIZATION_EU_INTERESTS); if (($euInterests != NULL) && array_key_exists('true', $euInterests)) { $statistics['type'] -> data['euInterests'] = new JObject(); $statistics['type'] -> data['euInterests'] -> id = 'euInterests'; $statistics['type'] -> data['euInterests'] -> name = JText :: _('EU_INTERESTS_ORGANIZATION'); $statistics['type'] -> data['euInterests'] -> count = $euInterests['true'] -> count; } $international = $this -> parseStatistics($xpath, self :: ORGANIZATION_INTERNATIONAL); if (($international != NULL) && array_key_exists('true', $international)) { $statistics['type'] -> data['international'] = new JObject(); $statistics['type'] -> data['international'] -> id = 'international'; $statistics['type'] -> data['international'] -> name = JText :: _('INTERNATIONAL_ORGANIZATION'); $statistics['type'] -> data['international'] -> count = $international['true'] -> count; } $enterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_ENTERPRISE); if (($enterprise != NULL) && array_key_exists('true', $enterprise)) { $statistics['type'] -> data['enterprise'] = new JObject(); $statistics['type'] -> data['enterprise'] -> id = 'enterprise'; $statistics['type'] -> data['enterprise'] -> name = JText :: _('ENTERPRISE'); $statistics['type'] -> data['enterprise'] -> count = $enterprise['true'] -> count; } $smallMediumEnterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE); if (($smallMediumEnterprise != NULL) && array_key_exists('true', $smallMediumEnterprise)) { $statistics['type'] -> data['smallMediumEnterprise'] = new JObject(); $statistics['type'] -> data['smallMediumEnterprise'] -> id = 'smallMediumEnterprise'; $statistics['type'] -> data['smallMediumEnterprise'] -> name = JText :: _('SMALL_MEDIUM_ENTERPRISE'); $statistics['type'] -> data['smallMediumEnterprise'] -> count = $smallMediumEnterprise['true'] -> count; } uasort($statistics['type'] -> data, function ($row1, $row2) {return $row2 -> count - $row1 -> count;}); JLog :: add('Retrieved organization statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving organization statistics (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve datasource statistics. // $locale the locale to use // return statistics (object) private function _getDatasourceStatistics($locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=refine&rTransformer=results_openaire_browse&fields=' . self :: DATASOURCE_TYPE . '&fields=' . self :: DATASOURCE_LANGUAGE . '&fields=' . self :: DATASOURCE_CONTENT . '&fields=' . self :: DATASOURCE_COMPATIBILITY . '&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); $statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'content', 'compatibility'), array('DATASOURCE_TYPE', 'DATASOURCE_LANGUAGE', 'CONTENT', 'COMPATIBILITY'), array('NO_DATASOURCE_TYPE_STATISTICS_FOUND', 'NO_DATASOURCE_LANGUAGE_STATISTICS_FOUND', 'NO_CONTENT_STATISTICS_FOUND', 'NO_COMPATIBILITY_STATISTICS_FOUND'), array(self :: DATASOURCE_TYPE, self :: DATASOURCE_LANGUAGE, self :: DATASOURCE_CONTENT, self :: DATASOURCE_COMPATIBILITY)); JLog :: add('Retrieved datasource statistics in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $statistics; } catch (Exception $e) { JLog :: add('Error retrieving datasource statistics locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for publications. // $keyword the keyword to search for // $articles flag to limit searching on articles; if all flags are FALSE no limits apply // $books flag to limit searching on books; if all flags are FALSE no limits apply // $theses flag to limit searching on books; if all flags are FALSE no limits apply // $reports flag to limit searching on reports; if all flags are FALSE no limits apply // $type the ID of the publication type to use as filter or NULL for no publication 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 // return a result (object) containing publications and statistics private function _searchPublications($keyword, $articles, $books, $theses, $reports, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY; $query .= ($keyword == NULL) ? '' : ' and "' . str_replace('"', '\\"', $keyword) . '"'; $types = array(); if ($articles) { $types[] = self :: PUBLICATION_ARTICLE; $types[] = self :: PUBLICATION_PREPRINT; } if ($books) { $types[] = self :: PUBLICATION_BOOK; $types[] = self :: PUBLICATION_BOOK_PART; } if ($theses) { $types[] = self :: PUBLICATION_PHD_THESIS; $types[] = self :: PUBLICATION_MASTER_THESIS; $types[] = self :: PUBLICATION_BACHELOR_THESIS; } if ($reports) { $types[] = self :: PUBLICATION_REPORT; $types[] = self :: PUBLICATION_INTERNAL_REPORT; $types[] = self :: PUBLICATION_EXTERNAL_REPORT; } $publicationType = self :: PUBLICATION_TYPE; $types = implode(' or ', array_map(function($type) use ($publicationType) {return '(' . $publicationType . ' exact "' . $type . '")';}, $types)); $query .= ($types == NULL) ? '' : (' and (' . $types . ')'); $query .= ($type == NULL) ? '' : (' and (' . self :: PUBLICATION_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: PUBLICATION_LANGUAGE . ' exact "' . $language . '")'); $query .= ($funder == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PUBLICATION_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($year == NULL) ? '' : (' and (' . self :: PUBLICATION_YEAR . ' exact ' . $year . ')'); $query .= ($accessMode == NULL) ? '' : (' and (' . self :: PUBLICATION_ACCESS_MODE . ' exact "' . $accessMode . '")'); $query .= ($datasource == NULL) ? '' : (' and (' . self :: PUBLICATION_DATASOURCE . ' exact "' . $datasource . '")'); $query .= ($community == NULL) ? '' : (' and (' . self :: PUBLICATION_CONTEXT . ' exact "' . $community . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PUBLICATION_TYPE . '&fields=' . self :: PUBLICATION_LANGUAGE . '&fields=' . self :: PUBLICATION_FUNDER . '&fields=' . self :: PUBLICATION_FUNDING_STREAM . '&fields=' . self :: PUBLICATION_SCIENTIFIC_AREA . '&fields=' . self :: PUBLICATION_YEAR . '&fields=' . self :: PUBLICATION_ACCESS_MODE . '&fields=' . self :: PUBLICATION_DATASOURCE . '&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); $result = new JObject(); $result -> totalPublications = $this -> parseTotalResults($xpath); $result -> publications = $this -> parsePublications($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource'), array('DOCUMENT_TYPE', 'DOCUMENT_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE'), array('NO_DOCUMENT_TYPE_STATISTICS_FOUND', 'NO_DOCUMENT_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_PUBLICATION_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: PUBLICATION_TYPE, self :: PUBLICATION_LANGUAGE, self :: PUBLICATION_FUNDER, self :: PUBLICATION_FUNDING_STREAM, self :: PUBLICATION_SCIENTIFIC_AREA, self :: PUBLICATION_YEAR, self :: PUBLICATION_ACCESS_MODE, self :: PUBLICATION_DATASOURCE)); JLog :: add('Simple search retrieved ' . count($result -> publications) . ' publications in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', articles: ' . ($articles ? 'true' : 'false') . ', books: ' . ($books ? 'true' : 'false') . ', theses: ' . ($theses ? 'true' : 'false') . ', reports: ' . ($reports ? 'true' : 'false') . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing publication simple search (keyword: ' . $keyword . ', articles: ' . ($articles ? 'true' : 'false') . ', books: ' . ($books ? 'true' : 'false') . ', theses: ' . ($theses ? 'true' : 'false') . ', reports: ' . ($reports ? 'true' : 'false') . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for datasets. // $keyword the keyword to search for // $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 // return a result (object) containing datasets and statistics private function _searchDatasets($keyword, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: DATASET_QUERY; $query .= ($keyword == NULL) ? '' : ' and "' . str_replace('"', '\\"', $keyword) . '"'; $query .= ($type == NULL) ? '' : (' and (' . self :: DATASET_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: DATASET_LANGUAGE . ' exact "' . $language . '")'); $query .= ($funder == NULL) ? '' : (' and (' . self :: DATASET_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: DATASET_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: DATASET_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($year == NULL) ? '' : (' and (' . self :: DATASET_YEAR . ' exact ' . $year . ')'); $query .= ($accessMode == NULL) ? '' : (' and (' . self :: DATASET_ACCESS_MODE . ' exact "' . $accessMode . '")'); $query .= ($datasource == NULL) ? '' : (' and (' . self :: DATASET_DATASOURCE . ' exact "' . $datasource . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: DATASET_TYPE . '&fields=' . self :: DATASET_LANGUAGE . '&fields=' . self :: DATASET_FUNDER . '&fields=' . self :: DATASET_FUNDING_STREAM . '&fields=' . self :: DATASET_SCIENTIFIC_AREA . '&fields=' . self :: DATASET_YEAR . '&fields=' . self :: DATASET_ACCESS_MODE . '&fields=' . self :: DATASET_DATASOURCE . '&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); $result = new JObject(); $result -> totalDatasets = $this -> parseTotalResults($xpath); $result -> datasets = $this -> parseDatasets($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource'), array('DATASET_TYPE', 'DATASET_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE'), array('NO_DATASET_TYPE_STATISTICS_FOUND', 'NO_DATASET_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_PUBLICATION_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: DATASET_TYPE, self :: DATASET_LANGUAGE, self :: DATASET_FUNDER, self :: DATASET_FUNDING_STREAM, self :: DATASET_SCIENTIFIC_AREA, self :: DATASET_YEAR, self :: DATASET_ACCESS_MODE, self :: DATASET_DATASOURCE)); JLog :: add('Simple search retrieved ' . count($result -> datasets) . ' datasets in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing dataset simple search (keyword: ' . $keyword . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for projects. // $keyword the keyword to search for // $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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to suse as filter or NULL for no end year filtering // $sc39 the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics private function _searchProjects($keyword, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY; $query .= ($keyword == NULL) ? '' : ' and ((' . self :: PROJECT_ACRONYM . ' = "' . str_replace('"', '\\"', $keyword) . '") or (' . self :: PROJECT_CODE . ' = "' . str_replace('"', '\\"', $keyword) . '") or (' . self :: PROJECT_TITLE . ' = "' . str_replace('"', '\\"', $keyword) . '"))'; $query .= ($funder == NULL) ? '' : (' and (' . self :: PROJECT_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PROJECT_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PROJECT_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($startYear == NULL) ? '' : (' and (' . self :: PROJECT_START_YEAR . ' exact ' . $startYear . ')'); $query .= ($endYear == NULL) ? '' : (' and (' . self :: PROJECT_END_YEAR . ' exact ' . $endYear . ')'); $query .= ($sc39 === NULL) ? '' : (' and (' . self :: PROJECT_SC39 . ' exact ' . ($sc39 ? 'true' : 'false') . ')'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=projects_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PROJECT_FUNDER . '&fields=' . self :: PROJECT_FUNDING_STREAM . '&fields=' . self :: PROJECT_SCIENTIFIC_AREA . '&fields=' . self :: PROJECT_START_YEAR . '&fields=' . self :: PROJECT_END_YEAR . '&fields=' . self :: PROJECT_SC39 . '&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); $result = new JObject(); $result -> totalProjects = $this -> parseTotalResults($xpath); $result -> projects = $this -> parseProjects($xpath); $result -> statistics = $this -> createStatistics($xpath, array('funder', 'fundingStream', 'scientificArea', 'startYear', 'endYear', 'sc39'), array('FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'START_YEAR', 'END_YEAR', 'SPECIAL_CLAUSE_39'), array('NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_START_YEAR_STATISTICS_FOUND', 'NO_END_YEAR_STATISTICS_FOUND', 'NO_SPECIAL_CLAUSE_39_STATISTICS_FOUND'), array(self :: PROJECT_FUNDER, self :: PROJECT_FUNDING_STREAM, self :: PROJECT_SCIENTIFIC_AREA, self :: PROJECT_START_YEAR, self :: PROJECT_END_YEAR, self :: PROJECT_SC39)); JLog :: add('Simple search retrieved ' . count($result -> projects) . ' projects in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing project simple search (keyword: ' . $keyword . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for people. // $keyword the keyword to search for // $country the country to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics private function _searchPeople($keyword, $country, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PERSON_QUERY; $query .= ($keyword == NULL) ? '' : ' and "' . str_replace('"', '\\"', $keyword) . '"'; $query .= ($country == NULL) ? '' : (' and ('. self :: PERSON_COUNTRY . ' exact "' . $country . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=persons_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PERSON_COUNTRY . '&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); $result = new JObject(); $result -> totalPeople = $this -> parseTotalResults($xpath); $result -> people = $this -> parsePeople($xpath); $result -> statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: PERSON_COUNTRY)); JLog :: add('Simple search retrieved ' . count($result -> people) . ' people in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing people simple search (keyword: ' . $keyword . ', country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for organizations. // $keyword the keyword to search for // $country the ID of the country to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics private function _searchOrganizations($keyword, $country, $type, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY; $query .= ($keyword == NULL) ? '' : (' and "' . str_replace('"', '\\"', $keyword) . '"'); $query .= ($country == NULL) ? '' : (' and ('. self :: ORGANIZATION_COUNTRY . ' exact "' . $country . '")'); switch ($type) { case 'legalBody': $query .= ' and (' . self :: ORGANIZATION_LEGAL_BODY . ' exact true)'; break; case 'legalPerson': $query .= ' and (' . self :: ORGANIZATION_LEGAL_PERSON . ' exact true)'; break; case 'nonProfit': $query .= ' and (' . self :: ORGANIZATION_NON_PROFIT . ' exact true)'; break; case 'research': $query .= ' and (' . self :: ORGANIZATION_RESEARCH . ' exact true)'; break; case 'euInterests': $query .= ' and (' . self :: ORGANIZATION_EU_INTERESTS . ' exact true)'; break; case 'international': $query .= ' and (' . self :: ORGANIZATION_INTERNATIONAL . ' exact true)'; break; case 'enterprise': $query .= ' and (' . self :: ORGANIZATION_ENTERPRISE . ' exact true)'; break; case 'smallMediumEnterprise': $query .= ' and (' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . ' exact true)'; } JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=organizations_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: ORGANIZATION_COUNTRY . '&fields=' . self :: ORGANIZATION_LEGAL_BODY . '&fields=' . self :: ORGANIZATION_LEGAL_PERSON . '&fields=' . self :: ORGANIZATION_NON_PROFIT . '&fields=' . self :: ORGANIZATION_RESEARCH . '&fields=' . self :: ORGANIZATION_EU_INTERESTS . '&fields=' . self :: ORGANIZATION_INTERNATIONAL . '&fields=' . self :: ORGANIZATION_ENTERPRISE . '&fields=' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . '&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); $result = new JObject(); $result -> totalOrganizations = $this -> parseTotalResults($xpath); $result -> organizations = $this -> parseOrganizations($xpath); $result -> statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: ORGANIZATION_COUNTRY)); $result -> statistics['type'] = new JObject(); $result -> statistics['type'] -> id = 'type'; $result -> statistics['type'] -> title = JText :: _('ORGANIZATION_TYPE'); $result -> statistics['type'] -> error = JText :: _('NO_ORGANIZATION_TYPE_STATISTICS_FOUND'); $result -> statistics['type'] -> data = array(); $legalBody = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_BODY); if (($legalBody != NULL) && array_key_exists('true', $legalBody)) { $result -> statistics['type'] -> data['legalBody'] = new JObject(); $result -> statistics['type'] -> data['legalBody'] -> id = 'legalBody'; $result -> statistics['type'] -> data['legalBody'] -> name = JText :: _('LEGAL_BODY'); $result -> statistics['type'] -> data['legalBody'] -> count = $legalBody['true'] -> count; } $legalPerson = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_PERSON); if (($legalPerson != NULL) && array_key_exists('true', $legalPerson)) { $result -> statistics['type'] -> data['legalPerson'] = new JObject(); $result -> statistics['type'] -> data['legalPerson'] -> id = 'legalPerson'; $result -> statistics['type'] -> data['legalPerson'] -> name = JText :: _('LEGAL_PERSON'); $result -> statistics['type'] -> data['legalPerson'] -> count = $legalPerson['true'] -> count; } $nonProfit = $this -> parseStatistics($xpath, self :: ORGANIZATION_NON_PROFIT); if (($nonProfit != NULL) && array_key_exists('true', $nonProfit)) { $result -> statistics['type'] -> data['nonProfit'] = new JObject(); $result -> statistics['type'] -> data['nonProfit'] -> id = 'nonProfit'; $result -> statistics['type'] -> data['nonProfit'] -> name = JText :: _('NON_PROFIT_ORGANIZATION'); $result -> statistics['type'] -> data['nonProfit'] -> count = $nonProfit['true'] -> count; } $research = $this -> parseStatistics($xpath, self :: ORGANIZATION_RESEARCH); if (($research != NULL) && array_key_exists('true', $research)) { $result -> statistics['type'] -> data['research'] = new JObject(); $result -> statistics['type'] -> data['research'] -> id = 'research'; $result -> statistics['type'] -> data['research'] -> name = JText :: _('RESEARCH_ORGANIZATION'); $result -> statistics['type'] -> data['research'] -> count = $research['true'] -> count; } $euInterests = $this -> parseStatistics($xpath, self :: ORGANIZATION_EU_INTERESTS); if (($euInterests != NULL) && array_key_exists('true', $euInterests)) { $result -> statistics['type'] -> data['euInterests'] = new JObject(); $result -> statistics['type'] -> data['euInterests'] -> id = 'euInterests'; $result -> statistics['type'] -> data['euInterests'] -> name = JText :: _('EU_INTERESTS_ORGANIZATION'); $result -> statistics['type'] -> data['euInterests'] -> count = $euInterests['true'] -> count; } $international = $this -> parseStatistics($xpath, self :: ORGANIZATION_INTERNATIONAL); if (($international != NULL) && array_key_exists('true', $international)) { $result -> statistics['type'] -> data['international'] = new JObject(); $result -> statistics['type'] -> data['international'] -> id = 'international'; $result -> statistics['type'] -> data['international'] -> name = JText :: _('INTERNATIONAL_ORGANIZATION'); $result -> statistics['type'] -> data['international'] -> count = $international['true'] -> count; } $enterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_ENTERPRISE); if (($enterprise != NULL) && array_key_exists('true', $enterprise)) { $result -> statistics['type'] -> data['enterprise'] = new JObject(); $result -> statistics['type'] -> data['enterprise'] -> id = 'enterprise'; $result -> statistics['type'] -> data['enterprise'] -> name = JText :: _('ENTERPRISE'); $result -> statistics['type'] -> data['enterprise'] -> count = $enterprise['true'] -> count; } $smallMediumEnterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE); if (($smallMediumEnterprise != NULL) && array_key_exists('true', $smallMediumEnterprise)) { $result -> statistics['type'] -> data['smallMediumEnterprise'] = new JObject(); $result -> statistics['type'] -> data['smallMediumEnterprise'] -> id = 'smallMediumEnterprise'; $result -> statistics['type'] -> data['smallMediumEnterprise'] -> name = JText :: _('SMALL_MEDIUM_ENTERPRISE'); $result -> statistics['type'] -> data['smallMediumEnterprise'] -> count = $smallMediumEnterprise['true'] -> count; } uasort($result -> statistics['type'] -> data, function ($row1, $row2) {return $row2 -> count - $row1 -> count;}); JLog :: add('Simple search retrieved ' . count($result -> organizations) . ' organizations in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing organization simple search (keyword: ' . $keyword . ', country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a simple search for datasources. // $keyword the keyword to search for // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language the ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no project filtering // $compatibility the ID of the compatibility level to use as filter or NULL for no compatibility level filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics private function _searchDatasources($keyword, $type, $language, $content, $compatibility, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY; $query .= ($keyword == NULL) ? '' : (' and "' . str_replace('"', '\\"', $keyword) . '"'); $query .= ($type == NULL) ? '' : (' and ('. self :: DATASOURCE_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and ('. self :: DATASOURCE_LANGUAGE . ' exact "' . $language . '")'); $query .= ($content == NULL) ? '' : (' and ('. self :: DATASOURCE_CONTENT . ' exact "' . $content . '")'); $query .= ($compatibility == NULL) ? '' : (' and ('. self :: DATASOURCE_COMPATIBILITY . ' exact "' . $compatibility . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=datasources_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: DATASOURCE_TYPE . '&fields=' . self :: DATASOURCE_LANGUAGE . '&fields=' . self :: DATASOURCE_CONTENT . '&fields=' . self :: DATASOURCE_COMPATIBILITY . '&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); $result = new JObject(); $result -> totalDatasources = $this -> parseTotalResults($xpath); $result -> datasources = $this -> parseDatasources($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'language', 'content', 'compatibility'), array('DATASOURCE_TYPE', 'DATASOURCE_LANGUAGE', 'CONTENT', 'COMPATIBILITY'), array('NO_DATASOURCE_TYPE_STATISTICS_FOUND', 'NO_DATASOURCE_LANGUAGE_STATISTICS_FOUND', 'NO_CONTENT_STATISTICS_FOUND', 'NO_COMPATIBILITY_STATISTICS_FOUND'), array(self :: DATASOURCE_TYPE, self :: DATASOURCE_LANGUAGE, self :: DATASOURCE_CONTENT, self :: DATASOURCE_COMPATIBILITY)); JLog :: add('Simple search retrieved ' . count($result -> datasources) . ' datasources in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing datasource simple search (keyword: ' . $keyword . ', type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for publications. // $type the ID of the publication type to use as filter or NULL for no publication 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 fundingStream 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 // $community the ID of the community 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 publications and statistics private function _browsePublications($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $community, $page, $size, $locale, $project, $author) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY; $query .= ($type == NULL) ? '' : (' and (' . self :: PUBLICATION_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: PUBLICATION_LANGUAGE . ' exact "' . $language . '")'); $query .= ($funder == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PUBLICATION_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($year == NULL) ? '' : (' and (' . self :: PUBLICATION_YEAR . ' exact ' . $year . ')'); $query .= ($accessMode == NULL) ? '' : (' and (' . self :: PUBLICATION_ACCESS_MODE . ' exact "' . $accessMode . '")'); $query .= ($datasource == NULL) ? '' : (' and (' . self :: PUBLICATION_DATASOURCE . ' exact "' . $datasource . '")'); $query .= ($project == NULL) ? '' : (' and (' . self :: PUBLICATION_PROJECT . ' exact "' . $project . '")'); $query .= ($author == NULL) ? '' : (' and (' . self :: PUBLICATION_AUTHOR_ID . ' exact "' . $author . '")'); $query .= ($community == NULL) ? '' : (' and (' . self :: PUBLICATION_CONTEXT . ' exact "' . $community . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PUBLICATION_TYPE . '&fields=' . self :: PUBLICATION_LANGUAGE . '&fields=' . self :: PUBLICATION_FUNDER . '&fields=' . self :: PUBLICATION_FUNDING_STREAM . '&fields=' . self :: PUBLICATION_SCIENTIFIC_AREA . '&fields=' . self :: PUBLICATION_YEAR . '&fields=' . self :: PUBLICATION_ACCESS_MODE . '&fields=' . self :: PUBLICATION_DATASOURCE . '&fields=' . self :: PUBLICATION_CONTEXT . '&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); $result = new JObject(); $result -> totalPublications = $this -> parseTotalResults($xpath); $result -> publications = $this -> parsePublications($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource', 'community'), array('DOCUMENT_TYPE', 'DOCUMENT_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE', 'COMMUNITY'), array('NO_DOCUMENT_TYPE_STATISTICS_FOUND', 'NO_DOCUMENT_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_CONTEXT_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: PUBLICATION_TYPE, self :: PUBLICATION_LANGUAGE, self :: PUBLICATION_FUNDER, self :: PUBLICATION_FUNDING_STREAM, self :: PUBLICATION_SCIENTIFIC_AREA, self :: PUBLICATION_YEAR, self :: PUBLICATION_ACCESS_MODE, self :: PUBLICATION_DATASOURCE, self :: PUBLICATION_CONTEXT)); JLog :: add('Browse retrieved ' . count($result -> publications) . ' publications in ' . (microtime(TRUE) - $time) . ' s (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', community: ' . (($community == NULL) ? 'null' : $community) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ', project: ' . (($project == NULL) ? 'null' : $project) . ', author: ' . (($author == NULL) ? 'null' : $author) . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing publication browse (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', community: ' . (($community == NULL) ? 'null' : $community) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ', project: ' . (($project == NULL) ? 'null' : $project) . ', author: ' . (($author == NULL) ? 'null' : $author) . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for datasets. // $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 fundingStream 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 private function _browseDatasets($type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale, $project, $author) { try { $time = microtime(TRUE); $query = self :: DATASET_QUERY; $query .= ($type == NULL) ? '' : (' and (' . self :: DATASET_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: DATASET_LANGUAGE . ' exact "' . $language . '")'); $query .= ($funder == NULL) ? '' : (' and (' . self :: DATASET_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: DATASET_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: DATASET_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($year == NULL) ? '' : (' and (' . self :: DATASET_YEAR . ' exact ' . $year . ')'); $query .= ($accessMode == NULL) ? '' : (' and (' . self :: DATASET_ACCESS_MODE . ' exact "' . $accessMode . '")'); $query .= ($datasource == NULL) ? '' : (' and (' . self :: DATASET_DATASOURCE . ' exact "' . $datasource . '")'); $query .= ($project == NULL) ? '' : (' and (' . self :: DATASET_PROJECT . ' exact "' . $project . '")'); $query .= ($author == NULL) ? '' : (' and (' . self :: DATASET_AUTHOR_ID . ' exact "' . $author . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: DATASET_TYPE . '&fields=' . self :: DATASET_LANGUAGE . '&fields=' . self :: DATASET_FUNDER . '&fields=' . self :: DATASET_FUNDING_STREAM . '&fields=' . self :: DATASET_SCIENTIFIC_AREA . '&fields=' . self :: DATASET_YEAR . '&fields=' . self :: DATASET_ACCESS_MODE . '&fields=' . self :: DATASET_DATASOURCE . '&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); $result = new JObject(); $result -> totalDatasets = $this -> parseTotalResults($xpath); $result -> datasets = $this -> parseDatasets($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'funder', 'fundingStream', 'scientificArea', 'year', 'accessMode', 'datasource'), array('DATASET_TYPE', 'DATASET_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE'), array('NO_DATASET_TYPE_STATISTICS_FOUND', 'NO_DATASET_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: DATASET_TYPE, self :: DATASET_LANGUAGE, self :: DATASET_FUNDER, self :: DATASET_FUNDING_STREAM, self :: DATASET_SCIENTIFIC_AREA, self :: DATASET_YEAR, self :: DATASET_ACCESS_MODE, self :: DATASET_DATASOURCE)); JLog :: add('Browse retrieved ' . count($result -> datasets) . ' datasets in ' . (microtime(TRUE) - $time) . ' s (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ', project: ' . (($project == NULL) ? 'null' : $project) . ', author: ' . (($author == NULL) ? 'null' : $author) . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing dataset browse (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ', project: ' . (($project == NULL) ? 'null' : $project) . ', author: ' . (($author == NULL) ? 'null' : $author) . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for projects. // $funder the ID of the funder to use as filter or NULL for no funder filtering // $fundingStream the ID of the fundingStream 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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to use as filter or NULL for no end year filtering // $$sc39 the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics private function _browseProjects($funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY; $query .= ($funder == NULL) ? '' : (' and (' . self :: PROJECT_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PROJECT_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PROJECT_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($startYear == NULL) ? '' : (' and (' . self :: PROJECT_START_YEAR . ' exact ' . $startYear . ')'); $query .= ($endYear == NULL) ? '' : (' and (' . self :: PROJECT_END_YEAR . ' exact ' . $endYear . ')'); $query .= ($sc39 === NULL) ? '' : (' and (' . self :: PROJECT_SC39 . ' exact ' . ($sc39 ? 'true' : 'false') . ')'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=projects_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PROJECT_FUNDER . '&fields=' . self :: PROJECT_FUNDING_STREAM . '&fields=' . self :: PROJECT_SCIENTIFIC_AREA . '&fields=' . self :: PROJECT_START_YEAR . '&fields=' . self :: PROJECT_END_YEAR . '&fields=' . self :: PROJECT_SC39 . '&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); $result = new JObject(); $result -> totalProjects = $this -> parseTotalResults($xpath); $result -> projects = $this -> parseProjects($xpath); $result -> statistics = $this -> createStatistics($xpath, array('funder', 'fundingStream', 'scientificArea', 'startYear', 'endYear', 'sc39'), array('FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'START_YEAR', 'END_YEAR', 'SPECIAL_CLAUSE_39'), array('NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_START_YEAR_STATISTICS_FOUND', 'NO_END_YEAR_STATISTICS_FOUND', 'NO_SPECIAL_CLAUSE_39_STATISTICS_FOUND'), array(self :: PROJECT_FUNDER, self :: PROJECT_FUNDING_STREAM, self :: PROJECT_SCIENTIFIC_AREA, self :: PROJECT_START_YEAR, self :: PROJECT_END_YEAR, self :: PROJECT_SC39)); JLog :: add('Browse retrieved ' . count($result -> projects) . ' projects in ' . (microtime(TRUE) - $time) . ' s (funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing project browse (funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for people. // $country the ID of the country to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics private function _browsePeople($country, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PERSON_QUERY; $query .= ($country == NULL) ? '' : (' and ('. self :: PERSON_COUNTRY . ' exact "' . $country . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=persons_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PERSON_COUNTRY . '&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); $result = new JObject(); $result -> totalPeople = $this -> parseTotalResults($xpath); $result -> people = $this -> parsePeople($xpath); $result -> statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: PERSON_COUNTRY)); JLog :: add('Browse retrieved ' . count($result -> people) . ' people in ' . (microtime(TRUE) - $time) . ' s (country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing people browse (country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for organizations. // $country the ID of the country to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing organizations and statistics private function _browseOrganizations($country, $type, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY; $query .= ($country == NULL) ? '' : (' and ('. self :: ORGANIZATION_COUNTRY . ' exact "' . $country . '")'); switch ($type) { case 'legalBody': $query .= ' and (' . self :: ORGANIZATION_LEGAL_BODY . ' exact true)'; break; case 'legalPerson': $query .= ' and (' . self :: ORGANIZATION_LEGAL_PERSON . ' exact true)'; break; case 'nonProfit': $query .= ' and (' . self :: ORGANIZATION_NON_PROFIT . ' exact true)'; break; case 'research': $query .= ' and (' . self :: ORGANIZATION_RESEARCH . ' exact true)'; break; case 'euInterests': $query .= ' and (' . self :: ORGANIZATION_EU_INTERESTS . ' exact true)'; break; case 'international': $query .= ' and (' . self :: ORGANIZATION_INTERNATIONAL . ' exact true)'; break; case 'enterprise': $query .= ' and (' . self :: ORGANIZATION_ENTERPRISE . ' exact true)'; break; case 'smallMediumEnterprise': $query .= ' and (' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . ' exact true)'; } JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=organizations_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: ORGANIZATION_COUNTRY . '&fields=' . self :: ORGANIZATION_LEGAL_BODY . '&fields=' . self :: ORGANIZATION_LEGAL_PERSON . '&fields=' . self :: ORGANIZATION_NON_PROFIT . '&fields=' . self :: ORGANIZATION_RESEARCH . '&fields=' . self :: ORGANIZATION_EU_INTERESTS . '&fields=' . self :: ORGANIZATION_INTERNATIONAL . '&fields=' . self :: ORGANIZATION_ENTERPRISE . '&fields=' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . '&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); $result = new JObject(); $result -> totalOrganizations = $this -> parseTotalResults($xpath); $result -> organizations = $this -> parseOrganizations($xpath); $result -> statistics = $this -> createStatistics($xpath, array('country'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: ORGANIZATION_COUNTRY)); $result -> statistics['type'] = new JObject(); $result -> statistics['type'] -> id = 'type'; $result -> statistics['type'] -> title = JText :: _('ORGANIZATION_TYPE'); $result -> statistics['type'] -> error = JText :: _('NO_ORGANIZATION_TYPE_STATISTICS_FOUND'); $result -> statistics['type'] -> data = array(); $legalBody = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_BODY); if (($legalBody != NULL) && array_key_exists('true', $legalBody)) { $result -> statistics['type'] -> data['legalBody'] = new JObject(); $result -> statistics['type'] -> data['legalBody'] -> id = 'legalBody'; $result -> statistics['type'] -> data['legalBody'] -> name = JText :: _('LEGAL_BODY'); $result -> statistics['type'] -> data['legalBody'] -> count = $legalBody['true'] -> count; } $legalPerson = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_PERSON); if (($legalPerson != NULL) && array_key_exists('true', $legalPerson)) { $result -> statistics['type'] -> data['legalPerson'] = new JObject(); $result -> statistics['type'] -> data['legalPerson'] -> id = 'legalPerson'; $result -> statistics['type'] -> data['legalPerson'] -> name = JText :: _('LEGAL_PERSON'); $result -> statistics['type'] -> data['legalPerson'] -> count = $legalPerson['true'] -> count; } $nonProfit = $this -> parseStatistics($xpath, self :: ORGANIZATION_NON_PROFIT); if (($nonProfit != NULL) && array_key_exists('true', $nonProfit)) { $result -> statistics['type'] -> data['nonProfit'] = new JObject(); $result -> statistics['type'] -> data['nonProfit'] -> id = 'nonProfit'; $result -> statistics['type'] -> data['nonProfit'] -> name = JText :: _('NON_PROFIT_ORGANIZATION'); $result -> statistics['type'] -> data['nonProfit'] -> count = $nonProfit['true'] -> count; } $research = $this -> parseStatistics($xpath, self :: ORGANIZATION_RESEARCH); if (($research != NULL) && array_key_exists('true', $research)) { $result -> statistics['type'] -> data['research'] = new JObject(); $result -> statistics['type'] -> data['research'] -> id = 'research'; $result -> statistics['type'] -> data['research'] -> name = JText :: _('RESEARCH_ORGANIZATION'); $result -> statistics['type'] -> data['research'] -> count = $research['true'] -> count; } $euInterests = $this -> parseStatistics($xpath, self :: ORGANIZATION_EU_INTERESTS); if (($euInterests != NULL) && array_key_exists('true', $euInterests)) { $result -> statistics['type'] -> data['euInterests'] = new JObject(); $result -> statistics['type'] -> data['euInterests'] -> id = 'euInterests'; $result -> statistics['type'] -> data['euInterests'] -> name = JText :: _('EU_INTERESTS_ORGANIZATION'); $result -> statistics['type'] -> data['euInterests'] -> count = $euInterests['true'] -> count; } $international = $this -> parseStatistics($xpath, self :: ORGANIZATION_INTERNATIONAL); if (($international != NULL) && array_key_exists('true', $international)) { $result -> statistics['type'] -> data['international'] = new JObject(); $result -> statistics['type'] -> data['international'] -> id = 'international'; $result -> statistics['type'] -> data['international'] -> name = JText :: _('INTERNATIONAL_ORGANIZATION'); $result -> statistics['type'] -> data['international'] -> count = $international['true'] -> count; } $enterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_ENTERPRISE); if (($enterprise != NULL) && array_key_exists('true', $enterprise)) { $result -> statistics['type'] -> data['enterprise'] = new JObject(); $result -> statistics['type'] -> data['enterprise'] -> id = 'enterprise'; $result -> statistics['type'] -> data['enterprise'] -> name = JText :: _('ENTERPRISE'); $result -> statistics['type'] -> data['enterprise'] -> count = $enterprise['true'] -> count; } $smallMediumEnterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE); if (($smallMediumEnterprise != NULL) && array_key_exists('true', $smallMediumEnterprise)) { $result -> statistics['type'] -> data['smallMediumEnterprise'] = new JObject(); $result -> statistics['type'] -> data['smallMediumEnterprise'] -> id = 'smallMediumEnterprise'; $result -> statistics['type'] -> data['smallMediumEnterprise'] -> name = JText :: _('SMALL_MEDIUM_ENTERPRISE'); $result -> statistics['type'] -> data['smallMediumEnterprise'] -> count = $smallMediumEnterprise['true'] -> count; } uasort($result -> statistics['type'] -> data, function ($row1, $row2) {return $row2 -> count - $row1 -> count;}); JLog :: add('Browse retrieved ' . count($result -> organizations) . ' organizations in ' . (microtime(TRUE) - $time) . ' s (country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing organization browse (country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a browse for datasources. // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language the ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no content filtering // $compatibility the ID of the compatibility level to use as filter or NULL for no compatibility status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics private function _browseDatasources($type, $language, $content, $compatibility, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY; $query .= ($type == NULL) ? '' : (' and ('. self :: DATASOURCE_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and ('. self :: DATASOURCE_LANGUAGE . ' exact "' . $language . '")'); $query .= ($content == NULL) ? '' : (' and ('. self :: DATASOURCE_CONTENT . ' exact "' . $content . '")'); $query .= ($compatibility == NULL) ? '' : (' and ('. self :: DATASOURCE_COMPATIBILITY . ' exact "' . $compatibility . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=datasources_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: DATASOURCE_TYPE . '&fields=' . self :: DATASOURCE_LANGUAGE . '&fields=' . self :: DATASOURCE_CONTENT . '&fields=' . self :: DATASOURCE_COMPATIBILITY . '&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); $result = new JObject(); $result -> totalDatasources = $this -> parseTotalResults($xpath); $result -> datasources = $this -> parseDatasources($xpath); $result -> statistics = $this -> createStatistics($xpath, array('type', 'languageFilter', 'content', 'compatibility'), array('DATASOURCE_TYPE', 'DATASOURCE_LANGUAGE', 'CONTENT', 'COMPATIBILITY'), array('NO_DATASOURCE_TYPE_STATISTICS_FOUND', 'NO_DATASOURCE_LANGUAGE_STATISTICS_FOUND', 'NO_CONTENT_STATISTICS_FOUND', 'NO_COMPATIBILITY_STATISTICS_FOUND'), array(self :: DATASOURCE_TYPE, self :: DATASOURCE_LANGUAGE, self :: DATASOURCE_CONTENT, self :: DATASOURCE_COMPATIBILITY)); JLog :: add('Browse retrieved ' . count($result -> datasources) . ' datasources in ' . (microtime(TRUE) - $time) . ' s (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing datasource browse (type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform an advanced search for publications. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are TITLE, AUTHOR, PUBLISHER and SUBJECT) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $types the IDs of the publication types to search for // $languages the IDs of the publication languages to search for // $funders the IDs of the funders to search for // $fundingStreams the IDs of the funding streams to search for // $scientificAreas the IDs of the scientific areas to search for // $date the publication date range to search for expressed in months before current date (if -1 search for any publication date, if 0 search explicitly using $fromMonth, $fromYear, $toMonth and $toYear) // $fromMonth start month of the publication date range to search for if $date has value 0 // $fromYear start year of the publication date range to search for if $date has value 0 // $toMonth end month of the publication date range to search for if $date has value 0 // $toYear end year of the publication date range to search for if $date has value 0 // $accessModes the IDs of the access modes to search for // $datasources the IDs of the datasources to search for // $type the ID of the publication type to use as filter or NULL for no publication type filtering // $language the ID of the publication language to use as filter or NULL for no publication 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 publication year to use as filter or NULL for no publication 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 // return a result (object) containing publications and statistics private function _advancedSearchPublications($keywords, $fields, $constraints, $types, $languages, $funders, $fundingStreams, $scientificAreas, $date, $fromMonth, $fromYear, $toMonth, $toYear, $accessModes, $datasources, $type, $language, $funder, $fundingStream, $scientificArea, $year, $accessMode, $datasource, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY; for ($i = 0; ($i < count($keywords)) && ($i < count($fields)) && ($i < count($constraints)); $i++) { $tokens = preg_split('/\s/', $keywords[$i], NULL, PREG_SPLIT_NO_EMPTY); switch ($constraints[$i]) { case OpenAireViewAdvancedSearchPublications :: ALL: $operator = ' and '; break; case OpenAireViewAdvancedSearchPublications :: ANY: $operator = ' or '; break; default: $operator = NULL; } switch ($fields[$i]) { case OpenAireViewAdvancedSearchPublications :: TITLE: $field = self :: PUBLICATION_TITLE; break; case OpenAireViewAdvancedSearchPublications :: AUTHOR: $field = self :: PUBLICATION_AUTHOR; break; case OpenAireViewAdvancedSearchPublications :: PUBLISHER: $field = self :: PUBLICATION_PUBLISHER; break; case OpenAireViewAdvancedSearchPublications :: SUBJECT: $field = self :: PUBLICATION_SUBJECT; break; default: $field = NULL; } $query .= ($tokens == NULL) ? '' : (' and (' . implode($operator, array_map(function ($keyword) use ($field) {return '(' . (($field == NULL) ? '' : ($field . ' = ')) . '"' . str_replace('"', '\\"', $keyword) . '")';}, $tokens)) . ')'); } $field = self :: PUBLICATION_TYPE; $query .= ($types == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($type) use ($field) {return '(' . $field . ' exact "' . $type . '")';}, $types)) . ')'); $field = self :: PUBLICATION_LANGUAGE; $query .= ($languages == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($language) use ($field) {return '(' . $field . ' exact "' . $language . '")';}, $languages)) . ')'); $field = self :: PUBLICATION_FUNDER; $query .= ($funders == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($funder) use ($field) {return '(' . $field . ' exact "' . $funder . '")';}, $funders)) . ')'); $field = self :: PUBLICATION_FUNDING_STREAM; $query .= ($fundingStreams == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($fundingStream) use ($field) {return '(' . $field . ' exact "' . $fundingStream . '")';}, $fundingStreams)) . ')'); $field = self :: PUBLICATION_SCIENTIFIC_AREA; $query .= ($scientificAreas == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($scientificArea) use ($field) {return '(' . $field . ' exact "' . $scientificArea . '")';}, $scientificAreas)) . ')'); $from = new DateTime(); $to = new DateTime(); switch ($date) { case -1: break; case 0: $from -> setDate($fromYear, $fromMonth, 1); $to -> setDate($toYear, $toMonth, 1); $to -> setDate($toYear, $toMonth, date('t', $to -> getTimestamp())); // update to with the last day of that month $query .= ' and (' . self :: PUBLICATION_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; break; default: $from -> sub(new DateInterval('P' . $date . 'M')); $query .= ' and (' . self :: PUBLICATION_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; } $field = self :: PUBLICATION_ACCESS_MODE; $query .= ($accessModes == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($accessMode) use ($field) {return '(' . $field . ' exact "' . $accessMode . '")';}, $accessModes)) . ')'); $field = self :: PUBLICATION_DATASOURCE; $query .= ($datasources == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($datasource) use ($field) {return '(' . $field . ' exact "' . $datasource . '")';}, $datasources)) . ')'); $query .= ($type == NULL) ? '' : (' and (' . self :: PUBLICATION_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: PUBLICATION_LANGUAGE . ' exact "' . $language . '")'); $query .= ($funder == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PUBLICATION_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PUBLICATION_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($year == NULL) ? '' : (' and (' . self :: PUBLICATION_YEAR . ' exact "' . $year . '")'); $query .= ($accessMode == NULL) ? '' : (' and (' . self :: PUBLICATION_ACCESS_MODE . ' exact "' . $accessMode . '")'); $query .= ($datasource == NULL) ? '' : (' and (' . self :: PUBLICATION_DATASOURCE . ' exact "' . $datasource . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PUBLICATION_TYPE . '&fields=' . self :: PUBLICATION_LANGUAGE . '&fields=' . self :: PUBLICATION_FUNDER . '&fields=' . self :: PUBLICATION_FUNDING_STREAM . '&fields=' . self :: PUBLICATION_SCIENTIFIC_AREA . '&fields=' . self :: PUBLICATION_YEAR . '&fields=' . self :: PUBLICATION_ACCESS_MODE . '&fields=' . self :: PUBLICATION_DATASOURCE . '&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); $result = new JObject(); $result -> totalPublications = $this -> parseTotalResults($xpath); $result -> publications = $this -> parsePublications($xpath); $result -> statistics = $this -> createStatistics($xpath, array('typeFilter', 'languageFilter', 'funderFilter', 'fundingStreamFilter', 'scientificAreaFilter', 'yearFilter', 'accessModeFilter', 'datasourceFilter'), array('DOCUMENT_TYPE', 'DOCUMENT_LANGUAGE', 'FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'PUBLICATION_YEAR', 'ACCESS_MODE', 'DATASOURCE'), array('NO_DOCUMENT_TYPE_STATISTICS_FOUND', 'NO_DOCUMENT_LANGUAGE_STATISTICS_FOUND', 'NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_PUBLICATION_YEAR_STATISTICS_FOUND', 'NO_ACCESS_MODE_STATISTICS_FOUND', 'NO_DATASOURCE_STATISTICS_FOUND'), array(self :: PUBLICATION_TYPE, self :: PUBLICATION_LANGUAGE, self :: PUBLICATION_FUNDER, self :: PUBLICATION_FUNDING_STREAM, self :: PUBLICATION_SCIENTIFIC_AREA, self :: PUBLICATION_YEAR, self :: PUBLICATION_ACCESS_MODE, self :: PUBLICATION_DATASOURCE)); JLog :: add('Advanced search retrieved ' . count($result -> publications) . ' publications in ' . (microtime(TRUE) - $time) . ' s (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], types: [' . implode(', ', $types) . '], languages: [' . implode(', ', $languages) . '], funders: [' . implode(', ', $funders) . '], funding streams: [' . implode(', ', $fundingStreams) . '], scientific areas: [' . implode(', ', $scientificAreas) . '], date: ' . $date . ', from month: ' . $fromMonth . ', from year: ' . $fromYear . ', to month: ' . $toMonth . ', to year: ' . $toYear . ', access modes: [' . implode(', ', $accessModes) . '], datasources: [' . implode(', ', $datasources) . '], type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing publication advanced search (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], types: [' . implode(', ', $types) . '], languages: [' . implode(', ', $languages) . '], funders: [' . implode(', ', $funders) . '], funding streams: [' . implode(', ', $fundingStreams) . '], scientific areas: [' . implode(', ', $scientificAreas) . '], date: ' . $date . ', from month: ' . $fromMonth . ', from year: ' . $fromYear . ', to month: ' . $toMonth . ', to year: ' . $toYear . ', access modes: [' . implode(', ', $accessModes) . '], datasources: [' . implode(', ', $datasources) . '], type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', year: ' . (($year == NULL) ? 'null' : $year) . ', access mode: ' . (($accessMode == NULL) ? 'null' : $accessMode) . ', datasource: ' . (($datasource == NULL) ? 'null' : $datasource) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform an advanced search for projects. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are ACRONYM, TITLE and KEYWORDS) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $funders the IDs of the funders to search for // $fundingStreams the IDs of the funding streams to search for // $scientificAreas the IDs of the scientific areas to search for // $startDate the start date range to search for expressed in months before current date (if -1 search for any start date, if 0 search explicitly using $startFromMonth, $startFromYear, $startToMonth and $startToYear) // $startFromMonth start month of the start date range to search for if $startDate has value 0 // $startFromYear start year of the start date range to search for if $startDate has value 0 // $startToMonth end month of the start date range to search for if $startDate has value 0 // $startToYear end year of the start date range to search for if $startDate has value 0 // $endDate the end date range to search for expressed in months brefore current date (if -1 search for any end date, if 0 search explicitly using $endFromMonth, $endFromYear, $endToMonth and $endToYear) // $endFromMonth start month of the end date range to search for if $endDate has value 0 // $endFromYear start year of the end date range to search for if $endDate has value 0 // $endToMonth end month of the end date range to search for if $endDate has value 0 // $endToYear end year of the end date range to search for if $endDate has value 0 // $sc39s the IDs of the SC-39 statuses to search for // $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 // $startYear the start year to use as filter or NULL for no start year filtering // $endYear the end year to use as filter or NULL for no end year filtering // $sc39 the ID of the SC-39 status to use as filter or NULL for no SC-39 status filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing projects and statistics private function _advancedSearchProjects($keywords, $fields, $constraints, $funders, $fundingStreams, $scientificAreas, $startDate, $startFromMonth, $startFromYear, $startToMonth, $startToYear, $endDate, $endFromMonth, $endFromYear, $endToMonth, $endToYear, $sc39s, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY; for ($i = 0; ($i < count($keywords)) && ($i < count($fields)) && ($i < count($constraints)); $i++) { $tokens = preg_split('/\s/', $keywords[$i], NULL, PREG_SPLIT_NO_EMPTY); switch ($constraints[$i]) { case OpenAireViewAdvancedSearchProjects :: ALL: $operator = ' and '; break; case OpenAireViewAdvancedSearchProjects :: ANY: $operator = ' or '; break; default: $operator = NULL; } switch ($fields[$i]) { case OpenAireViewAdvancedSearchProjects :: ACRONYM: $field = self :: PROJECT_ACRONYM; break; case OpenAireViewAdvancedSearchProjects :: TITLE: $field = self :: PROJECT_TITLE; break; case OpenAireViewAdvancedSearchProjects :: KEYWORDS: $field = self :: PROJECT_KEYWORDS; break; default: $field = NULL; } $query .= ($tokens == NULL) ? '' : (' and (' . implode($operator, array_map(function ($keyword) use ($field) {return '(' . (($field == NULL) ? '' : ($field . ' = ')) . '"' . str_replace('"', '\\"', $keyword) . '")';}, $tokens)) . ')'); } $field = self :: PROJECT_FUNDER; $query .= ($funders == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($funder) use ($field) {return '(' . $field . ' exact "' . $funder . '")';}, $funders)) . ')'); $field = self :: PROJECT_FUNDING_STREAM; $query .= ($fundingStreams == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($fundingStream) use ($field) {return '(' . $field . ' exact "' . $fundingStream . '")';}, $fundingStreams)) . ')'); $field = self :: PROJECT_SCIENTIFIC_AREA; $query .= ($scientificAreas == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($scientificArea) use ($field) {return '(' . $field . ' exact "' . $scientificArea . '")';}, $scientificAreas)) . ')'); $from = new DateTime(); $to = new DateTime(); switch ($startDate) { case -1: break; case 0: $from -> setDate($startFromYear, $startFromMonth, 1); $to -> setDate($startToYear, $startToMonth, 1); $to -> setDate($startToYear, $startToMonth, date('t', $to -> getTimestamp())); // update to with the last day of that month $query .= ' and (' . self :: PROJECT_START_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; break; default: $from -> sub(new DateInterval('P' . $startDate . 'M')); $query .= ' and (' . self :: PROJECT_START_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; } $from = new DateTime(); $to = new DateTime(); switch ($endDate) { case -1: break; case 0: $from -> setDate($endFromYear, $endFromMonth, 1); $to -> setDate($endToYear, $endToMonth, 1); $to -> setDate($endToYear, $endToMonth, date('t', $to -> getTimestamp())); // update to with the last day of that month $query .= ' and (' . self :: PROJECT_END_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; break; default: $from -> sub(new DateInterval('P' . $endDate . 'M')); $query .= ' and (' . self :: PROJECT_END_DATE . ' within "' . date('Y-m-d', $from -> getTimestamp()) . ' ' . date('Y-m-d', $to -> getTimestamp()) . '")'; } $field = self :: PROJECT_SC39; $query .= ($sc39s == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($sc39) use ($field) {return '(' . $field . ' exact "' . ($sc39 ? 'true' : 'false') . '")';}, $sc39s)) . ')'); $query .= ($funder == NULL) ? '' : (' and (' . self :: PROJECT_FUNDER . ' exact "' . $funder . '")'); $query .= ($fundingStream == NULL) ? '' : (' and (' . self :: PROJECT_FUNDING_STREAM . ' exact "' . $fundingStream . '")'); $query .= ($scientificArea == NULL) ? '' : (' and (' . self :: PROJECT_SCIENTIFIC_AREA . ' exact "' . $scientificArea . '")'); $query .= ($startYear == NULL) ? '' : (' and (' . self :: PROJECT_START_YEAR . ' exact "' . $startYear . '")'); $query .= ($endYear == NULL) ? '' : (' and (' . self :: PROJECT_END_YEAR . ' exact "' . $endYear . '")'); $query .= ($sc39 === NULL) ? '' : (' and (' . self :: PROJECT_SC39 . ' exact "' . ($sc39 ? 'true' : 'false') . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=projects_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PROJECT_FUNDER . '&fields=' . self :: PROJECT_FUNDING_STREAM . '&fields=' . self :: PROJECT_SCIENTIFIC_AREA . '&fields=' . self :: PROJECT_START_YEAR . '&fields=' . self :: PROJECT_END_YEAR . '&fields=' . self :: PROJECT_SC39 . '&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); $result = new JObject(); $result -> totalProjects = $this -> parseTotalResults($xpath); $result -> projects = $this -> parseProjects($xpath); $result -> statistics = $this -> createStatistics($xpath, array('funderFilter', 'fundingStreamFilter', 'scientificAreaFilter', 'startYearFilter', 'endYearFilter', 'sc39Filter'), array('FUNDER', 'FUNDING_STREAM', 'SCIENTIFIC_AREA', 'START_YEAR', 'END_YEAR', 'SPECIAL_CLAUSE_39'), array('NO_FUNDER_STATISTICS_FOUND', 'NO_FUNDING_STREAM_STATISTICS_FOUND', 'NO_SCIENTIFIC_AREA_STATISTICS_FOUND', 'NO_START_YEAR_STATISTICS_FOUND', 'NO_END_YEAR_STATISTICS_FOUND', 'NO_SPECIAL_CLAUSE_39_STATISTICS_FOUND'), array(self :: PROJECT_FUNDER, self :: PROJECT_FUNDING_STREAM, self :: PROJECT_SCIENTIFIC_AREA, self :: PROJECT_START_YEAR, self :: PROJECT_END_YEAR, self :: PROJECT_SC39)); JLog :: add('Advanced search retrieved ' . count($result -> projects) . ' projects in ' . (microtime(TRUE) - $time) . ' s (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], funders: [' . implode(', ', $funders) . '], funding streams: [' . implode(', ', $fundingStreams) . '], scientific areas: [' . implode(', ', $scientificAreas) . '], start date: ' . $startDate . ', start from month: ' . $startFromMonth . ', start from year: ' . $startFromYear . ', start to month: ' . $startToMonth . ', start to year: ' . $startToYear . ', end date: ' . $endDate . ', end from month: ' . $endFromMonth . ', end from year: ' . $endFromYear . ', end to month: ' . $endToMonth . ', end to year: ' . $endToYear . ', SC-39s: [' . implode(', ', array_map(function ($sc39) {return $sc39 ? 'true' : 'false';}, $sc39s)) . '], funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing publication advanced search (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], funders: [' . implode(', ', $funders) . '], funding streams: [' . implode(', ', $fundingStreams) . '], scientific areas: [' . implode(', ', $scientificAreas) . '], start date: ' . $startDate . ', start from month: ' . $startFromMonth . ', start from year: ' . $startFromYear . ', start to month: ' . $startToMonth . ', start to year: ' . $startToYear . ', end date: ' . $endDate . ', end from month: ' . $endFromMonth . ', end from year: ' . $endFromYear . ', end to month: ' . $endToMonth . ', end to year: ' . $endToYear . ', SC-39s: [' . implode(', ', array_map(function ($sc39) {return $sc39 ? 'true' : 'false';}, $sc39s)) . '], funder: ' . (($funder == NULL) ? 'null' : $funder) . ', funding stream: ' . (($fundingStream == NULL) ? 'null' : $fundingStream) . ', scientific area: ' . (($scientificArea == NULL) ? 'null' : $scientificArea) . ', start year: ' . (($startYear == NULL) ? 'null' : $startYear) . ', end year: ' . (($endYear == NULL) ? 'null' : $endYear) . ', SC-39: ' . (($sc39 === NULL) ? 'null' : ($sc39 ? 'true' : 'false')) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform an advanced search for people. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are LAST_NAME, FIRST_NAME and FULL_NAME) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $countries the IDs of the countries to search for // $country the ID of the coutnry to use as filter or NULL for no country filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing people and statistics private function _advancedSearchPeople($keywords, $fields, $constraints, $countries, $country, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: PERSON_QUERY; for ($i = 0; ($i < count($keywords)) && ($i < count($fields)) && ($i < count($constraints)); $i++) { $tokens = preg_split('/\s/', $keywords[$i], NULL, PREG_SPLIT_NO_EMPTY); switch ($constraints[$i]) { case OpenAireViewAdvancedSearchPeople :: ALL: $operator = ' and '; break; case OpenAireViewAdvancedSearchPeople :: ANY: $operator = ' or '; break; default: $operator = NULL; } switch ($fields[$i]) { case OpenAireViewAdvancedSearchPeople :: LAST_NAME: $field = self :: PERSON_LAST_NAME; break; case OpenAireViewAdvancedSearchPeople :: FIRST_NAME: $field = self :: PERSON_FIRST_NAME; break; case OpenAireViewAdvancedSearchPeople :: FULL_NAME: $field = self :: PERSON_FULL_NAME; break; default: $field = NULL; } $query .= ($tokens == NULL) ? '' : (' and (' . implode($operator, array_map(function ($keyword) use ($field) {return '(' . (($field == NULL) ? '' : ($field . ' = ')) . '"' . str_replace('"', '\\"', $keyword) . '")';}, $tokens)) . ')'); } $field = self :: PERSON_COUNTRY; $query .= ($countries == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($country) use ($field) {return '(' . $field . ' exact "' . $country . '")';}, $countries)) . ')'); $query .= ($country == NULL) ? '' : (' and (' . self :: PERSON_COUNTRY . ' exact "' . $country . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=persons_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: PERSON_COUNTRY . '&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); $result = new JObject(); $result -> totalPeople = $this -> parseTotalResults($xpath); $result -> people = $this -> parsePeople($xpath); $result -> statistics = $this -> createStatistics($xpath, array('countryFilter'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: PERSON_COUNTRY)); JLog :: add('Advanced search retrieved ' . count($result -> people) . ' people in ' . (microtime(TRUE) - $time) . ' s (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], countries: [' . implode(', ', $countries) . '], country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing datasource advanced search (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], countries: [' . implode(', ', $countries) . '], country: ' . (($country == NULL) ? 'null' : $country) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform an advanced search for organizations. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are NAME and SHORT_NAME) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $countries the IDs of the countries to search for // $types the IDs of the organization types to search for // $country the ID of the coutnry to use as filter or NULL for no country filtering // $type the ID of the organization type to use as filter or NULL for no organization type filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing organizations and statistics private function _advancedSearchOrganizations($keywords, $fields, $constraints, $countries, $types, $country, $type, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY; for ($i = 0; ($i < count($keywords)) && ($i < count($fields)) && ($i < count($constraints)); $i++) { $tokens = preg_split('/\s/', $keywords[$i], NULL, PREG_SPLIT_NO_EMPTY); switch ($constraints[$i]) { case OpenAireViewAdvancedSearchPeople :: ALL: $operator = ' and '; break; case OpenAireViewAdvancedSearchPeople :: ANY: $operator = ' or '; break; default: $operator = NULL; } switch ($fields[$i]) { case OpenAireViewAdvancedSearchOrganizations :: NAME: $field = self :: ORGANIZATION_NAME; break; case OpenAireViewAdvancedSearchOrganizations :: SHORT_NAME: $field = self :: ORGANIZATION_SHORT_NAME; break; default: $field = NULL; } $query .= ($tokens == NULL) ? '' : (' and (' . implode($operator, array_map(function ($keyword) use ($field) {return '(' . (($field == NULL) ? '' : ($field . ' = ')) . '"' . str_replace('"', '\\"', $keyword) . '")';}, $tokens)) . ')'); } $field = self :: ORGANIZATION_COUNTRY; $query .= ($countries == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($country) use ($field) {return '(' . $field . ' exact "' . $country . '")';}, $countries)) . ')'); $organizationLegalBody = self :: ORGANIZATION_LEGAL_BODY; $organizationLegalPerson = self :: ORGANIZATION_LEGAL_PERSON; $organizationNonProfit = self :: ORGANIZATION_NON_PROFIT; $organizationResearch = self :: ORGANIZATION_RESEARCH; $organizationEuInterests = self :: ORGANIZATION_EU_INTERESTS; $organizationInternational = self :: ORGANIZATION_INTERNATIONAL; $organizationEnterprise = self :: ORGANIZATION_ENTERPRISE; $organizationSmallMediumEnterprise = self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE; $query .= ($types == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($type) use ($organizationLegalBody, $organizationLegalPerson, $organizationNonProfit, $organizationResearch, $organizationEuInterests, $organizationInternational, $organizationEnterprise, $organizationSmallMediumEnterprise) {switch ($type) {case 'legalBody': return '(' . $organizationLegalBody . ' exact true)'; case 'legalPerson': return '(' . $organizationLegalPerson . ' exact true)'; case 'nonProfit': return '(' . $organizationNonProfit . ' exact true)'; case 'research': return '(' . $organizationResearch . ' exact true)'; case 'euInterests': return '(' . $organizationEuInterests . ' exact true)'; case 'international': return '(' . $organizationInternational . ' exact true)'; case 'enterprise': return '(' . $organizationEnterprise . ' exact true)'; case 'smallMediumEnterprise': return '(' . $organizationSmallMediumEnterprise . ' exact true)';}}, $types)) . ')'); $query .= ($country == NULL) ? '' : (' and (' . self :: ORGANIZATION_COUNTRY . ' exact "' . $country . '")'); switch ($type) { case 'legalBody': $query .= ' and (' . self :: ORGANIZATION_LEGAL_BODY . ' exact true)'; break; case 'legalPerson': $query .= ' and (' . self :: ORGANIZATION_LEGAL_PERSON . ' exact true)'; break; case 'nonProfit': $query .= ' and (' . self :: ORGANIZATION_NON_PROFIT . ' exact true)'; break; case 'research': $query .= ' and (' . self :: ORGANIZATION_RESEARCH . ' exact true)'; break; case 'euInterests': $query .= ' and (' . self :: ORGANIZATION_EU_INTERESTS . ' exact true)'; break; case 'international': $query .= ' and (' . self :: ORGANIZATION_INTERNATIONAL . ' exact true)'; break; case 'enterprise': $query .= ' and (' . self :: ORGANIZATION_ENTERPRISE . ' exact true)'; break; case 'smallMediumEnterprise': $query .= ' and (' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . ' exact true)'; } JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=organizations_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: ORGANIZATION_COUNTRY . '&fields=' . self :: ORGANIZATION_LEGAL_BODY . '&fields=' . self :: ORGANIZATION_LEGAL_PERSON . '&fields=' . self :: ORGANIZATION_NON_PROFIT . '&fields=' . self :: ORGANIZATION_RESEARCH . '&fields=' . self :: ORGANIZATION_EU_INTERESTS . '&fields=' . self :: ORGANIZATION_INTERNATIONAL . '&fields=' . self :: ORGANIZATION_ENTERPRISE . '&fields=' . self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE . '&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); $result = new JObject(); $result -> totalOrganizations = $this -> parseTotalResults($xpath); $result -> organizations = $this -> parseOrganizations($xpath); $result -> statistics = $this -> createStatistics($xpath, array('countryFilter'), array('COUNTRY'), array('NO_COUNTRY_STATISTICS_FOUND'), array(self :: ORGANIZATION_COUNTRY)); $result -> statistics['typeFilter'] = new JObject(); $result -> statistics['typeFilter'] -> id = 'typeFilter'; $result -> statistics['typeFilter'] -> title = JText :: _('ORGANIZATION_TYPE'); $result -> statistics['typeFilter'] -> error = JText :: _('NO_ORGANIZATION_TYPE_STATISTICS_FOUND'); $result -> statistics['typeFilter'] -> data = array(); $legalBody = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_BODY); if (($legalBody != NULL) && array_key_exists('true', $legalBody)) { $result -> statistics['typeFilter'] -> data['legalBody'] = new JObject(); $result -> statistics['typeFilter'] -> data['legalBody'] -> id = 'legalBody'; $result -> statistics['typeFilter'] -> data['legalBody'] -> name = JText :: _('LEGAL_BODY'); $result -> statistics['typeFilter'] -> data['legalBody'] -> count = $legalBody['true'] -> count; } $legalPerson = $this -> parseStatistics($xpath, self :: ORGANIZATION_LEGAL_PERSON); if (($legalPerson != NULL) && array_key_exists('true', $legalPerson)) { $result -> statistics['typeFilter'] -> data['legalPerson'] = new JObject(); $result -> statistics['typeFilter'] -> data['legalPerson'] -> id = 'legalPerson'; $result -> statistics['typeFilter'] -> data['legalPerson'] -> name = JText :: _('LEGAL_PERSON'); $result -> statistics['typeFilter'] -> data['legalPerson'] -> count = $legalPerson['true'] -> count; } $nonProfit = $this -> parseStatistics($xpath, self :: ORGANIZATION_NON_PROFIT); if (($nonProfit != NULL) && array_key_exists('true', $nonProfit)) { $result -> statistics['typeFilter'] -> data['nonProfit'] = new JObject(); $result -> statistics['typeFilter'] -> data['nonProfit'] -> id = 'nonProfit'; $result -> statistics['typeFilter'] -> data['nonProfit'] -> name = JText :: _('NON_PROFIT_ORGANIZATION'); $result -> statistics['typeFilter'] -> data['nonProfit'] -> count = $nonProfit['true'] -> count; } $research = $this -> parseStatistics($xpath, self :: ORGANIZATION_RESEARCH); if (($research != NULL) && array_key_exists('true', $research)) { $result -> statistics['typeFilter'] -> data['research'] = new JObject(); $result -> statistics['typeFilter'] -> data['research'] -> id = 'research'; $result -> statistics['typeFilter'] -> data['research'] -> name = JText :: _('RESEARCH_ORGANIZATION'); $result -> statistics['typeFilter'] -> data['research'] -> count = $research['true'] -> count; } $euInterests = $this -> parseStatistics($xpath, self :: ORGANIZATION_EU_INTERESTS); if (($euInterests != NULL) && array_key_exists('true', $euInterests)) { $result -> statistics['typeFilter'] -> data['euInterests'] = new JObject(); $result -> statistics['typeFilter'] -> data['euInterests'] -> id = 'euInterests'; $result -> statistics['typeFilter'] -> data['euInterests'] -> name = JText :: _('EU_INTERESTS_ORGANIZATION'); $result -> statistics['typeFilter'] -> data['euInterests'] -> count = $euInterests['true'] -> count; } $international = $this -> parseStatistics($xpath, self :: ORGANIZATION_INTERNATIONAL); if (($international != NULL) && array_key_exists('true', $international)) { $result -> statistics['typeFilter'] -> data['international'] = new JObject(); $result -> statistics['typeFilter'] -> data['international'] -> id = 'international'; $result -> statistics['typeFilter'] -> data['international'] -> name = JText :: _('INTERNATIONAL_ORGANIZATION'); $result -> statistics['typeFilter'] -> data['international'] -> count = $international['true'] -> count; } $enterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_ENTERPRISE); if (($enterprise != NULL) && array_key_exists('true', $enterprise)) { $result -> statistics['typeFilter'] -> data['enterprise'] = new JObject(); $result -> statistics['typeFilter'] -> data['enterprise'] -> id = 'enterprise'; $result -> statistics['typeFilter'] -> data['enterprise'] -> name = JText :: _('ENTERPRISE'); $result -> statistics['typeFilter'] -> data['enterprise'] -> count = $enterprise['true'] -> count; } $smallMediumEnterprise = $this -> parseStatistics($xpath, self :: ORGANIZATION_SMALL_MEDIUM_ENTERPRISE); if (($smallMediumEnterprise != NULL) && array_key_exists('true', $smallMediumEnterprise)) { $result -> statistics['typeFilter'] -> data['smallMediumEnterprise'] = new JObject(); $result -> statistics['typeFilter'] -> data['smallMediumEnterprise'] -> id = 'smallMediumEnterprise'; $result -> statistics['typeFilter'] -> data['smallMediumEnterprise'] -> name = JText :: _('SMALL_MEDIUM_ENTERPRISE'); $result -> statistics['typeFilter'] -> data['smallMediumEnterprise'] -> count = $smallMediumEnterprise['true'] -> count; } uasort($result -> statistics['typeFilter'] -> data, function ($row1, $row2) {return $row2 -> count - $row1 -> count;}); JLog :: add('Advanced search retrieved ' . count($result -> organizations) . ' organizations in ' . (microtime(TRUE) - $time) . ' s (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], countries: [' . implode(', ', $countries) . '], types: [' . implode(', ', $types) . '], country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing organization advanced search (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], countries: [' . implode(', ', $countries) . '], types: [' . implode(', ', $types) . '], country: ' . (($country == NULL) ? 'null' : $country) . ', type: ' . (($type == NULL) ? 'null' : $type) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform an advanced search for datasources. // $keywords the keywords to search for (array) // $fields the fields to match keywords with (array - possible values are NAME, ENGLISH_NAME and SUBJECT) // $constraints the constraints to apply to keywords (array - possible values are ALL and ANY) // $types the IDs of the datasource types to search for // $languages the IDs of the datasource languages to search for // $contents the IDs of the contents to search for // $compatibilities the IDs of the compatibilities to search for // $type the ID of the datasource type to use as filter or NULL for no datasource type filtering // $language the ID of the datasource language to use as filter or NULL for no datasource language filtering // $content the ID of the content to use as filter or NULL for no content filtering // $compatibility the ID of the compatibility to use as filter or NULL for no compatibility filtering // $page the page of results to retrieve // $size the size of the page of results to retrieve // $locale the locale to use // return a result (object) containing datasources and statistics private function _advancedSearchDatasources($keywords, $fields, $constraints, $types, $languages, $contents, $compatibilities, $type, $language, $content, $compatibility, $page, $size, $locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY; for ($i = 0; ($i < count($keywords)) && ($i < count($fields)) && ($i < count($constraints)); $i++) { $tokens = preg_split('/\s/', $keywords[$i], NULL, PREG_SPLIT_NO_EMPTY); switch ($constraints[$i]) { case OpenAireViewAdvancedSearchDatasources :: ALL: $operator = ' and '; break; case OpenAireViewAdvancedSearchDatasources :: ANY: $operator = ' or '; break; default: $operator = NULL; } switch ($fields[$i]) { case OpenAireViewAdvancedSearchDatasources :: NAME: $field = self :: DATASOURCE_NAME; break; case OpenAireViewAdvancedSearchDatasources :: ENGLISH_NAME: $field = self :: DATASOURCE_ENGLISH_NAME; break; case OpenAireViewAdvancedSearchDatasources :: SUBJECT: $field = self :: DATASOURCE_SUBJECT; break; default: $field = NULL; } $query .= ($tokens == NULL) ? '' : (' and (' . implode($operator, array_map(function ($keyword) use ($field) {return '(' . (($field == NULL) ? '' : ($field . ' = ')) . '"' . str_replace('"', '\\"', $keyword) . '")';}, $tokens)) . ')'); } $field = self :: DATASOURCE_TYPE; $query .= ($types == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($type) use ($field) {return '(' . $field . ' exact "' . $type . '")';}, $types)) . ')'); $field = self :: DATASOURCE_LANGUAGE; $query .= ($languages == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($language) use ($field) {return '(' . $field . ' exact "' . $language . '")';}, $languages)) . ')'); $field = self :: DATASOURCE_CONTENT; $query .= ($contents == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($content) use ($field) {return '(' . $field . ' exact "' . $content . '")';}, $contents)) . ')'); $field = self :: DATASOURCE_COMPATIBILITY; $query .= ($compatibilities == NULL) ? '' : (' and (' . implode(' or ', array_map(function ($compatibility) use ($field) {return '(' . $field . ' exact "' . $compatibility . '")';}, $compatibilities)) . ')'); $query .= ($type == NULL) ? '' : (' and (' . self :: DATASOURCE_TYPE . ' exact "' . $type . '")'); $query .= ($language == NULL) ? '' : (' and (' . self :: DATASOURCE_LANGUAGE . ' exact "' . $language . '")'); $query .= ($content == NULL) ? '' : (' and (' . self :: DATASOURCE_CONTENT . ' exact "' . $content . '")'); $query .= ($compatibility == NULL) ? '' : (' and (' . self :: DATASOURCE_COMPATIBILITY . ' exact "' . $compatibility . '")'); JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=searchNrefine&sTransformer=datasources_openaire&rTransformer=results_openaire_browse&query=' . urlencode($query) . '&page=' . $page . '&size=' . $size . '&fields=' . self :: DATASOURCE_TYPE . '&fields=' . self :: DATASOURCE_LANGUAGE . '&fields=' . self :: DATASOURCE_CONTENT . '&fields=' . self :: DATASOURCE_COMPATIBILITY . '&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); $result = new JObject(); $result -> totalDatasources = $this -> parseTotalResults($xpath); $result -> datasources = $this -> parseDatasources($xpath); $result -> statistics = $this -> createStatistics($xpath, array('typeFilter', 'languageFilter', 'contentFilter', 'compatibilityFilter'), array('DATASOURCE_TYPE', 'DATASOURCE_LANGUAGE', 'CONTENT', 'COMPATIBILITY'), array('NO_DATASOURCE_TYPE_STATISTICS_FOUND', 'NO_DATASOURCE_LANGUAGE_STATISTICS_FOUND', 'NO_CONTENT_STATISTICS_FOUND', 'NO_COMPATIBILITY_STATISTICS_FOUND'), array(self :: DATASOURCE_TYPE, self :: DATASOURCE_LANGUAGE, self :: DATASOURCE_CONTENT, self :: DATASOURCE_COMPATIBILITY)); JLog :: add('Advanced search retrieved ' . count($result -> datasources) . ' datasources in ' . (microtime(TRUE) - $time) . ' s (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], types: [' . implode(', ', $types) . '], languages: [' . implode(', ', $languages) . '], contents: [' . implode(', ', $contents) . '], compatibilities: [' . implode(', ', $compatibilities) . '], type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error performing datasource advanced search (keywords: [' . implode(', ', $keywords) . '], fields: [' . implode(', ', $fields) . '], constraints: [' . implode(', ', $constraints) . '], types: [' . implode(', ', $types) . '], languages: [' . implode(', ', $languages) . '], contents: [' . implode(', ', $contents) . '], compatibilities: [' . implode(', ', $compatibilities) . '], type: ' . (($type == NULL) ? 'null' : $type) . ', language: ' . (($language == NULL) ? 'null' : $language) . ', content: ' . (($content == NULL) ? 'null' : $content) . ', compatibility: ' . (($compatibility == NULL) ? 'null' : $compatibility) . ', page: ' . $page . ', size: ' . $size . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve a single publication by identifier. // $id the publication identifier // $locale the locale to use // return a publication (object) or NULL if no such publication exists private function _getPublication($id, $locale) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY . ' and (' . self :: PUBLICATION_ID . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=results_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); $publication = $this -> parsePublication($xpath, $locale); JLog :: add('Retrieved publication in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $publication; } catch (Exception $e) { JLog :: add('Error retrieving publication (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve results by identifier. // $ids the result identifiers // $locale the locale to use // return a result (object) or NULL if no such result exists private function _getResults($ids, $locale) { try { $time = microtime(TRUE); $query = self :: RESULT_QUERY . ' and ('; $parts = array(); foreach ($ids as $id){ $parts[] = ('(' . self :: RESULT_ID . ' exact "' . $id . '")'); } $query .= join(" OR ", $parts); $query .= ')'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=results_openaire&query=' . urlencode($query) . '&size=10000&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); $results = $this -> parseResults($xpath, $locale); JLog :: add('Retrieved results in ' . (microtime(TRUE) - $time) . ' s (ids: ' . join(",", $ids) . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $results; } catch (Exception $e) { JLog :: add('Error retrieving results (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve publications by identifier. // $ids the publication identifiers // $locale the locale to use // return a publication (object) or NULL if no such publication exists private function _getPublications($ids, $locale) { try { $time = microtime(TRUE); $query = self :: PUBLICATION_QUERY . ' and ('; $parts = array(); foreach ($ids as $id){ $parts[] = '(' . self :: PUBLICATION_ID . ' exact "' . $id . '")'; } $query .= join(" OR ", $parts); $query .= ')'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=results_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); $publications = $this -> parsePublications($xpath, $locale); JLog :: add('Retrieved publication in ' . (microtime(TRUE) - $time) . ' s (ids: ' . join(",", $ids) . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $publications; } catch (Exception $e) { JLog :: add('Error retrieving publication (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve publications by identifier. // $ids the publication identifiers // $locale the locale to use // return a publication (object) or NULL if no such publication exists private function _getProjects($ids, $locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY . ' and ('; $parts = array(); foreach ($ids as $id){ $parts[] = '(' . self :: PROJECT_ID . ' exact "' . $id . '")'; } $query .= join(" OR ", $parts); $query .= ')'; 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 -> parseProjects($xpath, $locale); JLog :: add('Retrieved projects in ' . (microtime(TRUE) - $time) . ' s (ids: ' . join(",", $ids) . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $projects; } catch (Exception $e) { JLog :: add('Error retrieving projects (ids: ' . join(",", $ids) . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve datasets by identifier. // $ids the datasets identifiers // $locale the locale to use // return datasets array of (object) or NULL if no such dataset exists private function _getDatasets($ids, $locale) { try { $time = microtime(TRUE); $query = self :: DATASET_QUERY . ' and ('; $parts = array(); foreach ($ids as $id){ $parts[] = '(' . self :: DATASET_ID . ' exact "' . $id . '")'; } $query .= join(" OR ", $parts); $query .= ')'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=results_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); $datasets = $this -> parseDatasets($xpath, $locale); JLog :: add('Retrieved publication in ' . (microtime(TRUE) - $time) . ' s (ids: ' . join(",", $ids) . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $datasets; } catch (Exception $e) { JLog :: add('Error retrieving publication (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve a single dataset by identifier. // $id the dataset identifier // $locale the locale to use // return a dataset (object) or NULL if no such dataset exists private function _getDataset($id, $locale) { try { $time = microtime(TRUE); $query = self :: DATASET_QUERY . ' and (' . self :: DATASET_ID . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=results_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); $dataset = $this -> parseDataset($xpath,$locale); JLog :: add('Retrieved dataset in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $dataset; } catch (Exception $e) { JLog :: add('Error retrieving dataset (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // 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; } } // Retrieve a single person by identifier. // $id the person identifier // $locale the locale to use // return a person (object) or NULL if no such person exists private function _getPerson($id, $locale) { try { $time = microtime(TRUE); $query = self :: PERSON_QUERY . ' and (' . self :: PERSON_ID . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=persons_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); $person = $this -> parsePerson($xpath); JLog :: add('Retrieved person in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $person; } catch (Exception $e) { JLog :: add('Error retrieving person (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve a single organization by identifier. // $id the organization identifier // $locale the locale to use // return an organization (object) or NULL if no such organization exists private function _getOrganization($id, $locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY . ' and (' . self :: ORGANIZATION_ID . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=organizations_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); $organization = $this -> parseOrganization($xpath); JLog :: add('Retrieved organization in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $organization; } catch (Exception $e) { JLog :: add('Error retrieving organization (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve the datasources of an organization. // $id the organization identifier // $size the maximum number of datasources to retrieve // $locale the locale to use // return a result (object) containing datasources and total private function _getOrganizationDatasources($id, $size, $locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY . ' and (' . self :: DATASOURCE_ORGANIZATION . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=datasources_openaire&query=' . urlencode($query) . '&size=' . $size . '&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); $result = new JObject(); $result -> totalDatasources = $this -> parseTotalResults($xpath); $result -> datasources = $this -> parseDatasources($xpath); JLog :: add('Retrieved ' . count($result -> datasources) . ' organization datasources in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $result; } catch (Exception $e) { JLog :: add('Error retrieving organization datasources (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve a single datasource by identifier. // $id the datasource identifier // $locale the locale to use // return a datasource (object) or NULL if no such datasource exists private function _getDatasource($id, $locale, $compatibility = false) { try { $time = microtime(TRUE); $datasource_query = $compatibility?self::DATASOURCE_QUERY_COMPATIBILITY:self::DATASOURCE_QUERY; $query = $datasource_query . ' and (' . self :: DATASOURCE_ID . ' exact "' . $id . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=datasources_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); $datasource = $this -> parseDatasource($xpath); JLog :: add('Retrieved datasource in ' . (microtime(TRUE) - $time) . ' s (id: ' . $id . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $datasource; } catch (Exception $e) { JLog :: add('Error retrieving datasource (id: ' . $id . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Retrieve all the OpenAIRE compatible datasources. // $locale the locale to use // return the datasources (array) or NULL if any errors occur private function _getCompatibleDatasources($locale) { try { $time = microtime(TRUE); $query = self :: DATASOURCE_QUERY . ' and (' . self :: DATASOURCE_COMPATIBILITY . ' <> "' . self :: DATASOURCE_COMPATIBILITY_NOT_COMPATIBLE . '")'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=datasources_openaire&query=' . urlencode($query) . '&size=1&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); $totalDatasources = $this -> parseTotalResults($xpath); if ($totalDatasources > 0) { if (($response = $this -> performGet('search?action=search&sTransformer=datasources_openaire&query=' . urlencode($query) . '&size=' . $totalDatasources . '&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); $datasources = $this -> parseDatasources($xpath); } else $datasources = array(); JLog :: add('Retrieved ' . count($datasources) . ' compatible datasources in ' . (microtime(TRUE) - $time) . ' s (locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $datasources; } catch (Exception $e) { JLog :: add('Error retrieving compatible datasources (locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a quick search for projects, searching only by acronym, title or code and funder. // $keyword the keyword to search for // $funder the funder to search for // $limit the maximum number of results to retrieve // $locale the locale to use // return projects (array) or NULL if any errors occur private function _quickSearchProjects($keyword, $funder, $limit, $locale) { try { $time = microtime(TRUE); $query = self :: PROJECT_QUERY . ' and ((' . self :: PROJECT_TITLE . ' = "' . $keyword . '") or (' . self :: PROJECT_ACRONYM . ' = "' . $keyword . '") or (' . self :: PROJECT_CODE . ' = "' . $keyword . '")) and (' . self :: PROJECT_FUNDER . ' exact ' . $funder . ')'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=projects_openaire&query=' . urlencode($query) . '&size=' . $limit . '&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 -> parseProjects($xpath); JLog :: add('Retrieved ' . count($projects) . ' projects in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', funder: ' . $funder . ', limit: ' . $limit . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $projects; } catch (Exception $e) { JLog :: add('Error retrieving projects (keyword: ' . $keyword . ', funder: ' . $funder . ', limit: ' . $limit . ', locale: ' . $locale . '): ' . $e -> getMessage(), JLog :: ERROR, self :: LOG); return NULL; } } // Perform a quick search for organizations, searching only by name or short name. // $keyword the keyword to search for // $limit the maximum number of results to retrieve // $locale the locale to use // return organizations (array) or NULL if any errors occur private function _quickSearchOrganizations($keyword, $limit, $locale) { try { $time = microtime(TRUE); $query = self :: ORGANIZATION_QUERY . ' and ((' . self :: ORGANIZATION_NAME . ' all "' . $keyword . '") or (' . self :: ORGANIZATION_SHORT_NAME . ' all "' . $keyword . '"))'; JLog :: add('Generated query is \'' . $query . '\'', JLog :: INFO, self :: LOG); if (($response = $this -> performGet('search?action=search&sTransformer=organizations_openaire&query=' . urlencode($query) . '&size=' . $limit . '&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); $organizations = $this -> parseOrganizations($xpath); JLog :: add('Retrieved ' . count($organizations) . ' organizations in ' . (microtime(TRUE) - $time) . ' s (keyword: ' . $keyword . ', limit: ' . $limit . ', locale: ' . $locale . ')', JLog :: INFO, self :: LOG); return $organizations; } catch (Exception $e) { JLog :: add('Error retrieving organizations (keyword: ' . $keyword . ', limit: ' . $limit . ', 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; } // Create statistics based on a search service XML response. // $xpath the DOMXPath to parse // $ids the identifiers of the statistics to create // $titles the titles of the statistics to create // $errors the error messages of the statistics to create // $data the field names of the statistics to create // return statistics (array) private function createStatistics($xpath, $ids, $titles, $errors, $data) { $statistics = array(); array_map(function ($id, $title, $error, $data) use ($xpath, &$statistics) {$statistics[$id] = new JObject(); $statistics[$id] -> id = $id; $statistics[$id] -> title = JText :: _($title); $statistics[$id] -> error = JText :: _($error); $statistics[$id] -> data = OpenAireModelSearch :: parseStatistics($xpath, $data);}, $ids, $titles, $errors, $data); return $statistics; } // Parse statistics from a search service XML response. // $xpath the DOMXPath to parse // $category the category to retrieve statistics for // return statistics (associative array) public function parseStatistics($xpath, $category) { if ((($browseResultsNodes = $xpath -> query('/response/browseResults')) == FALSE) || (($browseResultsNode = $browseResultsNodes -> item(0)) == NULL)) throw new Exception('error parsing statistics'); if (($fieldNodes = $xpath -> query('./result/field[@name = "' . $category . '"]', $browseResultsNode)) == FALSE) throw new Exception('error parsing statistics'); $statistics = array(); foreach ($fieldNodes as $fieldNode) { if ((($idNodes = $xpath -> query('./field[@name = "value"]/@value_original', $fieldNode)) == FALSE) || (($idNode = $idNodes -> item(0)) == NULL)) throw new Exception('error parsing statistics'); if ((($nameNodes = $xpath -> query('./field[@name = "value"]/@value', $fieldNode)) == FALSE) || (($nameNode = $nameNodes -> item(0)) == NULL)) throw new Exception('error parsing statistics'); if ((($countNodes = $xpath -> query('./field[@name = "count"]/@value', $fieldNode)) == FALSE) || (($countNode = $countNodes -> item(0)) == NULL)) throw new Exception('error parsing statistics'); $statistic = new JObject(); $statistic -> id = trim($idNode -> nodeValue); $statistic -> name = trim($nameNode -> nodeValue); $statistic -> count = intval(trim($countNode -> nodeValue)); $statistics[$statistic -> id] = $statistic; } return $statistics; } // 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)); } // Parse publications from a search service XML response. // xpath the DOMXPath to parse // return results (array) private function parseResults($xpath) { if (($resultNodes = $xpath -> query('/response/results/result')) == FALSE) throw new Exception('error parsing results'); $publications = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath -> query('./field[@name = "resultId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($datasourceNodes = $xpath -> query('./field[@name = "datasource"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($subjectNodes = $xpath -> query('./field[@name = "subject"]', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($relatedNodes = $xpath -> query('./field[@name = "related"]', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($authorNodes = $xpath -> query('./field[@name = "author"]', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($publisherNodes = $xpath -> query('./field[@name = "publisher"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($yearNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($languageNodes = $xpath -> query('./field[@name = "language"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($embargoEndDateNodes = $xpath -> query('./field[@name = "embargoenddate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); if (($descriptionNodes = $xpath -> query('./field[@name = "description"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing results'); $publication = new JObject(); $publication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $publication -> source = 'openaire'; $publication -> url = NULL; $publication -> accessMode = NULL; $publication -> datasources = array(); $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = array(); $publication -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $publication -> language = (($languageNode = $languageNodes -> item(0)) == NULL) ? NULL : trim($languageNode -> nodeValue); $publication -> projects = array(); $publication -> subjects = array(); $publication -> related = array(); $publication -> embargoEndDate = (($embargoEndDateNode = $embargoEndDateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($embargoEndDateNode -> nodeValue)); $publication -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); foreach ($subjectNodes as $subjectNode) { if (($titleNodes = $xpath -> query('./@value', $subjectNode)) == FALSE) throw new Exception('error parsing results'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing results'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing results'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing results'); $subject = new JObject(); $subject -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $subject -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $subject -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $subject -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); if (($subject -> title != NULL) || ($subject -> inferred != NULL) || ($subject -> trust != NULL) || ($subject -> provenance != NULL)) $publication -> subjects[] = $subject; } foreach ($relatedNodes as $relatedNode) { if (($titleNodes = $xpath -> query('./field[@name= "title"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing results'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing results'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing results'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing results'); $related = new JObject(); $related -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $related -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $related -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $related -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); if (($related -> title != NULL) || ($related -> inferred != NULL) || ($related -> trust != NULL) || ($related -> provenance != NULL)) $publication -> related[] = $related; } foreach ($datasourceNodes as $datasourceNode) { if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing results'); if (($accessModeNodes = $xpath -> query('./field[@name = "licenceid"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing results'); $datasource = new JObject(); $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) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN))) || (($datasource -> accessMode == self :: UNKNOWN) && ($publication -> accessMode == NULL)) || ((($datasource -> accessMode == NULL) && ($publication -> accessMode == NULL) && ($publication -> url == NULL))))) { $publication -> accessMode = $datasource -> accessMode; $publication -> url = $datasource -> url; } if (($datasource -> url != NULL) || ($datasource -> accessMode != NULL)) $publication -> datasources[] = $datasource; } foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing results'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing results'); if (($rankingNodes = $xpath -> query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing results'); $author = new JObject(); $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)) $publication -> authors[] = $author; usort($publication -> 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 results'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing results'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing results'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing results'); $project = new JObject(); $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)) $publication -> projects[] = $project; } if (($publication -> id != NULL) || ($publication -> source != NULL) || ($publication -> url != NULL) || ($publication -> accessMode != NULL) || ($publication -> datasources != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> publisher != NULL) || ($publication -> year != NULL) || ($publication -> language != NULL) || ($publication -> projects != NULL) || ($publication -> embargoEndDate != NULL) || ($publication -> description != NULL)) $publications[] = $publication; } return $publications; } // Parse publications from a search service XML response. // xpath the DOMXPath to parse // return publications (array) private function parsePublications($xpath) { if (($resultNodes = $xpath -> query('/response/results/result')) == FALSE) throw new Exception('error parsing publications'); $publications = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath -> query('./field[@name = "resultId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($datasourceNodes = $xpath -> query('./field[@name = "datasource"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($subjectNodes = $xpath -> query('./field[@name = "subject"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($relatedNodes = $xpath -> query('./field[@name = "related"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($authorNodes = $xpath -> query('./field[@name = "author"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($publisherNodes = $xpath -> query('./field[@name = "publisher"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($yearNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($languageNodes = $xpath -> query('./field[@name = "language"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($embargoEndDateNodes = $xpath -> query('./field[@name = "embargoenddate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); if (($descriptionNodes = $xpath -> query('./field[@name = "description"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publications'); $publication = new JObject(); $publication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $publication -> source = 'openaire'; $publication -> url = NULL; $publication -> accessMode = NULL; $publication -> datasources = array(); $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = array(); $publication -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $publication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $publication -> language = (($languageNode = $languageNodes -> item(0)) == NULL) ? NULL : trim($languageNode -> nodeValue); $publication -> projects = array(); $publication -> subjects = array(); $publication -> related = array(); $publication -> embargoEndDate = (($embargoEndDateNode = $embargoEndDateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($embargoEndDateNode -> nodeValue)); $publication -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); foreach ($subjectNodes as $subjectNode) { if (($titleNodes = $xpath -> query('./@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); $subject = new JObject(); $subject -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $subject -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $subject -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $subject -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); if (($subject -> title != NULL) || ($subject -> inferred != NULL) || ($subject -> trust != NULL) || ($subject -> provenance != NULL)) $publication -> subjects[] = $subject; } foreach ($relatedNodes as $relatedNode) { if (($titleNodes = $xpath -> query('./field[@name= "title"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publications'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publications'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publications'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publications'); $related = new JObject(); $related -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $related -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $related -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $related -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); if (($related -> title != NULL) || ($related -> inferred != NULL) || ($related -> trust != NULL) || ($related -> provenance != NULL)) $publication -> related[] = $related; } foreach ($datasourceNodes as $datasourceNode) { if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing publications'); if (($accessModeNodes = $xpath -> query('./field[@name = "licenceid"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing publications'); $datasource = new JObject(); $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) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN))) || (($datasource -> accessMode == self :: UNKNOWN) && ($publication -> accessMode == NULL)) || ((($datasource -> accessMode == NULL) && ($publication -> accessMode == NULL) && ($publication -> url == NULL))))) { $publication -> accessMode = $datasource -> accessMode; $publication -> url = $datasource -> url; } if (($datasource -> url != NULL) || ($datasource -> accessMode != NULL)) $publication -> datasources[] = $datasource; } foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publications'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publications'); if (($rankingNodes = $xpath -> query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publications'); $author = new JObject(); $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)) $publication -> authors[] = $author; usort($publication -> 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 publications'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publications'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publications'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publications'); $project = new JObject(); $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)) $publication -> projects[] = $project; } if (($publication -> id != NULL) || ($publication -> source != NULL) || ($publication -> url != NULL) || ($publication -> accessMode != NULL) || ($publication -> datasources != NULL) || ($publication -> title != NULL) || ($publication -> authors != NULL) || ($publication -> publisher != NULL) || ($publication -> year != NULL) || ($publication -> language != NULL) || ($publication -> projects != NULL) || ($publication -> embargoEndDate != NULL) || ($publication -> description != NULL)) $publications[] = $publication; } return $publications; } // Parse datasets from a search service XML response. // xpath the DOMXPath to parse // return datasets (array) private function parseDatasets($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 = "author"]', $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 JObject(); $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 = "licenceid"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing datasets'); $datasource = new JObject(); $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 JObject(); $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'); $project = new JObject(); $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; } 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 projects from a search service XML response. // xpath the DOMXPath to parse // return projects (array) private function parseProjects($xpath) { if (($resultNodes = $xpath -> query('/response/results/result')) == FALSE) throw new Exception('error parsing projects'); $projects = array(); foreach ($resultNodes as $resultNode) { 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 projects'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($codeNodes = $xpath -> query('./field[@name = "code"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($sc39Nodes = $xpath -> query('./field[@name = "ec_sc39"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($funderNodes = $xpath -> query('./field[@name = "funding_level_0"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($startYearNodes = $xpath -> query('./field[@name = "startyear"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($endYearNodes = $xpath -> query('./field[@name = "endyear"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing projects'); if (($organizationNodes = $xpath -> query('./field[@name = "organization"]', $resultNode)) == FALSE) throw new Exception('error parsing projects'); $project = new JObject(); $project -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $project -> acronym = ((($acronymNode = $acronymNodes -> item(0)) == 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); $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 -> funder = (($funderNode = $funderNodes -> item(0)) == NULL) ? NULL : trim($funderNode -> nodeValue); $project -> startYear = (($startYearNode = $startYearNodes -> item(0)) == NULL) ? NULL : intval(trim($startYearNode -> nodeValue)); $project -> endYear = (($endYearNode = $endYearNodes -> item(0)) == NULL) ? NULL : intval(trim($endYearNode -> nodeValue)); $project -> organizations = array(); foreach ($organizationNodes as $organizationNode) { if (($idNodes = $xpath -> query('./field[@name = "organizationid"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing projects'); if (($shortNameNodes = $xpath -> query('./field[@name = "legalshortname"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing projects'); if (($nameNodes = $xpath -> query('./field[@name = "legalname"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing projects'); $organization = new JObject(); $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; } if (($project -> id != NULL) || ($project -> acronym != NULL) || ($project -> title != NULL) || ($project -> code != NULL) || ($project -> sc39 != NULL) || ($project -> funder != NULL) || ($project -> startYear != NULL) || ($project -> endYear != NULL) || ($project -> organizations != NULL)) $projects[] = $project; } return $projects; } // Parse people from a search service XML response. // xpath the DOMXPath to parse // return people (array) private function parsePeople($xpath) { if (($resultNodes = $xpath -> query('/response/results/record')) == FALSE) throw new Exception('error parsing people'); $people = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing people'); if (($lastNameNodes = $xpath -> query('./field[@name = "secondnames"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing people'); if (($firstNameNodes = $xpath -> query('./field[@name = "firstname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing people'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing people'); if (($countryNodes = $xpath -> query('./field[@name = "nationalityid"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing people'); $person = new JObject(); $person -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $person -> lastName = (($lastNameNode = $lastNameNodes -> item(0)) == NULL) ? NULL : trim($lastNameNode -> nodeValue); $person -> firstName = (($firstNameNode = $firstNameNodes -> item(0)) == NULL) ? NULL : trim($firstNameNode -> nodeValue); $person -> fullName = (($fullNameNode = $fullNameNodes -> item(0)) == NULL) ? NULL : trim($fullNameNode -> nodeValue); $person -> country = (($countryNode = $countryNodes -> item(0)) == NULL) ? NULL : trim($countryNode -> nodeValue); if (($person -> id != NULL) || ($person -> lastName != NULL) || ($person -> firstName != NULL) || ($person -> fullName != NULL) || ($person -> country != NULL)) $people[] = $person; } return $people; } // Parse organizations from a search service XML response. // xpath the DOMXPath to parse // return organizations (array) private function parseOrganizations($xpath) { if (($resultNodes = $xpath -> query('/response/results/result')) == FALSE) throw new Exception('error parsing organizations'); $organizations = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath -> query('./field[@name = "organizationId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organizations'); if (($shortNameNodes = $xpath -> query('./field[@name = "legalshortname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organizations'); if (($nameNodes = $xpath -> query('./field[@name = "legalname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organizations'); if (($countryNodes = $xpath -> query('./field[@name = "countryname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organizations'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing organizations'); $organization = new JObject(); $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); $organization -> country = (($countryNode = $countryNodes -> item(0)) == NULL) ? NULL : trim($countryNode -> nodeValue); $organization -> projects = array(); foreach ($projectNodes as $projectNode) { if (($idNodes = $xpath -> query('./field[@name = "projectId"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organizations'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organizations'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organizations'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organizations'); $project = new JObject(); $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)) $organization -> projects[] = $project; } if (($organization -> id != NULL) || ($organization -> shortName != NULL) || ($organization -> name != NULL) || ($organization -> country != NULL) || ($organization -> projects != NULL)) $organizations[] = $organization; } return $organizations; } // Parse datasources from a search service XML response. // xpath the DOMXPath to parse // return datasources (array) private function parseDatasources($xpath) { if (($resultNodes = $xpath -> query('/response/results/result')) == FALSE) throw new Exception('error parsing datasources'); $datasources = array(); foreach ($resultNodes as $resultNode) { if (($idNodes = $xpath -> query('./field[@name = "datasourceId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($typeNodes = $xpath -> query('./field[@name = "datasourcetypeuiid"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($typeIdNodes = $xpath -> query('./field[@name = "datasourcetypeuiid"]/@value_original', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($compatibilityNodes = $xpath -> query('./field[@name = "openairecompatibilityid"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($urlNodes = $xpath -> query('./field[@name = "websiteurl"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($nameNodes = $xpath -> query('./field[@name = "officialname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($englishNameNodes = $xpath -> query('./field[@name = "englishname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($itemsNodes = $xpath -> query('./field[@name = "odnumberofitems"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($dateNodes = $xpath -> query('./field[@name = "odnumberofitemsdate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($languageNodes = $xpath -> query('./field[@name = "odlanguages"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($policyNodes = $xpath -> query('./field[@name = "odpolicies"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($contentNodes = $xpath -> query('./field[@name = "odcontenttypes"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($oaiPmhNodes = $xpath -> query('./field[@name = "accessinfopackage"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($descriptionNodes = $xpath -> query('./field[@name = "oddescription"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($organizationNodes = $xpath -> query('./field[@name = "organization"]', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); $datasource = new JObject(); $datasource -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $datasource -> type = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $datasource -> typeId = (($typeIdNode = $typeIdNodes -> item(0)) == NULL) ? NULL : trim($typeIdNode -> nodeValue); $datasource -> compatibility = (($compatibilityNode = $compatibilityNodes -> item(0)) == NULL) ? NULL : trim($compatibilityNode -> nodeValue); $datasource -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $datasource -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $datasource -> englishName = (($englishNameNode = $englishNameNodes -> item(0)) == NULL) ? NULL : trim($englishNameNode -> nodeValue); $datasource -> items = (($itemsNode = $itemsNodes -> item(0)) == NULL) ? NULL : intval(trim($itemsNode -> nodeValue)); $datasource -> date = (($dateNode = $dateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($dateNode -> nodeValue)); $datasource -> languages = array(); $datasource -> policies = array(); $datasource -> contents = array(); $datasource -> oaiPmhUrls = array(); $datasource -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); $datasource -> organizations = array(); foreach ($languageNodes as $languageNode) { if (trim($languageNode -> nodeValue) != NULL) $datasource -> languages[] = trim($languageNode -> nodeValue); } foreach ($policyNodes as $policyNode) { if (trim($policyNode -> nodeValue) != NULL) $datasource -> policies[] = trim($policyNode -> nodeValue); } foreach ($contentNodes as $contentNode) { if (trim($contentNode -> nodeValue) != NULL) $datasource -> contents[] = trim($contentNode -> nodeValue); } foreach ($oaiPmhNodes as $oaiPmhNode) { if (trim($oaiPmhNode -> nodeValue) != NULL) $datasource -> oaiPmhUrls[] = trim($oaiPmhNode -> nodeValue); } foreach ($organizationNodes as $organizationNode) { if (($idNodes = $xpath -> query('./field[@name = "organizationid"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing datasources'); if (($shortNameNodes = $xpath -> query('./field[@name = "legalname"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing datasources'); if (($nameNodes = $xpath -> query('./field[@name = "legalshortname"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing datasources'); if (($countryNodes = $xpath -> query('./field[@name = "countryname"]/@value', $organizationNode)) == FALSE) throw new Exception('error parsing datasources'); $organization = new JObject(); $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); $organization -> country = (($countryNode = $countryNodes -> item(0)) == NULL) ? NULL : trim($countryNode -> nodeValue); if (($organization -> id != NULL) || ($organization -> shortName != NULL) || ($organization -> name != NULL) || ($organization -> country != NULL)) $datasource -> organizations[] = $organization; } if (($datasource -> id != NULL) || ($datasource -> type != NULL) || ($datasource -> compatibility != NULL) || ($datasource -> url != NULL) || ($datasource -> name != NULL) || ($datasource -> englishName != NULL) || ($datasource -> items != NULL) || ($datasource -> date != NULL) || ($datsource -> languages != NULL) || ($datasource -> policies != NULL) || ($datasource -> contents != NULL) || ($datasource -> oaiPmhUrls != NULL) || ($datasource -> description != NULL) || ($datasource -> organizations != NULL)) $datasources[] = $datasource; } return $datasources; } // Parse a single publication from a search service XML response. // xpath the DOMXPath to parse // return publication (object) private function parsePublication($xpath,$locale) { if ((($resultsNodes = $xpath -> query('/response/results/result')) == FALSE) || (($resultNode = $resultsNodes -> item(0)) == NULL)) // result throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "resultId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($authorNodes = $xpath -> query('./field[@name = "author"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($dateNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($publisherNodes = $xpath -> query('./field[@name = "publisher"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($languageNodes = $xpath -> query('./field[@name = "language"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($typeNodes = $xpath -> query('./field[@name ="resulttypename"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($subjectNodes = $xpath -> query('./field[@name = "subject"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($embargoEndDateNodes = $xpath -> query('./field[@name = "embargoenddate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($descriptionNodes = $xpath -> query('./field[@name = "description"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($datasourceNodes = $xpath -> query('./field[@name = "datasource"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($collectedFromNodes = $xpath -> query('./field[@name = "collectedfrom"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($sourceNodes = $xpath -> query('./field[@name = "source"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($pidNodes = $xpath -> query('./field[@name = "pid"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($similarNodes = $xpath -> query('./field[@name = "hasAmongTopNSimilarDocuments"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($relatedNodes = $xpath -> query('./field[@name = "isRelatedTo"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($externalReferenceNodes = $xpath -> query('./field[@name = "externalreference"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); if (($contextNodes = $xpath -> query('./field[@name = "context"]', $resultNode)) == FALSE) throw new Exception('error parsing publication'); $publication = new JObject(); $publication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $publication -> source = 'openaire'; $publication -> accessMode = NULL; $publication -> url = NULL; $publication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $publication -> authors = array(); $publication -> year = (($dateNode = $dateNodes -> item(0)) == NULL) ? NULL : intval(trim($dateNode -> nodeValue)); $publication -> date = ($dateNode == NULL) ? NULL : strtotime(trim($dateNode -> nodeValue)); $publication -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $publication -> languages = array(); $publication -> type = array(); $publication -> subjects = array(); $publication -> embargoEndDate = (($embargoEndDateNode = $embargoEndDateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($embargoEndDateNode -> nodeValue)); $publication -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); $publication -> datasources = array(); $publication -> collectedFrom = array(); $publication -> sources = array(); $publication -> projects = array(); $publication -> pids = array(); $publication -> similarPublications = array(); $publication -> relatedPublications = array(); $publication -> relatedDatasets = array(); $publication -> externalPublications = array(); $publication -> externalDatasets = array(); $publication -> contexts = array(); foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); if (($rankingNodes = $xpath -> query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); $author = new JObject(); $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)) $publication -> authors[] = $author; usort($publication -> authors, function ($author1, $author2) {return $author1 -> ranking - $author2 -> ranking;}); } foreach ($languageNodes as $languageNode) { if ((($language = trim($languageNode -> nodeValue)) != NULL) && ($language != self :: UNDETERMINED)) $publication -> languages[] = $language; } foreach ($subjectNodes as $subjectNode) { if (($titleNodes = $xpath -> query('./@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $subjectNode)) == FALSE) throw new Exception('error parsing publications'); $subject = new JObject(); $subject -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $subject -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $subject -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $subject -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); if (($subject -> title != NULL) || ($subject -> inferred != NULL) || ($subject -> trust != NULL) || ($subject -> provenance != NULL)) $publication -> subjects[] = $subject; } foreach ($datasourceNodes as $datasourceNode) { if (($idNodes = $xpath -> query('./field[@name = "hostedby"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./field[@name = "hostedby"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing publication'); if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing publication'); if (($accessModeNodes = $xpath -> query('./field[@name = "licenceid"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing publication'); if (($typeNameNodes = $xpath -> query('./field[@name = "typename"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing publication'); $datasource = new JObject(); $datasource -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $datasource -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $datasource -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $datasource -> accessMode = (($accessModeNode = $accessModeNodes -> item(0)) == NULL) ? NULL : trim($accessModeNode -> nodeValue); $datasource -> type = (($typeNameNode = $typeNameNodes -> item(0)) == NULL) ? NULL : trim($typeNameNode -> nodeValue); if (($datasource -> url != NULL) && ((($datasource -> accessMode == self :: DATASOURCE_ACCESS_OPEN) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_EMBARGO) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_RESTRICTED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN) || ($publication -> accessMode == self :: DATASOURCE_ACCESS_CLOSED))) || (($datasource -> accessMode == self :: DATASOURCE_ACCESS_CLOSED) && (($publication -> accessMode == NULL) || ($publication -> accessMode == self :: UNKNOWN))) || (($datasource -> accessMode == self :: UNKNOWN) && ($publication -> accessMode == NULL)) || ((($datasource -> accessMode == NULL) && ($publication -> accessMode == NULL) && ($publication -> url == NULL))))) { $publication -> accessMode = $datasource -> accessMode; $publication -> url = $datasource -> url; if (!in_array($datasource->type, $publication->type)) { array_push ($publication -> type, $datasource -> type); } } if (($datasource -> id != NULL) || ($datasource -> name != NULL) || ($datasource -> url != NULL) || ($datasource -> accessMode != NULL)) $publication -> datasources[] = $datasource; } foreach ($collectedFromNodes as $collectedFromNode) { if (($idNodes = $xpath -> query('./@value_original', $collectedFromNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@value', $collectedFromNode)) == FALSE) throw new Exception('error parsing publication'); $collectedFrom = new JObject(); $collectedFrom -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $collectedFrom -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); if (($collectedFrom -> id != NULL) || ($collectedFrom -> name != NULL)) $publication -> collectedFrom[] = $collectedFrom; } foreach ($sourceNodes as $sourceNode) { if (($source = trim($sourceNode -> nodeValue)) != NULL) $publication -> sources[] = $source; } foreach ($projectNodes as $projectNode) { if (($idNodes = $xpath -> query('./field[@name = "projectId"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing publication'); if (($fundingNodes = $xpath -> query('./field[@name = "funding"]', $projectNode)) == FALSE) throw new Exception('error parsing publication'); $project = new JObject(); $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); $project -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $project -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $project -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $project -> funding = new JObject(); if (($fundingNode = $fundingNodes -> item(0)) == NULL) ; else { if (($funding0Nodes = $xpath -> query('./field[@name = "funding_level_0"]/@value', $fundingNode)) == FALSE) throw new Exception('error parsing publication test'); $project -> funding->funding_level_0 = (($funding0Node = $funding0Nodes -> item(0)) == NULL) ? NULL : trim($funding0Node -> nodeValue); } if (($project -> id != NULL) || ($project -> acronym != NULL) || ($project -> title != NULL) || ($project -> code != NULL)) $publication -> projects[] = $project; } foreach ($pidNodes as $pidNode) { if (($classNodes = $xpath -> query('./field[@name = "classid"]/@value', $pidNode)) == FALSE) throw new Exception('error parsing publication'); if (($valueNodes = $xpath -> query('./field[@name = "value"]/@value', $pidNode)) == FALSE) throw new Exception('error parsing publication'); $pid = new JObject(); $pid -> clazz = (($classNode = $classNodes -> item(0)) == NULL) ? NULL : trim($classNode -> nodeValue); $pid -> value = (($valueNode = $valueNodes -> item(0)) == NULL) ? NULL : trim($valueNode -> nodeValue); if (($pid -> clazz != NULL) && ($pid -> value != NULL)) $publication -> pids[] = $pid; } foreach ($similarNodes as $similarNode) { if (($typeNodes = $xpath -> query('./field[@name = "resulttypeid"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($typeNameNodes = $xpath -> query('./field[@name = "resulttypename"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "resultid"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); if (($yearNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $similarNode)) == FALSE) throw new Exception('error parsing publication'); $similarPublication = new JObject(); $similarPublication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $similarPublication -> source = 'openaire'; $similarPublication -> url = NULL; $similarPublication -> accessMode = NULL; $similarPublication -> datasources = array(); $similarPublication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $similarPublication -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $similarPublication -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $similarPublication -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $similarPublication -> authors = array(); $similarPublication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $similarPublication -> projects = array(); $similarPublication -> embargoEndDate = NULL; $similarPublication -> description = NULL; if (($similarPublication -> id != NULL) || ($similarPublication -> title != NULL) || ($similarPublication -> year != NULL)){ $publication -> similarPublications[] = $similarPublication; } } foreach ($relatedNodes as $relatedNode) { if (($typeNodes = $xpath -> query('./field[@name = "resulttypeid"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "resultid"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($yearNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); switch ((($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue)) { case self :: PUBLICATION: $relatedPublication = new JObject(); $relatedPublication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $relatedPublication -> source = 'openaire'; $relatedPublication -> url = NULL; $relatedPublication -> accessMode = NULL; $relatedPublication -> datasources = array(); $relatedPublication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $relatedPublication -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $relatedPublication -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $relatedPublication -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $relatedPublication -> authors = array(); $relatedPublication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $relatedPublication -> projects = array(); $relatedPublication -> embargoEndDate = NULL; $relatedPublication -> description = NULL; if (($relatedPublication -> id != NULL) || ($relatedPublication -> title != NULL) || ($relatedPublication -> year != NULL)) $publication -> relatedPublications[] = $relatedPublication; break; case self :: DATASET: $relatedDataset = new JObject(); $relatedDataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $relatedDataset -> source = 'openaire'; $relatedDataset -> url = NULL; $relatedDataset -> accessMode = NULL; $relatedDataset -> datasources = array(); $relatedDataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $relatedDataset -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $relatedDataset -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $relatedDataset -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $relatedDataset -> authors = array(); $relatedDataset -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $relatedDataset -> projects = array(); $relatedDataset -> embargoEndDate = NULL; $relatedDataset -> description = NULL; if (($relatedDataset -> id != NULL) || ($relatedDataset -> title != NULL) || ($relatedDataset -> year != NULL)) $publication -> relatedDatasets[] = $relatedDataset; break; } } foreach ($externalReferenceNodes as $externalReferenceNode) { if (($typeNodes = $xpath -> query('./field[@name = "typeid"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "refidentifier"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($labelNodes = $xpath -> query('./field[@name = "label"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($siteNameNodes = $xpath -> query('./field[@name = "sitename"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); switch ((($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue)) { case self :: PUBLICATION: $externalPublication = new JObject(); $externalPublication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $externalPublication -> source = NULL; $externalPublication -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $externalPublication -> accessMode = NULL; $externalPublication -> datasources = array(); $externalPublication -> title = (($labelNode = $labelNodes -> item(0)) == NULL) ? NULL : trim($labelNode -> nodeValue); $externalPublication -> authors = array(); $site = new JObject(); $site -> id = NULL; $site -> lastName = NULL; $site -> firstName = NULL; $site -> fullName = (($siteNameNode = $siteNameNodes -> item(0)) == NULL) ? NULL : trim($siteNameNode -> nodeValue); if ($site -> fullName != NULL) $externalPublication -> authors[] = $site; $externalPublication -> year = NULL; $externalPublication -> projects = array(); $externalPublication -> embargoEndDate = NULL; $externalPublication -> description = NULL; if (($externalPublication -> id != NULL) || ($externalPublication -> url != NULL) || ($externalPublication -> title != NULL)) $publication -> externalPublications[] = $externalPublication; break; case self :: DATASET: $externalDataset = new JObject(); $externalDataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $externalDataset -> source = NULL; $externalDataset -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $externalDataset -> accessMode = NULL; $externalDataset -> datasources = array(); $externalDataset -> title = (($labelNode = $labelNodes -> item(0)) == NULL) ? NULL : trim($labelNode -> nodeValue); $externalDataset -> authors = array(); $site = new JObject(); $site -> id = NULL; $site -> lastName = NULL; $site -> firstName = NULL; $site -> fullName = (($siteNameNode = $siteNameNodes -> item(0)) == NULL) ? NULL : trim($siteNameNode -> nodeValue); if ($site -> fullName != NULL) $externalDataset -> authors[] = $site; $externalDataset -> year = NULL; $externalDataset -> projects = array(); $externalDataset -> embargoEndDate = NULL; $externalDataset -> description = NULL; if (($externalDataset -> id != NULL) || ($externalDataset -> url != NULL) || ($externalDataset -> title != NULL)) $publication -> externalDatasets[] = $externalDataset; } } foreach ($contextNodes as $contextNode) { if (($idNodes = $xpath -> query('./@value', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@value_original', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($typeNodes = $xpath -> query('./field[@name = "contexttype"]/@value', $contextNode)) == FALSE) throw new Exception('error parsing publication'); if (($categoryNodes = $xpath -> query('./field[@name = "category"]', $contextNode)) == FALSE) throw new Exception('error parsing publication'); $context = new JObject(); $context -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $context -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $context -> type = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $context -> categories = array(); foreach ($categoryNodes as $categoryNode) { if (($idNodes = $xpath -> query('./@value_original', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@value', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); if (($conceptNodes = $xpath -> query('./field[@name = "concept"]', $categoryNode)) == FALSE) throw new Exception('error parsing publication'); $category = new JObject(); $category -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $category -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $category -> concepts = array(); foreach ($conceptNodes as $conceptNode) { if (($idNodes = $xpath -> query('./@value_original', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); if (($nameNodes = $xpath -> query('./@value', $conceptNode)) == FALSE) throw new Exception('error parsing publication'); $concept = new JObject(); $concept -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $concept -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); if (($concept -> id != NULL) || ($concept -> name != NULL)) $category -> concepts[] = $concept; } if (($category -> id != NULL) || ($category -> name != NULL) || ($category -> concepts != NULL)) $context -> categories[] = $category; } if (($context -> id != NULL) || ($context -> name != NULL) || ($context -> categories != NULL)) $publication -> contexts[] = $context; } return $publication; } // Parse a single dataset from a search service XML response. // xpath the DOMXPath to parse // return dataset (object) private function parseDataset($xpath,$locale) { if ((($resultsNodes = $xpath -> query('/response/results/result')) == FALSE) || (($resultNode = $resultsNodes -> item(0)) == NULL)) // result throw new Exception('error parsing dataset'); if (($idNodes = $xpath -> query('./field[@name = "resultId"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($authorNodes = $xpath -> query('./field[@name = "author"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($dateNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($publisherNodes = $xpath -> query('./field[@name = "publisher"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($languageNodes = $xpath -> query('./field[@name = "language"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($typeNodes = $xpath -> query('./field[@name ="resulttypename"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($subjectNodes = $xpath -> query('./field[@name = "subject"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($embargoEndDateNodes = $xpath -> query('./field[@name = "embargoenddate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($descriptionNodes = $xpath -> query('./field[@name = "description"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($datasourceNodes = $xpath -> query('./field[@name = "datasource"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($collectedFromNodes = $xpath -> query('./field[@name = "collectedfrom"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($sourceNodes = $xpath -> query('./field[@name = "source"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($pidNodes = $xpath -> query('./field[@name = "pid"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($relatedNodes = $xpath -> query('./field[@name = "isRelatedTo"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($externalReferenceNodes = $xpath -> query('./field[@name = "externalreference"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); if (($contextNodes = $xpath -> query('./field[@name = "context"]', $resultNode)) == FALSE) throw new Exception('error parsing dataset'); $dataset = new JObject(); $dataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $dataset -> source = 'openaire'; $dataset -> accessMode = NULL; $dataset -> url = NULL; $dataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $dataset -> authors = array(); $dataset -> year = (($dateNode = $dateNodes -> item(0)) == NULL) ? NULL : intval(trim($dateNode -> nodeValue)); $dataset -> date = ($dateNode == NULL) ? NULL : strtotime(trim($dateNode -> nodeValue)); $dataset -> publisher = (($publisherNode = $publisherNodes -> item(0)) == NULL) ? NULL : trim($publisherNode -> nodeValue); $dataset -> languages = array(); $dataset -> type = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $dataset -> subjects = array(); $dataset -> embargoEndDate = (($embargoEndDateNode = $embargoEndDateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($embargoEndDateNode -> nodeValue)); $dataset -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); $dataset -> datasources = array(); $dataset -> collectedFrom = array(); $dataset -> sources = array(); $dataset -> projects = array(); $dataset -> pids = array(); $dataset -> relatedPublications = array(); $dataset -> relatedDatasets = array(); $dataset -> externalPublications = array(); $dataset -> externalDatasets = array(); $dataset -> contexts = array(); foreach ($authorNodes as $authorNode) { if (($idNodes = $xpath -> query('./field[@name = "personId"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing dataset'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing dataset'); if (($rankingNodes = $xpath -> query('./field[@name = "ranking"]/@value', $authorNode)) == FALSE) throw new Exception('error parsing publication'); $author = new JObject(); $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 ($languageNodes as $languageNode) { if ((($language = trim($languageNode -> nodeValue)) != NULL) && ($language != self :: UNDETERMINED)) $dataset -> languages[] = $language; } foreach ($subjectNodes as $subjectNode) { if (($subject = trim($subjectNode -> nodeValue)) != NULL) $dataset -> subjects[] = $subject; } foreach ($datasourceNodes as $datasourceNode) { if (($idNodes = $xpath -> query('./field[@name = "hostedby"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing dataset'); if (($nameNodes = $xpath -> query('./field[@name = "hostedby"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing dataset'); if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $datasourceNode)) == FALSE) throw new Exception('error parsing dataset'); if (($accessModeNodes = $xpath -> query('./field[@name = "licenceid"]/@value_original', $datasourceNode)) == FALSE) throw new Exception('error parsing dataset'); $datasource = new JObject(); $datasource -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $datasource -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $datasource -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); // TODO if (substr($datasource -> url, 0, strlen('http://dx.doi.org/http://zenodo.org/record/')) == 'http://dx.doi.org/http://zenodo.org/record/') { $url = substr($datasource -> url, strlen('http://dx.doi.org/')); JLog :: add('Converting datasource URL ' . $datasource -> url . ' to ' . $url, JLog :: DEBUG, self :: LOG); $datasource -> url = $url; } // TODO $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 -> id != NULL) || ($datasource -> name != NULL) || ($datasource -> url != NULL) || ($datasource -> accessMode != NULL)) $dataset -> datasources[] = $datasource; } foreach ($collectedFromNodes as $collectedFromNode) { if (($idNodes = $xpath -> query('./@value_original', $collectedFromNode)) == FALSE) throw new Exception('error parsing dataset'); if (($nameNodes = $xpath -> query('./@value', $collectedFromNode)) == FALSE) throw new Exception('error parsing dataset'); $collectedFrom = new JObject(); $collectedFrom -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $collectedFrom -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); if (($collectedFrom -> id != NULL) || ($collectedFrom -> name != NULL)) $dataset -> collectedFrom[] = $collectedFrom; } foreach ($sourceNodes as $sourceNode) { if (($source = trim($sourceNode -> nodeValue)) != NULL) $dataset -> sources[] = $source; } foreach ($projectNodes as $projectNode) { if (($idNodes = $xpath -> query('./field[@name = "projectId"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing dataset'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing dataset'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing dataset'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing dataset'); $project = new JObject(); $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; } foreach ($pidNodes as $pidNode) { if (($classNodes = $xpath -> query('./field[@name = "classid"]/@value', $pidNode)) == FALSE) throw new Exception('error parsing dataset'); if (($valueNodes = $xpath -> query('./field[@name = "value"]/@value', $pidNode)) == FALSE) throw new Exception('error parsing dataset'); $pid = new JObject(); $pid -> clazz = (($classNode = $classNodes -> item(0)) == NULL) ? NULL : trim($classNode -> nodeValue); $pid -> value = (($valueNode = $valueNodes -> item(0)) == NULL) ? NULL : trim($valueNode -> nodeValue); if (($pid -> clazz != NULL) && ($pid -> value != NULL)) $dataset -> pids[] = $pid; } foreach ($relatedNodes as $relatedNode) { if (($typeNodes = $xpath -> query('./field[@name = "resulttypeid"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "resultid"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($inferredNodes = $xpath -> query('./field[@name = "inferred"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($trustNodes = $xpath -> query('./field[@name = "trust"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($provenanceNodes = $xpath -> query('./field[@name = "provenance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($titleNodes = $xpath -> query('./field[@name = "title"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); if (($yearNodes = $xpath -> query('./field[@name = "dateofacceptance"]/@value', $relatedNode)) == FALSE) throw new Exception('error parsing publication'); switch ((($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue)) { case self :: PUBLICATION: $relatedPublication = new JObject(); $relatedPublication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $relatedPublication -> source = 'openaire'; $relatedPublication -> url = NULL; $relatedPublication -> accessMode = NULL; $relatedPublication -> datasources = array(); $relatedPublication -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $relatedPublication -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $relatedPublication -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $relatedPublication -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $relatedPublication -> authors = array(); $relatedPublication -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $relatedPublication -> projects = array(); $relatedPublication -> embargoEndDate = NULL; $relatedPublication -> description = NULL; if (($relatedPublication -> id != NULL) || ($relatedPublication -> title != NULL) || ($relatedPublication -> year != NULL)) $dataset -> relatedPublications[] = $relatedPublication; break; case self :: DATASET: $relatedDataset = new JObject(); $relatedDataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $relatedDataset -> source = 'openaire'; $relatedDataset -> url = NULL; $relatedDataset -> accessMode = NULL; $relatedDataset -> datasources = array(); $relatedDataset -> title = (($titleNode = $titleNodes -> item(0)) == NULL) ? NULL : trim($titleNode -> nodeValue); $relatedDataset -> inferred = (($inferredNode = $inferredNodes -> item(0)) == NULL) ? NULL : trim($inferredNode -> nodeValue)=="true"?true:false; $relatedDataset -> trust = (($trustNode = $trustNodes -> item(0)) == NULL) ? NULL : trim($trustNode -> nodeValue); $relatedDataset -> provenance = (($provenanceNode = $provenanceNodes -> item(0)) == NULL) ? NULL : trim($provenanceNode -> nodeValue); $relatedDataset -> authors = array(); $relatedDataset -> year = (($yearNode = $yearNodes -> item(0)) == NULL) ? NULL : intval(trim($yearNode -> nodeValue)); $relatedDataset -> projects = array(); $relatedDataset -> embargoEndDate = NULL; $relatedDataset -> description = NULL; if (($relatedDataset -> id != NULL) || ($relatedDataset -> title != NULL) || ($relatedDataset -> year != NULL)) $dataset -> relatedDatasets[] = $relatedDataset; break; } } foreach ($externalReferenceNodes as $externalReferenceNode) { if (($typeNodes = $xpath -> query('./field[@name = "typeid"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($idNodes = $xpath -> query('./field[@name = "refidentifier"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($urlNodes = $xpath -> query('./field[@name = "url"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($labelNodes = $xpath -> query('./field[@name = "label"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); if (($siteNameNodes = $xpath -> query('./field[@name = "sitename"]/@value', $externalReferenceNode)) == FALSE) throw new Exception('error parsing publication'); switch ((($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue)) { case self :: PUBLICATION: $externalPublication = new JObject(); $externalPublication -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $externalPublication -> source = NULL; $externalPublication -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $externalPublication -> accessMode = NULL; $externalPublication -> datasources = array(); $externalPublication -> title = (($labelNode = $labelNodes -> item(0)) == NULL) ? NULL : trim($labelNode -> nodeValue); $externalPublication -> authors = array(); $site = new JObject(); $site -> id = NULL; $site -> lastName = NULL; $site -> firstName = NULL; $site -> fullName = (($siteNameNode = $siteNameNodes -> item(0)) == NULL) ? NULL : trim($siteNameNode -> nodeValue); if ($site -> fullName != NULL) $externalPublication -> authors[] = $site; $externalPublication -> year = NULL; $externalPublication -> projects = array(); $externalPublication -> embargoEndDate = NULL; $externalPublication -> description = NULL; if (($externalPublication -> id != NULL) || ($externalPublication -> url != NULL) || ($externalPublication -> title != NULL)) $dataset -> externalPublications[] = $externalPublication; break; case self :: DATASET: $externalDataset = new JObject(); $externalDataset -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $externalDataset -> source = NULL; $externalDataset -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $externalDataset -> accessMode = NULL; $externalDataset -> datasources = array(); $externalDataset -> title = (($labelNode = $labelNodes -> item(0)) == NULL) ? NULL : trim($labelNode -> nodeValue); $externalDataset -> authors = array(); $site = new JObject(); $site -> id = NULL; $site -> lastName = NULL; $site -> firstName = NULL; $site -> fullName = (($siteNameNode = $siteNameNodes -> item(0)) == NULL) ? NULL : trim($siteNameNode -> nodeValue); if ($site -> fullName != NULL) $externalDataset -> authors[] = $site; $externalDataset -> year = NULL; $externalDataset -> projects = array(); $externalDataset -> embargoEndDate = NULL; $externalDataset -> description = NULL; if (($externalDataset -> id != NULL) || ($externalDataset -> url != NULL) || ($externalDataset -> title != NULL)) $dataset -> externalDatasets[] = $externalDataset; } } foreach ($contextNodes as $contextNode) { if (($idNodes = $xpath -> query('./@value', $contextNode)) == FALSE) throw new Exception('error parsing dataset'); if (($nameNodes = $xpath -> query('./@value_original', $contextNode)) == FALSE) throw new Exception('error parsing dataset'); if (($categoryNodes = $xpath -> query('./field[@name = "category"]', $contextNode)) == FALSE) throw new Exception('error parsing dataset'); $context = new JObject(); $context -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $context -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $context -> categories = array(); foreach ($categoryNodes as $categoryNode) { if (($idNodes = $xpath -> query('./@value', $categoryNode)) == FALSE) throw new Exception('error parsing dataset'); if (($nameNodes = $xpath -> query('./@value_original', $categoryNode)) == FALSE) throw new Exception('error parsing dataset'); if (($conceptNodes = $xpath -> query('./field[@name = "concept"]', $categoryNode)) == FALSE) throw new Exception('error parsing dataset'); $category = new JObject(); $category -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $category -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $category -> concepts = array(); foreach ($conceptNodes as $conceptNode) { if (($idNodes = $xpath -> query('./@value', $conceptNode)) == FALSE) throw new Exception('error parsing dataset'); if (($nameNodes = $xpath -> query('./@value_original', $conceptNode)) == FALSE) throw new Exception('error parsing dataset'); $concept = new JObject(); $concept -> id = (($idNode = $idNodes -> item(0)) == NULL) ? NULL : trim($idNode -> nodeValue); $concept -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); if (($concept -> id != NULL) || ($concept -> name != NULL)) $category -> concepts[] = $concept; } if (($category -> id != NULL) || ($category -> name != NULL) || ($category -> concepts != NULL)) $context -> categories[] = $category; } if (($context -> id != NULL) || ($context -> name != NULL) || ($context -> categories != NULL)) $dataset -> contexts[] = $context; } return $dataset; } // 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)) throw new Exception('error parsing project'); 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 = "funding_level_0"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing project'); if (($fundingStreamNodes = $xpath -> query('./field[@name = "funding_level_1"]/field[@name = "fundingname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing project'); if (($scientificAreaNodes = $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 (($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'); $project = new JObject(); $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 -> 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 -> funding = new JObject(); $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 JObject(); $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; } return $project; } // Parse a single person from a search service XML response. // xpath the DOMXPath to parse // return person (object) private function parsePerson($xpath) { if ((($resultsNodes = $xpath -> query('/response/results/record')) == FALSE) || (($resultNode = $resultsNodes -> item(0)) == NULL)) throw new Exception('error parsing person'); if (($lastNameNodes = $xpath -> query('./field[@name = "secondnames"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing person'); if (($firstNameNodes = $xpath -> query('./field[@name = "firstname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing person'); if (($fullNameNodes = $xpath -> query('./field[@name = "fullname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing person'); if (($countryNodes = $xpath -> query('./field[@name = "nationalityname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing person'); $person = new JObject(); $person -> lastName = (($lastNameNode = $lastNameNodes -> item(0)) == NULL) ? NULL : trim($lastNameNode -> nodeValue); $person -> firstName = (($firstNameNode = $firstNameNodes -> item(0)) == NULL) ? NULL : trim($firstNameNode -> nodeValue); $person -> fullName = (($fullNameNode = $fullNameNodes -> item(0)) == NULL) ? NULL : trim($fullNameNode -> nodeValue); $person -> country = (($countryNode = $countryNodes -> item(0)) == NULL) ? NULL : trim($countryNode -> nodeValue); return $person; } // Parse a single organization from a search service XML response. // xpath the DOMXPath to parse // return organization (object) private function parseOrganization($xpath) { if ((($resultNodes = $xpath -> query('/response/results/result')) == FALSE) || (($resultNode = $resultNodes -> item(0)) == NULL)) throw new Exception('error parsing organization'); if (($shortNameNodes = $xpath -> query('./field[@name = "legalshortname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organization'); if (($nameNodes = $xpath -> query('./field[@name = "legalname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organization'); if (($urlNodes = $xpath -> query('./field[@name = "websiteurl"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organization'); if (($countryNodes = $xpath -> query('./field[@name = "countryname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing organization'); if (($projectNodes = $xpath -> query('./field[@name = "project"]', $resultNode)) == FALSE) throw new Exception('error parsing organization'); $organization = new JObject(); $organization -> shortName = (($shortNameNode = $shortNameNodes -> item(0)) == NULL) ? NULL : trim($shortNameNode -> nodeValue); $organization -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $organization -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $organization -> country = (($countryNode = $countryNodes -> item(0)) == NULL) ? NULL : trim($countryNode -> nodeValue); $organization -> projects = array(); foreach ($projectNodes as $projectNode) { if (($idNodes = $xpath -> query('./field[@name = "projectId"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organization'); if (($acronymNodes = $xpath -> query('./field[@name = "projectacronym"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organization'); if (($titleNodes = $xpath -> query('./field[@name = "projecttitle"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organization'); if (($codeNodes = $xpath -> query('./field[@name = "projectcode"]/@value', $projectNode)) == FALSE) throw new Exception('error parsing organization'); $project = new JObject(); $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)) $organization -> projects[] = $project; } return $organization; } // Parse a single datasource from a search service XML response. // xpath the DOMXPath to parse // return datasource (object) private function parseDatasource($xpath) { if ((($resultsNodes = $xpath -> query('/response/results/result')) == FALSE) || (($resultNode = $resultsNodes -> item(0)) == NULL)) throw new Exception('error parsing datasource'); if (($nameNodes = $xpath -> query('./field[@name = "officialname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($englishNameNodes = $xpath -> query('./field[@name = "englishname"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($urlNodes = $xpath -> query('./field[@name = "websiteurl"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($logoNodes = $xpath -> query('./field[@name = "logourl"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($typeNodes = $xpath -> query('./field[@name = "datasourcetypeuiid"]/@value', $resultNode)) == FALSE) throw new Exception('error pasrsing datasource'); if (($itemsNodes = $xpath -> query('./field[@name = "odnumberofitems"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($dateNodes = $xpath -> query('./field[@name = "odnumberofitemsdate"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($subjectsNodes = $xpath -> query('./field[@name = "odsubjects"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($languagesNodes = $xpath -> query('./field[@name = "odlanguages"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($contentsNodes = $xpath -> query('./field[@name = "odcontenttypes"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($policiesNodes = $xpath -> query('./field[@name = "odpolicies"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($compatibilityNodes = $xpath -> query('./field[@name = "openairecompatibilityid"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); if (($oaiPmhNodes = $xpath -> query('./field[@name = "accessinfopackage"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasources'); if (($descriptionNodes = $xpath -> query('./field[@nam = "oddescription"]/@value', $resultNode)) == FALSE) throw new Exception('error parsing datasource'); $datasource = new JObject(); $datasource -> name = (($nameNode = $nameNodes -> item(0)) == NULL) ? NULL : trim($nameNode -> nodeValue); $datasource -> englishName = (($englishNameNode = $englishNameNodes -> item(0)) == NULL) ? NULL : trim($englishNameNode -> nodeValue); $datasource -> url = (($urlNode = $urlNodes -> item(0)) == NULL) ? NULL : trim($urlNode -> nodeValue); $datasource -> logo = (($logoNode = $logoNodes -> item(0)) == NULL) ? NULL : trim($logoNode -> nodeValue); $datasource -> type = (($typeNode = $typeNodes -> item(0)) == NULL) ? NULL : trim($typeNode -> nodeValue); $datasource -> items = (($itemsNode = $itemsNodes -> item(0)) == NULL) ? NULL : intval(trim($itemsNode -> nodeValue)); $datasource -> date = (($dateNode = $dateNodes -> item(0)) == NULL) ? NULL : strtotime(trim($dateNode -> nodeValue)); $datasource -> subjects = (($subjectsNode = $subjectsNodes -> item(0)) == NULL) ? NULL : trim($subjectsNode -> nodeValue); $datasource -> languages = array(); foreach($languagesNodes as $languageNode) { if ((($language = trim($languageNode -> nodeValue)) != NULL) && ($language != self :: UNDETERMINED)) { $datasource -> languages[] = $language; } } $datasource -> contents = (($contentsNode = $contentsNodes -> item(0)) == NULL) ? NULL : trim($contentsNode -> nodeValue); $datasource -> policies = (($policiesNode = $policiesNodes -> item(0)) == NULL) ? NULL : trim($policiesNode -> nodeValue); $datasource -> compatibility = (($compatibilityNode = $compatibilityNodes -> item(0)) == NULL) ? NULL : trim($compatibilityNode -> nodeValue); $datasource -> oaiPmh = (($oaiPmhNode = $oaiPmhNodes -> item(0)) == NULL) ? NULL : trim($oaiPmhNode -> nodeValue); $datasource -> description = (($descriptionNode = $descriptionNodes -> item(0)) == NULL) ? NULL : trim($descriptionNode -> nodeValue); return $datasource; } }