/**
  * Get the requested event
  * This comes from the URL parameters ?type=<type>&id=<id>,
  * or from the URL extension /<type>-<id>
  */
 public function getEvent()
 {
     $input = JFactory::getApplication()->input;
     if ($input->get("type") && $input->get("id")) {
         $type = strtolower($input->get("type"));
         $id = (int) $input->get("id");
         switch ($type) {
             case "walk":
                 $factory = SWG::walkInstanceFactory();
                 break;
             case "social":
                 $factory = SWG::socialFactory();
                 break;
             case "weekend":
                 $factory = SWG::weekendFactory();
                 break;
             default:
                 jexit("Invalid event type");
         }
         $factory->includeAttendedBy = true;
         $factory->includeAttendees = true;
         $event = $factory->getSingle($id);
         if ($event == null) {
             jexit("Invalid event");
         }
         return $event;
     } else {
         jexit("TODO: Redirect");
     }
 }
 function display($tpl = null)
 {
     // What type of event to we want?
     // TODO: Probably shouldn't return anything that isn't OK to publish - this is publicly accessible. This may be the cause of null events in the bottomless page output.
     $type = JRequest::getVar('eventtype', null, "get");
     $id = JRequest::getVar('id', null, "get", "INTEGER");
     if (isset($id) && isset($type)) {
         // Single event - connect directly to SWG backend
         // TODO: eventFactory method to take strings as well
         switch (strtolower($type)) {
             case "social":
                 $factory = SWG::socialFactory();
                 break;
             case "walk":
                 $factory = SWG::walkInstanceFactory();
                 break;
             case "weekend":
                 $factory = SWG::weekendFactory();
                 break;
         }
         $result = $factory->getSingle($id);
         print $result->jsonEncode();
     } else {
         // Go through the model
         $events = $this->get('Events');
         $result = array();
         foreach ($events as $event) {
             $evtProps = $event->sharedProperties();
             // Remove contact details from past events. Not really the best place to do it, but oh well. At least it means end users can't see them.
             if (isset($event->endDate) && unixtojd($event->endDate) < unixtojd(time()) || isset($event->start) && unixtojd($event->start) < unixtojd(time())) {
                 unset($evtProps['leader']['telephone']);
             }
             $result[] = $evtProps;
         }
         print json_encode($result);
     }
 }
 public function onContentPrepare($context, &$article, &$params, $page = 0)
 {
     // Don't run this plugin when the content is being indexed
     if ($context == 'com_finder.indexer') {
         return true;
     }
     // simple performance check to determine whether bot should process further
     if (strpos($article->text, '{swg_nextevent') === false) {
         return true;
     }
     // Find the instances of the plugin and any parameters
     preg_match_all("/{swg_nextevent(|[^}]+)?}/", $article->text, $matches, PREG_SET_ORDER);
     foreach ($matches as $instance) {
         // Get the arguments of this instance
         // They're in $instance[1], but strip off the leading | first
         $instance[1] = substr($instance[1], 1);
         $args = explode("|", $instance[1]);
         if (count($args) < 2) {
             continue;
         }
         // Need at least 2 arguments
         list($type, $field) = $args;
         // Set the default text for if no events are found
         if (count($args) >= 3) {
             $return = $args[2];
         } else {
             $return = "None scheduled";
         }
         // Get the next event of that type
         // TODO: eventFactory method to take strings
         switch (strtolower($type)) {
             case "walk":
                 $factory = SWG::walkInstanceFactory();
                 break;
             case "newmembersocial":
                 $newMembers = true;
             case "social":
                 $factory = SWG::socialFactory();
                 $factory->getNormal = !$newMembers;
                 $factory->getNewMember = $newMembers;
                 break;
             case "weekend":
                 $factory = SWG::weekendFactory();
                 break;
         }
         $events = $factory->getNext(1);
         if (!empty($events)) {
             $event = $events[0];
             switch (strtolower($field)) {
                 case "date":
                     $return = date("l jS M", $event->start);
                     break;
                 case "newmemberstart":
                     $return = date("H:i", $event->newMemberStart);
                     break;
                 default:
                     $return = "{{Unknown field type: " . $field . "}}";
             }
         }
         // Put this text into the article
         $article->text = str_replace($instance[0], $return, $article->text);
     }
     return true;
 }
 /**
  * Loads the social specified, or a blank one if none specified
  * By default, a new social is visibile to current members.
  * @param int $id Social ID, or blank for a new social
  * @return Social
  */
 public function loadSocial($id = null)
 {
     if (empty($id)) {
         $this->social = new Social();
         $this->social->showNormal = true;
     } else {
         $factory = SWG::socialFactory();
         $this->social = $factory->getSingle($id);
     }
 }
JHTML::script("swg/js/events.js", true);
JHTML::script("modules/mod_swg_nextevents/script/nextevents.js", true);
// Load the menu item for the list page
$listPageID = $params->get("listPage");
$listPage = JRoute::_("index.php?Itemid={$listPageID}");
$showMoreLink = $params->get("moreLink", true);
$newMembers = false;
// Set this as a default
switch ($params->get('eventType')) {
    case Event::TypeWalk:
        $factory = SWG::walkInstanceFactory();
        $events = $factory->getNext($numEvents);
        require JModuleHelper::getLayoutPath('mod_swg_nextevents', 'walks');
        break;
    case Event::TypeNewMemberSocial:
        $newMembers = true;
        // Fallthrough
    // Fallthrough
    case Event::TypeSocial:
        $factory = SWG::socialFactory();
        $factory->getNormal = !$newMembers;
        $factory->getNewMember = $newMembers;
        $events = $factory->getNext($numEvents);
        require JModuleHelper::getLayoutPath('mod_swg_nextevents', 'socials');
        break;
    case Event::TypeWeekend:
        $factory = SWG::weekendFactory();
        $events = $factory->getNext($numEvents);
        require JModuleHelper::getLayoutPath('mod_swg_nextevents', 'weekends');
        break;
}