/** * 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"); } }
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; }
/** * 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); } }
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; }
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 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; }
/** * 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(); }