public IList<CmsContentTypeField> GetContentTypeFields(Data.Guid contentTypeGuid) { CmsContentTypeDao dao = new CmsContentTypeDao(); return dao.FindFieldsByContentTypeGuid(contentTypeGuid); }
public ContentQueryBuilder SetWhereClause(String clause) { if (this.subscriptionGuid == null) throw new ApplicationException("The subscription guid must be set prior to calling this method"); if (!String.IsNullOrEmpty(clause)) { CmsContentTypeDao dao = new CmsContentTypeDao(); //Get the fields and their types for the content type CmsContentType type = dao.FindBySiteAndName(this.subscriptionGuid, this.contentType); IList<CmsContentTypeField> fields = dao.FindFieldsByContentTypeGuid(type.Guid); //Perform error checking and make sure that there's not more than one paren pair int leftParens = clause.Count(f => f == '('); int rightParens = clause.Count(f => f == ')'); if (leftParens > 1) throw new ArgumentException("The where clause '" + clause + "' is not currently supported. Only a single set of parens may be present"); if (leftParens != rightParens) throw new ArgumentException("The where clause '" + clause + "' is not valid. Parentheses mitmatch. Expected " + leftParens + " but found " + rightParens); //Make sure there are not any conditional statements if (ConditionalMatch.IsMatch(clause)) throw new ArgumentException("The where clause '" + clause + "' is not valid: GooeyCms does not currently support conditional where clauses"); //Parse the actual string clause = clause.Replace("'", ""); clause = clause.Replace("(", ""); clause = clause.Replace(")", ""); Match match = StatementMatch.Match(clause); if (!match.Success) throw new ArgumentException("The where clause '" + clause + "' is not in a valid format. Format should be: field-name [<,>,=] value. Greater-than and Less-than are only supported on datetime field types."); String fieldname = match.Groups["fieldname"].Value; String condition = match.Groups["condition"].Value; String value = match.Groups["value"].Value; //Make sure that this fieldname is valid for the content type CmsContentTypeField field = null; try { field = fields.Single(f => f.SystemName.Equals(fieldname)); } catch (InvalidOperationException e) { StringBuilder builder = new StringBuilder(); foreach (CmsContentTypeField temp in fields) { builder.Append(temp.SystemName + "|"); } throw new ArgumentException("The where clause '" + clause + "' is not valid: The content type '" + type.Name + "' does not contain the field '" + fieldname + "'. Available fields:" + builder.ToString()); } WhereInfo whereInfo = new WhereInfo(); whereInfo.Value1 = value; whereInfo.Field = field; whereInfo.ParseConditional(condition); this.whereClauses.Add(whereInfo); } return this; }