Open Journal 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 
304  function getDateTimeFormats($format) {
305  $data = $this->getData($format);
306  $fallbackConfigVar = strtolower(preg_replace('/([A-Z])/', '_$1', $format));
307  foreach ($this->getSupportedFormLocales() as $supportedLocale) {
308  if (!array_key_exists($supportedLocale, $data)) $data[$supportedLocale] = Config::getVar('general', $fallbackConfigVar);
309  }
310 
311  return $data;
312  }
313 
318  function getLocalizedDateFormatShort($locale = null) {
319  if (is_null($locale)) {
320  $locale = AppLocale::getLocale();
321  }
322  $localizedData = $this->getData('dateFormatShort', $locale);
323  if (empty($localizedData)) {
324  $localizedData = Config::getVar('general', 'date_format_short');
325  }
326 
327  return $localizedData;
328  }
329 
334  function getLocalizedDateFormatLong($locale = null) {
335  if (is_null($locale)) {
336  $locale = AppLocale::getLocale();
337  }
338  $localizedData = $this->getData('dateFormatLong', $locale);
339  if (empty($localizedData)) {
340  $localizedData = Config::getVar('general', 'date_format_long');
341  }
342 
343  return $localizedData;
344  }
345 
350  function getLocalizedTimeFormat($locale = null) {
351  if (is_null($locale)) {
352  $locale = AppLocale::getLocale();
353  }
354  $localizedData = $this->getData('timeFormat', $locale);
355  if (empty($localizedData)) {
356  $localizedData = Config::getVar('general', 'time_format');
357  }
358 
359  return $localizedData;
360  }
361 
366  function getLocalizedDateTimeFormatShort($locale = null) {
367  if (is_null($locale)) {
368  $locale = AppLocale::getLocale();
369  }
370  $localizedData = $this->getData('datetimeFormatShort', $locale);
371  if (empty($localizedData)) {
372  $localizedData = Config::getVar('general', 'datetime_format_short');
373  }
374 
375  return $localizedData;
376  }
377 
382  function getLocalizedDateTimeFormatLong($locale = null) {
383  if (is_null($locale)) {
384  $locale = AppLocale::getLocale();
385  }
386  $localizedData = $this->getData('datetimeFormatLong', $locale);
387  if (empty($localizedData)) {
388  $localizedData = Config::getVar('general', 'datetime_format_long');
389  }
390 
391  return $localizedData;
392  }
393 
398  public abstract function getAssocType();
399 
404  function getSetting($name, $locale = null) {
405  return $this->getData($name, $locale);
406  }
407 
412  function getLocalizedSetting($name, $locale = null) {
413  return $this->getLocalizedData($name, $locale);
414  }
415 
423  function updateSetting($name, $value, $type = null, $isLocalized = false) {
424  $settingsDao = Application::getContextSettingsDAO();
425  return $settingsDao->updateSetting($this->getId(), $name, $value, $type, $isLocalized);
426  }
427 
432  function getViews() {
434  return $application->getPrimaryMetricByAssoc(Application::getContextAssocType(), $this->getId());
435  }
436 
437 
438  //
439  // Statistics API
440  //
446  function getMetricTypes($withDisplayNames = false) {
447  // Retrieve report plugins enabled for this journal.
448  $reportPlugins = PluginRegistry::loadCategory('reports', true, $this->getId());
449  if (empty($reportPlugins)) return array();
450 
451  // Run through all report plugins and retrieve all supported metrics.
452  $metricTypes = array();
453  foreach ($reportPlugins as $reportPlugin) {
454  $pluginMetricTypes = $reportPlugin->getMetricTypes();
455  if ($withDisplayNames) {
456  foreach ($pluginMetricTypes as $metricType) {
457  $metricTypes[$metricType] = $reportPlugin->getMetricDisplayType($metricType);
458  }
459  } else {
460  $metricTypes = array_merge($metricTypes, $pluginMetricTypes);
461  }
462  }
463 
464  return $metricTypes;
465  }
466 
475  function getDefaultMetricType() {
476  $defaultMetricType = $this->getData('defaultMetricType');
477 
478  // Check whether the selected metric type is valid.
479  $availableMetrics = $this->getMetricTypes();
480  if (empty($defaultMetricType)) {
481  if (count($availableMetrics) === 1) {
482  // If there is only a single available metric then use it.
483  $defaultMetricType = $availableMetrics[0];
484  } else {
485  // Use the site-wide default metric.
487  $defaultMetricType = $application->getDefaultMetricType();
488  }
489  } else {
490  if (!in_array($defaultMetricType, $availableMetrics)) return null;
491  }
492 
493  return $defaultMetricType;
494  }
495 
511  function getMetrics($metricType = null, $columns = array(), $filter = array(), $orderBy = array(), $range = null) {
512  // Add a context filter and run the report.
513  $filter[STATISTICS_DIMENSION_CONTEXT_ID] = $this->getId();
515  return $application->getMetrics($metricType, $columns, $filter, $orderBy, $range);
516  }
517 }
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
$application
$application
Definition: index.php:65
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\getDateTimeFormats
getDateTimeFormats($format)
Definition: Context.inc.php:304
Context\getLocalizedDateTimeFormatShort
getLocalizedDateTimeFormatShort($locale=null)
Definition: Context.inc.php:366
Context\getLocalizedDescription
getLocalizedDescription()
Definition: Context.inc.php:166
Context\getDefaultMetricType
getDefaultMetricType()
Definition: Context.inc.php:475
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:423
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:404
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:199
Context\getLocalizedDateTimeFormatLong
getLocalizedDateTimeFormatLong($locale=null)
Definition: Context.inc.php:382
Context\getLocalizedDateFormatLong
getLocalizedDateFormatLong($locale=null)
Definition: Context.inc.php:334
Context\setContactEmail
setContactEmail($contactEmail)
Definition: Context.inc.php:77
Context\getLocalizedSetting
getLocalizedSetting($name, $locale=null)
Definition: Context.inc.php:412
Context\getLocalizedDateFormatShort
getLocalizedDateFormatShort($locale=null)
Definition: Context.inc.php:318
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
Context\getAcronym
getAcronym($locale)
Definition: Context.inc.php:183
Context\getMetricTypes
getMetricTypes($withDisplayNames=false)
Definition: Context.inc.php:446
Context\getSupportedLocales
getSupportedLocales()
Definition: Context.inc.php:270
Context\getEnabled
getEnabled()
Definition: Context.inc.php:119
Context\getLocalizedTimeFormat
getLocalizedTimeFormat($locale=null)
Definition: Context.inc.php:350
Context\getViews
getViews()
Definition: Context.inc.php:432
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:511