<?php

class uploadsModel extends baseModel
{
    public $tableName = "uploads";

	public function insert($path, $type, $orig_filename)
	{
		date_default_timezone_set('CDT');
		date_default_timezone_get();
		
		$this->db->insert($this->tableName, [
            'file' => $path,
            'type' => $type,
            'uploaded_by' => $_SESSION['user_id'],
            'timestamp' => time(),
            'orig_filename' => $orig_filename,
            'created' => date('Y-m-d H:i:s')
        ]);

        return $this->db->insert_id();
	}

	function update($id, $data) {
		$this->db->where('id=?', $id)
			->update($this->tableName, $data);
	}

	function select($id) {
		return @current($this->db->where('id=?', $id)->select($this->tableName));
	}
	
	function deleteFile($id) {
		$this->db->where('id=?', $id);
		$this->db->delete('uploads');
	}	
}