/** * Browse Service * @todo move all queries to the query class * * @param KCommandContext $context */ protected function _actionBrowse(KCommandContext $context) { if ($this->locatable) { if (in_array($this->getView()->getLayout(), array('selector', 'list_selector'))) { $keyword = $this->q ? $this->getService('anahita:filter.term')->sanitize($this->q) : ''; $query = $this->getService('com://site/locations.domain.query.selector')->keyword($keyword)->excludeIds(AnHelperArray::collect($this->locatable->locations, 'id'))->locatable($this->locatable)->nearbyLatitude($this->nearby_latitude)->nearbyLongitude($this->nearby_longitude); } else { $query = $this->locatable->locations->order('name'); } $query->limit($this->limit, $this->start); return $this->getState()->setList($query->toEntityset())->getList(); } return parent::_actionBrowse($context); }
/** * Browse Service * @todo move all queries to the query class * * @param KCommandContext $context */ protected function _actionBrowse(KCommandContext $context) { // @todo move these queries to query classes $keyword = $this->q ? $this->getService('anahita:filter.term')->sanitize($this->q) : ''; if ($this->locatable) { if (in_array($this->getView()->getLayout(), array('selector', 'list_selector'))) { $query = $this->getService('repos:locations.location')->getQuery(); $excludeIds = AnHelperArray::collect($this->locatable->locations, 'id'); if (count($excludeIds)) { $query->where('location.id', 'NOT IN', $excludeIds); } if ($keyword != '') { $query->keyword = $keyword; } if ($this->nearby_latitude && $this->nearby_longitude) { $earth_radius = 6371000; $lat = (double) $this->nearby_latitude; $lng = (double) $this->nearby_longitude; $calc_distance = 'CEIL((ACOS(SIN(' . $lat . '*PI()/180) * SIN(location.geo_latitude*PI()/180) + COS(' . $lat . '*PI()/180) * COS(location.geo_latitude*PI()/180) * COS((' . $lng . '*PI()/180) - (location.geo_longitude*PI()/180) )) *' . $earth_radius . '))'; $query->select(array($calc_distance . ' AS `distance`')); $query->having('distance < 5000'); $query->order('distance'); } } else { $query = $this->locatable->locations; $query->order('name'); } } elseif ($keyword != '') { $query = $this->getService('repos:locations.location')->getQuery(); $query->keyword = $keyword; } else { $entities = parent::_actionBrowse($context); $query = $entities->getQuery(); $edgeType = 'ComTagsDomainEntityTag,ComLocationsDomainEntityTag,com:locations.domain.entity.tag'; $query->where('edge.type', '=', $edgeType)->group('location.id'); } $query->limit($this->limit, $this->offset); //print str_replace('#_', 'jos', $query); return $this->getState()->setList($query->toEntityset())->getList(); }