protected People GetVicesAndAdmins() { People result = new People(); foreach (BasicPersonRole role in _authority.LocalPersonRoles) { if (role.Type == RoleType.LocalLead) { People localPeople = new People(); RoleLookup allRoles = RoleLookup.FromGeographyAndOrganization(role.GeographyId, role.OrganizationId); Roles viceRoles = allRoles[RoleType.LocalDeputy]; Roles adminRoles = allRoles[RoleType.LocalAdmin]; foreach (PersonRole localRole in viceRoles) { localPeople.Add(localRole.Person); } foreach (PersonRole localRole in adminRoles) { localPeople.Add(localRole.Person); } result = result.LogicalOr(localPeople); } } return(result); }
protected Person GetDistrictLead(Geography geography, int stopGeography) { // First, climb to district level or top level Geography district = geography; // Changed below since district.AtLevel(GeographyLevel.District) is never true // because AtLevel presumes that district is present in GeographyOfficialDesignations wich it isn't // So the only reliable method of finding the districts is to detect that they ar children of country while (district.ParentGeographyId != 0 && district.ParentGeographyId != stopGeography) { district = district.Parent; } // We are now at District or world RoleLookup roleLookup = RoleLookup.FromGeographyAndOrganization(district.Identity, Organization.PPSEid); if (roleLookup[RoleType.LocalLead].Count == 0) { return(Person.FromIdentity(1)); } return(roleLookup[RoleType.LocalLead][0].Person); }
private string GenerateAdministrators(Organization org, Geography geo, RoleLookup officers) { List <Person> aggregate = new List <Person>(); foreach (PersonRole role in officers[RoleType.LocalActive]) { aggregate.Add(role.Person); } foreach (PersonRole role in officers[RoleType.LocalAdmin]) { aggregate.Add(role.Person); } StringBuilder result = new StringBuilder("<b>Administrators at this level:</b><br/>"); if (aggregate.Count > 0) { result.Append(GeneratePerson(aggregate[0])); for (int index = 1; index < aggregate.Count; index++) { result.Append(", ").Append(GeneratePerson(aggregate[index])); } } else { result.Append("none"); } result.Append("<br/>"); return(result.ToString()); }
void PrintGeography(XmlElement currentNode, Geography geo, int level) { BasicGeographyDesignation[] officialdesignations = geo.GetGeographyDesignations(); XmlElement thisNode = currentNode; if (officialdesignations.Length == 0) { thisNode = currentNode.OwnerDocument.CreateElement("GEOGRAPHY"); } else if (officialdesignations[0].GeographyLevel == GeographyLevel.Municipality) { thisNode = currentNode.OwnerDocument.CreateElement("GEOGRAPHY"); } else if (officialdesignations[0].GeographyLevel == GeographyLevel.ElectoralCircuit) { thisNode = currentNode.OwnerDocument.CreateElement("GEOGRAPHY"); } if (thisNode != currentNode) { currentNode.AppendChild(thisNode); RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); thisNode.SetAttribute("name", geo.Name); thisNode.SetAttribute("hierlevel", level.ToString()); thisNode.SetAttribute("geographyid", geo.Identity.ToString()); if (officialdesignations.Length > 0) { thisNode.SetAttribute("level", ((int)officialdesignations[0].GeographyLevel).ToString()); if (valkretsbyte.ContainsKey(officialdesignations[0].Designation)) { thisNode.SetAttribute("key", valkretsbyte[officialdesignations[0].Designation]); } } if (officers[RoleType.LocalLead].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalLead]) { GeneratePerson(thisNode, RoleType.LocalLead, r.Person); } } if (officers[RoleType.LocalDeputy].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalDeputy]) { GeneratePerson(thisNode, RoleType.LocalDeputy, r.Person); } } } foreach (Geography subGeo in geo.Children) { PrintGeography(thisNode, subGeo, level + 1); } }
private void PopulateFacts() { Organization org = this.SelectOrganizationLine.SelectedOrganization; Geography geo = this.GeographyTree.SelectedGeography; if (geo == null || org == null) { return; } if (org.Identity == 1 && geo.Identity == 1) { StringBuilder result = new StringBuilder("<b>Organization-level roles:</b><br/>"); result.Append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"); result.Append(GenerateTableLine("Board Chairman", 1)); result.Append(GenerateTableLine("Board Vice Chairman", 5)); result.Append(GenerateTableLine("Board Second Vice Chairman", 11443)); result.Append(GenerateTableLine("Party Secretary", 967)); result.Append(GenerateTableLine("Treasurer", 3419)); result.Append(GenerateTableLine("Board Member", 2613)); result.Append(GenerateTableLine("Board Member", 3365)); result.Append(GenerateTableLine("Board Member", 1007)); result.Append(GenerateTableLine("Board Member", 9561)); result.Append(GenerateTableLine("Board Member", 437)); result.Append(GenerateTableLine("Board Deputy", 290)); result.Append(GenerateTableLine(" ", " ", string.Empty)); result.Append(GenerateTableLine("Party Leader", 1)); result.Append(GenerateTableLine("Vice Party Leader", 5)); result.Append(GenerateTableLine("Second Vice Party Leader", 11443)); result.Append("</table><br/>"); result.Append(GenerateAdministrators(org, geo)); this.LiteralFacts.Text = result.ToString(); } else { StringBuilder result = new StringBuilder("<b>"); result.Append(HttpUtility.HtmlEncode(org.NameShort)).Append(" at "); result.Append(HttpUtility.HtmlEncode(geo.Name)).Append(":</b><br />"); result.Append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"); RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); result.Append(GenerateLeadLine(officers[RoleType.LocalLead], "Local Lead")); result.Append(GenerateLeadLine(officers[RoleType.LocalDeputy], "Local Second")); result.Append("</table><br />"); result.Append(GenerateAdministrators(org, geo, officers)); result.Append("<br/>").Append(GenerateActivists(org, geo)); this.LiteralFacts.Text = result.ToString(); } }
private int GenerateOfficers(XmlElement thisNode, RoleLookup officers) { int tot = 0; Dictionary <int, bool> dupCheck = new Dictionary <int, bool>(); if (officers[RoleType.LocalLead].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalLead]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalLead, r.Person); } } } if (officers[RoleType.LocalDeputy].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalDeputy]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalDeputy, r.Person); } } } if (officers[RoleType.LocalAdmin].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalAdmin]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalAdmin, r.Person); } } } return(tot); }
public static int GetCityLeadCount(int organizationId, int countryId) { Geographies cities = Geographies.FromLevel(countryId, GeographyLevel.Municipality); int leadCount = 0; foreach (Geography city in cities) { RoleLookup roles = RoleLookup.FromGeographyAndOrganization(city.Identity, organizationId); if (roles[RoleType.LocalLead].Count > 0) { leadCount++; } } return(leadCount); }
protected People GetDirectReports() { People result = new People(); foreach (BasicPersonRole role in _authority.LocalPersonRoles) { if (role.Type == RoleType.LocalLead || role.Type == RoleType.LocalDeputy || role.Type == RoleType.LocalAdmin) { Geographies geographies = Geography.FromIdentity(role.GeographyId).Children; // HACK: Compensate for current bad tree structure if (role.GeographyId == 34) { //Lägg till Skåne till Södra geographies = geographies.LogicalOr(Geography.FromIdentity(36).Children); } if (role.GeographyId == 32) { //Lägg till Västra Götaland till Västra geographies = geographies.LogicalOr(Geography.FromIdentity(355).Children); } foreach (Geography geography in geographies) { People localLead = new People(); RoleLookup allRoles = RoleLookup.FromGeographyAndOrganization(geography.Identity, role.OrganizationId); Roles leadRoles = allRoles[RoleType.LocalLead]; foreach (PersonRole leadRole in leadRoles) { localLead.Add(leadRole.Person); } result = result.LogicalOr(localLead); } } } return(result); }
int PrintGeography(XmlElement currentNode, Geography geo, int level) { XmlElement thisNode = currentNode.OwnerDocument.CreateElement("GEOGRAPHY"); currentNode.AppendChild(thisNode); thisNode.SetAttribute("name", geo.Name); thisNode.SetAttribute("geographyid", geo.Identity.ToString()); RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); int totOfficers = GenerateOfficers(thisNode, officers); Geography supGeo = geo.Parent; if (supGeo != null && supGeo.GeographyId != Geography.SwedenId) { totOfficers += PrintGeography(currentNode, supGeo, level + 1); } return(totOfficers); }
private int GenerateOfficers (XmlElement thisNode, RoleLookup officers) { int tot = 0; Dictionary<int, bool> dupCheck = new Dictionary<int, bool>(); if (officers[RoleType.LocalLead].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalLead]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalLead, r.Person); } } } if (officers[RoleType.LocalDeputy].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalDeputy]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalDeputy, r.Person); } } } if (officers[RoleType.LocalAdmin].Count > 0) { foreach (PersonRole r in officers[RoleType.LocalAdmin]) { if (!dupCheck.ContainsKey(r.Person.Identity)) { ++tot; dupCheck[r.Person.Identity] = true; GeneratePerson(thisNode, RoleType.LocalAdmin, r.Person); } } } return tot; }
string PrintGeography(Geography geo) { StringBuilder sbl = new StringBuilder(); RoleType[] rolesToShow = new RoleType[] { RoleType.OrganizationChairman, RoleType.OrganizationVice1, RoleType.OrganizationSecretary, RoleType.LocalLead, RoleType.LocalDeputy }; Organizations orgs = Organizations.GetOrganizationsAvailableAtGeography(geo.Identity); foreach (Organization org in orgs) { Dictionary <int, bool> listedPersons = new Dictionary <int, bool>(); if (org.IsOrInherits(Organization.UPSEid)) { if (org.AnchorGeographyId == geo.Identity || org.UptakeGeographies.Contains(geo)) { RoleLookup officers = RoleLookup.FromOrganization(org); bool foundRole = false; foreach (RoleType rt in rolesToShow) { foundRole |= officers[rt].Count > 0; if (foundRole) { break; } } if (foundRole) { sbl.Append("<br><br><b>" + HttpUtility.HtmlEncode(org.Name) + ":</b>"); foreach (RoleType rt in rolesToShow) { foreach (Activizr.Logic.Pirates.PersonRole r in officers[rt]) { if (!listedPersons.ContainsKey(r.PersonId)) { sbl.Append(PrintOfficer(r)); listedPersons[r.PersonId] = true; } } } sbl.Append("<br>"); } } } else { RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo, org); if (officers[RoleType.LocalLead].Count > 0 || officers[RoleType.LocalDeputy].Count > 0) { sbl.Append("<br><br><b>" + HttpUtility.HtmlEncode(org.Name) + ", " + HttpUtility.HtmlEncode(geo.Name) + ":</b>"); foreach (RoleType rt in rolesToShow) { foreach (Activizr.Logic.Pirates.PersonRole r in officers[rt]) { if (!listedPersons.ContainsKey(r.PersonId)) { sbl.Append(PrintOfficer(r)); listedPersons[r.PersonId] = true; } } } sbl.Append("<br>"); } } } return(sbl.ToString()); }
public static bool HasRole(string name) { return(RoleLookup.ContainsKey(name)); }
public string SwedishCircuitMapOrgStrengthLookupReplacer(Match match) { // Five groups: "color" and "id" are the keys, "start", "middle" and "end" are what to paste in between. Dictionary <string, int> lookup = new Dictionary <string, int>(); lookup["2N"] = 2; lookup["2S"] = 38; lookup["1"] = 40; Organization org = Organization.FromIdentity(1); // Replace later for more generic string resultColorString = "#000000"; string id = match.Groups["id"].Value; int geoId = 0; try { if (lookup.ContainsKey(id)) { geoId = lookup[id]; } else { geoId = Int32.Parse(id); } Geography geo = Geography.FromIdentity(geoId); RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); bool hasLead = officers[RoleType.LocalLead].Count > 0; bool hasSecond = officers[RoleType.LocalDeputy].Count > 0; Geographies geoTree = geo.GetTree(); int cities = 0; int citiesWithLead = 0; foreach (Geography localGeo in geoTree) { if (localGeo.Identity == geo.Identity) { continue; } if (localGeo.Name.EndsWith("kommun")) { cities++; officers = RoleLookup.FromGeographyAndOrganization(localGeo.Identity, org.Identity); if (officers[RoleType.LocalLead].Count > 0) { citiesWithLead++; } } } int cityLeadPercent = 100; if (cities > 0) { cityLeadPercent = citiesWithLead * 100 / cities; } // Determine color Color color = Color.Red; if (!hasLead) { color = Color.Red; } else if (cityLeadPercent > 80 && hasSecond) { color = Color.Green; } else { // Find a hue between Orange and Light Green. Say, between 30 and 120. cityLeadPercent += 30; if (cityLeadPercent > 120) { cityLeadPercent = 120; } color = ColorFromAhsb(100, cityLeadPercent, 1.0f, 0.5f); } resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); } catch (Exception) { // Ignore - color will be black } return(match.Groups["start"].Value + resultColorString + match.Groups["middle"].Value + id + match.Groups["end"].Value); }
private string GenerateAdministrators (Organization org, Geography geo, RoleLookup officers) { List<Person> aggregate = new List<Person>(); foreach (PersonRole role in officers[RoleType.LocalActive]) { aggregate.Add(role.Person); } foreach (PersonRole role in officers[RoleType.LocalAdmin]) { aggregate.Add(role.Person); } StringBuilder result = new StringBuilder("<b>Administrators at this level:</b><br/>"); if (aggregate.Count > 0) { result.Append(GeneratePerson(aggregate[0])); for (int index = 1; index < aggregate.Count; index++) { result.Append(", ").Append(GeneratePerson(aggregate[index])); } } else { result.Append("none"); } result.Append("<br/>"); return result.ToString(); }
protected void ButtonAddRole_Click(object sender, EventArgs e) { int personId = (Person.FromIdentity(Convert.ToInt32("" + Request["id"]))).Identity; int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); RoleType roleType = (RoleType)Enum.Parse(typeof(RoleType), DropRolesLocal.SelectedValue); int nodeId = Convert.ToInt32(DropGeographies.SelectedValue); int organizationId = Convert.ToInt32(DropOrganizationsLocal.SelectedValue); if (!_authority.HasPermission(Permission.CanEditLocalRoles, organizationId, nodeId, Authorization.Flag.Default)) { Page.ClientScript.RegisterStartupScript(typeof(Page), "ErrorMessage", "alert ('You do not have permissions to add local roles for that combination of organisation and geography.');", true); return; } /* Fix for Ticket #46 */ // Check if role being added is lead, if so check if lead is already filled, if so return error, else continue if (roleType == RoleType.LocalLead) { List <Person> aggregate = new List <Person>(); RoleLookup lead = RoleLookup.FromGeographyAndOrganization(nodeId, organizationId); foreach (PersonRole role in lead[RoleType.LocalLead]) { aggregate.Add(role.Person); } // If we have one or more people in this role already, throw error (typically it should only be filled by one other person) if (aggregate.Count > 0) { string name = aggregate[0].Name; // Handle multiple users with this role if (aggregate.Count > 1) { name = String.Empty; int count = 0; foreach (Person person in aggregate) { count++; name += person.Name; if (count < aggregate.Count) { name += ", "; } } } Page.ClientScript.RegisterStartupScript(typeof(Page), "ErrorMessage", "alert ('This role is already filled by " + name + ". To assign a new user to this role please remove the old user first.');", true); return; } } int roleId = PersonRole.Create(personId, roleType, organizationId, nodeId).Identity; // If we made it this far, add the role Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.AddedRole, currentUserId, organizationId, nodeId, personId, (int)roleType, string.Empty); this.GridLocalRoles.DataBind(); }
public string SwedishCityMapOrgStrengthLookupReplacer(Match match) { // Five groups: "color" and "id" are the keys, "start", "middle" and "end" are what to paste in between. Organization org = Organization.FromIdentity(1); // Replace later for more generic string resultColorString = "#000000"; string id = match.Groups["id"].Value; // If not constructed for this instance, construct the volunteer cache if (this.volunteerCache == null) { this.volunteerCache = new Dictionary <int, bool>(); Volunteers volunteers = Volunteers.GetOpen(); foreach (Volunteer volunteer in volunteers) { volunteerCache[volunteer.Geography.Identity] = true; } } try { Geography geo = Geography.FromOfficialDesignation(1, GeographyLevel.Municipality, id); int circuitLeadCount = 0; int cityLeadCount = 0; int cityVolunteerCount = 0; RoleLookup lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { cityLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { cityLeadCount = 2; } } if (volunteerCache.ContainsKey(geo.Identity)) { cityVolunteerCount = 1; } // Move up to circuit level while (!(geo.AtLevel(GeographyLevel.ElectoralCircuit))) { geo = geo.Parent; } lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { circuitLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { circuitLeadCount = 2; } } float saturation = 1.0f; float brightness = 0.15f + 0.2f * circuitLeadCount; float hue = cityLeadCount * 60; // red, yellow, green hues at 0°, 60°, 120° if (cityLeadCount < 2 && cityVolunteerCount > 0) { hue += 30; // There are volunteers? Place at orange (for none) or yellow-green (for one). } Color color = ColorFromAhsb(255, hue, saturation, brightness); resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); } catch (Exception) { } /* * try * { * if (lookup.ContainsKey(id)) * { * geoId = lookup[id]; * } * else * { * geoId = Int32.Parse(id); * } * * Geography geo = Geography.FromIdentity(geoId); * * RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); * * bool hasLead = officers[RoleType.LocalLead].Count > 0; * bool hasSecond = officers[RoleType.LocalDeputy].Count > 0; * * Geographies geoTree = geo.GetTree(); * * int cities = 0; * int citiesWithLead = 0; * * foreach (Geography localGeo in geoTree) * { * if (localGeo.Identity == geo.Identity) * { * continue; * } * * if (localGeo.Name.EndsWith("kommun")) * { * cities++; * * officers = RoleLookup.FromGeographyAndOrganization(localGeo.Identity, org.Identity); * * if (officers[RoleType.LocalLead].Count > 0) * { * citiesWithLead++; * } * } * } * * int cityLeadPercent = 100; * * if (cities > 0) * { * cityLeadPercent = citiesWithLead * 100 / cities; * } * * // Determine color * * Color color = Color.Red; * * if (!hasLead) * { * color = Color.Red; * } * else if (cityLeadPercent > 80 && hasSecond) * { * color = Color.Green; * } * else * { * // Find a hue between Orange and Light Green. Say, between 30 and 120. * * cityLeadPercent += 30; * if (cityLeadPercent > 120) * { * cityLeadPercent = 120; * } * * color = ColorFromAhsb(100, cityLeadPercent, 1.0f, 0.5f); * } * * resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); * } * catch (Exception) * { * // Ignore - color will be black * } * */ return(match.Groups["start"].Value + resultColorString + match.Groups["middle"].Value + id + match.Groups["end"].Value); }
private string GenerateAdministrators(Organization org, Geography geo) { RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); return(GenerateAdministrators(org, geo, officers)); }