Changeset 56
- Timestamp:
- 04/14/10 08:50:14 (2 years ago)
- Files:
-
- 7 modified
-
application/webtracker/controller/user.php (modified) (4 diffs)
-
application/webtracker/model/database/trip.php (modified) (2 diffs)
-
application/webtracker/model/database/user.php (modified) (1 diff)
-
application/webtracker/view/html/user/trip-details.phtml (modified) (1 diff)
-
libraries/Nickel_Core/Controller.php (modified) (1 diff)
-
libraries/Nickel_Core/Database/Querybuilder/All.php (modified) (1 diff)
-
libraries/Nickel_Core/Database/Table.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
application/webtracker/controller/user.php
r53 r56 46 46 $trip = $tripModel->getById($this->_helper->getParam('trip', 0)); 47 47 48 $mintime = $this->_helper->getParam('mintime', 0); 49 $maxtime = $this->_helper->getParam('maxtime', 0); 50 51 if ($trip === null || $trip->user != $user->id) { 48 if (count($trip) == 0) { 52 49 nickelException ('No such trip!', 'bad-route'); die(); 53 50 } 54 51 52 $mintime = $this->_helper->getParam('mintime', 0); 53 $maxtime = $this->_helper->getParam('maxtime', 0); 54 55 55 $this->_view->user = $user; 56 56 $this->_view->trip = $trip; 57 $this->_view->tripraw = $this->_helper->getParam('trip', 0); 57 58 $this->_view->mintime = $mintime; 58 59 $this->_view->maxtime = $maxtime; 60 $this->_view->nospeed = $this->_helper->getParam('nospeed', 'false'); 59 61 } 62 63 64 function summaryAction() { 65 66 $userModel = $this->_helper->model('Database_User'); 67 $tripModel = $this->_helper->model('Database_Trip'); 68 69 $username = $this->_helper->getParam('username', false); 70 71 if ($username === false) { 72 nickelException ('No such user!', 'bad-route'); die(); 73 } 74 75 $user = $userModel->getByUser($username); 76 77 if ($user === null) { 78 nickelException ('No such user!', 'bad-route'); die(); 79 } 80 81 $lowspeedTrips = $user->getLowspeedTrips(); 82 83 $url = array('module' => 'webtracker', 84 'controller' => 'user', 85 'action' => 'tripDetails', 86 'username' => $username, 87 'trip' => implode(',', $lowspeedTrips), 88 'nospeed' => 'true'); 89 90 $this->redirect($url); 91 } 92 60 93 61 94 function tripDetailsAjaxAction() { … … 79 112 } 80 113 81 $trip = $tripModel->getById($this->_helper->getParam('trip', 0)); 82 $mintime = $this->_helper->getParam('mintime', 0); 83 $maxtime = $this->_helper->getParam('maxtime', 0); 84 85 if ($trip === null || $trip->user != $user->id) { 86 // TODO: JSON error 87 nickelException ('No such trip!', 'bad-route'); die(); 88 } 89 90 $nelat = $this->_helper->getParam('nelat', false); 91 $nelng = $this->_helper->getParam('nelng', false); 92 $swlat = $this->_helper->getParam('swlat', false); 93 $swlng = $this->_helper->getParam('swlng', false); 94 $latdif = $nelat-$swlat; 95 $lngdif = $nelng-$swlng; 96 $latdif7 = abs($latdif / 7); 97 $lngdif7 = abs($lngdif / 7); 98 99 $data = $trip->getPointsByBounds($swlat - $latdif7, $swlng - $lngdif7, $nelat + $latdif7, $nelng + $lngdif7, 160, $mintime, $maxtime); 100 101 if(!isset($data[0])) { 102 $dataOutput['segments'] = array(); 103 104 ob_end_clean(); 105 echo(json_encode($dataOutput)); 106 die(); 107 } 108 109 $mintime = $data[0]['time']; 110 $maxtime = $data[count($data)-1]['time']; 111 $timeThatCountsAsAPause = (($maxtime - $mintime) / count($data)) * 4; 112 if ($timeThatCountsAsAPause < 60) $timeThatCountsAsAPause = 80; 114 $trips = explode(',', $this->_helper->getParam('trip', 0)); 113 115 114 116 $dataOutput = array(); … … 117 119 $markers = array(); 118 120 119 $pointsPerMarker = ((int)count($data))/5; 120 121 foreach ($data as $index => $point) { 122 if (count($segment) != 0 && $segment[count($segment)-1]['time'] < $point['time'] - $timeThatCountsAsAPause) { 123 $segments[] = $segment; 124 $segment = array(); 121 foreach ($trips as $tripid) { 122 123 $trip = $tripModel->getById($tripid); 124 $mintime = $this->_helper->getParam('mintime', 0); 125 $maxtime = $this->_helper->getParam('maxtime', 0); 126 127 if ($trip === null || $trip->user != $user->id) { 128 // TODO: JSON error 129 nickelException ('No such trip!', 'bad-route'); die(); 125 130 } 126 $segment[] = $point; 127 if ($index % $pointsPerMarker == 0 || $index == count($data) - 1) { 128 $markers[] = array($point, $this->_helper->url(array('module'=>'webtracker','controller'=>'index','action'=>'generateMarkerSpeed','speed'=>$point['speed'],'time'=>$point['time']))); 131 132 $nelat = $this->_helper->getParam('nelat', false); 133 $nelng = $this->_helper->getParam('nelng', false); 134 $swlat = $this->_helper->getParam('swlat', false); 135 $swlng = $this->_helper->getParam('swlng', false); 136 $latdif = $nelat-$swlat; 137 $lngdif = $nelng-$swlng; 138 $latdif7 = abs($latdif / 7); 139 $lngdif7 = abs($lngdif / 7); 140 141 $data = $trip->getPointsByBounds($swlat - $latdif7, $swlng - $lngdif7, $nelat + $latdif7, $nelng + $lngdif7, 160, $mintime, $maxtime); 142 143 if(!isset($data[0])) { 144 continue; 129 145 } 146 147 $mintime = $data[0]['time']; 148 $maxtime = $data[count($data)-1]['time']; 149 $timeThatCountsAsAPause = (($maxtime - $mintime) / count($data)) * 4; 150 if ($timeThatCountsAsAPause < 60) $timeThatCountsAsAPause = 80; 151 152 $pointsPerMarker = ((int)count($data))/5; 153 154 foreach ($data as $index => $point) { 155 if (count($segment) != 0 && $segment[count($segment)-1]['time'] < $point['time'] - $timeThatCountsAsAPause) { 156 $segments[] = $segment; 157 $segment = array(); 158 } 159 $segment[] = $point; 160 161 if ($this->_helper->getParam('nospeed', 'false') == 'false') { 162 if ($index % $pointsPerMarker == 0 || $index == count($data) - 1) { 163 $markers[] = array($point, $this->_helper->url(array('module'=>'webtracker','controller'=>'index','action'=>'generateMarkerSpeed','speed'=>$point['speed'],'time'=>$point['time']))); 164 } 165 } 166 } 167 168 $segments[] = $segment; 130 169 } 131 132 $segments[] = $segment; 133 170 134 171 $dataOutput['segments'] = $segments; 135 172 $dataOutput['markers'] = $markers; 136 173 137 174 ob_end_clean(); 138 175 echo(json_encode($dataOutput)); … … 140 177 141 178 } 179 180 142 181 } -
application/webtracker/model/database/trip.php
r53 r56 4 4 5 5 public function __construct() { 6 parent::__construct('webtracker_trip', 'id', 'Webtracker_Model_Database_Trip_Row' );6 parent::__construct('webtracker_trip', 'id', 'Webtracker_Model_Database_Trip_Row', 'Webtracker_Model_Database_Trip_Resultset'); 7 7 } 8 8 … … 10 10 return $this->aggregate('distance', 'sum', array('date' => $day, 'user' => $user)); 11 11 } 12 } 13 14 class Webtracker_Model_Database_Trip_Resultset extends Database_Resultset { 12 15 13 16 public function getGoogleMapsBoundsString() { 17 $minlat = false; 18 $minlng = false; 19 $maxlat = false; 20 $maxlng = false; 21 22 foreach ($this as $row) { 23 $bounds = $row->getGoogleMapsBounds(); 24 if ($minlat === false || (float)$minlat > (float)$bounds['minlat']) $minlat = $bounds['minlat']; 25 if ($minlng === false || (float)$minlng > (float)$bounds['minlng']) $minlng = $bounds['minlng']; 26 if ($maxlat === false || (float)$maxlat < (float)$bounds['maxlat']) $maxlat = $bounds['maxlat']; 27 if ($maxlng === false || (float)$maxlng < (float)$bounds['maxlng']) $maxlng = $bounds['maxlng']; 28 } 29 30 return 'new GLatLngBounds(new GLatLng('.$minlat.', '.$minlng.'), new GLatLng('.$maxlat.', '.$maxlng.'))'; 31 } 14 32 } 15 33 16 34 class Webtracker_Model_Database_Trip_Row extends Database_Row { 17 35 36 public function getGoogleMapsBounds() { 37 // This code sucks, and only works when you're only on one specific quadrent of the world for the entire trip. 38 $pointModel = $this->_helper->model('Database_Point'); 39 40 $aggregateBounds = $this->_db->queryFetchRow($pointModel->select(array( 41 'min(lat)' => 'minlat', 42 'min(lon)' => 'minlng', 43 'max(lat)' => 'maxlat', 44 'max(lon)' => 'maxlng', 45 ))->where(array('trip' => $this->id))); 46 47 return $aggregateBounds; 48 } 49 18 50 public function getGoogleMapsBoundsString() { 19 // This code sucks, and only works when you're only on one specific quadrent of the world for the entire trip. 20 $pointModel = $this->_helper->model('Database_Point'); 21 22 $aggregateBounds = $this->_db->queryFetchRow($pointModel->select(array( 23 'min(lat)' => 'minlat', 24 'min(lon)' => 'minlng', 25 'max(lat)' => 'maxlat', 26 'max(lon)' => 'maxlng', 27 ))->where(array('trip' => $this->id))); 51 52 $aggregateBounds = $this->getGoogleMapsBounds(); 28 53 29 54 return 'new GLatLngBounds(new GLatLng('.$aggregateBounds['minlat'].', '.$aggregateBounds['minlng'].'), new GLatLng('.$aggregateBounds['maxlat'].', '.$aggregateBounds['maxlng'].'))'; -
application/webtracker/model/database/user.php
r42 r56 4 4 5 5 public function __construct() { 6 parent::__construct('webtracker_user', 'id' );6 parent::__construct('webtracker_user', 'id', 'Webtracker_Model_Database_User_Row'); 7 7 } 8 8 9 9 } 10 11 12 class Webtracker_Model_Database_User_Row extends Database_Row { 13 14 15 public function getLowspeedTrips() { 16 $tripModel = $this->_helper->model('Database_Trip'); 17 $pointModel = $this->_helper->model('Database_Point'); 18 19 $tripsSlow = array(); 20 21 $trips = $tripModel->fetchAll(array('user = ?' => $this->id)); 22 foreach ($trips as $trip) { 23 if ($pointModel->aggregate('id', 'count', array('trip' => $trip->id, 'speed > 40')) == 0) { 24 $tripsSlow[] = $trip->id; 25 } 26 } 27 28 return $tripsSlow; 29 } 30 31 32 public function getGoogleMapsBoundsString() { 33 // This code sucks, and only works when you're only on one specific quadrent of the world for the entire trip. 34 $pointModel = $this->_helper->model('Database_Point'); 35 36 $aggregateBounds = $this->_db->queryFetchRow($pointModel->select(array( 37 'min(lat)' => 'minlat', 38 'min(lon)' => 'minlng', 39 'max(lat)' => 'maxlat', 40 'max(lon)' => 'maxlng', 41 ))->where(array('trip' => $this->id))); 42 43 return 'new GLatLngBounds(new GLatLng('.$aggregateBounds['minlat'].', '.$aggregateBounds['minlng'].'), new GLatLng('.$aggregateBounds['maxlat'].', '.$aggregateBounds['maxlng'].'))'; 44 } 45 46 } 47 -
application/webtracker/view/html/user/trip-details.phtml
r53 r56 10 10 <?php echo $this->addElement(new Element_AjaxGoogleMaps('map', '', 11 11 array( 12 'overlayService' => array('module'=>'webtracker','controller'=>'user','action'=>'tripDetailsAjax','username'=>$this->user->user,'trip'=>$this->trip ->id,'mintime'=>$this->mintime,'maxtime'=>$this->maxtime),12 'overlayService' => array('module'=>'webtracker','controller'=>'user','action'=>'tripDetailsAjax','username'=>$this->user->user,'trip'=>$this->tripraw,'mintime'=>$this->mintime,'maxtime'=>$this->maxtime,'nospeed'=>$this->nospeed), 13 13 'initialLocation' => $this->trip->getGoogleMapsBoundsString(), 14 14 'initialMode' => 'G_NORMAL_MAP' -
libraries/Nickel_Core/Controller.php
r28 r56 61 61 */ 62 62 public function redirect($uri) { 63 header ('Location: '.$this->_helper->baseUrl().$uri); 63 header ('Location: '.$this->_helper->url($uri)); 64 die(); 64 65 } 65 66 -
libraries/Nickel_Core/Database/Querybuilder/All.php
r47 r56 112 112 $this->_clauses['WHERE'][] = ' '.$value.' '; 113 113 } else { 114 $id = ':pdoval'.count($this->_values);115 $this->_values[$id] = $value;116 114 if (strpos($key, '?') === false) { 117 115 //array('column', 'value') 118 $this->_clauses['WHERE'][] = ' '.$key.' = '.$id.' '; 116 if (is_array($value)) { 117 //array('column', array('value1', 'value2', 'value3')) 118 $inclause = array(); 119 foreach ($value as $v) { 120 $id = ':pdoval'.count($this->_values); 121 $this->_values[$id] = $v; 122 $inclause[] = $id; 123 } 124 if (count($inclause) == 0) { 125 $this->_clauses['WHERE'][] = ' FALSE '; 126 } else { 127 $this->_clauses['WHERE'][] = ' '.$key.' IN ('.implode(',', $inclause).') '; 128 } 129 } else { 130 $id = ':pdoval'.count($this->_values); 131 $this->_values[$id] = $value; 132 $this->_clauses['WHERE'][] = ' '.$key.' = '.$id.' '; 133 } 119 134 } else { 120 135 //array('column = ?', 'value') 136 $id = ':pdoval'.count($this->_values); 137 $this->_values[$id] = $value; 121 138 $this->_clauses['WHERE'][] = ' '.str_replace('?', $id, $key).' '; 122 139 } -
libraries/Nickel_Core/Database/Table.php
r45 r56 6 6 public $_primaryKey; 7 7 public $_rowClass; 8 public $_resultSetClass; 8 9 public $_helper; 9 10 public $_db; 10 11 11 public function __construct($table = '', $primaryKey = '', $rowClass = '' ) {12 public function __construct($table = '', $primaryKey = '', $rowClass = '', $resultSetClass = '') { 12 13 global $nickelGlobals; 13 14 … … 16 17 $this->_primaryKey = $primaryKey; 17 18 $this->_rowClass = $rowClass; 19 $this->_resultSetClass = $resultSetClass; 18 20 $this->_db = new Database(); 19 21 } … … 47 49 */ 48 50 public function _createResultSet($array) { 49 return new Database_Resultset($this, $array); 51 if ($this->_resultSetClass == '') { 52 return new Database_Resultset($this, $array); 53 } else { 54 return new $this->_resultSetClass($this, $array); 55 } 50 56 } 51 57 … … 118 124 $query = $this->_db->queryBuilder() 119 125 ->select($this->_table) 120 ->where( $column, $value);126 ->where(array($column => $value)); 121 127 122 128 return $this->_createResultSet($this->_db->queryFetchAll($query));
![(please configure the [header_logo] section in trac.ini)](/trac/chrome/site/your_project_logo.png)