Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
NativeXmlUserGroupFilter.inc.php
1 <?php
2 
16 import('lib.pkp.plugins.importexport.native.filter.NativeImportFilter');
17 
23  function NativeXmlUserGroupFilter($filterGroup) {
24  $this->setDisplayName('Native XML userGroup import');
25  parent::NativeImportFilter($filterGroup);
26  }
27 
28  //
29  // Implement template methods from NativeImportFilter
30  //
35  function getPluralElementName() {
36  return 'user_groups';
37  }
38 
44  return 'user_group';
45  }
46 
47  //
48  // Implement template methods from PersistableFilter
49  //
53  function getClassName() {
54  return 'lib.pkp.plugins.importexport.users.filter.NativeXmlUserGroupFilter';
55  }
56 
57 
63  function handleElement($node) {
64  $deployment = $this->getDeployment();
65  $context = $deployment->getContext();
66 
67  // Create the UserGroup object.
68  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
69  $userGroup = $userGroupDao->newDataObject();
70  $userGroup->setContextId($context->getId());
71 
72  // Extract the name node element to see if this user group exists already.
73  $nodeList = $node->getElementsByTagNameNS($deployment->getNamespace(), 'name');
74  if ($nodeList->length == 1) {
75  $content = $this->parseLocalizedContent($nodeList->item(0)); // $content[1] contains the localized name.
76  $userGroups = $userGroupDao->getByContextId($context->getId());
77  while ($testGroup = $userGroups->next()) {
78  if (in_array($content[1], $testGroup->getName(null))) {
79  return $testGroup; // we found one with the same name.
80  }
81  }
82 
83  for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) if (is_a($n, 'DOMElement')) switch($n->tagName) {
84  case 'role_id': $userGroup->setRoleId($n->textContent); break;
85  case 'path': $userGroup->setPath($n->textContent); break;
86  case 'is_default': $userGroup->setDefault($n->textContent); break;
87  case 'show_title': $userGroup->setShowTitle($n->textContent); break;
88  case 'name': $userGroup->setName($n->textContent, $n->getAttribute('locale')); break;
89  case 'abbrev': $userGroup->setAbbrev($n->textContent, $n->getAttribute('locale')); break;
90  case 'permit_self_registration': $userGroup->setPermitSelfRegistration($n->textContent); break;
91  }
92 
93  $userGroupId = $userGroupDao->insertObject($userGroup);
94 
95  $stageNodeList = $node->getElementsByTagNameNS($deployment->getNamespace(), 'stage_assignments');
96  if ($stageNodeList->length == 1) {
97  $n = $stageNodeList->item(0);
98  $assignedStages = preg_split('/:/', $n->textContent);
99  foreach ($assignedStages as $stage) {
100  if($stage >= WORKFLOW_STAGE_ID_SUBMISSION && $stage <= WORKFLOW_STAGE_ID_PRODUCTION) {
101  $userGroupDao->assignGroupToStage($context->getId(), $userGroupId, $stage);
102  }
103  }
104  }
105 
106  return $userGroup;
107  } else {
108  fatalError("unable to find \"name\" userGroup node element. Check import XML document structure for validity.");
109  }
110  }
111 }
112 
113 ?>
static & getDAO($name, $dbconn=null)
Base class that converts a Native XML document to a set of user groups.
setDisplayName($displayName)
Definition: Filter.inc.php:140
Base class that converts a Native XML document to a DataObject.