2011-07-22 00:08:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Note extends CI_Model {
|
|
|
|
|
2023-05-03 07:38:28 +00:00
|
|
|
function list_all($api_key = null) {
|
|
|
|
if ($api_key == null) {
|
|
|
|
$user_id = $this->session->userdata('user_id');
|
|
|
|
} else {
|
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('api_model');
|
|
|
|
if (strpos($this->api_model->access($api_key), 'r') !== false) {
|
|
|
|
$this->api_model->update_last_used($api_key);
|
|
|
|
$user_id = $this->api_model->key_userid($api_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db->where('user_id', $user_id);
|
2011-07-22 00:08:47 +00:00
|
|
|
return $this->db->get('notes');
|
|
|
|
}
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
$data = array(
|
2019-10-05 20:57:44 +00:00
|
|
|
'cat' => xss_clean($this->input->post('category')),
|
|
|
|
'title' => xss_clean($this->input->post('title')),
|
2021-09-20 10:24:58 +00:00
|
|
|
'note' => xss_clean($this->input->post('content')),
|
|
|
|
'user_id' => $this->session->userdata('user_id')
|
2011-07-22 00:08:47 +00:00
|
|
|
);
|
|
|
|
|
2021-09-20 10:24:58 +00:00
|
|
|
$this->db->insert('notes', $data);
|
2011-07-22 00:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function edit() {
|
|
|
|
$data = array(
|
2019-10-05 20:57:44 +00:00
|
|
|
'cat' => xss_clean($this->input->post('category')),
|
|
|
|
'title' => xss_clean($this->input->post('title')),
|
|
|
|
'note' => xss_clean($this->input->post('content'))
|
2011-07-22 00:08:47 +00:00
|
|
|
);
|
|
|
|
|
2019-10-05 20:57:44 +00:00
|
|
|
$this->db->where('id', xss_clean($this->input->post('id')));
|
2021-09-20 10:24:58 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
|
|
$this->db->update('notes', $data);
|
2011-07-22 00:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete($id) {
|
2021-09-20 10:24:58 +00:00
|
|
|
$this->db->delete('notes', array('id' => xss_clean($id), 'user_id' =>$this->session->userdata('user_id')));
|
2011-07-22 00:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function view($id) {
|
|
|
|
// Get Note
|
2021-09-20 10:24:58 +00:00
|
|
|
$this->db->where('id', xss_clean($id));
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2011-07-22 00:08:47 +00:00
|
|
|
return $this->db->get('notes');
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:06:01 +00:00
|
|
|
function ClaimAllNotes($id = NULL) {
|
|
|
|
// if $id is empty then use session user_id
|
|
|
|
if (empty($id)) {
|
|
|
|
// Get the first USER ID from user table in the database
|
|
|
|
$id = $this->db->get("users")->row()->user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'user_id' => $id,
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->update('notes', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function CountAllNotes() {
|
|
|
|
// count all notes
|
2022-10-11 16:10:44 +00:00
|
|
|
$this->db->where('user_id =', NULL);
|
2022-10-11 13:54:34 +00:00
|
|
|
$query = $this->db->get('notes');
|
|
|
|
return $query->num_rows();
|
2022-10-10 14:06:01 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 00:08:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 10:24:58 +00:00
|
|
|
?>
|