Answers.Body: <p>Unfortunately this won't be possible with Solspace Calendar since we are extending <code>ElementCriteria</code> with <code>Calendar_EventCriteriaModel</code>, which has a layer on top of it allowing us to build recurring events and return a padded list of events. We also return <code>Event</code> objects instead of <code>EventModel</code> objects, because working with Craft Dates makes it difficult/impossible for Calendar to have the dates it needs. Sorry :/</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-23T18:26:24.260Z
Answers.Text: FWIW, in Craft 3 we've stop extending PHP's Date class with one of our own.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-23T16:31:45.763Z
Answers.LastActivityDate: 2016-12-23T16:31:45.763Z
Answers.UserDisplayName: Solspace
Answers.Body: <p>While not the ideal solution, there seems to be enough meta information to build out the recurring events manually.</p>
  
  <pre><code>'transformer' =&gt; function(Calendar_EventModel $event) {
    $exceptions = [];
    foreach($event-&gt;exceptions as $exception) {
      $exceptions[] = $exception-&gt;date;
    }
  
    return [
      'id' =&gt; $event-&gt;id,
      'title' =&gt; $event-&gt;title,
      'calendarId' =&gt; $event-&gt;calendarId,
      'slug' =&gt; $event-&gt;slug,
      'startDate' =&gt; $event-&gt;startDate,
      'endDate' =&gt; $event-&gt;endDate,
      'freq' =&gt; $event-&gt;$freq,
      'interval' =&gt; $event-&gt;interval,
      'exceptions' =&gt; $exceptions,
      'byMonth' =&gt; $event-&gt;byMonth,
      'byYearDay' =&gt; $event-&gt;byYearDay,
      'byMonthDay' =&gt; $event-&gt;byMonthDay,
      'byDay' =&gt; $event-&gt;byDay
    ];
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-23T18:50:08.147Z
Answers.LastActivityDate: 2016-12-23T18:50:08.147Z
Answers.UserDisplayName: aw04
Answers.Body: <p>Looks like you've got the <a href="https://github.com/theolampert/ElementAPI#setup" rel="nofollow noreferrer">Element API syntax</a> wrong.  Try this:</p>
  
  <pre><code>return [
      'endpoints' =&gt; [
          'api/events.json' =&gt; [
              'elementType' =&gt; 'Calendar_Event',
              'transformer' =&gt; function(Calendar_EventModel $event) {
                  return [
                      'title' =&gt; $event-&gt;title,
                  ];
              },
          ],
      ]
  ];
  </code></pre>
  
  <p>Note that I don't have the Calendar plugin, so I can't test this, and I'm guessing that their event model class is called <code>Calendar_EventModel</code>, so you'll want to verify that.  You can return any of the properties they have listed here: <a href="https://solspace.com/craft/calendar/docs/event/" rel="nofollow noreferrer">https://solspace.com/craft/calendar/docs/event/</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:20:37.373Z
Answers.Text: The code I have gives the same result as yours (with different fields of course as I didn't specify a transformer..), if there's an error I don't see it.  The issue isn't with the fields, it's the number of records returned.
Answers.UserDisplayName: aw04
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:21:31.770Z
Answers.Text: I found the event model class looking in the craft_elements table, didn't see it in the documentation but it's the only option I see related to the Calendar plugin so I assume it is correct
Answers.UserDisplayName: aw04
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:25:14.890Z
Answers.Text: fyi I'm using the function syntax because I have a parameter, I removed some code for the sake of a simple example :)
Answers.UserDisplayName: aw04
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:29:40.260Z
Answers.Text: Updated the question to hopefully be more clear
Answers.UserDisplayName: aw04
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:39:28.413Z
Answers.Text: Ahh, my bad. Forgot you could specify a closure for an endpoint. Will see if I can get a copy of the plugin from Solspace.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T20:50:20.873Z
Answers.Text: Oh cool thanks. There's a param loadOccurrences to the template function here, but I'm not sure how it relates to the element api. It doesn't seem to respect it. https://solspace.com/craft/calendar/docs/calendar.events
Answers.UserDisplayName: aw04
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-22T18:10:35.233Z
Answers.LastActivityDate: 2016-12-22T18:10:35.233Z
Answers.UserDisplayName: Brad Bell
Body: <p>When looping through all events in Twig, repeated events will continuously come in. On a weekly event, for instance, it pulls one for this week, one for next week, etc. Lets say I have a meeting event set to repeat weekly, it would come back like this:</p>
  
  <pre><code>{% for event in craft.calendar.events %} ...
  
  Meeting Event
  Meeting Event
  Meeting Event
  ...
  </code></pre>
  
  <p>I'm looking to load events asynchronously with the Element API plugin but I'm only able to get back each event once (even the repeated ones). How do I achieve the same behavior? Here is the basic setup:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  return [
    'endpoints' =&gt; [
      'api/events.json' =&gt; function() {
        return [
          'elementType' =&gt; 'Calendar_Event'
        ];
      }
    ]
  ];
  </code></pre>
  
  <p>And it only returns:</p>
  
  <pre><code>Meeting Event
  </code></pre>
  
Tags: <plugin-elementapi><plugin-solspacecalendar>
Title: Get repeated events with the Solspace Calendar and Element API plugins
ThreadText: # Get repeated events with the Solspace Calendar and Element API plugins
  
  (Asked by: username_0 on 2016-12-22)
  
  When looping through all events in Twig, repeated events will continuously come in. On a weekly event, for instance, it pulls one for this week, one for next week, etc. Lets say I have a meeting event set to repeat weekly, it would come back like this:
  
  ```
  {% for event in craft.calendar.events %} ...
  
  Meeting Event
  Meeting Event
  Meeting Event
  ...
  
  ```
  
  I'm looking to load events asynchronously with the Element API plugin but I'm only able to get back each event once (even the repeated ones). How do I achieve the same behavior? Here is the basic setup:
  
  ```
  <?php
  namespace Craft;
  
  return [
    'endpoints' => [
      'api/events.json' => function() {
        return [
          'elementType' => 'Calendar_Event'
        ];
      }
    ]
  ];
  
  ```
  
  And it only returns:
  
  ```
  Meeting Event
  
  ```
  
  **Tags:** plugin-elementapi, plugin-solspacecalendar
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2016-12-23. Score: 3
  
  Unfortunately this won't be possible with username_1 Calendar since we are extending `ElementCriteria` with `Calendar_EventCriteriaModel`, which has a layer on top of it allowing us to build recurring events and return a padded list of events. We also return `Event` objects instead of `EventModel` objects, because working with Craft Dates makes it difficult/impossible for Calendar to have the dates it needs. Sorry :/
  
  > **Comments:**
  > **username_2**: FWIW, in Craft 3 we've stop extending PHP's Date class with one of our own.  
  
  ---
  
  ### Answer by username_0 on 2016-12-23. Score: 1
  
  While not the ideal solution, there seems to be enough meta information to build out the recurring events manually.
  
  ```
  'transformer' => function(Calendar_EventModel $event) {
    $exceptions = [];
    foreach($event->exceptions as $exception) {
      $exceptions[] = $exception->date;
    }
  
    return [
      'id' => $event->id,
      'title' => $event->title,
      'calendarId' => $event->calendarId,
      'slug' => $event->slug,
      'startDate' => $event->startDate,
      'endDate' => $event->endDate,
      'freq' => $event->$freq,
      'interval' => $event->interval,
      'exceptions' => $exceptions,
      'byMonth' => $event->byMonth,
      'byYearDay' => $event->byYearDay,
      'byMonthDay' => $event->byMonthDay,
      'byDay' => $event->byDay
    ];
  }
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2016-12-22. Score: 0
  
  Looks like you've got the [Element API syntax](https://github.com/theolampert/ElementAPI#setup) wrong. Try this:
  
  ```
  return [
      'endpoints' => [
          'api/events.json' => [
              'elementType' => 'Calendar_Event',
              'transformer' => function(Calendar_EventModel $event) {
                  return [
                      'title' => $event->title,
                  ];
              },
          ],
      ]
  ];
  
  ```
  
  Note that I don't have the Calendar plugin, so I can't test this, and I'm guessing that their event model class is called `Calendar_EventModel`, so you'll want to verify that. You can return any of the properties they have listed here: <https://username_1.com/craft/calendar/docs/event/>
  
  > **Comments:**
  > **username_0**: The code I have gives the same result as yours (with different fields of course as I didn't specify a transformer..), if there's an error I don't see it.  The issue isn't with the fields, it's the number of records returned.  
  > **username_0**: I found the event model class looking in the craft_elements table, didn't see it in the documentation but it's the only option I see related to the Calendar plugin so I assume it is correct  
  > **username_0**: fyi I'm using the function syntax because I have a parameter, I removed some code for the sake of a simple example :)  
  > **username_0**: Updated the question to hopefully be more clear  
  > **username_2**: Ahh, my bad. Forgot you could specify a closure for an endpoint. Will see if I can get a copy of the plugin from username_1.  
  > **username_0**: Oh cool thanks. There's a param loadOccurrences to the template function here, but I'm not sure how it relates to the element api. It doesn't seem to respect it. https://username_1.com/craft/calendar/docs/calendar.events  
  
  ---
  
  