Changeset 57418
- Timestamp:
- 04/07/08 16:40:13 (5 months ago)
- Location:
- modules/marketdemandmap/trunk
- Files:
-
- 3 modified
-
code/controller/DemandPointRestfulServer.php (modified) (4 diffs)
-
javascript/demandmap.DemandCategoryControl.js (modified) (1 diff)
-
javascript/demandmap.DemandPointList.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
modules/marketdemandmap/trunk/code/controller/DemandPointRestfulServer.php
r56979 r57418 11 11 } 12 12 13 protected function search($className, $params = null, $sort = null, $limit = null, $existingQuery = null) { 14 15 if(singleton($className)->hasMethod('getRestfulSearchContext')) { 16 $searchContext = singleton($className)->{'getRestfulSearchContext'}(); 17 } else { 18 $searchContext = singleton($className)->getDefaultSearchContext(); 19 } 20 21 if(isset($params['clustered']) && $params['clustered']) { 22 // we need bounds to cluster onto, otherwise its kinda pointless 23 if(!isset($params['Bounds']) || !singleton('LatLngBoundsFilter')->isValid($params['Bounds'])) return false; 24 // don't apply limit clause, we'll do this later in clustering 25 $query = $searchContext->getQuery($params, $sort, null, $existingQuery); 26 27 return $this->cluster($query, $params['Bounds']); 28 } else { 29 $query = $searchContext->getQuery($params, $sort, $limit, $existingQuery); 30 if( 31 (isset($limit['limit']) && $limit['limit'] > DemandPoint::$default_cluster_markercount) 32 || (!isset($limit['limit']) && $query->unlimitedRowCount() > DemandPoint::$default_cluster_markercount) 33 && isset($params['Bounds']) 34 ) { 35 $query = $searchContext->getQuery($params, $sort, null, $existingQuery); 36 return $this->cluster($query, $params['Bounds']); 37 } else { 38 return singleton($className)->buildDataObjectSet($query->execute()); 39 } 40 } 13 protected function needsCluster($query, $params, $sort, $limit) { 14 return ( 15 (isset($limit['limit']) && $limit['limit'] > DemandPoint::$default_cluster_markercount) 16 || (!isset($limit['limit']) && $query->unlimitedRowCount() > DemandPoint::$default_cluster_markercount) 17 && isset($params['Bounds']) 18 ); 41 19 } 42 20 … … 204 182 } 205 183 206 /** 207 * HACK to set custom fields if clustering is necessary 208 * as we're requiring different fields outside of the normal $db 209 * array - and can't anticipate in the RESTful request 210 * if those cluster fields are needed. 211 * 212 * @todo Need a way to determine custom fields on a by-result and by-class basis. 213 */ 214 protected function getHandler($className, $id, $relation) { 184 protected function getHandler($className, $id, $relationName) { 215 185 $sort = array( 216 186 'sort' => $this->request->getVar('sort'), … … 222 192 ); 223 193 194 $params = $this->request->getVars(); 195 224 196 $responseFormatter = $this->getResponseDataFormatter(); 225 197 if(!$responseFormatter) return $this->unsupportedMediaType(); 226 198 199 // $obj can be either a DataObject or a DataObjectSet, 200 // depending on the request 227 201 if($id) { 228 $obj = DataObject::get_by_id($className, $id); 202 // Format: /api/v1/<MyClass>/<ID> 203 $query = $this->getObjectQuery($className, $id, $params); 204 $obj = singleton($className)->buildDataObjectSet($query->execute()); 229 205 if(!$obj) return $this->notFound(); 206 $obj = $obj->First(); 230 207 if(!$obj->canView()) return $this->permissionFailure(); 231 232 if($relation) { 233 if($relationClass = $obj->many_many($relation)) { 234 $query = $obj->getManyManyComponentsQuery($relation); 235 } elseif($relationClass = $obj->has_many($relation)) { 236 $query = $obj->getComponentsQuery($relation); 237 } elseif($relationClass = $obj->has_one($relation)) { 238 $query = null; 239 } elseif($obj->hasMethod("{$relation}Query")) { 240 // @todo HACK Switch to ComponentSet->getQuery() once we implement it (and lazy loading) 241 $query = $obj->{"{$relation}Query"}(null, $sort, null, $limit); 242 $relationClass = $obj->{"{$relation}Class"}(); 208 209 // Format: /api/v1/<MyClass>/<ID>/<Relation> 210 if($relationName) { 211 $query = $this->getObjectRelationQuery($obj, $params, $sort, $limit, $relationName); 212 if($query === false) return $this->notFound(); 213 if($this->needsCluster($query, $params, $sort, $limit)) { 214 $obj = $this->cluster($query, $params['Bounds']); 243 215 } else { 244 return $this->notFound(); 216 $searchQuery = $this->getSearchQuery($className, $params, $sort, $limit); 217 $obj = singleton($className)->buildDataObjectSet($searchQuery->execute()); 245 218 } 246 247 // get all results 248 $obj = $this->search($relationClass, $this->request->getVars(), $sort, $limit, $query); 249 if(!$obj) $obj = new DataObjectSet(); 250 } 219 } 220 251 221 } else { 252 $obj = $this->search($className, $this->request->getVars(), $sort, $limit); 222 // Format: /api/v1/<MyClass> 223 $query = $this->getObjectsQuery($className, $params, $sort, $limit); 224 if($this->needsCluster($query, $params, $sort, $limit)) { 225 $obj = $this->cluster($query, $params['Bounds']); 226 } else { 227 $searchQuery = $this->getSearchQuery($className, $params, $sort, $limit); 228 $obj = singleton($className)->buildDataObjectSet($searchQuery->execute()); 229 } 230 253 231 // show empty serialized result when no records are present 254 232 if(!$obj) $obj = new DataObjectSet(); 233 } 234 235 $this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType()); 236 237 if($obj instanceof DataObjectSet) { 238 $responseFormatter->setTotalSize($query->unlimitedRowCount()); 255 239 256 240 // HACK Customization (see method comment) … … 264 248 )); 265 249 } 266 } 267 268 $this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType()); 269 270 if($obj instanceof DataObjectSet) return $responseFormatter->convertDataObjectSet($obj); 271 else return $responseFormatter->convertDataObject($obj); 272 } 273 250 251 return $responseFormatter->convertDataObjectSet($obj); 252 } else { 253 return $responseFormatter->convertDataObject($obj); 254 } 255 } 256 274 257 protected function getResponseDataFormatter() { 275 258 $responseFormatter = $this->getDataFormatter(true); -
modules/marketdemandmap/trunk/javascript/demandmap.DemandCategoryControl.js
r57365 r57418 83 83 _setLoading(false, i); 84 84 }); 85 $map.fn('addPoints', markersJson );85 $map.fn('addPoints', markersJson.items); 86 86 87 $this.trigger('DemandCategoryControl:loadcategories', [categoryIDs, markersJson ]);87 $this.trigger('DemandCategoryControl:loadcategories', [categoryIDs, markersJson.items]); 88 88 } 89 89 ); -
modules/marketdemandmap/trunk/javascript/demandmap.DemandPointList.js
r57410 r57418 16 16 // config 17 17 var defaults = { 18 18 'pageSize': 20 19 19 }; 20 20 … … 55 55 // ######## public methods ######### 56 56 $this.fn({ 57 'refresh' : function(force ) {57 'refresh' : function(force, url) { 58 58 if(!$this.is(':visible') && !force) return false; 59 59 60 varurl = demandControl.fn('getDataURL');60 if(!url) url = demandControl.fn('getDataURL'); 61 61 62 62 // don't set this above the cluster threshold, 63 63 // or the clustering will kick in 64 url += '&limit= 40';64 url += '&limit=' + options.pageSize; 65 65 66 66 $.getJSON( … … 89 89 // body definition 90 90 html += '<tbody>'; 91 for(var i=0; i<markers.length; i++) { 92 var m = markers[i]; 93 console.debug(markers[i]); 91 for(var i=0; i<markers.items.length; i++) { 92 var m = markers.items[i]; 94 93 html += 95 94 '<tr class="vcard">' … … 115 114 html += '</table>'; 116 115 116 // pagination 117 html += '<ul class="pagination">'; 118 html += '<li>'; 119 html += '<a href="#"></a>'; 120 html += '</li>'; 121 html += '</ul>'; 122 117 123 // insert html 118 124 $this.html(html);
