Exemple #1
0
		// makes the ul
		public String makeUnorderedList(ComponentLinkField componentLinkField, string ulClass, string extraClass)
		{
			int i = 1;
			StringBuilder output = new StringBuilder();
			string liClass = string.Empty;
			output.AppendLine("<ul class=\"kolom" + ulClass + "\">");
			
			// makes the corresponding li's
			foreach (Component comp in componentLinkField.Values)
			{					
				// marks the last li as the last one 
				if (i == componentLinkField.Values.Count)
				{
					liClass = " class=\"last\"";
				}
				output.AppendLine("<li" + liClass + ">");

				// what does this do??????  
				// This is weird, We only open and close <li> when componentSize is 2 or 3
				// Yet we append something EVERYTIME in the old code (and this code)???  
				string mappingComponentWebDAVURL = "/webdav/CS%20Netherlands/Building%20Blocks%20Management/System%20OFS/system/Schema-CT%20mapping/Schema-CT%20mapping%20homepage.xml";
				if (" klant".Equals(extraClass))
				{ 
					output.Append(RenderComponentPresentation(comp, mappingComponentWebDAVURL, extraClass));
				} else {
					output.Append(RenderComponentPresentation(comp, mappingComponentWebDAVURL));
				}
				
				output.AppendLine("</li>");
				i = i + 1;
			}
			output.AppendLine("</ul>");
			
			return output.ToString();
		}
Exemple #2
0
        protected Component GetComponentValue(String fieldNAme, ItemFields fields)
        {
            if (fields.Contains(fieldNAme))
            {
                ComponentLinkField field = fields[fieldNAme] as ComponentLinkField;
                return(field.Value);
            }

            return(null);
        }
