Open Preprint Systems  3.3.0
SectionService.inc.php
1 <?php
2 
16 namespace APP\Services;
17 
18 use \Services;
19 use \PKP\Services\interfaces\EntityPropertyInterface;
20 
21 class SectionService implements EntityPropertyInterface {
22 
31  public function getSectionList($contextId, $activeOnly = false) {
32  $sectionDao = \DAORegistry::getDAO('SectionDAO'); /* $sectionDao SectionDAO */
33  $sectionIterator = $sectionDao->getByContextId($contextId);
34 
35  $sections = array();
36  while ($section = $sectionIterator->next()) {
37  if (!$activeOnly || ($activeOnly && !$section->getIsInactive())) {
38  $sections[] = array(
39  'id' => $section->getId(),
40  'title' => $section->getLocalizedTitle(),
41  'group' => $section->getIsInactive(),
42  );
43  }
44  }
45 
46  return $sections;
47  }
48 
52  public function getProperties($section, $props, $args = null) {
53  $values = array();
54  foreach ($props as $prop) {
55  switch ($prop) {
56  case 'id':
57  $values[$prop] = (int) $section->getId();
58  break;
59  case 'abbrev':
60  $values[$prop] = $section->getAbbrev(null);
61  break;
62  case 'title':
63  $values[$prop] = $section->getTitle(null);
64  break;
65  case 'seq':
66  $values[$prop] = (int) $section->getSequence();
67  break;
68  }
69  }
70 
71  $locales = $args['request']->getContext()->getSupportedFormLocales();
72  $values = Services::get('schema')->addMissingMultilingualValues(SCHEMA_GALLEY, $values, $locales);
73 
74  \HookRegistry::call('Section::getProperties::values', array(&$values, $section, $props, $args));
75 
76  ksort($values);
77 
78  return $values;
79  }
80 
84  public function getSummaryProperties($section, $args = null) {
85  $props = array (
86  'id','abbrev','title','seq',
87  );
88 
89  \HookRegistry::call('Section::getProperties::summaryProperties', array(&$props, $section, $args));
90 
91  return $this->getProperties($section, $props, $args);
92  }
93 
97  public function getFullProperties($section, $args = null) {
98  // No fuller representation of a section is used at this time
99  $props = $this->getSummaryProperties($section, $args);
100 
101  \HookRegistry::call('Section::getProperties::fullProperties', array(&$props, $section, $args));
102 
103  return $props;
104  }
105 
116  public function addSection($section, $context) {
117  $sectionDao = \DAORegistry::getDAO('SectionDAO'); /* $sectionDao SectionDAO */
118 
119  // Don't allow sections to be added to any other context
120  $section->setJournalId($context->getId());
121 
122  $sectionDao->insertObject($section);
123 
124  return $section;
125  }
126 }
APP\Services\SectionService\getFullProperties
getFullProperties($section, $args=null)
Definition: SectionService.inc.php:97
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
APP\Services\SectionService\getSectionList
getSectionList($contextId, $activeOnly=false)
Definition: SectionService.inc.php:31
APP\Services\SectionService
Definition: SectionService.inc.php:21
APP\Services
Definition: ContextService.inc.php:15
APP\Services\SectionService\addSection
addSection($section, $context)
Definition: SectionService.inc.php:116
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
APP\Services\SectionService\getSummaryProperties
getSummaryProperties($section, $args=null)
Definition: SectionService.inc.php:84
APP\Services\SectionService\getProperties
getProperties($section, $props, $args=null)
Definition: SectionService.inc.php:52
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49