Пример #1
0
 /**
  * Returns the Dummy event factory
  * @return DummyEventFactory
  */
 public static function dummyFactory()
 {
     if (!isset(self::$factoryDummy)) {
         self::$factoryDummy = new DummyEventFactory();
     }
     return self::$factoryDummy;
 }
 public static function canEditWalk($walkOrID)
 {
     if (JFactory::getUser()->authorise("walk.editall", "com_swg_events")) {
         return true;
     }
     $f = SWG::walkInstanceFactory();
     $walk = $f->getSingle($walkOrID);
     return isset($walk) && JFactory::getUser()->authorise("walk.edit", "com_swg_events") && $walk->leader->joomlaUserID == JFactory::getUser()->id;
 }
 function __construct($form = null)
 {
     parent::__construct($form);
     $this->fb = SWG::getFacebook();
     if (!$this->fb) {
         $this->fb = new Facebook(SWG::$fbconf);
     }
     if ($this->fb->getUser()) {
         $this->value = $this->fb->getAccessToken();
     } else {
         $this->value = "NONE";
     }
 }
 public function facebook()
 {
     $fb = SWG::getFacebook();
     if (!$fb) {
         return;
     }
     // Do we have publish permissions?
     $perms = $fb->api('me/permissions');
     $session = JFactory::getSession();
     if (empty($perms['data'][0]['publish_actions'])) {
         if ($session->get("FBRequestPerm", false)) {
             // Already requested permissions, don't do it again
             $session->set("FBRequestPerm", false);
             throw new UserException("Need publish permission", 0, "You need to give the Sheffield Walking Group app publish permissions to post events to Facebook.");
         } else {
             // Get publish permissions, then return here. Store a note in the session so we can handle the user rejecting the permission
             //$session->set("FBRequestPerm", true);
             $current = JURI::getInstance();
             $url = $fb->getLoginUrl(array("scope" => 'publish_actions', "redirect_uri" => $current->toString()));
             // TODO: check if we're using the API - can't redirect that
             header("Location: " . $url);
             exit(0);
         }
     }
     $session->set("FBRequestPerm", false);
     // Post the event
     $evtid = JRequest::getInt("evtid");
     // 		$factory = SWG::eventFactory();
     // 		$event = $factory->getSingle($evtid);
     $eventURI = new JURI("index.php?option=com_swg_events&view=eventlisting");
     // TODO: Individual event links
     switch (JRequest::getInt("evttype")) {
         case Event::TypeWalk:
             // TODO: Did this person lead the walk?
             $action = "do";
             $type = "walk";
             break;
         case Event::TypeSocial:
             $action = "go_to";
             $type = "social";
             $url = "http://samples.ogp.me/205234152933611";
             break;
         case Event::TypeWeekend:
             $action = "go_to";
             $type = "weekend_away";
             break;
     }
     $fb->api('me/sheffwalkinggroup:' . $action, 'POST', array($type => $eventURI->toString()));
     // TODO: Need to store this post ID (event attendance table?) in case we change it later
 }
 function display($tpl = null)
 {
     // Model defaults are the current user and the next unpublished programme. That's what we want, so don't change it
     $this->form = $this->get("form");
     $this->programme = $this->get("programme");
     $this->leader = $this->get("leader");
     // Pre-load the dates of weekends away during this programme (only check start and end dates now, we'll check exact dates when using them)
     $weFactory = SWG::WeekendFactory();
     $weFactory->reset();
     $weFactory->startDate = $this->programme->startDate;
     $weFactory->endDate = $this->programme->endDate;
     $weFactory->showUnpublished = true;
     $this->weekends = $weFactory->get();
     parent::display($tpl);
 }
 /**
  * Returns the walk specified by the walkid parameter in the get string.
  * Loads it from the database if necessary.
  */
 public function getWalkInstance()
 {
     // TODO: Check user has permission to view this walk
     if (isset($this->wi)) {
         return $this->wi;
     }
     $wiFact = SWG::walkInstanceFactory();
     // Do we have a walk from the form?
     // Get the data from the form POST
     $formWI = JRequest::getInt('wi', 0, 'post', 'array');
     if (!empty($formWI)) {
         $this->wi = $wiFact->getSingle($formWI);
     } else {
         $this->wi = $wiFact->getSingle(JRequest::getInt("wi", 0, "get"));
     }
     return $this->wi;
 }
 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);
     }
 }
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;
}
Пример #9
0
    public function getInput()
    {
        if (is_string($this->value)) {
            // Value is a string - must be a single location
            $this->addLocation(SWG::parseLatLongTuple($this->value));
        } else {
            // Set up our initial location
            if (isset($this->value['start'])) {
                $this->start = SWG::parseLatLongTuple($this->value['start']);
            } else {
                if (isset($this->element['start'])) {
                    $this->start = SWG::parseLatLongTuple($this->element['start']);
                }
            }
            if (isset($this->element['zoom']) && is_numeric($this->element['zoom']) && (int) $this->element['zoom'] > 0) {
                $this->zoom = (int) $this->element['zoom'];
            }
            if (isset($this->value['location'])) {
                $this->location[0] = SWG::parseLatLongTuple($this->value['location']);
                // If we have no explicit start, or the location overrides the default start, use this
                if (empty($this->start) || $this->value['locationOverridesStart']) {
                    $this->start = $this->location[0];
                }
            }
        }
        // Final fallback for starting location
        if (empty($this->start)) {
            $this->start = new LatLng(53.38155556, -1.469722222);
            // Middle of Sheffield
        }
        // Prepare variables for JS
        $jsStartPos = json_encode($this->start);
        $jsZoom = $this->zoom;
        $jsLocations = json_encode($this->locations);
        $jsGridRefFieldIDs = json_encode(explode(",", $this->element['gridRefFields']));
        $jsLocationNameFieldIDs = json_encode(explode(",", $this->element['locationNameFields']));
        $jsPlaceMarker = json_encode(explode(",", $this->element['placeMarkerButtons']));
        $jsMultiLocations = !empty($this->element['multipleLocations']) ? "true" : "false";
        $routes = array();
        foreach ($this->routes as $rt) {
            $routes[] = $rt->sharedProperties();
        }
        $jsRoutes = json_encode($routes);
        // Load the maps JS
        $document = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $document->addScript('/libraries/openlayers/OpenLayers.debug.js');
        $document->addScript('/swg/js/maps.js');
        $document->addScript(JURI::base() . "administrator/components/com_swg_events/models/fields/location.js");
        $document->addScriptDeclaration(<<<MAP
\t\t
window.addEvent('domready', function()
{
\tvar mapJS = new JFormFieldLocation("{$this->id}", {$jsStartPos}, {$jsZoom},{$jsMultiLocations}, {$jsLocations}, {$jsGridRefFieldIDs}, {$jsLocationNameFieldIDs}, {$jsRoutes}, {$jsPlaceMarker});
});
MAP
);
        $html = <<<FLD
<div id='{$this->id}_map' style='width:600px;height:400px;'>
\t<div id="{$this->id}_search" class="searchpanel">
\t\t<h4>Search</h4>
\t\t<input type="text" class="searchfield" />
\t\t<input type="button" class="submit" value="Search" />
\t</div>
</div>
<input type='hidden' size='80' name='{$this->name}' id='{$this->id}' value='{$jsLocations}' />
FLD;
        return $html;
    }