Exemple #3
0
 protected IList <Component> GetComponentValues(string fieldName, ItemFields fields)
 {
     if (fields.Contains(fieldName))
     {
         ComponentLinkField field = (ComponentLinkField)fields[fieldName];
         return((field.Values.Count > 0) ? field.Values : null);
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
        /// <summary>
        /// Retrieves multiple <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> field values.
        /// </summary>
        /// <param name="itemField"><see cref="T:Tridion.ContentManager.ContentManagement.Fields.ItemField" /></param>
        /// <returns><see cref="T:Tridion.ContentManager.ContentManagement.Component" /> values</returns>
        public static IList <Component> ComponentValues(this ItemField itemField)
        {
            if (itemField != null)
            {
                ComponentLinkField field = itemField as ComponentLinkField;

                if (field != null && field.Values.Count > 0)
                {
                    return(field.Values);
                }
            }

            return(new List <Component>());
        }
        public void Transform(Engine engine, Package package)
        {
            RepositoryLocalObject context;

            if (package.GetByName(Package.ComponentName) != null)
            {
                context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.ComponentName));
            }
            else if (package.GetByName(Package.PageName) != null)
            {
                context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
            }
            else
            {
                throw new Exception("Could not determine context from package. Did not find page or component in package");
            }
            Repository contextPublication = context.ContextRepository;

            if (contextPublication.Metadata == null)
            {
                return;
            }
            ItemFields         metadata      = new ItemFields(contextPublication.Metadata, contextPublication.MetadataSchema);
            ComponentLinkField configuration = (ComponentLinkField)metadata["SiteConfiguration"];

            foreach (Component c in configuration.Values)
            {
                ItemFields content = new ItemFields(c.Content, c.Schema);
                foreach (ItemField field in content)
                {
                    var textField = field as TextField;
                    if (textField != null)
                    {
                        package.PushItem(textField.Name, package.CreateStringItem(ContentType.Text, textField.Value));
                    }
                }
            }
        }
 private void OutputComponentLinkValues(ComponentLinkField field, StringBuilder sb)
 {
     if (field.Values.Count() == 0)
     {
         sb.Append("<empty/>\n");
         return;
     }
     foreach (Component component in field.Values)
     {
         sb.Append("<componentLink>");
         sb.Append(component.Id);
         sb.Append("</componentLink>");
     }
 }
        public static void OnPageCreate(Page page, LoadEventArgs args, EventPhases phases)
        {
            // only react on new Pages
            if (page.Id == TcmUri.UriNull)
            {
                StackTrace stackTrace = new StackTrace();
                foreach (var frame in stackTrace.GetFrames())
                {
                    // build Class.Method
                    MethodBase method = frame.GetMethod();
                    string     name   = method.ReflectedType.Name + "." + method.Name;

                    // only trigger on CoreServiceBase.GetDefaultData, not on CoreServiceBase.Create (which is the second call)
                    if (name.Equals("CoreServiceBase.GetDefaultData"))
                    {
                        break;
                    }
                    if (name.Equals("CoreServiceBase.Create"))
                    {
                        return;
                    }
                }

                const string metadataFieldName = "relatedContent";
                // bad example of hardcoding TCMURIs, but we at least use the context Publication
                string pageMetadataSchemaUri = string.Format("tcm:{0}-209-8", page.OrganizationalItem.Id.PublicationId);
                string seoSchemaUri          = string.Format("tcm:{0}-520-8", page.OrganizationalItem.Id.PublicationId);
                string seoFolderUri          = string.Format("tcm:{0}-1-2", page.OrganizationalItem.Id.PublicationId);

                if (page.MetadataSchema == null)
                {
                    // set Page metadata Schema
                    Schema meta = (Schema)page.Session.GetObject(pageMetadataSchemaUri);
                    page.MetadataSchema = meta;
                    page.Metadata       = meta.GetInstanceData(page.OrganizationalItem, LoadFlags.Expanded).Metadata;

                    Logger.Write(string.Format("Added metadata to Page {0} ({1})", page.Title, page.Id), "ExampleEventHandlerExtension", LoggingCategory.General, TraceEventType.Information);
                }

                // check if Component hasn't already been set
                ItemFields pageMeta = new ItemFields(page.Metadata, page.MetadataSchema);
                if (pageMeta.Contains(metadataFieldName))
                {
                    ComponentLinkField field = (ComponentLinkField)pageMeta[metadataFieldName];
                    if (field != null && field.Value == null)
                    {
                        // create a new SEO Component
                        Folder    folder    = (Folder)page.Session.GetObject(seoFolderUri);
                        Schema    seoSchema = (Schema)page.Session.GetObject(seoSchemaUri);
                        Component comp      = folder.GetNewObject <Component>();
                        comp.Title   = string.Format("Auto SEO Component {0}", Guid.NewGuid().ToString("N"));
                        comp.Schema  = seoSchema;
                        comp.Content = seoSchema.GetInstanceData(folder, LoadFlags.Expanded).Content;
                        comp.Save(true);
                        Logger.Write(string.Format("Created Component {0} ({1})", comp.Title, comp.Id), "ExampleEventHandlerExtension", LoggingCategory.General, TraceEventType.Information);

                        // set link in Page metadata
                        field.Value   = comp;
                        page.Metadata = pageMeta.ToXml();

                        Logger.Write(string.Format("Added Component Link to metadata of Page {0} ({1})", page.Title, page.Id), "ExampleEventHandlerExtension", LoggingCategory.General, TraceEventType.Information);
                    }
                }
            }
        }
        /// <summary>
        /// Populates the dictionary with values from the item fields.
        /// </summary>
        /// <param name="itemFields">The Tridion itemfields to populate the dictionary with.</param>
        private void PopulateDynamicItemFields(ItemFields itemFields)
        {
            if (itemFields == null)
            {
                return;
            }

            foreach (ItemField itemField in itemFields)
            {
                string key = itemField.Name.ToLower();

                if (itemField is XhtmlField)
                {
                    XhtmlField xhtmlField = (XhtmlField)itemField;
                    if (xhtmlField.Definition.MaxOccurs == 1)
                    {
                        _dictionary[key] = TemplateUtilities.ResolveRichTextFieldXhtml(xhtmlField.Value);
                    }
                    else
                    {
                        List <string> values = new List <string>();
                        foreach (string value in xhtmlField.Values)
                        {
                            values.Add(TemplateUtilities.ResolveRichTextFieldXhtml(value));
                        }
                        _dictionary[key] = values;
                    }
                }
                else if (itemField is TextField)
                {
                    TextField textField = (TextField)itemField;
                    if (textField.Definition.MaxOccurs == 1)
                    {
                        _dictionary[key] = textField.Value;
                    }
                    else
                    {
                        _dictionary[key] = textField.Values;
                    }
                }
                else if (itemField is DateField)
                {
                    DateField dateField = (DateField)itemField;
                    if (dateField.Definition.MaxOccurs == 1)
                    {
                        _dictionary[key] = dateField.Value;
                    }
                    else
                    {
                        _dictionary[key] = dateField.Values;
                    }
                }
                else if (itemField is KeywordField)
                {
                    KeywordField keywordField = (KeywordField)itemField;
                    if (keywordField.Definition.MaxOccurs == 1)
                    {
                        if (keywordField.Value == null)
                        {
                            _dictionary[key] = null;
                        }
                        else
                        {
                            _dictionary[key] = new KeywordModel(_engine, keywordField.Value);
                        }
                    }
                    else
                    {
                        List <KeywordModel> keywords = new List <KeywordModel>();
                        int i = 0;
                        foreach (Keyword k in keywordField.Values)
                        {
                            var kw = new KeywordModel(_engine, k);
                            kw.Index  = i++;
                            kw.IsLast = Index == keywordField.Values.Count - 1;
                            keywords.Add(kw);
                        }
                        _dictionary[key] = keywords;
                    }
                }
                else if (itemField is EmbeddedSchemaField)
                {
                    EmbeddedSchemaField embeddedSchemaField = (EmbeddedSchemaField)itemField;
                    if (embeddedSchemaField.Definition.MaxOccurs == 1)
                    {
                        if (embeddedSchemaField.Values.Count == 0)
                        {
                            _dictionary[key] = null;
                        }
                        else
                        {
                            _dictionary[key] = new DynamicItemFields(_engine, embeddedSchemaField.Value);
                        }
                    }
                    else
                    {
                        List <dynamic> embeddedFields = new List <dynamic>();

                        int i = 0;
                        foreach (ItemFields fields in embeddedSchemaField.Values)
                        {
                            var dif = new DynamicItemFields(_engine, fields);
                            dif.Index  = i++;
                            dif.IsLast = dif.Index == embeddedSchemaField.Values.Count - 1;
                            embeddedFields.Add(dif);
                        }
                        _dictionary[key] = embeddedFields;
                    }
                }
                else if (itemField is ComponentLinkField)
                {
                    ComponentLinkField componentLinkField = (ComponentLinkField)itemField;
                    if (componentLinkField.Definition.MaxOccurs == 1)
                    {
                        if (componentLinkField.Value == null)
                        {
                            _dictionary[key] = null;
                        }
                        else
                        {
                            _dictionary[key] = new ComponentModel(_engine, componentLinkField.Value);
                        }
                    }
                    else
                    {
                        List <ComponentModel> components = new List <ComponentModel>();
                        int i = 0;
                        foreach (Component c in componentLinkField.Values)
                        {
                            var cm = new ComponentModel(_engine, c);
                            cm.Index  = i++;
                            cm.IsLast = cm.Index == componentLinkField.Values.Count - 1;
                            components.Add(cm);
                        }
                        _dictionary[key] = components;
                    }
                }
                else if (itemField is ExternalLinkField)
                {
                    ExternalLinkField externalLink = (ExternalLinkField)itemField;
                    if (externalLink.Definition.MaxOccurs == 1)
                    {
                        _dictionary[key] = externalLink.Value;
                    }
                    else
                    {
                        _dictionary[key] = externalLink.Values;
                    }
                }
                else if (itemField is NumberField)
                {
                    NumberField numberField = (NumberField)itemField;
                    if (itemField.Definition.MaxOccurs == 1)
                    {
                        _dictionary[key] = numberField.Value;
                    }
                    else
                    {
                        _dictionary[key] = numberField.Values;
                    }
                }
                else
                {
                    _dictionary[key] = itemField.ToString();
                }
            }
        }
