Open Preprint Systems  3.3.0
Submission.inc.php
1 <?php
2 
23 // Author display in ToC
24 define ('AUTHOR_TOC_DEFAULT', 0);
25 define ('AUTHOR_TOC_HIDE', 1);
26 define ('AUTHOR_TOC_SHOW', 2);
27 
28 // Article access constants -- see Publication::getData('accessStatus')
29 define('ARTICLE_ACCESS_OPEN', 1);
30 
31 import('lib.pkp.classes.submission.PKPSubmission');
32 
33 class Submission extends PKPSubmission {
34 
35  //
36  // Get/set methods
37  //
38 
46  function _getContextLicenseFieldValue($locale, $field, $publication = null) {
47  $context = Services::get('context')->get($this->getData('contextId'));
48  $fieldValue = null; // Scrutinizer
49  switch ($field) {
50  case PERMISSIONS_FIELD_LICENSE_URL:
51  $fieldValue = $context->getData('licenseUrl');
52  break;
53  case PERMISSIONS_FIELD_COPYRIGHT_HOLDER:
54  switch($context->getData('copyrightHolderType')) {
55  case 'author':
56  $fieldValue = array($context->getPrimaryLocale() => $this->getAuthorString());
57  break;
58  case 'context':
59  case null:
60  $fieldValue = $context->getName(null);
61  break;
62  default:
63  $fieldValue = $context->getData('copyrightHolderOther');
64  break;
65  }
66  break;
67  case PERMISSIONS_FIELD_COPYRIGHT_YEAR:
68  // Default copyright year to current year
69  $fieldValue = date('Y');
70 
71  // Use preprint publish date of current publication
72  if (!$publication) {
73  $publication = $this->getCurrentPublication();
74  }
75  if ($publication) {
76  $fieldValue = date('Y', strtotime($publication->getData('datePublished')));
77  }
78  break;
79  default: assert(false);
80  }
81 
82  // Return the fetched license field
83  if ($locale === null) return $fieldValue;
84  if (isset($fieldValue[$locale])) return $fieldValue[$locale];
85  return null;
86  }
87 
93  function getBestArticleId() {
94  return parent::getBestId();
95  }
96 
102  function getJournalId() {
103  return $this->getData('contextId');
104  }
105 
111  function setJournalId($journalId) {
112  return $this->setData('contextId', $journalId);
113  }
114 
119  function getSectionId() {
120  $publication = $this->getCurrentPublication();
121  if (!$publication) {
122  return 0;
123  }
124  return $publication->getData('sectionId');
125  }
126 
131  function setSectionId($sectionId) {
132  $publication = $this->getCurrentPublication();
133  if ($publication) {
134  $publication->setData('sectionId', $sectionId);
135  }
136  }
137 
144  $publication = $this->getCurrentPublication();
145  if (!$publication) {
146  return '';
147  }
148  $coverImage = $publication->getLocalizedData('coverImage');
149  return empty($coverImage['uploadName']) ? '' : $coverImage['uploadName'];
150  }
151 
158  function getCoverImage($locale) {
159  $publication = $this->getCurrentPublication();
160  if (!$publication) {
161  return '';
162  }
163  $coverImage = $publication->getData('coverImage', $locale);
164  return empty($coverImage['uploadName']) ? '' : $coverImage['uploadName'];
165  }
166 
173  $publication = $this->getCurrentPublication();
174  if (!$publication) {
175  return '';
176  }
177  $coverImage = $publication->getLocalizedData('coverImage');
178  return empty($coverImage['altText']) ? '' : $coverImage['altText'];
179  }
180 
187  function getCoverImageAltText($locale) {
188  $publication = $this->getCurrentPublication();
189  if (!$publication) {
190  return '';
191  }
192  $coverImage = $publication->getData('coverImage', $locale);
193  return empty($coverImage['altText']) ? '' : $coverImage['altText'];
194  }
195 
203  $publication = $this->getCurrentPublication();
204  if (!$publication) {
205  return '';
206  }
207  return $publication->getLocalizedCoverImageUrl($this->getData('contextId'));
208  }
209 
215  function getGalleys() {
216  $galleys = $this->getData('galleys');
217  if (is_null($galleys)) {
218  $this->setData('galleys', Application::get()->getRepresentationDAO()->getByPublicationId($this->getCurrentPublication()->getId(), $this->getData('contextId'))->toArray());
219  return $this->getData('galleys');
220  }
221  return $galleys;
222  }
223 
229  function getLocalizedGalleys() {
230  $allGalleys = $this->getData('galleys');
231  $galleys = array();
232  foreach (array(AppLocale::getLocale(), AppLocale::getPrimaryLocale()) as $tryLocale) {
233  foreach (array_keys($allGalleys) as $key) {
234  if ($allGalleys[$key]->getLocale() == $tryLocale) {
235  $galleys[] = $allGalleys[$key];
236  }
237  }
238  if (!empty($galleys)) {
239  HookRegistry::call('ArticleGalleyDAO::getLocalizedGalleysByArticle', array(&$galleys));
240  return $galleys;
241  }
242  }
243 
244  return $galleys;
245  }
246 
251  function getTotalGalleyViews() {
252  $application = Application::get();
253  $publications = $this->getPublishedPublications();
254  $views = 0;
255 
256  foreach ($publications as $publication) {
257  foreach ((array) $publication->getData('galleys') as $galley) {
258  $file = $galley->getFile();
259  if (!$galley->getRemoteUrl() && $file) {
260  $views = $views + $application->getPrimaryMetricByAssoc(ASSOC_TYPE_SUBMISSION_FILE, $file->getId());
261  }
262  }
263  }
264  return $views;
265  }
266 
272  function getHideAuthor() {
273  $publication = $this->getCurrentPublication();
274  if (!$publication) {
275  return 0;
276  }
277  return $publication->getData('hideAuthor');
278  }
279 }
Submission\getHideAuthor
getHideAuthor()
Definition: Submission.inc.php:272
DataObject\getData
& getData($key, $locale=null)
Definition: DataObject.inc.php:100
Submission\_getContextLicenseFieldValue
_getContextLicenseFieldValue($locale, $field, $publication=null)
Definition: Submission.inc.php:46
Submission\getLocalizedGalleys
getLocalizedGalleys()
Definition: Submission.inc.php:229
Submission
Article class.
Definition: Submission.inc.php:33
PKPSubmission
The Submission class implements the abstract data model of a scholarly submission.
Definition: PKPSubmission.inc.php:36
AppLocale\getPrimaryLocale
static getPrimaryLocale()
Definition: env1/MockAppLocale.inc.php:95
PKPSubmission\getLocale
getLocale()
Definition: PKPSubmission.inc.php:453
Submission\setJournalId
setJournalId($journalId)
Definition: Submission.inc.php:111
Submission\setSectionId
setSectionId($sectionId)
Definition: Submission.inc.php:131
Submission\getCoverImageAltText
getCoverImageAltText($locale)
Definition: Submission.inc.php:187
Submission\getBestArticleId
getBestArticleId()
Definition: Submission.inc.php:93
Submission\getLocalizedCoverImageUrl
getLocalizedCoverImageUrl()
Definition: Submission.inc.php:202
Submission\getSectionId
getSectionId()
Definition: Submission.inc.php:119
PKPSubmission\getCurrentPublication
getCurrentPublication()
Definition: PKPSubmission.inc.php:68
DataObject\getId
getId()
Definition: DataObject.inc.php:206
Submission\getGalleys
getGalleys()
Definition: Submission.inc.php:215
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PKPSubmission\getPublishedPublications
getPublishedPublications()
Definition: PKPSubmission.inc.php:105
Submission\getJournalId
getJournalId()
Definition: Submission.inc.php:102
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
Submission\getLocalizedCoverImage
getLocalizedCoverImage()
Definition: Submission.inc.php:143
Submission\getCoverImage
getCoverImage($locale)
Definition: Submission.inc.php:158
DataObject\setData
setData($key, $value, $locale=null)
Definition: DataObject.inc.php:132
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49
Submission\getLocalizedCoverImageAltText
getLocalizedCoverImageAltText()
Definition: Submission.inc.php:172
Submission\getTotalGalleyViews
getTotalGalleyViews()
Definition: Submission.inc.php:251