require_once JPATH_BASE . "/../swg/swg.php";
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
foreach ($this->items as $i => $item) {
    ?>
	<tr class="row<?php 
    echo $i % 2;
    ?>
">
		<td>
			<?php 
    echo $item->id;
    ?>
		</td>
		<td>
			<?php 
    echo $item->text;
    ?>
		</td>
		<td>
			<?php 
    echo ucfirst(SWG::printableEventType($item->eventtype)) . "s";
    ?>
		</td>
		<td>
		
		</td>
	</tr>
<?php 
}
 /**
  * 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);
     }
 }
Пример #12
0
if (!isset($walkid) && !isset($routeid) && !isset($walkinstanceid)) {
    jexit("Walk or route ID must be specified");
}
include_once JPATH_BASE . "/swg/Models/Route.php";
// If a routeID is specified, return that route.
if (isset($routeid)) {
    $route = Route::loadSingle($routeid);
    if (!empty($route)) {
        print $route->jsonEncode();
        jexit();
    }
}
// If we get here, we failed to load a route.
// Get a route for a walkinstance (this means getting the walk)
if (isset($walkinstanceid)) {
    $f = SWG::walkInstanceFactory();
    $walk = $f->getSingle($walkinstanceid);
}
// Get the route for a particular walk if walkid is set
if (isset($walkid)) {
    include_once JPATH_BASE . "/swg/Models/Walk.php";
    $walk = Walk::getSingle($walkid);
}
if (isset($walk)) {
    $routes = Route::loadForWalkable($walk, true, $type, 1);
    // TODO: Support logged routes
    if (!empty($routes)) {
        $result = $routes[0];
    } else {
        $result = false;
    }
Пример #13
0
 /**
  * Outputs arrays of user stats
  * @param JUser $user 			User to get stats for. Default is current user.
  * @param int 	$distanceUnits	Convert distance units to this unit. Includes unit suffix, abbreviated - intended for display
  */
 static function getStats($user = null, $distanceUnits = null)
 {
     // Get attended walks
     if (!isset($user)) {
         $user = JFactory::getUser();
     }
     $wiFact = SWG::WalkInstanceFactory();
     $wiFact->reset();
     $wiFact->endDate = Event::DateEnd;
     $wiFact->addAttendee($user->id);
     $soFact = SWG::SocialFactory();
     $soFact->reset();
     $soFact->endDate = Event::DateEnd;
     $soFact->addAttendee($user->id);
     $weFact = SWG::WeekendFactory();
     $weFact->reset();
     $weFact->endDate = Event::DateEnd;
     $weFact->addAttendee($user->id);
     // TODO: Put into loops
     $startDates = array('alltime' => 0, 'year' => 365, '3month' => 90, 'month' => 30);
     foreach ($startDates as $period => $days) {
         if (empty($days)) {
             $start = 0;
         } else {
             $start = time() - $days * 86400;
         }
         $wiFact->startDate = $start;
         $weFact->startDate = $start;
         $soFact->startDate = $start;
         $walkData = $wiFact->cumulativeStats();
         $socials[$period] = $soFact->cumulativeStats();
         $weekend[$period] = $weFact->cumulativeStats();
         // Stats for all-day walks (walks starting at or before 14:00)
         $wiFact->startTimeMax = 14 * 3600;
         $dayWalkData = $wiFact->cumulativeStats();
         $wiFact->startTimeMax = null;
         // TODO: Check this doesn't fail for non-leaders: should say "0"
         $wiFact->leader = Leader::fromJoomlaUser($user->id);
         if (!empty($wiFact->leader)) {
             $ledData = $wiFact->cumulativeStats();
         } else {
             $ledData = array("count" => 0, "sum_miles" => 0);
         }
         // Convert walk units if needed
         if (isset($distanceUnits)) {
             $walkData['sum_miles'] = UnitConvert::displayDistance($walkData['sum_miles'], UnitConvert::Mile, $distanceUnits, false);
             $walkData['mean_miles'] = UnitConvert::displayDistance($walkData['mean_miles'], UnitConvert::Mile, $distanceUnits, false);
             $walkData['sum_distance'] = UnitConvert::displayDistance($walkData['sum_distance'], UnitConvert::Metre, $distanceUnits, false);
             $walkData['mean_distance'] = UnitConvert::displayDistance($walkData['mean_distance'], UnitConvert::Metre, $distanceUnits, false);
             $dayWalkData['sum_miles'] = UnitConvert::displayDistance($dayWalkData['sum_miles'], UnitConvert::Mile, $distanceUnits, false);
             $dayWalkData['mean_miles'] = UnitConvert::displayDistance($dayWalkData['mean_miles'], UnitConvert::Mile, $distanceUnits, false);
             $dayWalkData['sum_distance'] = UnitConvert::displayDistance($dayWalkData['sum_distance'], UnitConvert::Metre, $distanceUnits, false);
             $dayWalkData['mean_distance'] = UnitConvert::displayDistance($dayWalkData['mean_distance'], UnitConvert::Metre, $distanceUnits, false);
             if (!empty($wiFact->leader)) {
                 $ledData['sum_miles'] = UnitConvert::displayDistance($ledData['sum_miles'], UnitConvert::Mile, $distanceUnits, false);
                 $ledData['mean_miles'] = UnitConvert::displayDistance($ledData['mean_miles'], UnitConvert::Mile, $distanceUnits, false);
                 $ledData['sum_distance'] = UnitConvert::displayDistance($ledData['sum_distance'], UnitConvert::Metre, $distanceUnits, false);
                 $ledData['mean_distance'] = UnitConvert::displayDistance($ledData['mean_distance'], UnitConvert::Metre, $distanceUnits, false);
             }
         }
         $walks[$period] = $walkData;
         $dayWalks[$period] = $dayWalkData;
         $led[$period] = $ledData;
         $wiFact->leader = null;
         // Note: this is AFTER the conversions, we check if the leader is set in there
     }
     return array('walks' => $walks, 'daywalks' => $dayWalks, 'led' => $led, 'socials' => $socials, 'weekends' => $weekend);
 }
 /**
  * Load the walk instance we're adding/editing and returns its values as an array
  * If this is a new walk instance, set some defaults
  */
 public function getWalkInstance()
 {
     // Load or create the walk instance if not already done
     if (!isset($this->wi)) {
         $factory = SWG::walkInstanceFactory();
         if (JRequest::getInt("walkinstanceid", 0, "get")) {
             $this->wi = $factory->getSingle(JRequest::getInt("walkinstanceid", 0, "get"));
         } else {
             if (JRequest::getInt("walkid", 0, "get")) {
                 $this->wi = $factory->createFromWalk($factory->getSingle(JRequest::getInt("walkid", 0, "get")));
             } else {
                 $this->wi = new WalkInstance();
             }
         }
     }
     return $this->wi->valuesToForm();
 }
