当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getSearchedItems方法代码示例

本文整理汇总了PHP中app\models\Product::getSearchedItems方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getSearchedItems方法的具体用法?PHP Product::getSearchedItems怎么用?PHP Product::getSearchedItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Product的用法示例。


在下文中一共展示了Product::getSearchedItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_getSearchedItems

    public function test_getSearchedItems()
    {
        /** Test 1 : tests method with all good inputs .. to be mocked later #TODO **/
        // Create 2 products as a setup
        $faker = Faker\Factory::create();
        for($i=0; $i< 2; $i++)
        {
            $input = array(
                'user_id'               => 1,
                'university_id'         => 20,
                'title'                 => $faker->sentence, 
                'description'           => $faker->paragraph(4),
                'primary_image_path'    => 'main_image_'.rand(1,4).'.jpeg',
                'delivery'              => 1,
                'pickup'                => 1,
                'free'                  => 1,
                'price'                 => 0
            );
            print_r($input);
            $product =  Product::create($input);
            ProductKeyword::create([
                    'product_id'   => $product->id,
                    'keyword_id'   => 10
                ]); 
            ProductKeyword::create([
                    'product_id'   => $product->id,
                    'keyword_id'   => 20
                ]); 
            ProductCategory::create([
                'product_id'   => $product->id,
                'category_id'  => 25
            ]);       

        }

        $whereIn['keyword_id'] = array(10, 20);
        $where['category_id'] = 25;
        $where['university_id'] = 20;
        $where['delivery'] = 1;
        $where['pickup'] = 1;
        $where['free'] = 1;
        $where['price'] = 0;
        $sort['products.updated_at'] = 'desc';
        
        $results = Product::getSearchedItems($where, $whereIn, $sort);
    } 
开发者ID:shwetasabne,项目名称:StudentBarter,代码行数:46,代码来源:ProductTest.php

示例2: searchItemsAlgoOne


//.........这里部分代码省略.........
  **/
 public function searchItemsAlgoOne(Request $request)
 {
     /**          Algorithm
      * First pass the input search string through a profanity filter - TODO
      * Pass above through regular words filter to remove prepositions - TODO
      * Now that we have a much smaller stripped search string, we keep that array of keywords
      * With other input params that are indexable like delivery, free, status, etc we get an array of products from db
      * Now for the keywords, we use php to filter the returned record 
      *          Testing Strategy
      * loadTesting
      **/
     $where = array();
     $whereIn = array();
     $sort = array();
     $ultimate_array = array();
     try {
         //  Process keywords
         if ($request->has('searchTerm')) {
             //$sanitized_keywords = ProfanityFilter::sanitize($request->input('searchTerms'));
             //$removed_regular_list = RegularWordsRemoval::remove($sanitized_keywords);
             $removed_regular_list = explode(" ", $request->input('searchTerm'));
             $ks = new KeywordsService();
             $keyword_id = array();
             $keyword_id = $ks->getKeywordsByName($removed_regular_list);
             $whereIn['keyword_id'] = $keyword_id;
         }
         // Process categories
         if ($request->has('category_id') && $request->input('category_id') != -1) {
             $where['category_id'] = $request->input('category_id');
         }
         // Process university_id
         $us = new UniversitiesService();
         if ($request->has('university_name')) {
             $university_id = $us->getUniversityIdByName($request->input('university_name'));
             $where['university_id'] = $university_id;
         }
         // Process delivery_only
         if ($request->has('delivery')) {
             $where['delivery'] = 1;
         }
         // Process pickup_only
         if ($request->has('pickup')) {
             $where['pickup'] = 1;
         }
         // Process free_only
         if ($request->has('freeonly')) {
             $where['free'] = 1;
         }
         // Process usage
         if ($request->input('usage') == 'new') {
             $where['new'] = 1;
         } else {
             if ($request->input('usage') == 'used') {
                 $where['used'] = 1;
             }
         }
         // Process sort fields
         $sort_date = 0;
         $sort_price_asc = 0;
         $sort_price_desc = 0;
         $sortfield_value = "";
         $sortfield_value = "";
         if ($request->has('sortfield')) {
             $sortfield_value = $request->input('sortfield');
         }
         switch ($sortfield_value) {
             case "date_desc":
                 $field = "products.updated_at";
                 $order = "desc";
                 $sort_date = 1;
                 break;
             case "price_asc":
                 $field = "products.price";
                 $order = "asc";
                 $sort_price_asc = 1;
                 break;
             case "price_desc":
                 $field = "products.price";
                 $order = "desc";
                 $sort_price_desc = 1;
                 break;
             default:
                 $field = "products.updated_at";
                 $order = "desc";
                 $sort_date = 1;
         }
         $sort = array();
         $sort[$field] = $order;
         // Now call the DB function...
         $results = Product::getSearchedItems($where, $whereIn, $sort);
         $output['status'] = true;
         $output['data'] = $results;
         return $output;
     } catch (Exception $e) {
         $output['status'] = true;
         $output['data'] = $e->getMessage();
         return $output;
     }
 }
开发者ID:shwetasabne,项目名称:StudentBarter,代码行数:101,代码来源:SearchService.php


注:本文中的app\models\Product::getSearchedItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。