コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validation = Validator::make(Input::all(), ['duration' => 'required | integer', 'pace' => 'required | integer', 'dog_friendliness' => 'required | integer', 'comments' => 'required']);
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation->messages());
     }
     $walk = new Walk();
     $duration = Input::get('duration');
     $dog_friendliness = Input::get('dog_friendliness');
     $pace = Input::get('pace');
     $comments = Input::get('comments');
     $start = new DateTime();
     $start->setTimezone(new DateTimeZone('America/New_York'));
     $dateInterval = new DateInterval('PT' . $duration . 'M');
     $finish = date_add($start, $dateInterval);
     $walk->start = $start;
     $walk->finish = $finish;
     $walk->host_id = Auth::user()->id;
     $walk->dog_friendliness = $dog_friendliness;
     $walk->pace = $pace;
     $walk->comments = $comments;
     if ($walk->save()) {
         return Redirect::route('walk.index');
     }
 }
コード例 #2
0
 /**
  * Returns the walk specified by the walkid parameter in the get string.
  * Loads it from the database if necessary.
  */
 public function getWalk()
 {
     if (!$this->fetchedWalk) {
         // TODO: Check user has permission to view this walk
         $this->walk = Walk::getSingle(JRequest::getInt("walkid", 0, "get"));
         $this->fetchedWalk = true;
     }
     return $this->walk;
 }
コード例 #3
0
 public function getWalks()
 {
     // If we have a custom walk list, return that
     if (isset($this->walkList)) {
         return $this->walkList;
     }
     // Otherwise, get the default data
     switch (JRequest::getInt("initialView")) {
         case 0:
         default:
             return array();
         case 1:
             // Get this leader's record
             $leader = Leader::fromJoomlaUser(JFactory::getUser()->id);
             if (!empty($leader)) {
                 return Walk::getWalksBySuggester($leader);
             } else {
                 return array();
             }
     }
 }
コード例 #4
0
 function canEdit($walkOrID)
 {
     if (JFactory::getUser()->authorise("walk.editall", "com_swg_walklibrary")) {
         return true;
     } else {
         if (!JFactory::getUser()->authorise("walk.editown", "com_swg_walklibrary")) {
             return false;
         } else {
             if (is_numeric($walkOrID)) {
                 $walk = Walk::getSingle($walkOrID);
             } else {
                 if ($walkOrID instanceof Walk) {
                     $walk = $walkOrID;
                 }
             }
             if (empty($walk)) {
                 throw new InvalidArgumentException("Invalid walk or ID");
             }
             return $walk->suggestedBy == Leader::fromJoomlaUser(JFactory::getUser()->id);
         }
     }
 }
コード例 #5
0
 public function pay_walker()
 {
     $walk_id = Input::get('walk_id');
     $amount = Input::get('amount');
     $walk = Walk::find($walk_id);
     $walk->is_paid = 1;
     $walk->amount = $amount;
     $walk->save();
     return Redirect::to('/admin/walk/map/' . $walk_id);
 }
コード例 #6
0
 public function updItem($data)
 {
     $this->walk->save();
 }
