Exemple #1
0
 public function onRun()
 {
     $shares_counter = 0;
     $likes_counter = 0;
     // if(isset(post('link'))){
     $link = 'https://graph.facebook.com/';
     $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     //$url = "http://www.agroo.gr/blog/post/azalea-problhmata-kai-antimetwpish"; // azalea-problhmata-kai-antimetwpish
     $link .= $url;
     $json = file_get_contents($link);
     $data = json_decode($json);
     if (isset($data->likes)) {
         $like_counter = $data->likes;
     }
     if (isset($data->shares)) {
         $shares_counter = $data->shares;
     }
     $this->page['likes'] = $likes_counter;
     $this->page['shares'] = $shares_counter;
     // $url = "$_SERVER[REQUEST_URI]";
     // $slug = end((explode('/', rtrim($url, '/'))));
     $slug = $this->property('slug');
     /*}
             else{
     
                 return 'Broken Link';
                 $this->page['shares'] = 0;
             }*/
     $tempdb = DB::table('tiipiik_catalog_products')->where('slug', $slug)->first();
     $prid = $tempdb->id;
     $this->page['productid'] = $prid;
     $this->page['products'] = Product::orderByRaw("RAND()")->get();
     $query = DB::table('fotis_reviews_prod_rates')->where('product_id', '=', $prid)->get();
     if (!$query) {
         $rating = new ProdRate();
         $rating->product_id = $prid;
         $rating->total_reviews = 0;
         $rating->total_ratings = 0;
         $rating->index_rating = 0;
         $rating->total_views = 0;
         $rating->wishlist = 0;
         // new
         $rating->buy = 0;
         // new
         $rating->save();
     } else {
     }
     DB::table('fotis_reviews_prod_rates')->where('product_id', $prid)->increment('total_views');
     $query = DB::table('fotis_reviews_prod_rates')->where('product_id', '=', $prid)->get();
     $rating = $query[0]->total_ratings;
     $reviews = $query[0]->total_reviews;
     $views = $query[0]->total_views;
     $wishlist = $query[0]->wishlist;
     $buy = $query[0]->buy;
     $this->page['totalviews'] = $views;
     $this->page['wishlist'] = $wishlist;
     $this->page['buy'] = $buy;
     if ($reviews != 0 and $rating != 0) {
         $this->page['NewRating'] = $rating / $reviews;
         $index_rating = $rating / $reviews;
     } else {
         $this->page['NewRating'] = 2.5;
         $index_rating = 2.5;
     }
     $morating = $this->moratingcalc($index_rating, $views, $shares_counter, $wishlist, $buy);
     $this->page['mytotalrating'] = $morating;
     DB::table('fotis_reviews_prod_rates')->where('product_id', $prid)->update(['index_rating' => $morating]);
 }
Exemple #2
0
 public function initvalues()
 {
     $this->page['maxprice'] = Product::where('is_published', '=', '1')->max('price');
     $this->page['pricevalue'] = round(Product::where('is_published', '=', '1')->avg('price'));
     $this->page['SIvalue'] = round(Product::where('is_published', '=', '1')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id')->avg('index_rating'));
     $this->page['deliveryareas'] = $this->getstoredeliveryareas(36);
     // 36
     $this->page['categories'] = $this->getcategories();
     //$result = Product::where('is_published', '=', '1')->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id');
     $result = Product::where('is_published', '=', '1')->with(array('stores' => function ($query) {
         $query->with('customfields');
     }))->with('categories')->with('customfields')->leftJoin('fotis_reviews_prod_rates', 'tiipiik_catalog_products.id', '=', 'fotis_reviews_prod_rates.product_id');
     $result = $this->Search($result);
     if (isset($_GET["categoryset"])) {
         $categoryset = $_GET["categoryset"];
         $this->page['categoryset'] = $categoryset;
         $result->whereHas('categories', function ($q) use($categoryset) {
             $q->where('name', '=', $categoryset);
         });
     }
     if (isset($_GET["areaset"])) {
         $areaset = $_GET["areaset"];
         $this->page['areaset'] = $areaset;
         $result->whereHas('customfields', function ($q) use($areaset) {
             $q->where('value', '=', $areaset);
         });
     }
     if (isset($_GET["deliveryareaset"])) {
         $deliveryareaset = $_GET["deliveryareaset"];
         $this->page['deliveryareaset'] = $deliveryareaset;
         $result = $this->filterbystorecustomfields($result, $deliveryareaset);
     }
     $this->proproducts = $result->get();
     $result = $this->Pagination($result, 0);
     $result = $result->orderBy('title', 'desc')->get();
     $this->products = $result;
     return $result;
 }