Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
Context.inc.php
1 <?php
2 
16 class Context extends DataObject {
20  function Context() {
21  parent::DataObject();
22  }
23 
29  function getLocalizedName($preferredLocale = null) {
30  return $this->getLocalizedSetting('name', $preferredLocale);
31  }
32 
37  function setName($name, $locale = null) {
38  $this->setData('name', $name, $locale);
39  }
40 
44  function getName($locale = null) {
45  return $this->getSetting('name', $locale);
46  }
47 
52  function getContactName() {
53  return $this->getSetting('contactName');
54  }
55 
60  function setContactName($contactName) {
61  $this->setData('contactName', $contactName);
62  }
63 
68  function getContactEmail() {
69  return $this->getSetting('contactEmail');
70  }
71 
76  function setContactEmail($contactEmail) {
77  $this->setData('contactEmail', $contactEmail);
78  }
79 
85  function getDescription($locale = null) {
86  return $this->getData('description', $locale);
87  }
88 
94  function setDescription($description, $locale = null) {
95  $this->setData('description', $description, $locale);
96  }
97 
102  function getPath() {
103  return $this->getData('path');
104  }
105 
110  function setPath($path) {
111  return $this->setData('path', $path);
112  }
113 
118  function getEnabled() {
119  return $this->getData('enabled');
120  }
121 
126  function setEnabled($enabled) {
127  return $this->setData('enabled', $enabled);
128  }
129 
134  function getPrimaryLocale() {
135  return $this->getData('primaryLocale');
136  }
137 
142  function setPrimaryLocale($primaryLocale) {
143  return $this->setData('primaryLocale', $primaryLocale);
144  }
149  function getSequence() {
150  return $this->getData('sequence');
151  }
152 
157  function setSequence($sequence) {
158  return $this->setData('sequence', $sequence);
159  }
160 
166  return $this->getLocalizedSetting('description');
167  }
168 
173  function getLocalizedAcronym() {
174  return $this->getLocalizedSetting('acronym');
175  }
176 
182  function getAcronym($locale) {
183  return $this->getSetting('acronym', $locale);
184  }
185 
191  return $this->getSetting('supportedFormLocales');
192  }
193 
200  $supportedLocales =& $this->getData('supportedFormLocaleNames');
201 
202  if (!isset($supportedLocales)) {
203  $supportedLocales = array();
204  $localeNames =& AppLocale::getAllLocales();
205 
206  $locales = $this->getSupportedFormLocales();
207  if (!isset($locales) || !is_array($locales)) {
208  $locales = array();
209  }
210 
211  foreach ($locales as $localeKey) {
212  $supportedLocales[$localeKey] = $localeNames[$localeKey];
213  }
214  }
215 
216  return $supportedLocales;
217  }
218 
224  return $this->getSetting('supportedSubmissionLocales');
225  }
226 
234  $supportedLocales =& $this->getData('supportedSubmissionLocaleNames');
235 
236  if (!isset($supportedLocales)) {
237  $supportedLocales = array();
238  $localeNames =& AppLocale::getAllLocales();
239 
240  $locales = $this->getSupportedSubmissionLocales();
241  if (!isset($locales) || !is_array($locales)) {
242  $locales = array();
243  }
244 
245  foreach ($locales as $localeKey) {
246  $supportedLocales[$localeKey] = $localeNames[$localeKey];
247  }
248  }
249 
250  return $supportedLocales;
251  }
252 
257  function getSupportedLocales() {
258  return $this->getSetting('supportedLocales');
259  }
260 
267  $supportedLocales =& $this->getData('supportedLocaleNames');
268 
269  if (!isset($supportedLocales)) {
270  $supportedLocales = array();
271  $localeNames =& AppLocale::getAllLocales();
272 
273  $locales = $this->getSupportedLocales();
274  if (!isset($locales) || !is_array($locales)) {
275  $locales = array();
276  }
277 
278  foreach ($locales as $localeKey) {
279  $supportedLocales[$localeKey] = $localeNames[$localeKey];
280  }
281  }
282 
283  return $supportedLocales;
284  }
285 
290  function getAssocType() {
291  assert(false); // Must be overridden by subclasses
292  }
293 
298  static function getSettingsDAO() {
299  assert(false); // Must be implemented by subclasses
300  }
301 
306  static function getDAO() {
307  assert(false); // Must be implemented by subclasses
308  }
309 
314  function &getSettings() {
315  $settingsDao = $this->getSettingsDAO();
316  $settings =& $settingsDao->getSettings($this->getId());
317  return $settings;
318  }
319 
326  function &getSetting($name, $locale = null) {
327  $settingsDao = $this->getSettingsDAO();
328  $setting =& $settingsDao->getSetting($this->getId(), $name, $locale);
329  return $setting;
330  }
331 
339  function updateSetting($name, $value, $type = null, $isLocalized = false) {
340  $settingsDao = $this->getSettingsDAO();
341  return $settingsDao->updateSetting($this->getId(), $name, $value, $type, $isLocalized);
342  }
343 
349  function &getLocalizedSetting($name) {
350  $returner = $this->getSetting($name, AppLocale::getLocale());
351  if ($returner === null) {
352  $returner = $this->getSetting($name, AppLocale::getPrimaryLocale());
353  }
354  return $returner;
355  }
356 
361  function getViews() {
362  $application = Application::getApplication();
363  return $application->getPrimaryMetricByAssoc(Application::getContextAssocType(), $this->getId());
364  }
365 
366 
367  //
368  // Statistics API
369  //
375  function getMetricTypes($withDisplayNames = false) {
376  // Retrieve report plugins enabled for this journal.
377  $reportPlugins =& PluginRegistry::loadCategory('reports', true, $this->getId());
378  if (!is_array($reportPlugins)) return array();
379 
380  // Run through all report plugins and retrieve all supported metrics.
381  $metricTypes = array();
382  foreach ($reportPlugins as $reportPlugin) {
383  $pluginMetricTypes = $reportPlugin->getMetricTypes();
384  if ($withDisplayNames) {
385  foreach ($pluginMetricTypes as $metricType) {
386  $metricTypes[$metricType] = $reportPlugin->getMetricDisplayType($metricType);
387  }
388  } else {
389  $metricTypes = array_merge($metricTypes, $pluginMetricTypes);
390  }
391  }
392 
393  return $metricTypes;
394  }
395 
404  function getDefaultMetricType() {
405  $defaultMetricType = $this->getSetting('defaultMetricType');
406 
407  // Check whether the selected metric type is valid.
408  $availableMetrics = $this->getMetricTypes();
409  if (empty($defaultMetricType)) {
410  if (count($availableMetrics) === 1) {
411  // If there is only a single available metric then use it.
412  $defaultMetricType = $availableMetrics[0];
413  } else {
414  // Use the site-wide default metric.
415  $application = PKPApplication::getApplication();
416  $defaultMetricType = $application->getDefaultMetricType();
417  }
418  } else {
419  if (!in_array($defaultMetricType, $availableMetrics)) return null;
420  }
421 
422  return $defaultMetricType;
423  }
424 
440  function getMetrics($metricType = null, $columns = array(), $filter = array(), $orderBy = array(), $range = null) {
441  // Add a context filter and run the report.
442  $filter[STATISTICS_DIMENSION_CONTEXT_ID] = $this->getId();
443  $application = PKPApplication::getApplication();
444  return $application->getMetrics($metricType, $columns, $filter, $orderBy, $range);
445  }
446 }
447 
448 ?>
getLocalizedAcronym()
getSupportedSubmissionLocaleNames()
Basic class describing a context.
Definition: Context.inc.php:16
setPath($path)
static getPrimaryLocale()
getSupportedFormLocaleNames()
getLocalizedDescription()
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
getAssocType()
getSupportedLocaleNames()
static & getAllLocales()
updateSetting($name, $value, $type=null, $isLocalized=false)
static getLocale()
& getData($key, $locale=null)
& getSettings()
setDescription($description, $locale=null)
Definition: Context.inc.php:94
getLocalizedName($preferredLocale=null)
Definition: Context.inc.php:29
setContactEmail($contactEmail)
Definition: Context.inc.php:76
static getContextAssocType()
getPrimaryLocale()
static getSettingsDAO()
getMetricTypes($withDisplayNames=false)
getDescription($locale=null)
Definition: Context.inc.php:85
Any class with an associated DAO should extend this class.
static getDAO()
getDefaultMetricType()
& getLocalizedSetting($name)
setData($key, $value, $locale=null)
setName($name, $locale=null)
Definition: Context.inc.php:37
getSupportedLocales()
setPrimaryLocale($primaryLocale)
getSupportedSubmissionLocales()
getAcronym($locale)
getContactName()
Definition: Context.inc.php:52
getSupportedFormLocales()
getMetrics($metricType=null, $columns=array(), $filter=array(), $orderBy=array(), $range=null)
& getSetting($name, $locale=null)
getContactEmail()
Definition: Context.inc.php:68
setContactName($contactName)
Definition: Context.inc.php:60
getName($locale=null)
Definition: Context.inc.php:44
setEnabled($enabled)
setSequence($sequence)