2011-11-05 15:49:55 -04:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Viewer extends CI_Model {
|
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_viewer($ip, $id) {
|
|
|
|
$this->db->select('image_id')->where('image_id',$id)->where('ip',$ip);
|
|
|
|
$query = $this->db->get('viewers');
|
|
|
|
|
|
|
|
if($query->num_rows() == 0) {
|
|
|
|
$data = array(
|
|
|
|
'ip' => $ip,
|
|
|
|
'image_id' => $id,
|
|
|
|
'timestamp' => time()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->insert('viewers',$data);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-11-05 16:10:30 -04:00
|
|
|
|
|
|
|
function clean_viewers($duration) {
|
|
|
|
$clean_time = time() - $duration;
|
2011-11-11 19:50:51 -05:00
|
|
|
|
|
|
|
$this->db->where('timestamp <', $clean_time)->delete('viewers');
|
2011-11-05 16:10:30 -04:00
|
|
|
}
|
2011-11-05 15:49:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|