public static function search($params, $page_num, $page_size) { //return require_once 'D:/test/test_vehicle.php'; $ret = array('data' => array('count' => 0, 'vehicles' => array()), 'query' => array()); $cityid = $params['city_id']; $field = 'time'; $direct = '1'; if (isset($params['sort_f']) && isset($params['sort_d'])) { $field_arr = array('y' => 'register_time', 'm' => 'miles', 'p' => 'price'); $direct_arr = array('a' => '0', 'd' => '1'); $field = $params['sort_f']; $direct = $params['sort_d']; $field = $field_arr[$field]; $direct = $direct_arr[$direct]; } if (!empty($_GET['kw'])) { $query_filter = array('query' => htmlspecialchars($_GET['kw']), 'city' => $cityid); $query_filter = array_filter($query_filter); $ret = SearchApi::getMsVehicles($query_filter, $page_num, $page_size, SearchApi::ONSALE); } else { $query_filter = self::_buildQueryCondition($params); $query_filter['city'] = $cityid; $query_filter['type'] = array(1, 1); $query_filter = array_filter($query_filter); $query = array('query' => $query_filter, 'page_num' => $page_num, 'page_size' => $page_size, 'order' => $field, 'desc' => $direct, 'offsite' => 0); $ret = SearchApi::SearchMs($query); } if ($ret['errno'] == 0 && !empty($ret['data']['vehicles'])) { foreach ($ret['data']['vehicles'] as &$vehicle) { $vehicle['json'] = base64_decode($vehicle['json']); $vehicle_info = json_decode($vehicle['json'], true); $vehicle = array_merge($vehicle_info, $vehicle); unset($vehicle['json']); unset($vehicle['name']); } unset($vehicle); } return $ret; }
public function executeFindConnections() { $request = $this->getRequest(); if ($id2 = $request->getParameter('id2')) { if (!($this->entity2 = EntityApi::get($id2))) { $this->forward404(); } $page = $this->page; $num = $request->getParameter('num', 10); $options = array('cat_ids' => $request->getParameter('cat_ids', '1')); //get all chains $chains = SearchApi::getEntitiesChains($this->entity['id'], $id2, $options); $offset = ($page - 1) * $num; $flat_chains = array(); foreach ($chains as $degree => $ary) { foreach ($ary as $ids) { $flat_chains[] = $ids; } } $page_chains = array_slice($flat_chains, $offset, $num); $full_chains = array(); foreach ($page_chains as $ids) { $full = array(); $chain = SearchApi::buildRelationshipChain($ids, explode(',', $options['cat_ids'])); foreach ($chain as $id => $rels) { $entity = EntityApi::get($id); $entity['Relationships'] = count($rels) ? BatchApi::getRelationships($rels, array()) : array(); $full[] = $entity; } $full_chains[] = $full; } // foreach ($page_chains as $degree => $ary) // { // foreach ($ary as $ids) // { // if ($count == $page) // { // $chain = SearchApi::buildRelationshipChain($ids, explode(',', $options['cat_ids'])); // break 2; // } // $count++; // } // } // count total number of chains // $total = 0; // foreach ($chains as $degree => $ary) // { // $total += count($ary); // } if ($total = count($flat_chains)) { $chainAry = array_fill(0, $total, null); array_splice($chainAry, $offset, $num, $full_chains); $this->chain_pager = new LsDoctrinePager($chainAry, $page, $num); } // get entities for chain // if ($chain) // { // $this->entities = array(); // foreach ($chain as $id => $rels) // { // $entity = EntityApi::get($id); // $entity['Relationships'] = count($rels) ? BatchApi::getRelationships($rels, array()) : array(); // $this->entities[] = $entity; // } // $chainAry = array_fill(0, $total, null); // $chainAry[$page-1] = $this->entities; // $this->chain_pager = new LsDoctrinePager($chainAry, $page, $num); // } } else { //form submission, display matching persons if ($request->hasParameter('q')) { $num = $request->getParameter('num', 10); $page = $request->getParameter('page', 1); if (!($terms = $request->getParameter('q'))) { $this->entity_pager = new LsDoctrinePager(array(), $page, $num); } else { switch (sfConfig::get('app_search_engine')) { case 'sphinx': $this->entity_pager = EntityTable::getSphinxPager($terms, $page, $num); break; case 'lucene': $ary = EntityTable::getLuceneArray($terms, null); $this->entity_pager = new LsDoctrinePager($ary, $page, $num); break; case 'mysql': default: $terms = explode(' ', $terms); $q = EntityTable::getSimpleSearchQuery($terms); $this->entity_pager = new Doctrine_Pager($q, $page, $num); break; } } } } }
protected function _getVehicleList($page_num, $page_size) { $params = $this->_filter_array; if (!empty($_GET['kw'])) { $query = $_GET['kw']; return SearchApi::query($params, $query, $page_num, $page_size); } else { return SearchApi::search($params, $page_num, $page_size); } }
<?php require_once "Swagger.php"; require_once "UserApi.php"; require_once "models/User.php"; $apiServer = "http://localhost:8080"; $apiKey = ""; $apiClient = new APIClient("http://localhost:8080", ""); $userApi = new UserApi($apiClient); $user = $userApi->getUser(1); var_dump($user); $searchApi = new SearchApi($apiClient); $users = $searchApi->searchUsers("T"); var_dump($users);
public function executeEntitiesChains($request) { $options = $this->getParams(array('cat_ids', 'page')); $id1 = $request->getParameter('id1'); $id2 = $request->getParameter('id2'); if (!isset($options['cat_ids'])) { $options['cat_ids'] = '1'; } $this->chains = SearchApi::getEntitiesChains($id1, $id2, $options); $this->chain = null; $page = isset($options['page']) ? $options['page'] : 1; $count = 1; foreach ($this->chains as $degree => $ary) { foreach ($ary as $ids) { if ($count == $page) { $this->chain = SearchApi::buildRelationshipChain($ids, $options['cat_ids']); break 2; } $count++; } } if ($this->chain) { $this->entities = array(); foreach ($this->chain as $id => $rels) { $this->entities[$id] = EntityApi::get($id); $this->entities[$id]['relationship_ids'] = implode(',', $rels); } } return 'Xml'; }