Exemplo n.º 1
0
        public void AddContentType(Data.Guid siteGuid, CmsContentType type)
        {
            if (String.IsNullOrEmpty(type.Guid))
                type.Guid = Data.Guid.Create().Value;

            if (!type.IsGlobalType)
                type.SubscriptionId = siteGuid.Value;

            //make sure this name doesn't already exist
            CmsContentTypeDao dao = new CmsContentTypeDao();

            CmsContentType existing = dao.FindBySiteAndName(type.SubscriptionId, type.Name);
            if (existing != null)
                throw new ArgumentException("This type name already exists and may not be used again.");

            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsContentType>(type);
                tx.Commit();
            }

            type = GetContentType(type.Guid);
        }
Exemplo n.º 2
0
        public void AddContentTypeField(CmsContentType type, CmsContentTypeField field)
        {
            CmsContentTypeDao dao = new CmsContentTypeDao();
            field.Parent = type;

            using (Transaction tx = new Transaction())
            {
                dao.Save<CmsContentTypeField>(field);
                tx.Commit();
            }
        }
Exemplo n.º 3
0
 public void Save(CmsContentType type)
 {
     CmsContentTypeDao dao = new CmsContentTypeDao();
     using (Transaction tx = new Transaction())
     {
         dao.Save<CmsContentType>(type);
         tx.Commit();
     }
 }
Exemplo n.º 4
0
        public IList<CmsContentType> GetContentTypes(Data.Guid siteGuid, ContentTypeFilter filter)
        {
            CmsContentTypeDao dao = new CmsContentTypeDao();

            List<CmsContentType> results = new List<CmsContentType>();
            if (filter == ContentTypeFilter.IncludeGlobalTypes)
            {
                IList<CmsContentType> global = dao.FindGlobalContentTypes();
                if (global != null)
                    results.AddRange(global);
            }

            IList<CmsContentType> local = dao.FindBySite(siteGuid);
            if (local != null)
                results.AddRange(local);

            return results;
        }
Exemplo n.º 5
0
        /*
        public static IList<CmsContentTypeField> GetSystemDefaultFields()
        {
            if (defaultFields.Count == 0)
            {
                CmsContentTypeField field = new CmsContentTypeField();
                field.SystemName = "title";
                field.Name = "Title";
                field.ObjectType = "System.String";
                field.FieldType = "Textbox";
                field.Description = "[default] The title of the content";
                field.IsRequired = true;
                field.IsSystemDefault = true;
                defaultFields.Add(field);

                field = new CmsContentTypeField();
                field.SystemName = "description";
                field.Name = "Description";
                field.Description = "[default] The description of the content";
                field.FieldType = "Textbox";
                field.ObjectType = "System.String";
                field.IsRequired = true;
                field.IsSystemDefault = true;
                defaultFields.Add(field);
            }

            return defaultFields;
        }
         * */
        public IList<CmsContentType> GetGlobalContentTypes()
        {
            CmsContentTypeDao dao = new CmsContentTypeDao();
            return dao.FindGlobalContentTypes();
        }
Exemplo n.º 6
0
 public CmsContentTypeField GetContentTypeField(Data.Guid contentTypeGuid, int fieldKey)
 {
     CmsContentTypeDao dao = new CmsContentTypeDao();
     return dao.FindFieldByContentTypeAndKey(contentTypeGuid, fieldKey);
 }
Exemplo n.º 7
0
 public IList<CmsContentTypeField> GetContentTypeFields(Data.Guid contentTypeGuid)
 {
     CmsContentTypeDao dao = new CmsContentTypeDao();
     return dao.FindFieldsByContentTypeGuid(contentTypeGuid);
 }
Exemplo n.º 8
0
 public CmsContentType GetContentType(Data.Guid guid)
 {
     CmsContentTypeDao dao = new CmsContentTypeDao();
     return dao.FindByGuid(guid);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a duplicate of the specified content type. Adjusting the names as necessary to avoid conflicts.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="systemType"></param>
        public void Duplicate(Data.Guid siteGuid, CmsContentType typeToCopy)
        {
            String systemName = typeToCopy.Name;

            //Make sure that this system name doesn't already exist
            CmsContentTypeDao dao = new CmsContentTypeDao();
            CmsContentType existing = dao.FindBySiteAndName(siteGuid.Value, systemName);

            if (existing != null)
                systemName = systemName + "_c";

            CmsContentType type = new CmsContentType();
            type.Guid = System.Guid.NewGuid().ToString();
            type.DisplayName = typeToCopy.DisplayName;
            type.Description = type.Description;
            type.IsEditorVisible = type.IsEditorVisible;
            type.IsFileType = type.IsFileType;
            type.IsGlobalType = false;
            type.Name = systemName;
            type.SubscriptionId = siteGuid.Value;
            type.TitleFieldName = typeToCopy.TitleFieldName;

            AddContentType(siteGuid,type);

            //Copy all of the fields
            IList<CmsContentTypeField> fieldsToCopy = GetContentTypeFields(typeToCopy.Guid);
            foreach (CmsContentTypeField fieldToCopy in fieldsToCopy)
            {
                CmsContentTypeField field = new CmsContentTypeField();
                field._SelectOptions = fieldToCopy._SelectOptions;
                field.Columns = fieldToCopy.Columns;
                field.Description = fieldToCopy.Description;
                field.FieldType = fieldToCopy.FieldType;
                field.IsRequired = fieldToCopy.IsRequired;
                field.IsSystemDefault = fieldToCopy.IsSystemDefault;
                field.Name = fieldToCopy.Name;
                field.ObjectType = fieldToCopy.ObjectType;
                field.Parent = fieldToCopy.Parent;
                field.Position = fieldToCopy.Position;
                field.Rows = fieldToCopy.Rows;
                field.SystemName = fieldToCopy.SystemName;

                AddContentTypeField(type, field);
            }
        }
Exemplo n.º 10
0
 public void DeleteField(Data.Guid contentTypeGuid, int fieldKey)
 {
     CmsContentTypeField field = GetContentTypeField(contentTypeGuid, fieldKey);
     if (field != null)
     {
         CmsContentTypeDao dao = new CmsContentTypeDao();
         using (Transaction tx = new Transaction())
         {
             dao.Delete<CmsContentTypeField>(field);
             tx.Commit();
         }
     }
 }
Exemplo n.º 11
0
 public void Delete(CmsContentType contentType)
 {
     if (contentType != null)
     {
         CmsContentTypeDao dao = new CmsContentTypeDao();
         using (Transaction tx = new Transaction())
         {
             dao.Delete<CmsContentType>(contentType);
             tx.Commit();
         }
     }
 }
Exemplo n.º 12
0
        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;
        }