Exemple #1
0
 /**
  *  Create single table for each advertisement hit
  * 
  */
 public function count_ad_hit()
 {
     $hits = 0;
     if (!Model_Visit::is_bot() and $this->loaded() and $this->status == Model_Ad::STATUS_PUBLISHED and core::config('advertisement.count_visits') == 1) {
         if (!Auth::instance()->logged_in()) {
             $visitor_id = NULL;
         } else {
             $visitor_id = Auth::instance()->get_user()->id_user;
         }
         //insert new visit
         if ($this->id_user != $visitor_id) {
             $new_hit = DB::insert('visits', array('id_ad', 'id_user'))->values(array($this->id_ad, $visitor_id))->execute();
         }
         //count how many matches are found
         $hits = new Model_Visit();
         $hits = $hits->where('id_ad', '=', $this->id_ad)->count_all();
     }
     return $hits;
 }
Exemple #2
0
 /**
  * ads a new hit in visits DB and counts how many visits has
  * @return integer count
  */
 public function count_hit()
 {
     if (!Model_Visit::is_bot() and $this->loaded() and core::config('product.count_visits') == 1) {
         //adding a visit only if not the owner
         if (!Auth::instance()->logged_in()) {
             $visitor_id = NULL;
         } else {
             $visitor_id = Auth::instance()->get_user()->id_user;
         }
         //adding affiliate if any
         $id_affiliate = NULL;
         if (Model_Affiliate::current()->loaded()) {
             $id_affiliate = Model_Affiliate::current()->id_user;
         }
         //new visit if not owner nad not bot
         if ($this->id_user != $visitor_id) {
             $new_hit = DB::insert('visits', array('id_product', 'id_user', 'id_affiliate', 'ip_address'))->values(array($this->id_product, $visitor_id, $id_affiliate, ip2long(Request::$client_ip)))->execute();
         }
         //count how many visits has
         $hits = new Model_Visit();
         return $hits->where('id_product', '=', $this->id_product)->count_all();
     }
     return 0;
 }