1
|
<?php
|
2
|
|
3
|
defined('_JEXEC') or die('Access denied');
|
4
|
|
5
|
jimport('joomla.methods');
|
6
|
|
7
|
// This helper formats projects.
|
8
|
abstract class ProjectHelper {
|
9
|
const MAX_ORGANIZATIONS = 15;
|
10
|
|
11
|
// Format a project.
|
12
|
// $project the project to format
|
13
|
// $itemId the item ID to use for internal links
|
14
|
// return a string containing the full HTML for the project or an empty string if any errors occur
|
15
|
public static function formatProject($project, $itemId) {
|
16
|
if (($project == NULL) || (($project -> acronym == NULL) && ($project -> title == NULL)))
|
17
|
return '';
|
18
|
return '<div class="srchRow"><h4' . ($project -> sc39 ? (' class="sc39" title="' . JText :: _('SPECIAL_CLAUSE_39') . '"') : '') . '>' . (($project -> id == NULL) ? '' : ('<a ' . 'href="' . JRoute :: _(JURI :: base() . 'index.php?option=com_openaire&view=project&Itemid=' . $itemId . '&projectId=' . $project -> id) . '">')) . $project -> acronym . ((($project -> acronym == NULL) || ($project -> title == NULL)) ? '' : ' - ') . $project -> title . (($project -> code == NULL) ? '' : (' ('. $project -> code . ')')) . (($project -> id == NULL) ? '' : ('</a>')) . '</h4>' . ProjectHelper :: _formatData($project, $itemId) . '</div>';
|
19
|
}
|
20
|
|
21
|
public static function _formatData($project, $itemId) {
|
22
|
if ($project == NULL)
|
23
|
return '';
|
24
|
$years = ProjectHelper :: _formatYears($project -> startYear, $project -> endYear);
|
25
|
$organizations = ProjectHelper :: _formatOrganizations($project -> organizations, $itemId);
|
26
|
return (($project -> funder == NULL) && ($organizations == NULL) && ($years == NULL)) ? '' : ('<div class="biblio">' . $project -> funder . ((($project -> funder == NULL) || ($years == NULL)) ? '' : ' ') . $years . (((($project -> funder == NULL) && ($years == NULL)) || ($organizations == NULL)) ? '' : '<br />') . (($organizations == NULL) ? '' : (JText :: _('PARTICIPANTS_') . ' ' . $organizations)) . '</div>');
|
27
|
}
|
28
|
|
29
|
public static function _formatYears($startYear, $endYear) {
|
30
|
return (($startYear == NULL) && ($endYear == NULL)) ? '' : ('<span class="year">(' . $startYear . ((($startYear == NULL) || ($endYear == NULL)) ? '' : ' - ') . $endYear . ')</span>');
|
31
|
}
|
32
|
|
33
|
public static function _formatOrganizations($organizations, $itemId) {
|
34
|
$organizations = ($organizations == NULL) ? NULL : array_filter(array_map(function ($organization) use ($itemId) {return ProjectHelper :: _formatOrganization($organization, $itemId);}, $organizations));
|
35
|
return ($organizations == NULL) ? '' : (implode(', ' , array_slice($organizations, 0, ProjectHelper :: MAX_ORGANIZATIONS)) . ((count($organizations) > ProjectHelper :: MAX_ORGANIZATIONS) ? ',...' : ''));
|
36
|
}
|
37
|
|
38
|
public static function _formatOrganization($organization, $itemId) {
|
39
|
return (($organization == NULL) || (($organization -> shortName == NULL) && ($organization -> name == NULL))) ? '' : ('<span class="organization">' . (($organization -> id == NULL) ? '' : ('<a href="' . JRoute :: _(JURI :: base() . 'index.php?option=com_openaire&view=organization&Itemid=' . $itemId . '&organizationId=' . $organization -> id) . '">')) . (($organization -> shortName == NULL) ? $organization -> name : $organization -> shortName) . (($organization -> id == NULL) ? '' : '</a>') . '</span>');
|
40
|
}
|
41
|
}
|
42
|
|