<?php

// no direct access
defined('_JEXEC') or die('Restricted access');
require_once dirname(__FILE__) . '/helper.php';
require_once JPATH_BASE . "/swg/swg.php";
// TODO: Move main code to helper file or delete helper file
$user = JFactory::getUser();
// TODO: Get as much as possible with a single query
$db = JFactory::getDbo();
$db->setQuery('SELECT profile_value FROM #__user_profiles' . ' WHERE user_id = ' . (int) $user->id . " AND profile_key = 'swg_extras.joindate'" . ' LIMIT 1');
$db->query();
if ($db->getNumRows()) {
    $results = $db->loadAssoc();
    $joindate = strtotime($results['profile_value']);
}
// Load JS to handle attendance changes
JHtml::_('behavior.framework', true);
JHTML::script("swg/js/events.js", true);
JHTML::script("modules/mod_swg_profile/script/profile.js", true);
// Get attended walks
$wiFact = SWG::WalkInstanceFactory();
$wiFact->reset();
$wiFact->startDate = 0;
$wiFact->endDate = Event::DateEnd;
$wiFact->addAttendee($user->id);
$numWalks = $wiFact->numEvents();
$walkStats = $wiFact->cumulativeStats();
require JModuleHelper::getLayoutPath('mod_swg_profile');
Пример #16
0
 public function __set($name, $value)
 {
     switch ($name) {
         case "name":
         case "description":
         case "bookingsInfo":
         case "clipartFilename":
         case "cost":
         case "location":
             $this->{$name} = $value;
             break;
         case "okToPublish":
         case "showNormal":
         case "showNewMember":
             $this->{$name} = (bool) $value;
             break;
         case "start":
         case "newMemberStart":
         case "end":
         case "newMemberEnd":
             if (!empty($value) && is_numeric($value)) {
                 $this->{$name} = $value;
             } else {
                 if ($value == "") {
                     $this->{$name} = null;
                 } else {
                     var_dump($name);
                     var_dump($value);
                 }
             }
             break;
         case "latLng":
             if ($value instanceof LatLng) {
                 $this->{$name} = $value;
             } else {
                 if (is_string($value)) {
                     // Is it in JSON?
                     if (substr($value, 0, 2) == "[{") {
                         $value = json_decode($value);
                         $value = $value[0];
                         $this->{$name} = new LatLng($value->lat, $value->lon);
                     } else {
                         $this->{$name} = SWG::parseLatLongTuple($this->value);
                     }
                 } else {
                     if (is_array($value)) {
                         // Convert to LatLng - deliberate fallthrough
                         if (isset($value['lat']) && isset($value['lng'])) {
                             if (is_numeric($value['lat']) && isset($value['lng']) && is_numeric($value['lng'])) {
                                 $this->{$name} = new LatLng($value['lat'], $value['lng']);
                             } else {
                                 if ($value['lat'] == "" && $value['lng'] == "") {
                                     $this->{$name} = null;
                                 }
                             }
                         }
                     } else {
                         if ($value == null) {
                             $this->{$name} = null;
                         }
                     }
                 }
             }
             break;
         case "postcode":
             // Geolocate this postcode
             // TODO: This will wipe any existing latLng...
             // Get the postcode passed in
             if (preg_match("/^([A-Z]{1,2}[0-9]{1,2}[A-Z]?[ ]?[0-9][A-Z]{2})\$/", $value)) {
                 $postcode = str_replace(" ", "", $value);
                 $curl = curl_init("http://www.uk-postcodes.com/postcode/" . $postcode . ".json");
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 $res = json_decode(curl_exec($curl));
                 if (isset($res->geo)) {
                     $this->latLng = new LatLng($res->geo->lat, $res->geo->lng);
                 }
             }
             $this->postcode = $value;
             break;
         default:
             // All others - fall through to Event
             parent::__set($name, $value);
     }
 }
