1
|
<?php
|
2
|
|
3
|
defined('_JEXEC') or die('Access denied');
|
4
|
|
5
|
jimport('joomla.methods');
|
6
|
|
7
|
// This helper _formats datasets.
|
8
|
abstract class DatasetHelper {
|
9
|
const OPENAIRE = 'openaire';
|
10
|
const MAX_AUTHORS = 15;
|
11
|
const MAX_PROJECTS = 15;
|
12
|
const MAX_DESCRIPTION = 500;
|
13
|
const SUFFIX = '...';
|
14
|
const OPEN_ACCESS = 'OPEN';
|
15
|
const CLOSED_ACCESS = 'CLOSED';
|
16
|
const RESTRICTED_ACCESS = 'RESTRICTED';
|
17
|
const EMBARGO_ACCESS = 'EMBARGO';
|
18
|
|
19
|
// Format a dataset.
|
20
|
// $dataset the dataset to format
|
21
|
// $itemId the item ID to use for internal links
|
22
|
// return a string containing the full HTML for the dataset or an empty string if any errors occur
|
23
|
public static function formatDataset($dataset, $itemId) {
|
24
|
if ($dataset == NULL)
|
25
|
return '';
|
26
|
$dataset = DatasetHelper :: _formatTitle($dataset -> title, $dataset -> accessMode, $dataset -> id, $dataset -> source, $dataset -> url, $itemId, isset($dataset -> inferred)?$dataset -> inferred:false, isset($dataset -> inferred)?$dataset -> trust:"", isset($dataset -> inferred)?$dataset -> provenance:"") . DatasetHelper :: _formatData($dataset, $itemId) . DatasetHelper :: _formatDescription($dataset -> description);
|
27
|
return ($dataset == NULL) ? '' : ('<div class="srchRow">' . $dataset . '</div>');
|
28
|
}
|
29
|
|
30
|
public static function _formatTitle($title, $accessMode, $id, $source, $url, $itemId, $inferred = false, $trust = "", $provenance = "") {
|
31
|
switch ($accessMode) {
|
32
|
case DatasetHelper :: OPEN_ACCESS:
|
33
|
$accessModeClass = 'openAccess';
|
34
|
$accessModeTitle = JText :: _('OPEN_ACCESS');
|
35
|
break;
|
36
|
case DatasetHelper :: EMBARGO_ACCESS:
|
37
|
$accessModeClass = 'embargoAccess';
|
38
|
$accessModeTitle = JText :: _('EMBARGO_ACCESS');
|
39
|
break;
|
40
|
case DatasetHelper :: RESTRICTED_ACCESS:
|
41
|
$accessModeClass = 'restrictedAccess';
|
42
|
$accessModeTitle = JText :: _('RESTRICTED_ACCESS');
|
43
|
break;
|
44
|
case DatasetHelper :: CLOSED_ACCESS:
|
45
|
$accessModeClass = 'closedAccess';
|
46
|
$accessModeTitle = JText :: _('CLOSED_ACCESS');
|
47
|
break;
|
48
|
default:
|
49
|
$accessModeClass = NULL;
|
50
|
$accessModeTitle = NULL;
|
51
|
}
|
52
|
//return ($title == NULL) ? '' : ('<h4' . (($accessModeClass == NULL) ? '' : (' class="' . $accessModeClass . '" title="' . $accessModeTitle . '"')) . '>' . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('<a href="' . JRoute :: _(JURI :: base() . 'index.php?option=com_openaire&view=dataset&Itemid=' . $itemId . '&datasetId=' . $id) . '">')) : (($url == NULL) ? '' : ('<a target="_blank" class="icon-external" href="' . $url . '">'))) . $title . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('</a>')) : (($url == NULL) ? '' : ('</a>'))) . ($inferred == true?" <span class='inferred'><img src='templates/yoo_solar/styles/openaire/images/box_info_ok.png' /></span><div style='display: none'><div class='inferred-popup' id='popup-". $id. "'>trust: $trust, provenance: $provenance </div></div>" :"") . '</h4>');
|
53
|
return ($title == NULL) ? '' : ('<h4' . (($accessModeClass == NULL) ? '' : (' class="' . $accessModeClass . '" title="' . $accessModeTitle . '"')) . '>' . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('<a href="' . JRoute :: _('index.php?option=com_openaire&view=dataset&Itemid=' . $itemId . '&datasetId=' . $id) . '">')) : (($url == NULL) ? '' : ('<a target="_blank" class="icon-external" href="' . $url . '">'))) . $title . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('</a>')) : (($url == NULL) ? '' : ('</a>'))) . '</h4>');
|
54
|
|
55
|
}
|
56
|
|
57
|
public static function _formatData($dataset, $itemId) {
|
58
|
if ($dataset == NULL)
|
59
|
return '';
|
60
|
$info = array();
|
61
|
$info[] = DatasetHelper :: _formatAuthors($dataset -> authors, $itemId);
|
62
|
$info[] = DatasetHelper :: _formatYear($dataset -> year);
|
63
|
$data = array();
|
64
|
$data[] = implode(' ', array_filter($info));
|
65
|
$data[] = DatasetHelper :: _formatPublisher(isset($dataset -> publisher)?$dataset -> publisher:"");
|
66
|
$data[] = DatasetHelper :: _formatProjects($dataset -> projects, $itemId);
|
67
|
$data[] = DatasetHelper :: _formatEmbargoEndDate($dataset -> embargoEndDate);
|
68
|
$data = array_filter($data);
|
69
|
return ($data == NULL) ? '' : ('<div class="biblio">' . implode('<br />', $data) . '</div>');
|
70
|
}
|
71
|
|
72
|
public static function _formatAuthors($authors, $itemId) {
|
73
|
$authors = ($authors == NULL) ? NULL : array_filter(array_map(function ($author) use ($itemId) {return DatasetHelper :: _formatAuthor($author, $itemId);}, $authors));
|
74
|
return ($authors == NULL) ? '' : (implode('; ', array_slice($authors, 0, DatasetHelper :: MAX_AUTHORS)) . ((count($authors) > DatasetHelper :: MAX_AUTHORS) ? ';...' : ''));
|
75
|
}
|
76
|
|
77
|
public static function _formatAuthor($author, $itemId) {
|
78
|
return (($author == NULL) || ((($author -> lastName == NULL) || ($author -> firstName == NULL)) && ($author -> fullName == NULL))) ? '' : ('<span class="auth">' . (($author -> id == NULL) ? '' : ('<a href="' . JRoute :: _('index.php?option=com_openaire&view=person&Itemid=' . $itemId . '&personId=' . $author -> id) . '">')) . ((($author -> lastName == NULL) || ($author -> firstName == NULL)) ? $author -> fullName : ($author -> lastName . ', ' . $author -> firstName)) . (($author -> id == NULL) ? '' : '</a>') . '</span>');
|
79
|
}
|
80
|
|
81
|
public static function _formatYear($year) {
|
82
|
return ($year == NULL) ? '' : ('<span class="year">(' . $year . ')</span>');
|
83
|
}
|
84
|
|
85
|
public static function _formatPublisher($publisher) {
|
86
|
return ($publisher == NULL) ? '' : (JText :: _('PUBLISHER_') . ' ' . $publisher);
|
87
|
}
|
88
|
|
89
|
public static function _formatProjects($projects, $itemId) {
|
90
|
$projects = ($projects == NULL) ? NULL : array_filter(array_map(function ($project) use ($itemId) {return DatasetHelper :: _formatProject($project, $itemId);}, $projects));
|
91
|
return ($projects == NULL) ? '' : (JText :: _('PROJECTS_') . ' ' . implode(', ', array_slice($projects, 0, DatasetHelper :: MAX_PROJECTS)) . ((count($projects) > DatasetHelper :: MAX_PROJECTS) ? ',...' : ''));
|
92
|
}
|
93
|
|
94
|
public static function _formatProject($project, $itemId) {
|
95
|
return (($project -> acronym == NULL) && ($project -> title == NULL)) ? '' : ('<span class="proj">' . (($project -> id == NULL) ? '' : ('<a href="' . JRoute :: _('index.php?option=com_openaire&view=project&Itemid=' . $itemId . '&projectId=' . $project -> id) . '">')) . (($project -> acronym == NULL) ? $project -> title : $project -> acronym) . (($project -> code == NULL) ? '' : (' (' . $project -> code . ')')) . (($project -> id == NULL) ? '' : '</a>') . '</span>');
|
96
|
}
|
97
|
|
98
|
public static function _formatEmbargoEndDate($embargoEndDate) {
|
99
|
return ($embargoEndDate == NULL) ? '' : (JText :: _('EMBARGO_END_DATE_') . ' <span class="embargoDate">' . date(JText :: _('DATE_FORMAT'), $embargoEndDate) . '</span>');
|
100
|
}
|
101
|
|
102
|
public static function _formatDescription($description) {
|
103
|
return ($description == NULL) ? '' : ('<div class="description">' . ((strlen($description) > DatasetHelper :: MAX_DESCRIPTION) ? (substr($description, 0, DatasetHelper :: MAX_DESCRIPTION - strlen(DatasetHelper :: SUFFIX)) . DatasetHelper :: SUFFIX) : $description) . '</div>');
|
104
|
}
|
105
|
}
|
106
|
|