/** * @param SimpleXMLElement $xml_element_ugroups * * @return array */ private function getUgroupsFromXMLToAdd(Project $project, SimpleXMLElement $xml_element_ugroups) { $ugroups = array(); $project_members = array(); $rng_path = realpath(dirname(__FILE__) . '/../xml/resources/ugroups.rng'); $this->xml_validator->validate($xml_element_ugroups, $rng_path); $this->logger->debug("XML Ugroups is valid"); foreach ($xml_element_ugroups->ugroup as $ugroup) { $ugroup_name = (string) $ugroup['name']; $ugroup_description = (string) $ugroup['description']; $dynamic_ugroup_id = $this->ugroup_manager->getDynamicUGoupIdByName($ugroup_name); if ($this->ugroup_manager->getUGroupByName($project, $ugroup_name) && empty($dynamic_ugroup_id)) { $this->logger->debug("Ugroup {$ugroup_name} already exists in project -> skipped"); continue; } $users = $this->getListOfUgroupMember($ugroup); if ($dynamic_ugroup_id == ProjectUGroup::PROJECT_MEMBERS) { $project_members = $users; } else { $ugroups[$ugroup_name]['name'] = $ugroup_name; $ugroups[$ugroup_name]['description'] = $ugroup_description; $ugroups[$ugroup_name]['users'] = $users; } } return array($ugroups, $project_members); }
/** * Extract Field data from XML input * * @param Tracker_FormElement_Field $field * @param SimpleXMLElement $field_change * * @return mixed */ public function getFieldData(Tracker_FormElement_Field $field, SimpleXMLElement $field_change) { $data = array('use_artifact_permissions' => (int) $field_change['use_perm'], 'u_groups' => array()); foreach ($field_change->ugroup as $ugroup_xml) { if (isset($ugroup_xml['ugroup_id'])) { $data['u_groups'][] = (int) $ugroup_xml['ugroup_id']; } elseif (isset($ugroup_xml['ugroup_name'])) { $ugroup_manager = new UGroupManager(); $ugroup = $ugroup_manager->getUGroupByName($field->getTracker()->getProject(), (string) $ugroup_xml['ugroup_name']); $data['u_groups'][] = $ugroup->getId(); } } return $data; }
private function getUgroupIdsForPermissions(Project $project, SimpleXMLElement $permission_xmlnode) { $ugroup_ids = array(); foreach ($permission_xmlnode->children() as $ugroup) { if ($ugroup->getName() === self::UGROUP_TAG) { $ugroup_name = (string) $ugroup; $ugroup = $this->ugroup_manager->getUGroupByName($project, $ugroup_name); if ($ugroup === null) { $this->logger->error("Could not find any ugroup named {$ugroup_name}"); throw new GitXmlImporterUGroupNotFoundException($ugroup_name); } array_push($ugroup_ids, $ugroup->getId()); } } return $ugroup_ids; }
public function getFullRESTValue(Tracker_FormElement_Field_List_Value $value) { $class_user_representation = '\\Tuleap\\Project\\REST\\UserGroupRepresentation'; $ugroup_representation = new $class_user_representation(); $ugroup_manager = new UGroupManager(); $project = $this->getField()->getTracker()->getProject(); $user_group = $ugroup_manager->getUGroupByName($project, $value->getLabel()); $ugroup_representation->build($project->getID(), $user_group); return $ugroup_representation; }
/** * Creates a Field_List_Bind Object * * @param SimpleXMLElement $xml containing the structure of the imported bind * @param Tracker_FormElement_Field $field to which the bind is attached * @param array &$xmlMapping where the newly created formElements indexed by their XML IDs are stored * * @return Tooltip Object */ public function getInstanceFromXML($xml, $field, &$xmlMapping) { $row = array('type' => (string) $xml['type'], 'field' => $field, 'default_values' => null, 'decorators' => null); if (isset($xml->decorators)) { $row['decorators'] = array(); foreach ($xml->decorators->decorator as $deco) { $ID = (string) $deco['REF']; $row['decorators'][$ID] = $this->getDecoratorInstance($field, $ID, (int) $deco['r'], (int) $deco['g'], (int) $deco['b']); } } $type = (string) $xml['type']; switch ($type) { case self::STATIK: $row['is_rank_alpha'] = (int) $xml['is_rank_alpha']; $values = array(); if ($xml->items->item) { $i = 0; foreach ($xml->items->item as $item) { $ID = (string) $item['ID']; $description = ''; if (isset($item->description)) { $description = (string) $item->description; } $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0; $values[$ID] = $this->getStaticValueInstance($ID, (string) $item['label'], $description, $i++, $is_hidden); $xmlMapping[$ID] = $values[$ID]; } } $row['values'] = $values; break; case self::USERS: $values = array(); if ($xml->items->item) { foreach ($xml->items->item as $item) { $values[] = (string) $item['label']; } } $row['value_function'] = implode(',', $values); break; case self::UGROUPS: $values = array(); if ($xml->items->item) { foreach ($xml->items->item as $item) { $ugroup = $this->ugroup_manager->getUGroupByName($field->getTracker()->getProject(), (string) $item['label']); if ($ugroup) { $ID = (string) $item['ID']; $is_hidden = isset($item['is_hidden']) && (int) $item['is_hidden'] ? 1 : 0; $values[$ID] = new Tracker_FormElement_Field_List_Bind_UgroupsValue($ID, $ugroup, $is_hidden); $xmlMapping[$ID] = $values[$ID]; } } } $row['values'] = array_filter($values); break; default: break; } if (isset($xml->default_values)) { $row['default_values'] = array(); foreach ($xml->default_values->value as $default_value) { if (isset($default_value['REF'])) { $ID = (string) $default_value['REF']; if (isset($xmlMapping[$ID])) { $row['default_values'][$ID] = $xmlMapping[$ID]; } } else { $xml_helper = new Tracker_XMLImport_XMLImportHelper(UserManager::instance()); $user = $xml_helper->getUser($default_value); $row['default_values'][$user->getId()] = new Tracker_FormElement_Field_List_Bind_UsersValue($user->getId()); } } } return $this->getInstanceFromRow($row); }