Exemple #9
0
		public override void Transform(Tridion.ContentManager.Templating.Engine engine, Tridion.ContentManager.Templating.Package package)
		{
			// initialized variables
			this.Initialize(engine, package);
			Component component = this.GetComponent();
			ItemFields content = new ItemFields(component.Content, component.Schema);
			String output = string.Empty;
			
			string extraClass = GetSingleStringValue("extraClass", content);
			List<string> fundList = new List<string>();
			Logger.Debug("FundCount : " + fundList.Count);
			ComponentLinkField componentLinkField = (ComponentLinkField)content["blocks"];
			
			// a hack, but i dont know for what...
			// probably because you do + extraclass in the switch statement 
			if (extraClass.Length > 0)
			{
				extraClass = " " + extraClass;
			}

			// check if it's an "OFS CS Fund"
			bool isOFSFund = false;
			foreach (Component comp in componentLinkField.Values)
			{
				if (String.Compare(comp.Schema.Title, "OFS CS Fund", true) == 0)
				{
					isOFSFund = true;
					package.PushItem("hasFunds", package.CreateStringItem(ContentType.Text, "true"));
					break;
				}
			}

			/*
			If it's an "OFS CS Fund" li's should be from top to bottom
			in all other cases where the size is 2 or 3, li's should be 
			from right to left
			*/
			if (isOFSFund)
			{
				int fundCount = 0;
				foreach (Component comp in componentLinkField.Values){
					ItemFields fields = new ItemFields(comp.Content, comp.Schema);
					package.PushItem("HtmlBlockPackage", package.CreateHtmlItem(GetSingleStringValue("htmlBlock", fields)));

					fundList.Add(GetSingleStringValue("isin", fields));
					Logger.Debug("Isin : " + GetSingleStringValue("isin", fields));
					fundCount = fundCount + 1;
					//package.PushItem("fundCount", package.CreateStringItem(ContentType.Html, fundCount.ToString()));
				}	
			} else {
				string ulClass = string.Empty;
				
				// makes the correct ul
				switch (componentLinkField.Values.Count)
				{
					case 2:
						Logger.Debug("Case 2");
						ulClass = " twee" + extraClass;
						output = makeUnorderedList(componentLinkField, ulClass, extraClass);
						break;
					case 3:
						Logger.Debug("Case 3");
						ulClass = " drie" + extraClass; ;
						output = makeUnorderedList(componentLinkField, ulClass, extraClass);
						break;
					default:
						Logger.Debug("Default case");
						break;
				}
			}
			
            // make the javascript block for the fundSelection
            Logger.Debug("FundCount : " + fundList.Count);

            if (fundList.Count > 0)
            {
                StringBuilder outputJS = new StringBuilder();
                outputJS.AppendLine("<script type=\"text/javascript\">");
                outputJS.AppendLine("\tvar dict = [];");
                foreach (string isin in fundList)
                {
                    outputJS.AppendLine("\t\tvar isFund-" + isin + "-On = false;");
                }
                outputJS.AppendLine();
                outputJS.AppendLine("\twindow.onload = function(){");
                outputJS.AppendLine("\t\twa.fSetEvent('Top5SelectFunds', [ { switchedFunds: dict, switchMethod:'selectButtonClick' } ] );");
                outputJS.AppendLine("\t}");
                outputJS.AppendLine();

                outputJS.AppendLine("\tFireTagging = function(className, isinCode, productName, method){");
                outputJS.AppendLine("\t\tswitch (isinCode) {");
                foreach (string isin in fundList)
                {
                    outputJS.AppendLine("\t\t\tcase \"" + isin + "\": ");
                    outputJS.AppendLine("\t\t\t\tisFund-" + isin + "-On = (isFund-" + isin + "-On)?false:true;");
                    outputJS.AppendLine("\t\t\t\tbreak;");
                }
               outputJS.AppendLine("\t\t\t\tdefault:");
                outputJS.AppendLine("\t\t\t\tconsole.log(\"default\")");
                outputJS.AppendLine("\t}");
                outputJS.AppendLine();
                outputJS.Append("\tif(className === \"button-alpha orange selectButton\" ");
                foreach (string isin in fundList)
                {
                    outputJS.Append("|| isFund-" +isin + "-On === true ");
                }
                outputJS.AppendLine(") {");
                outputJS.AppendLine("\t\t\twa.fSetEvent('Top5SelectFunds', [ { switchedFunds: [ { sIsinCode: isinCode, sProductName: productName} ], switchMethod: method} ] );");
                outputJS.AppendLine("\t\t\tdict.push({ sIsinCode: isinCode, sProductName: productName});");
                outputJS.AppendLine("\t\t} else {");
                outputJS.AppendLine("\t\tfor (var i = 0, len = dict.length; i < len; i++) {");
                outputJS.AppendLine("\t\t\tif (dict[i].sIsinCode === isinCode) {");
                outputJS.AppendLine("\t\t\t\tdict.splice(i, 1);");
                outputJS.AppendLine("\t\t\t\t}");
                outputJS.AppendLine("\t\t\t}");
                outputJS.AppendLine("\t\t}");
                outputJS.AppendLine("\t}");
                outputJS.AppendLine("");
                outputJS.AppendLine("\tTaggingBuyFunds = function(){");
                outputJS.AppendLine("\t\twa.fSetEvent('Top5BuyFunds', [{ selectedFunds: dict }] );");
                outputJS.AppendLine("</script>");
                package.PushItem("homeJS", package.CreateStringItem(ContentType.Html, outputJS.ToString()));
            }

            package.PushItem("homeBlocks", package.CreateStringItem(ContentType.Html, output));

            //Determine if this component is the last on the Page
            if (isLastComponentOnPage(component))
            {
                package.PushItem("lastContainerClass", package.CreateStringItem(ContentType.Text, " lasthome"));
            }

        }