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