protected function doSearch(PostArrayAdapter $params) { /* * Параметры */ $process = $params->int('process'); $action = $params->int('action'); $actionParent = $params->int('parent_action'); $dateFrom = $params->int('date_from'); $dateTo = $params->int('date_to'); /* * Запрос */ $what[] = 'id_rec'; $what[] = 'concat(ifnull(id_user, ""), concat("/", id_user_authed)) as user_authed'; $what[] = 'dt_event'; $what[] = 'n_action'; $what[] = 'v_data'; $what[] = 'b_encoded'; $where['id_process'] = $process; if ($actionParent) { $where['id_rec_parent'] = $actionParent; } if ($action) { $where['n_action'] = $action; } if ($dateFrom) { $where[] = Query::assocParam('dt_event', $dateFrom, true, '>='); } if ($dateTo) { $where[] = Query::assocParam('dt_event', $dateTo, true, '<='); } $order = 'dt_event asc, id_rec asc'; $limit = 500; /* * Работа с данными */ $query = Query::select($what, 'ps_audit', $where, null, $order, $limit); $result = PSDB::getArray($query); foreach ($result as &$row) { //Декодируем действие $row['n_action'] = BaseAudit::getByCode($process)->decodeAction($row['n_action'], false); //Декодируем данные $encoded = 1 * $row['b_encoded']; if ($encoded) { $row['v_data'] = print_r(BaseAudit::decodeData($row['v_data']), true); } unset($row['b_encoded']); } $results = new SearchResults($result, $query); $results->addSetting('v_data', SearchResults::COL_PRE); $results->addSetting('n_action', SearchResults::COL_NOWRAP); return $results; }
public function find($strQuery, $blnExact = false) { global $_CONF; //*** Set query property. $objReturn = new SearchResults(); $objReturn->setQuery($strQuery); $strQuery = str_replace("*", "%", $strQuery); //*** Convert query to stem. $arrWords = array_values($this->stemPhrase($strQuery)); $intWordCount = count($arrWords); //*** Query does not validate. if (!$arrWords) { return $objReturn; } //*** Set query property. $objReturn->setQuery($strQuery); $strSql = sprintf("SELECT DISTINCT pcms_search_index.elementId, COUNT(pcms_search_index.id) as word,\n\t\t\t\t\tSUM(pcms_search_index.count) as count FROM pcms_search_index, pcms_element WHERE\n\t\t\t\t\tpcms_search_index.elementId = pcms_element.id AND\n\t\t\t\t\tpcms_element.accountId = '%s' AND ", quote_smart($_CONF['app']['account']->getId())); $strSql .= '(' . implode(' OR ', array_fill(0, $intWordCount, '?')) . ') GROUP BY pcms_search_index.elementId'; //*** AND query? if ($blnExact) { $strSql .= ' HAVING word = ' . $intWordCount; } $strSql .= ' ORDER BY word DESC, count DESC'; //*** Inject the search words into the query. $arrSql = explode('?', $strSql); $strTempSql = ""; for ($i = 0; $i < $intWordCount; $i++) { $equal = stripos($arrWords[$i], "%") !== false ? "LIKE" : "="; $strTempSql .= $arrSql[$i] . "word {$equal} '" . $arrWords[$i] . "'"; } $strTempSql .= $arrSql[$i]; //*** Query the database. $objSearchIndexes = SearchIndex::select($strTempSql); foreach ($objSearchIndexes as $objSearchIndex) { $objElement = Element::selectByPk($objSearchIndex->getElementId()); if (!isset($intMaxWeight)) { $intMaxWeight = $objSearchIndex->getCount(); } if (!isset($intMaxCount)) { $intMaxCount = $objSearchIndex->getWord(); } $intRatio = round(100 / ($intMaxWeight * $intMaxCount) * $objSearchIndex->getCount() * $objSearchIndex->getWord()); $objSearchResult = new SearchResult(); $objSearchResult->id = $objSearchIndex->getElementId(); $objSearchResult->name = $objElement->getName(); $objSearchResult->value = $objElement->getDescription(); $objSearchResult->ratio = $intRatio; $objReturn->addObject($objSearchResult); } return $objReturn; }
/** * [nearestNeighbour description] * @param Node $node [description] * @param Point $originPoint [description] * @param SearchResults $results [description] * @param integer $depth [description] * @return [type] [description] */ public static function nearestNeighbour(Node $node, Point $originPoint, SearchResults $results, $depth = 0) { $numDimensions = $originPoint->getNumDimensions(); $axis = $depth % $numDimensions; $originToNodeDistance = self::euclidianDistance($originPoint, $node->getPoint()); $results->insertResult($node, $originToNodeDistance); $originNodeSplittingCoordinate = $originPoint[$axis]; $currentNodeSplittingCoordinate = $node->getPoint()[$axis]; $searchDirection = $originNodeSplittingCoordinate < $currentNodeSplittingCoordinate ? 'left' : 'right'; switch ($searchDirection) { case 'left': $targetNode = $node->getLeftChild(); $oppositeNode = $node->getRightChild(); break; case 'right': $targetNode = $node->getRightChild(); $oppositeNode = $node->getLeftChild(); break; } if ($targetNode) { self::nearestNeighbour($targetNode, $originPoint, $results, $depth + 1); } if ($oppositeNode) { $tempSearchPoint = new Point(); for ($i = 0; $i < $numDimensions; $i++) { if ($i == $axis) { $tempSearchPoint[$i] = $node->getPoint()[$i]; } else { if ($originPoint[$i] <= $oppositeNode->getHyperRectangle()[$i]['min']) { $tempSearchPoint[$i] = $oppositeNode->getHyperRectangle()[$i]['min']; } elseif ($originPoint[$i] < $oppositeNode->getHyperRectangle()[$i]['max']) { $tempSearchPoint[$i] = $originPoint[$i]; } else { $tempSearchPoint[$i] = $oppositeNode->getHyperRectangle()[$i]['max']; } } } $tempDistance = self::euclidianDistance($tempSearchPoint, $originPoint); if ($tempDistance <= $results->getLastResultDistance()) { self::nearestNeighbour($oppositeNode, $originPoint, $results, $depth + 1); } } }
public function getMemberAdvertisements($memberID, $currentPage, $pagingAmount, $dbConnection) { $advertisementSearchResults = null; $advertisementSkeletons = null; try { //Construct Search Parameter object $advertisementSearchParameters = new SearchParameters(); $advertisementSearchParameters->setVariable(SearchConstants::CURRENT_PAGE_ID, $currentPage); $advertisementSearchParameters->setVariable(SearchConstants::PAGING_AMOUNT_ID, $pagingAmount); $advertisementSearchParameters->setVariable(AdvertisementSearchConstants::MEMBER_INPUT_ID, $memberID); $advertisementCount = AdvertisementSearchDao::getSearchAdvertisementsCount($advertisementSearchParameters, $dbConnection); $advertisementSkeletons = AdvertisementSearchDao::searchAdvertisements($advertisementSearchParameters, $dbConnection); $advertisementSearchResults = new SearchResults(); $advertisementSearchResults->setVariable(SearchResults::SEARCH_PARAMETERS, $advertisementSearchParameters); $advertisementSearchResults->setVariable(SearchResults::SKELETONS, $advertisementSkeletons); $advertisementSearchResults->setVariable(SearchResults::COUNT, $advertisementCount); $advertisementSearchResults->setVariable(SearchResults::PAGE_COUNT, ceil($advertisementCount / $pagingAmount)); } catch (Exception $ex) { $advertisementSearchResults = null; echo 'Caught exception: ' . $ex->getMessage(); } return $advertisementSearchResults; }
public function loader($workflow = false) { if (!current_user_can('shopp_products')) { return; } add_screen_option('per_page', array('label' => __('Products Per Page', 'Shopp'), 'default' => 20, 'option' => 'edit_' . ShoppProduct::$posttype . '_per_page')); $per_page_option = get_current_screen()->get_option('per_page'); $defaults = array('cat' => false, 'paged' => 1, 'per_page' => $per_page_option['default'], 's' => '', 'sl' => '', 'matchcol' => '', 'view' => $this->view, 'is_inventory' => false, 'is_trash' => false, 'is_bestselling' => false, 'categories_menu' => false, 'inventory_menu' => false, 'lowstock' => 0, 'columns' => '', 'orderby' => '', 'order' => '', 'where' => array(), 'joins' => array()); $args = array_merge($defaults, $_GET); if (false !== ($user_per_page = get_user_option($per_page_option['option']))) { $args['per_page'] = $user_per_page; } extract($args, EXTR_SKIP); $url = ShoppAdminController::url($_GET); $subs = array('all' => array('label' => Shopp::__('All'), 'where' => array("p.post_status!='trash'")), 'published' => array('label' => Shopp::__('Published'), 'where' => array("p.post_status='publish'")), 'drafts' => array('label' => Shopp::__('Drafts'), 'where' => array("p.post_status='draft'")), 'onsale' => array('label' => Shopp::__('On Sale'), 'where' => array("s.sale='on' AND p.post_status != 'trash'")), 'featured' => array('label' => Shopp::__('Featured'), 'where' => array("s.featured='on' AND p.post_status != 'trash'")), 'bestselling' => array('label' => Shopp::__('Bestselling'), 'where' => array("p.post_status!='trash'", BestsellerProducts::threshold() . " < s.sold"), 'order' => 'bestselling'), 'inventory' => array('label' => Shopp::__('Inventory'), 'where' => array("s.inventory='on' AND p.post_status != 'trash'")), 'trash' => array('label' => Shopp::__('Trash'), 'where' => array("p.post_status='trash'"))); if (!shopp_setting_enabled('inventory')) { unset($subs['inventory']); } switch ($view) { case 'inventory': if (shopp_setting_enabled('inventory')) { $is_inventory = true; } else { Shopp::redirect(add_query_arg('view', null, $url), true); } break; case 'trash': $is_trash = true; break; case 'bestselling': $is_bestselling = true; break; } if ($is_inventory) { $per_page = 50; } $pagenum = absint($paged); $start = $per_page * ($pagenum - 1); $where = $subs[$this->view]['where']; if (!empty($s)) { $SearchResults = new SearchResults(array('search' => $s, 'nostock' => 'on', 'published' => 'off', 'paged' => -1)); $SearchResults->load(); $ids = array_keys($SearchResults->products); $where[] = "p.ID IN (" . join(',', $ids) . ")"; } if (!empty($cat)) { global $wpdb; $joins[$wpdb->term_relationships] = "INNER JOIN {$wpdb->term_relationships} AS tr ON (p.ID=tr.object_id)"; $joins[$wpdb->term_taxonomy] = "INNER JOIN {$wpdb->term_taxonomy} AS tt ON (tr.term_taxonomy_id=tt.term_taxonomy_id AND tt.term_id={$cat})"; if (-1 == $cat) { unset($joins[$wpdb->term_taxonomy]); $joins[$wpdb->term_relationships] = "LEFT JOIN {$wpdb->term_relationships} AS tr ON (p.ID=tr.object_id)"; $where[] = 'tr.object_id IS NULL'; } } // Detect custom taxonomies $taxonomies = array_intersect(get_object_taxonomies(ShoppProduct::$posttype), array_keys($_GET)); if (!empty($taxonomies)) { foreach ($taxonomies as $n => $taxonomy) { global $wpdb; $term = get_term_by('slug', $_GET[$taxonomy], $taxonomy); if (!empty($term->term_id)) { $joins[$wpdb->term_relationships . '_' . $n] = "INNER JOIN {$wpdb->term_relationships} AS tr{$n} ON (p.ID=tr{$n}.object_id)"; $joins[$wpdb->term_taxonomy . '_' . $n] = "INNER JOIN {$wpdb->term_taxonomy} AS tt{$n} ON (tr{$n}.term_taxonomy_id=tt{$n}.term_taxonomy_id AND tt{$n}.term_id={$term->term_id})"; } } } if (!empty($sl) && shopp_setting_enabled('inventory')) { switch ($sl) { case "ns": foreach ($where as &$w) { $w = str_replace("s.inventory='on'", "s.inventory='off'", $w); } $where[] = "s.inventory='off'"; break; case "oos": $where[] = "(s.inventory='on' AND s.stock = 0)"; break; case "ls": $ls = shopp_setting('lowstock_level'); if (empty($ls)) { $ls = '0'; } $where[] = "(s.inventory='on' AND s.lowstock != 'none')"; break; case "is": $where[] = "(s.inventory='on' AND s.stock > 0)"; } } $lowstock = shopp_setting('lowstock_level'); // Setup queries $pd = WPDatabaseObject::tablename(ShoppProduct::$table); $pt = ShoppDatabaseObject::tablename(ShoppPrice::$table); $ps = ShoppDatabaseObject::tablename(ProductSummary::$table); $orderdirs = array('asc', 'desc'); if (in_array($order, $orderdirs)) { $orderd = strtolower($order); } else { $orderd = 'asc'; } if (isset($subs[$this->view]['order'])) { $order = $subs[$this->view]['order']; } $ordercols = ''; switch ($orderby) { case 'name': $order = 'title'; if ('desc' == $orderd) { $order = 'reverse'; } break; case 'price': $order = 'lowprice'; if ('desc' == $orderd) { $order = 'highprice'; } break; case 'date': $order = 'newest'; if ('desc' == $orderd) { $order = 'oldest'; } break; case 'sold': $ordercols = 's.sold ' . $orderd; break; case 'gross': $ordercols = 's.grossed ' . $orderd; break; case 'inventory': $ordercols = 's.stock ' . $orderd; break; case 'sku': $ordercols = 'pt.sku ' . $orderd; break; } if (in_array($this->view, array('onsale', 'featured', 'inventory'))) { $joins[$ps] = "INNER JOIN {$ps} AS s ON p.ID=s.product"; } $loading = array('where' => $where, 'joins' => $joins, 'limit' => "{$start},{$per_page}", 'load' => array('categories', 'coverimages'), 'published' => false, 'order' => $order, 'nostock' => true); if (!empty($ordercols)) { unset($loading['order']); $loading['orderby'] = $ordercols; } if ($is_inventory) { // Override for inventory products $where[] = "(pt.context='product' OR pt.context='variation') AND pt.type != 'N/A'"; $loading = array('columns' => "pt.id AS stockid,IF(pt.context='variation',CONCAT(p.post_title,': ',pt.label),p.post_title) AS post_title,pt.sku AS sku,pt.stock AS stock", 'joins' => array_merge(array($pt => "LEFT JOIN {$pt} AS pt ON p.ID=pt.product"), $joins), 'where' => $where, 'groupby' => 'pt.id', 'orderby' => str_replace('s.', 'pt.', $ordercols), 'limit' => "{$start},{$per_page}", 'nostock' => true, 'published' => false); } // Override loading product meta and limiting by pagination in the workflow list if ($workflow) { unset($loading['limit']); $loading['ids'] = true; $loading['pagination'] = false; $loading['load'] = array(); } $this->products = new ProductCollection(); $this->products->load($loading); // Overpagination protection, redirect to page 1 if the requested page doesn't exist $num_pages = ceil($this->products->total / $per_page); if ($paged > 1 && $paged > $num_pages) { Shopp::redirect(add_query_arg('paged', null, $url)); } // Return a list of product keys for workflow list requests if ($workflow) { return $this->products->worklist(); } // Get sub-screen counts $subcounts = Shopp::cache_get('shopp_product_subcounts', 'shopp_admin'); if ($subcounts) { foreach ($subcounts as $name => $total) { if (isset($subs[$name])) { $subs[$name]['total'] = $total; } } } else { $subcounts = array(); foreach ($subs as $name => &$subquery) { $subquery['total'] = 0; $query = array('columns' => "count(*) AS total", 'table' => "{$pd} as p", 'joins' => array(), 'where' => array()); $query = array_merge($query, $subquery); $query['where'][] = "p.post_type='shopp_product'"; if (in_array($name, array('onsale', 'bestselling', 'featured', 'inventory'))) { $query['joins'][$ps] = "INNER JOIN {$ps} AS s ON p.ID=s.product"; } $query = sDB::select($query); $subquery['total'] = sDB::query($query, 'auto', 'col', 'total'); $subcounts[$name] = $subquery['total']; } Shopp::cache_set('shopp_product_subcounts', $subcounts, 'shopp_admin'); } $this->subs = $subs; }
/** * Interface processor for the product list manager * * @return void **/ function products ($workflow=false) { global $Ecart,$Products; $db = DB::get(); $Settings = &EcartSettings(); if ( !(is_ecart_userlevel() || current_user_can('ecart_products')) ) wp_die(__('You do not have sufficient permissions to access this page.')); $defaults = array( 'cat' => false, 'pagenum' => 1, 'per_page' => 20, 's' => '', 'sl' => '', 'matchcol' => '', 'f' => '' ); $args = array_merge($defaults,$_GET); extract($args,EXTR_SKIP); if (!$workflow) { if (empty($categories)) $categories = array(''); $category_table = DatabaseObject::tablename(Category::$table); $query = "SELECT id,name,parent FROM $category_table ORDER BY parent,name"; $categories = $db->query($query,AS_ARRAY); $categories = sort_tree($categories); if (empty($categories)) $categories = array(); $categories_menu = '<option value="">'.__('View all categories','Ecart').'</option>'; $categories_menu .= '<option value="-"'.($cat=='-'?' selected="selected"':'').'>'.__('Uncategorized','Ecart').'</option>'; foreach ($categories as $category) { $padding = str_repeat(" ",$category->depth*3); if ($cat == $category->id) $categories_menu .= '<option value="'.$category->id.'" selected="selected">'.$padding.esc_html($category->name).'</option>'; else $categories_menu .= '<option value="'.$category->id.'">'.$padding.esc_html($category->name).'</option>'; } $inventory_filters = array( 'all' => __('View all products','Ecart'), 'is' => __('In stock','Ecart'), 'ls' => __('Low stock','Ecart'), 'oos' => __('Out-of-stock','Ecart'), 'ns' => __('Not stocked','Ecart') ); $inventory_menu = menuoptions($inventory_filters,$sl,true); } $subfilters = array('f' => 'featured','p' => 'published','s' => 'onsale','i' => 'inventory'); $subs = array( 'all' => array('label' => __('All','Ecart'),'columns' => "count(distinct pd.id) AS total",'where'=>'true'), 'published' => array('label' => __('Published','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.status='publish'",'request' => 'p'), 'onsale' => array('label' => __('On Sale','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pt.sale='on'",'request' => 's'), 'featured' => array('label' => __('Featured','Ecart'),'total' => 0,'columns' => "count(distinct pd.id) AS total",'where'=>"pd.featured='on'",'request' => 'f'), 'inventory' => array('label' => __('Inventory','Ecart'),'total' => 0,'columns' => "count(distinct pt.id) AS total",'where'=>"pt.inventory='on' AND pt.type!='N/A'",'grouping'=>'pt.id','request' => 'i') ); if ('i' == $f) $per_page = 50; $pagenum = absint( $pagenum ); if ( empty($pagenum) ) $pagenum = 1; if( !$per_page || $per_page < 0 ) $per_page = 20; $start = ($per_page * ($pagenum-1)); $pd = DatabaseObject::tablename(Product::$table); $pt = DatabaseObject::tablename(Price::$table); $catt = DatabaseObject::tablename(Category::$table); $clog = DatabaseObject::tablename(Catalog::$table); $orderby = "pd.created DESC"; $where = "true"; $having = ""; if (!empty($s)) { $products = new SearchResults(array("search"=>$s)); $products->load_products(array("load"=>array())); $ids = array_keys($products->products); $where .= " AND pd.id IN (".join(',',$ids).")"; } // if (!empty($cat)) $where .= " AND cat.id='$cat' AND (clog.category != 0 OR clog.id IS NULL)"; if (!empty($cat)) { if ($cat == "-") { $having = "HAVING COUNT(cat.id) = 0"; } else { $matchcol .= ", GROUP_CONCAT(DISTINCT cat.id ORDER BY cat.id SEPARATOR ',') AS catids"; $where .= " AND cat.id IN (SELECT parent FROM $clog WHERE parent=$cat AND type='category')"; } } if (!empty($sl)) { switch($sl) { case "ns": $where .= " AND pt.inventory='off'"; break; case "oos": $where .= " AND (pt.inventory='on')"; $having .= (empty($having)?"HAVING ":" AND ")."SUM(pt.stock) = 0"; break; case "ls": $ls = $Settings->get('lowstock_level'); if (empty($ls)) $ls = '0'; $where .= " AND (pt.inventory='on' AND pt.stock <= $ls AND pt.stock > 0)"; break; case "is": $where .= " AND (pt.inventory='on' AND pt.stock > 0)"; } } if (!empty($f)) $where .= " AND ".$subs[$subfilters[$f]]['where']; $base = $Settings->get('base_operations'); if ($base['vat']) $taxrate = ecart_taxrate(); if (empty($taxrate)) $taxrate = 0; if ('i' == $f) { $columns = "SQL_CALC_FOUND_ROWS pt.id,pd.id as product,pd.name,pd.slug,pt.label,pt.optionkey,pt.stock,pt.sku"; // Load the products $query = "SELECT $columns $matchcol FROM $pt AS pt LEFT JOIN $pd AS pd ON pd.id=pt.product LEFT JOIN $clog AS clog ON pd.id=clog.product LEFT JOIN $catt AS cat ON cat.id=clog.parent AND clog.type='category' WHERE $where GROUP BY pt.id $having ORDER BY pd.id,pt.sortorder LIMIT $start,$per_page"; $Products = $db->query($query,AS_ARRAY); $productcount = $db->query("SELECT FOUND_ROWS() as total"); } else { $columns = "SQL_CALC_FOUND_ROWS pd.id,pd.name,pd.slug,pd.featured,pd.variations,GROUP_CONCAT(DISTINCT cat.name ORDER BY cat.name SEPARATOR ', ') AS categories, IF(pt.options=0,IF(pt.tax='off',pt.price,pt.price+(pt.price*$taxrate)),-1) AS mainprice, IF(MAX(pt.tax)='off',MAX(pt.price),MAX(pt.price+(pt.price*$taxrate))) AS maxprice, IF(MAX(pt.tax)='off',MIN(pt.price),MIN(pt.price+(pt.price*$taxrate))) AS minprice, IF(pt.inventory='on','on','off') AS inventory, ROUND(SUM(pt.stock)/IF(clog.id IS NULL,1,count(DISTINCT clog.id)),0) AS stock"; if ($workflow) $columns = "pd.id"; // Load the products $query = "SELECT $columns $matchcol FROM $pd AS pd LEFT JOIN $pt AS pt ON pd.id=pt.product AND pt.type != 'N/A' AND pt.context != 'addon' LEFT JOIN $clog AS clog ON pd.id=clog.product LEFT JOIN $catt AS cat ON cat.id=clog.parent AND clog.type='category' WHERE $where GROUP BY pd.id $having ORDER BY $orderby LIMIT $start,$per_page"; $Products = $db->query($query,AS_ARRAY); $productcount = $db->query("SELECT FOUND_ROWS() as total"); } foreach ($subs as $name => &$subquery) { if ($name == "all") { $subquery['total'] = (int)$productcount->total; continue; } $columns = $subquery['columns']; if (!empty($f)) $where = str_replace(" AND ".$subs[$subfilters[$f]]['where'],"",$where); $w = ($where == "true")?$subquery['where']:"$where AND ({$subquery['where']})"; $category_join = (strpos($w,"type='category'") !== false)?"LEFT JOIN $clog AS clog ON pd.id=clog.product LEFT JOIN $catt AS cat ON cat.id=clog.parent AND clog.type='category'":""; $grouping = "GROUP BY ".(isset($subquery['grouping'])?$subquery['grouping']:"pd.id"); $query = "SELECT $columns $matchcol FROM $pd AS pd LEFT JOIN $pt AS pt ON pd.id=pt.product AND pt.type != 'N/A' $category_join WHERE $w $grouping $having"; $db->query($query); $found = $db->query("SELECT FOUND_ROWS() as total"); if (isset($found->total)) $subquery['total'] = number_format((int)$found->total); } $num_pages = ceil($productcount->total / $per_page); $page_links = paginate_links( array( 'base' => add_query_arg(array("edit"=>null,'pagenum' => '%#%')), 'format' => '', 'total' => $num_pages, 'current' => $pagenum, )); if ('i' == $f) { include(ECART_ADMIN_PATH."/products/inventory.php"); return; } if ($workflow) return $Products; include(ECART_ADMIN_PATH."/products/products.php"); }
public function select_product() { $SearchResults = new SearchResults(array('load' => array('prices'), 'search' => $_GET['s'], 'nostock' => 'on', 'published' => 'off', 'paged' => -1, 'limit' => 10)); $SearchResults->load(); $results = array(); foreach ($SearchResults->products as $Product) { foreach ($Product->prices as $Variant) { if ('N/A' == $Variant->type) { continue; } // Skip disabled prices $results[] = array('id' => "{$Product->id}-{$Variant->id}", 'name' => $Product->name, 'variant' => Shopp::__('Price & Delivery') != $Variant->label ? $Variant->label : '', 'unitprice' => $Variant->promoprice); } } header('Content-Type: application/json; charset=utf-8'); echo json_encode($results); exit; }
public function searchForBandMembersAdvanced($bandID, $firstName, $lastName, $gender, $ageRange, $country, $state, $city, $region, $searchType, $currentPage, $pagingAmount, $dbConnection = null) { $memberSearchResults = null; $memberSkeletons = null; $countryID = null; $stateID = null; $cityID = null; $regionID = null; try { $memberSearchParameters = new SearchParameters(); $memberSearchParameters->setVariable(SearchConstants::SEARCH_TYPE_INPUT_ID, $searchType); $memberSearchParameters->setVariable(SearchConstants::CURRENT_PAGE_ID, $currentPage); $memberSearchParameters->setVariable(SearchConstants::PAGING_AMOUNT_ID, $pagingAmount); $memberSearchParameters->setVariable(MemberSearchConstants::BAND_INPUT_ID, $bandID); //These elements are common to both search types $countryID = SearchUtilities::processSelectValues($country, 'defaultValue', '0'); if ($countryID != null) { $stateID = SearchUtilities::processSelectValues($state, 'defaultValue', '0'); } if ($stateID != null) { $cityID = SearchUtilities::processSelectValues($city, 'defaultValue', '0'); } if ($cityID != null) { $regionID = SearchUtilities::processSelectValues($region, 'defaultValue', '0'); } $memberSearchParameters->setVariable(LocationConstants::LOCATION_COUNTRY_INPUT_ID, $countryID); $memberSearchParameters->setVariable(LocationConstants::LOCATION_STATE_INPUT_ID, $stateID); $memberSearchParameters->setVariable(LocationConstants::LOCATION_CITY_INPUT_ID, $cityID); $memberSearchParameters->setVariable(LocationConstants::LOCATION_REGION_INPUT_ID, $regionID); $memberSearchParameters->setVariable(MemberSearchConstants::FIRST_NAME_INPUT_ID, $firstName); $memberSearchParameters->setVariable(MemberSearchConstants::LAST_NAME_INPUT_ID, $lastName); $memberSearchParameters->setVariable(MemberSearchConstants::GENDER_INPUT_ID, $gender); $memberSearchParameters->setVariable(MemberSearchConstants::AGE_INPUT_ID, $lastName); $memberCount = MemberSearchDao::getMemberSearchCount($memberSearchParameters, $dbConnection); $memberSkeletons = MemberSearchDao::searchMembers($memberSearchParameters, $ageRange); $memberSearchResults = new SearchResults(); $memberSearchResults->setVariable(SearchResults::SEARCH_PARAMETERS, $memberSearchParameters); $memberSearchResults->setVariable(SearchResults::SKELETONS, $memberSkeletons); $memberSearchResults->setVariable(SearchResults::COUNT, $memberCount); $memberSearchResults->setVariable(SearchResults::PAGE_COUNT, ceil($memberCount / $pagingAmount)); } catch (Exception $e) { $memberSearchResults = null; echo 'Caught exception: ', $e->getMessage(), "\n"; } return $memberSearchResults; }
public function browseAdvertisementByLocation($country, $state, $city, $region, $searchType, $currentPage, $pagingAmount, $dbConnection = null) { $advertisementSearchResults = null; $advertisementSkeletons = null; $countryID = null; $stateID = null; $cityID = null; $regionID = null; try { //Construct Search Parameter object $advertisementSearchParameters = new SearchParameters(); $advertisementSearchParameters->setVariable(SearchConstants::CURRENT_PAGE_ID, $currentPage); $advertisementSearchParameters->setVariable(SearchConstants::PAGING_AMOUNT_ID, $pagingAmount); //These elements are common to both search types $countryID = SearchUtilities::processSelectValues($country, 'defaultValue', '0'); if ($countryID != null) { $stateID = SearchUtilities::processSelectValues($state, 'defaultValue', '0'); } if ($stateID != null) { $cityID = SearchUtilities::processSelectValues($city, 'defaultValue', '0'); } if ($cityID != null) { $regionID = SearchUtilities::processSelectValues($region, 'defaultValue', '0'); } $advertisementSearchParameters->setVariable(LocationConstants::LOCATION_COUNTRY_INPUT_ID, $countryID); $advertisementSearchParameters->setVariable(LocationConstants::LOCATION_STATE_INPUT_ID, $stateID); $advertisementSearchParameters->setVariable(LocationConstants::LOCATION_CITY_INPUT_ID, $cityID); $advertisementSearchParameters->setVariable(LocationConstants::LOCATION_REGION_INPUT_ID, $regionID); $advertisementCount = AdvertisementSearchDao::getSearchAdvertisementsCount($advertisementSearchParameters, $dbConnection); $advertisementSkeletons = AdvertisementSearchDao::searchAdvertisements($advertisementSearchParameters, $dbConnection); $advertisementSearchResults = new SearchResults(); $advertisementSearchResults->setVariable(SearchResults::SEARCH_PARAMETERS, $advertisementSearchParameters); $advertisementSearchResults->setVariable(SearchResults::SKELETONS, $advertisementSkeletons); $advertisementSearchResults->setVariable(SearchResults::COUNT, $advertisementCount); $advertisementSearchResults->setVariable(SearchResults::PAGE_COUNT, ceil($advertisementCount / $pagingAmount)); } catch (Exception $e) { $advertisementSearchResults = null; echo 'Caught exception: ', $e->getMessage(), "\n"; } return $advertisementSearchResults; }
public function find($strQuery, $arrFilters = array(), $blnExact = FALSE, $arrAllowedTypes = array()) { /* Search for elements containing keywords * * Filters may look like this: * array("element.Shops", "template.HomePage > element.Misc > templates.Banner", "element:1399") * * Allowed types may look like this: * array("element.Shops", "template.HomePage", "element:1399") * */ $objReturn = new SearchResults(); if (!empty($strQuery)) { $objSearch = new Search(); $objReturn = $objSearch->find($strQuery, $blnExact); //*** Filters. if (count($arrFilters) > 0) { //*** Parse filters. $arrElementIds = array(); foreach ($arrFilters as $strFilter) { $arrRecursive = explode(">", $strFilter); $objElement = $this; foreach ($arrRecursive as $strRecursive) { $arrFilter = explode(".", trim($strRecursive)); if (!empty($arrFilter[1])) { switch ($arrFilter[0]) { case "element": if (is_numeric($arrFilter[1])) { $objElement = $this->getElementById($arrFilter[1]); } else { $objElement = $objElement->get($arrFilter[1]); } break; case "elements": if (is_numeric($arrFilter[1])) { $objElement = $this->getElementById($arrFilter[1])->getElements(); } else { $objElement = $objElement->getElements($arrFilter[1]); } break; case "template": if (is_numeric($arrFilter[1])) { $objElement = $objElement->getElementByTemplateId($arrFilter[1]); } else { $objElement = $objElement->getElementByTemplate($arrFilter[1]); } break; case "templates": if (is_numeric($arrFilter[1])) { $objElement = $objElement->getElementsByTemplateId($arrFilter[1]); } else { $objElement = $objElement->getElementsByTemplate($arrFilter[1]); } break; } } } if (method_exists($objElement, "count")) { $objElements = $objElement; foreach ($objElements as $objElement) { array_push($arrElementIds, $objElement->getElement()->getId()); } } else { array_push($arrElementIds, $objElement->getElement()->getId()); } } //*** Apply filters. $objResults = new SearchResults(); $objResults->setQuery($objReturn->getQuery()); foreach ($objReturn as $objResult) { foreach ($arrElementIds as $intElementId) { $objElement = $this->getElementById($objResult->id); if (is_object($objElement) && $objElement->hasParentId($intElementId)) { if (count($arrAllowedTypes) > 0) { foreach ($arrAllowedTypes as $allowedType) { $arrFilter = explode(".", trim($allowedType)); if (!empty($arrFilter[1])) { switch ($arrFilter[0]) { case "element": if (is_numeric($arrFilter[1])) { if ($objElement->getId() == $arrFilter[1]) { $objResults->addObject($objResult); } } else { if ($objElement->getName() == $arrFilter[1]) { $objResults->addObject($objResult); } } break; case "template": if ($objElement->getTemplateName() == $arrFilter[1]) { $objResults->addObject($objResult); } break; } } } } else { $objResults->addObject($objResult); } } } } $objReturn = $objResults; } } return $objReturn; }
protected function processImpl(PostArrayAdapter $adapter, $button) { return new AjaxSuccess(SearchResults::convert($this->doSearch($adapter))->toAttay()); }
<?php /** * File the search * Call: call/window.search.php */ require '../inc/class.Frontend.php'; $Frontend = new Frontend(); $showResults = !empty($_POST); if (isset($_GET['get']) && $_GET['get'] == 'true') { $_POST = array_merge($_POST, $_GET); $showResults = true; SearchFormular::transformOldParamsToNewParams(); } if (empty($_POST) || Request::param('get') == 'true') { echo '<div class="panel-heading">'; echo '<h1>' . __('Search for activities') . '</h1>'; echo '</div>'; $Formular = new SearchFormular(); $Formular->display(); } $Results = new SearchResults($showResults); $Results->display();