Open Preprint Systems  3.3.0
Context.inc.php
1 <?php
2 
16  // Constant used to distinguish whether metadata is enabled and whether it
17  // should be requested or required during submission
18  define('METADATA_DISABLE', 0);
19  define('METADATA_ENABLE', 'enable');
20  define('METADATA_REQUEST', 'request');
21  define('METADATA_REQUIRE', 'require');
22 
23 abstract class Context extends DataObject {
24 
30  function getLocalizedName($preferredLocale = null) {
31  return $this->getLocalizedData('name', $preferredLocale);
32  }
33 
38  function setName($name, $locale = null) {
39  $this->setData('name', $name, $locale);
40  }
41 
45  function getName($locale = null) {
46  return $this->getData('name', $locale);
47  }
48 
53  function getContactName() {
54  return $this->getData('contactName');
55  }
56 
61  function setContactName($contactName) {
62  $this->setData('contactName', $contactName);
63  }
64 
69  function getContactEmail() {
70  return $this->getData('contactEmail');
71  }
72 
77  function setContactEmail($contactEmail) {
78  $this->setData('contactEmail', $contactEmail);
79  }
80 
86  function getDescription($locale = null) {
87  return $this->getData('description', $locale);
88  }
89 
95  function setDescription($description, $locale = null) {
96  $this->setData('description', $description, $locale);
97  }
98 
103  function getPath() {
104  return $this->getData('urlPath');
105  }
106 
111  function setPath($path) {
112  $this->setData('urlPath', $path);
113  }
114 
119  function getEnabled() {
120  return $this->getData('enabled');
121  }
122 
127  function setEnabled($enabled) {
128  $this->setData('enabled', $enabled);
129  }
130 
135  function getPrimaryLocale() {
136  return $this->getData('primaryLocale');
137  }
138 
143  function setPrimaryLocale($primaryLocale) {
144  $this->setData('primaryLocale', $primaryLocale);
145  }
150  function getSequence() {
151  return $this->getData('seq');
152  }
153 
158  function setSequence($sequence) {
159  $this->setData('seq', $sequence);
160  }
161 
167  return $this->getLocalizedData('description');
168  }
169 
174  function getLocalizedAcronym() {
175  return $this->getLocalizedData('acronym');
176  }
177 
183  function getAcronym($locale) {
184  return $this->getData('acronym', $locale);
185  }
186 
191  function getLocalizedFavicon() {
192  $faviconArray = $this->getData('favicon');
193  foreach (array(AppLocale::getLocale(), AppLocale::getPrimaryLocale()) as $locale) {
194  if (isset($faviconArray[$locale])) return $faviconArray[$locale];
195  }
196  return null;
197  }
198 
204  return $this->getData('supportedFormLocales');
205  }
206 
213  $supportedLocales =& $this->getData('supportedFormLocaleNames');
214 
215  if (!isset($supportedLocales)) {
216  $supportedLocales = array();
217  $localeNames =& AppLocale::getAllLocales();
218 
219  $locales = $this->getSupportedFormLocales();
220  if (!isset($locales) || !is_array($locales)) {
221  $locales = array();
222  }
223 
224  foreach ($locales as $localeKey) {
225  $supportedLocales[$localeKey] = $localeNames[$localeKey];
226  }
227  }
228 
229  return $supportedLocales;
230  }
231 
237  return $this->getData('supportedSubmissionLocales');
238  }
239 
247  $supportedLocales =& $this->getData('supportedSubmissionLocaleNames');
248 
249  if (!isset($supportedLocales)) {
250  $supportedLocales = array();
251  $localeNames =& AppLocale::getAllLocales();
252 
253  $locales = $this->getSupportedSubmissionLocales();
254  if (!isset($locales) || !is_array($locales)) {
255  $locales = array();
256  }
257 
258  foreach ($locales as $localeKey) {
259  $supportedLocales[$localeKey] = $localeNames[$localeKey];
260  }
261  }
262 
263  return $supportedLocales;
264  }
265 
270  function getSupportedLocales() {
271  return $this->getData('supportedLocales');
272  }
273 
280  $supportedLocales =& $this->getData('supportedLocaleNames');
281 
282  if (!isset($supportedLocales)) {
283  $supportedLocales = array();
284  $localeNames =& AppLocale::getAllLocales();
285 
286  $locales = $this->getSupportedLocales();
287  if (!isset($locales) || !is_array($locales)) {
288  $locales = array();
289  }
290 
291  foreach ($locales as $localeKey) {
292  $supportedLocales[$localeKey] = $localeNames[$localeKey];
293  }
294  }
295 
296  return $supportedLocales;
297  }
298 
303  public abstract function getAssocType();
304 
309  function getSetting($name, $locale = null) {
310  return $this->getData($name, $locale);
311  }
312 
317  function getLocalizedSetting($name, $locale = null) {
318  return $this->getLocalizedData($name, $locale);
319  }
320 
328  function updateSetting($name, $value, $type = null, $isLocalized = false) {
329  $settingsDao = Application::getContextSettingsDAO();
330  return $settingsDao->updateSetting($this->getId(), $name, $value, $type, $isLocalized);
331  }
332 
337  function getViews() {
338  $application = Application::get();
339  return $application->getPrimaryMetricByAssoc(Application::getContextAssocType(), $this->getId());
340  }
341 
342 
343  //
344  // Statistics API
345  //
351  function getMetricTypes($withDisplayNames = false) {
352  // Retrieve report plugins enabled for this journal.
353  $reportPlugins = PluginRegistry::loadCategory('reports', true, $this->getId());
354  if (empty($reportPlugins)) return array();
355 
356  // Run through all report plugins and retrieve all supported metrics.
357  $metricTypes = array();
358  foreach ($reportPlugins as $reportPlugin) {
359  $pluginMetricTypes = $reportPlugin->getMetricTypes();
360  if ($withDisplayNames) {
361  foreach ($pluginMetricTypes as $metricType) {
362  $metricTypes[$metricType] = $reportPlugin->getMetricDisplayType($metricType);
363  }
364  } else {
365  $metricTypes = array_merge($metricTypes, $pluginMetricTypes);
366  }
367  }
368 
369  return $metricTypes;
370  }
371 
380  function getDefaultMetricType() {
381  $defaultMetricType = $this->getData('defaultMetricType');
382 
383  // Check whether the selected metric type is valid.
384  $availableMetrics = $this->getMetricTypes();
385  if (empty($defaultMetricType)) {
386  if (count($availableMetrics) === 1) {
387  // If there is only a single available metric then use it.
388  $defaultMetricType = $availableMetrics[0];
389  } else {
390  // Use the site-wide default metric.
391  $application = Application::get();
392  $defaultMetricType = $application->getDefaultMetricType();
393  }
394  } else {
395  if (!in_array($defaultMetricType, $availableMetrics)) return null;
396  }
397 
398  return $defaultMetricType;
399  }
400 
416  function getMetrics($metricType = null, $columns = array(), $filter = array(), $orderBy = array(), $range = null) {
417  // Add a context filter and run the report.
418  $filter[STATISTICS_DIMENSION_CONTEXT_ID] = $this->getId();
419  $application = Application::get();
420  return $application->getMetrics($metricType, $columns, $filter, $orderBy, $range);
421  }
422 }
Context\getContactEmail
getContactEmail()
Definition: Context.inc.php:69
Context\setEnabled
setEnabled($enabled)
Definition: Context.inc.php:127
DataObject\getData
& getData($key, $locale=null)
Definition: DataObject.inc.php:100
PKPLocale\getAllLocales
static & getAllLocales()
Definition: PKPLocale.inc.php:537
DataObject\getLocalizedData
getLocalizedData($key, $preferredLocale=null)
Definition: DataObject.inc.php:71
DataObject
Any class with an associated DAO should extend this class.
Definition: DataObject.inc.php:18
Context\getDescription
getDescription($locale=null)
Definition: Context.inc.php:86
Context\getLocalizedDescription
getLocalizedDescription()
Definition: Context.inc.php:166
Context\getDefaultMetricType
getDefaultMetricType()
Definition: Context.inc.php:380
Context
Basic class describing a context.
Definition: Context.inc.php:23
Context\getLocalizedName
getLocalizedName($preferredLocale=null)
Definition: Context.inc.php:30
Context\getSupportedLocaleNames
getSupportedLocaleNames()
Definition: Context.inc.php:279
Context\updateSetting
updateSetting($name, $value, $type=null, $isLocalized=false)
Definition: Context.inc.php:328
AppLocale\getPrimaryLocale
static getPrimaryLocale()
Definition: env1/MockAppLocale.inc.php:95
Context\getSupportedFormLocaleNames
getSupportedFormLocaleNames()
Definition: Context.inc.php:212
Context\getSupportedSubmissionLocales
getSupportedSubmissionLocales()
Definition: Context.inc.php:236
Context\getSetting
getSetting($name, $locale=null)
Definition: Context.inc.php:309
Context\getPath
getPath()
Definition: Context.inc.php:103
Context\getAssocType
getAssocType()
Context\getLocalizedFavicon
getLocalizedFavicon()
Definition: Context.inc.php:191
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
Application\getContextAssocType
static getContextAssocType()
Definition: Application.inc.php:177
Context\setContactEmail
setContactEmail($contactEmail)
Definition: Context.inc.php:77
Context\getLocalizedSetting
getLocalizedSetting($name, $locale=null)
Definition: Context.inc.php:317
Context\getAcronym
getAcronym($locale)
Definition: Context.inc.php:183
Context\getMetricTypes
getMetricTypes($withDisplayNames=false)
Definition: Context.inc.php:351
Context\getSupportedLocales
getSupportedLocales()
Definition: Context.inc.php:270
Context\getEnabled
getEnabled()
Definition: Context.inc.php:119
Context\getViews
getViews()
Definition: Context.inc.php:337
Context\getPrimaryLocale
getPrimaryLocale()
Definition: Context.inc.php:135
Context\setSequence
setSequence($sequence)
Definition: Context.inc.php:158
Context\setPrimaryLocale
setPrimaryLocale($primaryLocale)
Definition: Context.inc.php:143
DataObject\getId
getId()
Definition: DataObject.inc.php:206
Context\getContactName
getContactName()
Definition: Context.inc.php:53
Context\setName
setName($name, $locale=null)
Definition: Context.inc.php:38
Context\setDescription
setDescription($description, $locale=null)
Definition: Context.inc.php:95
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
Context\getName
getName($locale=null)
Definition: Context.inc.php:45
Context\getSequence
getSequence()
Definition: Context.inc.php:150
Context\setContactName
setContactName($contactName)
Definition: Context.inc.php:61
Context\getSupportedSubmissionLocaleNames
getSupportedSubmissionLocaleNames()
Definition: Context.inc.php:246
Context\setPath
setPath($path)
Definition: Context.inc.php:111
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
Context\getSupportedFormLocales
getSupportedFormLocales()
Definition: Context.inc.php:203
Context\getLocalizedAcronym
getLocalizedAcronym()
Definition: Context.inc.php:174
DataObject\setData
setData($key, $value, $locale=null)
Definition: DataObject.inc.php:132
Context\getMetrics
getMetrics($metricType=null, $columns=array(), $filter=array(), $orderBy=array(), $range=null)
Definition: Context.inc.php:416