1
0
Fork 0

A lot of commits involving the image view controller, view and model that probably should have been seperate.

This commit is contained in:
Andrew Tomaka 2011-11-05 15:49:55 -04:00
parent 3c5c19a712
commit 9ece596c4d
4 changed files with 71 additions and 4 deletions

View File

@ -2,6 +2,10 @@
class View extends CI_Controller {
public function index() {
}
public function specific() {
$this->load->model('fileupload');
$id = $this->uri->segment($this->uri->total_segments());
@ -13,8 +17,23 @@ class View extends CI_Controller {
$upload = $this->fileupload->get_upload($id);
$this->load->model('viewer');
$display_views = $upload->views;
print_r($upload);
$this->load->model('viewer');
if($this->viewer->add_viewer($_SERVER['REMOTE_ADDR'], $id)) {
$this->fileupload->add_view($id);
$display_views++;
}
$this->data['prev'] = $id - 1;
$this->data['next'] = ($id + 1 <= $total_uploads) ? $id + 1 : 0;
$this->data['image'] = $id . $upload->extension;
$this->data['original'] = $upload->original_name;
$this->data['views'] = $display_views;
$this->data['created'] = $upload->created;
$this->template->load('template', 'view', $this->data);
}
}

View File

@ -21,10 +21,16 @@ class Fileupload extends CI_Model {
}
function get_upload($id) {
$this->db->select('extension, views, created')->from('uploads')->where('id',$id);
$this->db->select('extension, original_name, views, created')->from('uploads')->where('id',$id);
$query = $this->db->get();
return $query->result();
$result = $query->result();
return $result[0];
}
function add_view($id) {
$this->db->query("UPDATE uploads SET views = views + 1 WHERE id = $id");
}
}

View File

@ -0,0 +1,28 @@
<?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;
}
}
}
?>

View File

@ -0,0 +1,14 @@
<?php if($prev != 0) { ?>
<div id="left">
<a href="<?php echo base_url('/view/specific/' . $prev); ?>" class="navigation"></a>
</div>
<?php } ?>
<?php if($next != 0) { ?>
<div id="right">
<a href="<?php echo base_url('/view/specific/' . $next); ?>" class="navigation"></a>
</div>
<?php } ?>
<div id="imageContainer">
<img src="<?php echo base_url('/uploads/' . $image); ?>" class="image" />
</div>