Пример #17
0
 /**
  * Loads a route from the database from its ID
  * @param int $id Route ID to load
  * @param Walkable $w Walk to attach this route to, if the object already exists. A new one will be created if not.
  * @throws InvalidArgumentException If walkable passed in does not match walkable set in database
  */
 public static function loadSingle($id, Walkable $w = null)
 {
     $id = (int) $id;
     $db =& JFactory::getDBO();
     // First, get the route's general data
     $query = $db->getQuery(true);
     $query->select("*");
     $query->from("routes");
     $query->where(array("routeid = " . $id));
     $db->setQuery($query);
     $res = $db->query();
     if ($db->getNumRows($res) == 0) {
         return null;
     }
     $dbArr = $db->loadAssoc();
     $wiFactory = SWG::walkInstanceFactory();
     // If we've been given a Walkable, make sure it matches the one on the route
     // It's OK to load a route for a WalkInstance on a Walk, and vice-versa
     if ($w != null) {
         if ($w instanceof Walk) {
             if ($dbArr['walkid'] != $w->id) {
                 // Try to load a matching walkInstance
                 if (!empty($dbArr['walkinstanceid'])) {
                     $wi = $wiFactory->getSingle($dbArr['walkinstanceid']);
                     if ($wi->walkid != $w->id) {
                         throw new InvalidArgumentException("Loaded route is for WalkInstance " . $wi->id . ", Walk " . $wi->walkid . " (does not match Walk " . $w->id . ")");
                     }
                 } else {
                     throw new InvalidArgumentException("Loaded route is for Walk " . $dbArr['walkid'] . " (does not match Walk " . $w->id . ")");
                 }
             }
         } else {
             if ($dbArr['walkinstanceid'] != $w->id && $dbArr['walkid'] != $w->walkid) {
                 throw new InvalidArgumentException("Loaded route is not for given WalkInstance");
             }
         }
     } else {
         // Load the Walkable
         if (empty($dbArr['walkinstanceid'])) {
             // A Walk
             $w = Walk::getSingle($dbArr['walkid']);
         } else {
             // A WalkInstance
             $w = $wiFactory->getSingle($dbArr['walkinstanceid']);
         }
     }
     // Create the route object
     $rt = new Route($w);
     // TODO: uploadedby/time, length, ascent
     // Load the basic route properties
     $rt->id = $id;
     $rt->distance = $dbArr['length'];
     $rt->ascent = $dbArr['ascent'];
     $rt->uploadedBy = $dbArr['uploadedby'];
     // TODO: Load the actual user? Also, uploadedby should be a Joomla user, not a Leader
     $rt->uploadedDateTime = strtotime($dbArr['uploadeddatetime']);
     $rt->visibility = (int) $dbArr['visibility'];
     $rt->type = (int) $dbArr['type'];
     // Set all the waypoints
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from("routepoints");
     $query->where(array("routeid = " . $id));
     $query->order("sequenceid ASC");
     $db->setQuery($query);
     $res = $db->query();
     // Joomla can't be arsed to support/provide documentation for fetching individual rows like EVERYTHING ELSE DOES
     $megaArray = $db->loadAssocList("sequenceid");
     foreach ($megaArray as $i => $dbArr) {
         $wp = new Waypoint();
         $wp->osRef = new OSRef($dbArr['easting'], $dbArr['northing']);
         $wp->altitude = $dbArr['altitude'];
         $wp->time = $dbArr['datetime'];
         $rt->setWaypoint($i, $wp);
     }
     return $rt;
 }
 /**
  * Loads and caches events of a specified type
  * Can only load 100 events at a time to avoid slowdowns - more will be loaded as a 'bottomless page' type thing
  * @param int $eventType Event type - see SWG constants
  */
 private function loadEvents($eventType)
 {
     // Get the parameters set
     $factory = SWG::eventFactory($eventType);
     $startDate = $this->paramDateToValue(JRequest::getInt("startDateType"), JRequest::getString("startDateSpecify"));
     $endDate = $this->paramDateToValue(JRequest::getInt("endDateType"), JRequest::getString("endDateSpecify"));
     $factory->reset();
     // Set specific factory parameters
     if ($eventType == Event::TypeSocial) {
         $factory->getNormal = true;
         $factory->getNewMember = true;
     }
     if ($eventType == Event::TypeWalk) {
         if (JRequest::getInt("walkProgramme") != 0) {
             switch (JRequest::getInt("walkProgramme")) {
                 case 1:
                     // Current published
                     $factory->walkProgramme = WalkProgramme::getCurrentProgrammeID();
                     break;
                 case 2:
                     $factory->walkProgramme = WalkProgramme::getNextProgrammeID();
                     break;
                 case 3:
                     // Specify
                     $factory->walkProgramme = JRequest::getInt("walkProgrammeSpecify");
                     break;
             }
         }
     }
     // Set standard/shared factory parameters
     $factory->startDate = $startDate;
     $factory->endDate = $endDate;
     $factory->limit = 100;
     $factory->offset = JRequest::getInt("offset", 0);
     $factory->reverse = JRequest::getBool("order");
     $factory->showUnpublished = JRequest::getBool("unpublished", false);
     $factory->includeAttendees = true;
     $factory->includeAttendedBy = Jfactory::getUser()->id;
     if (JRequest::getBool("diaryMode", false)) {
         // Default is the current logged in user.
         // TODO: Allow view access to other people's diaries
         $factory->addAttendee(JFactory::getUser()->id);
     }
     // Get events from factories
     switch ($eventType) {
         case Event::TypeWalk:
             $this->numWalks = $factory->numEvents();
             $this->walks = $factory->get();
             break;
         case Event::TypeSocial:
             $this->numSocials = $factory->numEvents();
             $this->socials = $factory->get();
             break;
         case Event::TypeWeekend:
             $this->numWeekends = $factory->numEvents();
             $this->weekends = $factory->get();
             break;
     }
 }
 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 weekend specified, or a blank one if none specified
  */
 public function loadWeekend($id)
 {
     if (empty($id)) {
         $this->weekend = new Weekend();
         $this->weekend->swg = true;
     } else {
         $factory = SWG::weekendFactory();
         $this->weekend = $factory->getSingle($id);
     }
 }