コード例 #7
0
 public function cancel_walk()
 {
     if (Request::isMethod('post')) {
         $walk_id = Input::get('walk_id');
         $token = Input::get('token');
         $walker_id = Input::get('id');
         $validator = Validator::make(array('walk_id' => $walk_id, 'token' => $token, 'walker_id' => $walker_id), array('walk_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $is_admin = $this->isAdmin($token);
             if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($walker_data->token_expiry) || $is_admin) {
                     // Do necessary operations
                     if ($walk = Walk::find($walk_id)) {
                         if ($walk->walker_id == $walker_id) {
                             if ($walk->is_walk_started == 0) {
                                 $walk->walker_id = 0;
                                 $walk->is_confirmed = 0;
                                 $walk->save();
                                 $response_array = array('success' => true);
                                 $response_code = 200;
                             } else {
                                 $response_array = array('success' => false, 'error' => 'Walk Already Started', 'error_code' => 416);
                                 $response_code = 200;
                             }
                         } else {
                             $response_array = array('success' => false, 'error' => 'Walk ID doesnot matches with Walker ID', 'error_code' => 407);
                             $response_code = 200;
                         }
                     } else {
                         $response_array = array('success' => false, 'error' => 'Walk ID Not Found', 'error_code' => 408);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     $response_array = array('success' => false, 'error' => 'Walker ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
コード例 #8
0
<?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// What type of event to we want?
// TODO: Probably shouldn't return anything that isn't OK to publish - this is publicly accessible.
$id = JRequest::getVar('id', null, "get", "INTEGER");
if (!isset($id)) {
    jexit("ID must be specified");
}
include_once JPATH_BASE . "/swg/Models/Walk.php";
$result = Walk::getSingle($id);
echo $result->jsonEncode();
die;
コード例 #9
0
 public function __get($name)
 {
     // Load connected objects from the database as needed
     switch ($name) {
         case "meetPoint":
             $this->meetPoint = new WalkMeetingPoint($this->meetPointId, $this->start, $this->meetPlaceTime);
             break;
         case "leader":
             $this->leader = Leader::getLeader($this->leaderId);
             if (!empty($this->leaderName)) {
                 $this->leader->setDisplayName($this->leaderName);
             }
             break;
         case "backmarker":
             $this->backmarker = Leader::getLeader($this->backmarkerId);
             if (!empty($this->backmarkerName)) {
                 $this->backmarker->setDisplayName($this->backmarkerName);
             }
             break;
         case "walk":
             return Walk::getSingle($this->walkid);
         case "track":
             // Load the track if we don't have it already
             // TODO: Only try once, and catch exceptions
             if (!isset($this->track)) {
                 $this->loadTrack();
             }
             return $this->track;
         case "distance":
             // If we don't have a (real) distance set, convert the (estimated) miles into metres and give that
             break;
             // If the walk is circular, return the equivalent start point
         // If the walk is circular, return the equivalent start point
         case "endPlaceName":
         case "endLatLng":
         case "endGridRef":
             if ($this->isLinear) {
                 return $this->{$name};
             } else {
                 $var = "start" . substr($name, 3);
                 return $this->{$var};
             }
     }
     return $this->{$name};
     // TODO: What params should be exposed?
 }
コード例 #10
0
    $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;
    }
    // Error condition - notify caller there are no routes available
}
if ($result instanceof SWGBaseModel) {
    echo $result->jsonEncode();
} else {
    echo json_encode($result);
コード例 #11
0
 public static function getSingle($id)
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select("*");
     $query->from("walks");
     $query->where(array("ID = " . intval($id)));
     $db->setQuery($query);
     $res = $db->query();
     if ($db->getNumRows($res) == 1) {
         $walk = new Walk();
         $walk->fromDatabase($db->loadAssoc());
         return $walk;
     } else {
         return null;
     }
 }
コード例 #12
0
<?php

define("_JEXEC", true);
define("JPATH_BASE", "/home/peter/swg/website/public_html");
require_once "../swg.php";
include_once "../Models/Walk.php";
$walk = new Walk();
$route = new Route($walk);
$route->readGPX(DOMDocument::loadXML(file_get_contents($argv[1])));
$walk->setRoute($route);
echo "Distance: " . $walk->miles . " miles (" . $walk->distanceGrade . ")\n";
if ($walk->isLinear) {
    echo "Linear";
} else {
    echo "Circular";
}
echo "\n";
echo "Start: " . $walk->startGridRef . " (" . $walk->startPlaceName . ")\n";
echo "End: " . $walk->endGridRef . " (" . $walk->endPlaceName . ")\n";
$route->save();
コード例 #13
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;
 }
コード例 #14
0
 /**
  * Performs a search with the current parameters
  */
 public function search()
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select("*");
     $query->from("walks");
     if (isset($this->name)) {
         $query->where("walkName LIKE '" . $db->escape($this->name)) . "'";
     }
     if (isset($this->grade)) {
         // An array of grade combinations in database format. These are imploded with an OR.
         $grades = array();
         foreach ($this->grade as $grade) {
             $grades[] = "(difficultygrade = '" . $grade['difficulty'] . "' AND distancegrade = '" . $grade['distance'] . "')";
         }
         $query->where("(" . implode(" OR ", $grades) . ")");
     } else {
         if (isset($this->distanceGrade)) {
             $query->where("distancegrade IN (" . implode(",", $this->distanceGrade) . ")");
         }
         if (isset($this->difficultyGrade)) {
             $query->where("difficultygrade IN (" . implode(",", $this->difficultyGrade) . ")");
         }
     }
     // TODO: Length (miles)
     // Location (general area)
     if (isset($this->location)) {
         $query->where("location IN (" . implode(",", $this->location) . ")");
     }
     if (isset($this->isLinear)) {
         $query->where("islinear = " . $this->isLinear);
     }
     // TODO: Start grid ref
     // TODO: End grid ref
     if (isset($this->description)) {
         $query->where("routedescription LIKE '" . $db->escape($this->description)) . "'";
     }
     if (isset($this->information)) {
         $query->where("information LIKE '" . $db->escape($this->information)) . "'";
     }
     if (isset($this->dogFriendly)) {
         $query->where("dogfriendly = " . $this->dogFriendly);
     }
     if (isset($this->childFriendly)) {
         $query->where("childfriendly = " . $this->childFriendly);
     }
     // TODO: Transport by car/public
     if (isset($this->transportByCar)) {
         $query->where("transportbycar = " . $this->transportByCar);
     }
     if (isset($this->transportPublic)) {
         $query->where("transportpublic = " . $this->transportPublic);
     }
     if (isset($this->textPublic)) {
         $query->where("(walkname LIKE '%" . $db->escape($this->textPublic) . "%' OR routedescription LIKE '%" . $db->escape($this->textPublic) . "%')");
     }
     if (isset($this->textAll)) {
         $query->where("(walkname LIKE '%" . $db->escape($this->textAll) . "%' OR routedescription LIKE '%" . $db->escape($this->textAll) . "%' OR information LIKE '%" . $db->escape($this->textAll) . "%')");
     }
     // Suggested by
     if (isset($this->suggestedBy)) {
         $query->where("suggestedby = " . $this->suggestedBy->id);
     }
     // TODO: Sorting
     $db->setQuery($query);
     $cursor = $db->query();
     // TODO: Filtering
     // Return results as array of walks
     $results = array();
     $walkData = $db->loadAssocList();
     foreach ($walkData as $row) {
         $walk = new Walk();
         $walk->fromDatabase($row);
         $results[] = $walk;
     }
     return $results;
 }