wavelog/application/models/Note.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2011-07-22 01:08:47 +01:00
<?php
class Note extends CI_Model {
function list_all($api_key = null) {
if ($api_key == null) {
$user_id = $this->session->userdata('user_id');
} else {
2024-08-14 13:29:07 +02:00
$this->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 01:08:47 +01:00
return $this->db->get('notes');
}
function add() {
$data = array(
2024-08-14 13:29:07 +02:00
'cat' => $this->input->post('category', TRUE),
'title' => $this->input->post('title', TRUE),
'note' => $this->input->post('content', TRUE),
'user_id' => $this->session->userdata('user_id')
2011-07-22 01:08:47 +01:00
);
$this->db->insert('notes', $data);
2011-07-22 01:08:47 +01:00
}
function edit() {
$data = array(
2024-08-14 13:29:07 +02:00
'cat' => $this->input->post('category', TRUE),
'title' => $this->input->post('title', TRUE),
'note' => $this->input->post('content', TRUE)
2011-07-22 01:08:47 +01:00
);
2024-08-14 13:29:07 +02:00
$this->db->where('id', $this->input->post('id', TRUE));
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->update('notes', $data);
2011-07-22 01:08:47 +01:00
}
function delete($id) {
2024-08-14 13:29:07 +02:00
$clean_id = $this->security->xss_clean($id);
if (! is_numeric($clean_id)) {
show_404();
}
$this->db->delete('notes', array('id' => $clean_id, 'user_id' => $this->session->userdata('user_id')));
2011-07-22 01:08:47 +01:00
}
function view($id) {
2024-08-14 13:29:07 +02:00
$clean_id = $this->security->xss_clean($id);
if (! is_numeric($clean_id)) {
show_404();
}
2011-07-22 01:08:47 +01:00
// Get Note
2024-08-14 13:29:07 +02:00
$this->db->where('id', $clean_id);
$this->db->where('user_id', $this->session->userdata('user_id'));
2011-07-22 01:08:47 +01:00
return $this->db->get('notes');
}
2022-10-10 15:06:01 +01:00
function CountAllNotes() {
// count all notes
$this->db->where('user_id =', NULL);
2022-10-11 14:54:34 +01:00
$query = $this->db->get('notes');
return $query->num_rows();
2022-10-10 15:06:01 +01:00
}
2011-07-22 01:08:47 +01:00
}
?>