Пример #21
0
 public function __set($name, $value)
 {
     switch ($name) {
         case "name":
         case "placeName":
         case "area":
         case "description":
         case "url":
         case "contact":
         case "bookingsOpen":
         case "cost":
             $this->{$name} = $value;
             break;
         case "places":
             $this->{$name} = (int) $value;
             break;
         case "okToPublish":
         case "challenge":
         case "swg":
             $this->{$name} = (bool) $value;
             break;
         case "start":
             if (!empty($value)) {
                 $this->{$name} = $value;
                 // Calculate the payment due date.
                 // Payment is due by the end of the month before the date 2 weeks before the weekend
                 // Looks like "last day of -1 month" is only supported by PHP 5.3, so let's do this the old-fashioned way
                 $threeWeeksBefore = $value - 86400 * 14;
                 // Looks like "last day of -1 month" is only supported by PHP 5.3, so let's do this the old-fashioned way
                 $this->paymentDue = strtotime(strftime("%Y-%m-01", $threeWeeksBefore)) - 86400;
             } else {
                 $this->{$name} = null;
                 $this->paymentDue = null;
             }
             break;
         case "endDate":
             if (!empty($value)) {
                 $this->{$name} = $value;
             } else {
                 $this->{$name} = null;
             }
             break;
         case "latLng":
             if ($value instanceof LatLng) {
                 $this->{$name} = $value;
             } else {
                 if (is_string($value)) {
                     // Is it in JSON?
                     if (substr($value, 0, 2) == "[{") {
                         $value = json_decode($value);
                         $value = $value[0];
                         $this->{$name} = new LatLng($value->lat, $value->lon);
                     } else {
                         $this->{$name} = SWG::parseLatLongTuple($this->value);
                     }
                 } else {
                     if (is_array($value)) {
                         // Convert to LatLng
                         if (isset($value['lat']) && isset($value['lng'])) {
                             if (is_numeric($value['lat']) && is_numeric($value['lng'])) {
                                 $this->{$name} = new LatLng($value['lat'], $value['lng']);
                             } else {
                                 $this->{$name} = null;
                             }
                         }
                     }
                 }
             }
             break;
         default:
             // All others - fall through to Event
             parent::__set($name, $value);
     }
 }