/// <summary> /// Returns the metadata about the attributes that are columns on the primary /// table. Does not include the allowed values for those columns that have them. /// </summary> /// <param name="entityType">Only Properties is supported.</param> /// <param name="userRoles">The roles the current user has. /// Only attributes they can see will be returned.</param> /// <returns>All the attribute metadata for the specified columns.</returns> public static IList <PdbAttribute> GetPrimaryTableColumns( PdbEntityType entityType, IEnumerable <SecurityRole> userRoles) { DaoCriteria crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("EntityType", entityType)); crit.Expressions.Add(new EqualExpression("InPrimaryTable", true)); return(GetAttribRecords(crit, userRoles)); }
/// <summary> /// Gets all the attributes, without values, as a dictionary keyed by attribute display name. /// </summary> /// <param name="entityType">Only Properties is supported.</param> /// <param name="userRoles">The roles the current user has. /// Only attributes they can see will be returned.</param> /// <returns>All the attributes visible to someone with these roles.</returns> public static IDictionary <string, PdbAttribute> GetAttributesDictionary(PdbEntityType entityType, IEnumerable <SecurityRole> userRoles) { DaoCriteria crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("EntityType", entityType)); IList <PdbAttribute> attrList = GetAttribRecords(crit, userRoles, true); IDictionary <string, PdbAttribute> retVal = new CheckedDictionary <string, PdbAttribute>(); foreach (PdbAttribute attr in attrList) { retVal[attr.UID] = attr; } return(retVal); }
/// <summary> /// Gets all columns (visible to the user anyway) and includes the allowed /// values for columns that have entries in the Attribute_Values table. /// </summary> /// <param name="entityType">Only Properties is supported.</param> /// <param name="userRoles">The roles the current user has. /// Only attributes they can see will be returned.</param> /// <returns>All the attribute metadata for the specified columns.</returns> public static IList <PdbCategory> GetAttributesForClient( PdbEntityType entityType, IEnumerable <SecurityRole> userRoles) { IDictionary <string, IDictionary <string, IList <PdbAttribute> > > attrsByCatAndSub = new CheckedDictionary <string, IDictionary <string, IList <PdbAttribute> > >(); IDictionary <string, IList <PdbAttribute> > attrsByCat = new CheckedDictionary <string, IList <PdbAttribute> >(); DaoCriteria crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("EntityType", entityType)); IList <PdbAttribute> attrs = GetAttribRecords(crit, userRoles); // Get all the attributes and split 'em up. Put them either into the single // or double-nested dictionary depending on if they have subcategories. foreach (PdbAttribute attr in attrs) { IDictionary <string, IList <PdbAttribute> > catSubCats; IList <PdbAttribute> catAttrs; if (attrsByCatAndSub.ContainsKey(attr.Category)) { catSubCats = attrsByCatAndSub[attr.Category]; catAttrs = attrsByCat[attr.Category]; } else { catSubCats = new CheckedDictionary <string, IList <PdbAttribute> >(); catAttrs = new List <PdbAttribute>(); attrsByCatAndSub[attr.Category] = catSubCats; attrsByCat[attr.Category] = catAttrs; } // Now either it has a subcategory, in which case it's filed there, or // it doesn't, and it's filed under the category directly. if (StringHelper.IsNonBlank(attr.SubCategory)) { IList <PdbAttribute> subcatList; if (catSubCats.ContainsKey(attr.SubCategory)) { subcatList = catSubCats[attr.SubCategory]; } else { subcatList = new List <PdbAttribute>(); catSubCats[attr.SubCategory] = subcatList; } subcatList.Add(attr); } else { catAttrs.Add(attr); } } // Now they're all split up, create the returnable object types. // Remember it is impossible for any of the collections to be empty, since we created // them all based on records we had. List <PdbCategory> retVal = new List <PdbCategory>(); foreach (KeyValuePair <string, IDictionary <string, IList <PdbAttribute> > > kvp in attrsByCatAndSub) { IDictionary <string, IList <PdbAttribute> > subCatLists = kvp.Value; List <PdbSubCategory> subCats = new List <PdbSubCategory>(); PdbAttribute anAttr = null; foreach (IList <PdbAttribute> subCatList in subCatLists.Values) { subCats.Add(new PdbSubCategory(subCatList[0].SubCategory, subCatList[0].FilterAttrOrder, SimplifyAndGetValues(subCatList))); // save one indicator for the category info. if (anAttr == null) { anAttr = subCatList[0]; } } if (anAttr == null) { // subCatList and attrsByCat can't BOTH be empty or we wouldn't have this category. anAttr = attrsByCat[kvp.Key][0]; } retVal.Add(new PdbCategory(anAttr.Category, anAttr.FilterCatOrder, SimplifyAndGetValues(attrsByCat[kvp.Key]), subCats)); } retVal.Sort(); return(retVal); }