list people who signed up in Composite.Community.EventCalendar

Topics: Standard packages
Jun 14, 2011 at 10:12 PM

Hi All,

I hope the title says it all. I want to list the people who signed up to an event in Composite.Community.EventCalendar. I want to see those persons on the page of the event itself so like John Doe, Jane Doe and Ronald already signed up for this event!

tia Ronald

Jun 14, 2011 at 10:58 PM

If you right click an event element in the navigation tree you should find a command "View sign-ups".

Jun 15, 2011 at 7:48 PM

Yes I can find that but I meant more like on the webpage.

Like:

Event: Composite Demo for Dummies

Already signed up:
Ronald
Mawtex
Composite CEO
John Doe

Jun 15, 2011 at 10:23 PM
Edited Jun 15, 2011 at 10:27 PM

Okay, got it - you need two join two tables (data types) to get this info, one of which is only readily available to C#. The steps here will introduce a new function which takes a DataReference<Events> and return xml describing all persons signed up for that event and if they are queued or not. This XML can be used from XSLT's to output what you need.

  1. On the Functions perspective create a new "Inline C# Function"
  2. Namespace it Composite.Community.EventCalendar and name it GetSignupXmlForEvent
  3. On the Assembly Reference tab add a reference to Composite.Community.EventCalendar (this assembly holds the type ISignupQueue which we need to join with)
  4. On the Input Parameters tab add a new parameter named "eventReference" and give it type DataReference<Events> - also give it a test value so you can preview this functions result
  5. Paste in the C# belowon the Source tab
  6. Save and preview to see that this works as expected(you get signups for the event you selected as test parameter value).

This introduce Composite.Community.EventCalendar.GetSignupXmlForEvent which take a Event reference - you could call this from the existing function Composite.Community.EventCalendar.EventPresentation - this function happens to take the same type of param, so you just pass it on and you should have the data ready to print from XSLT.

The code that digs out the data and return it as XML:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Composite.Data;
using Composite.Community.EventCalendar;
using Composite.Data.Types;

namespace Composite.Community.EventCalendar
{
  public static class InlineMethodFunction
  {
    public static IEnumerable<XElement> GetSignupXmlForEvent(DataReference<Event> eventReference)
    {            
        Guid eventId = (Guid)eventReference.KeyValue;

        using (var dc = new DataConnection())
        {
            var signupElements = from queueitem in dc.Get<ISignupQueue>()
                    join signup in dc.Get<Signup>() on queueitem.SignupId equals signup.Id
                    where queueitem.Event == eventId
                    select new XElement("Signup",
                        new XAttribute("InQueue", queueitem.InQueue),
                        new XAttribute("Name", signup.Name));

            return signupElements;

        }

    }
  }
}
Jun 16, 2011 at 3:37 PM

Hi mawtex,

I've followed your instructions but after staring at your last sentences for over 2 hours I still do not get these.
I don't see how I get the results (that I am seeing in the preview) in the EventPresentation.

You can call me a newbie but can you PLEASE explain how to get the results on to the xslt function EventPresentation.

Jun 17, 2011 at 12:36 PM

elSteenwijker,
To keep things simple I've re-done sample from mawtex..
1. Add file SignupList.cs to App_Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using Composite.Data;

namespace Composite.Community.EventCalendar
{
	public class SignupList
	{
		public static IEnumerable<XElement> GetSignupXmlForEvent()
		{
			Guid eventId;
			Guid.TryParse(HttpContext.Current.Request["eventid"], out eventId);

			using (var dc = new DataConnection())
			{
				var signupElements = from queueitem in dc.Get<ISignupQueue>()
									 join signup in dc.Get<Signup>() on queueitem.SignupId equals signup.Id
									 where queueitem.Event == eventId
									 select new XElement("Signup",
										 new XAttribute("InQueue", queueitem.InQueue),
										 new XAttribute("Name", signup.Name));

				return signupElements;
			}
		}
	}
}

2. Functions => C# functions => Add External C# Function => Composite.Community.EventCalendar.SignupList => select "GetSignupXmlForEvent" from the list. 
3. Add new XSLT function = MySignupList, add function call Composite.Community.EventCalendar.SignupList.GetSignupXmlForEvent, use XSLT below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
  xmlns:lang="http://www.composite.net/ns/localization/1.0"
  xmlns:f="http://www.composite.net/ns/function/1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c1="http://c1.composite.net/StandardFunctions"
  exclude-result-prefixes="xsl in lang f c1">

 <xsl:variable name="subscribers" select="/in:inputs/in:result[@name='GetSignupXmlForEvent']/Signup" />
    
  <xsl:template match="/">
    <html>
      <head>
      </head>
 
      <body>
        <xsl:if test="count($subscribers)>0">
        <ul>
          <xsl:apply-templates select="$subscribers" />
        </ul>
        </xsl:if>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Signup">
    <li>
      <xsl:value-of select="@Name" />
    </li>
  </xsl:template>   
</xsl:stylesheet>
4. Insert this XSLT function same page where EventCalendarAndSignup located.
Jun 17, 2011 at 2:48 PM

Whoop, whoop!!

That worked like a charm. And is EXCACTLY hat I wanted!!

Thanks aeont and mawtex for your efforts!

Jun 17, 2011 at 2:50 PM

@elSteenwijker and thank you for flying Composite C1 ;-)

Feb 7, 2015 at 7:22 PM
Hi all,

It has been a while.. :) but i like to create this same functionality but in Razor this time.

What object has the signup for an event?

Someone can give this dummie some directions?
Feb 15, 2015 at 2:17 PM
I figured it out

I added this to the razor function

using (var dc = new DataConnection())
            {
                var signupElements = from queueitem in dc.Get<ISignupQueue>()
                                     join signup in dc.Get<Signup>() on queueitem.SignupId equals signup.Id
                                     where queueitem.Event == idGuid
                                     select new XElement("Signup",
                                         new XAttribute("InQueue", queueitem.InQueue),
                                         new XAttribute("Name", signup.Name));
                if (signupElements.Count() > 0)
                {
                    <h2>De volgende personen hebben zich al aangemeld:</h2>
                    <ul>
                        @foreach (var signup in signupElements)
                        {
                            if (GetAtrValue(signup, "InQueue").ToString().ToLower() == "false")
                            {
                                <li>@GetAtrValue(signup, "Name")</li>
                            }
                        }
                    </ul>
                }
            }