[eluser]swgj19[/eluser]
Model:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Comment_model extends CI_Model {
// --------------------------------------------------------------------
/**
* __construct()
*
* Constructor PHP 5+ NOTE: Not needed if not setting values!
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
}
// --------------------------------------------------------------------
/**
* get_comments()
*
* Description:
*
* @access public
* @param string
* @return void
*/
public function get_comments($post_id = null)
{
$data = array();
$this->db->where('post_id', $post_id);
$query = $this->db->get('comments');
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
// --------------------------------------------------------------------
/**
* get_all_comments()
*
* Description:
*
* @access public
* @return void
*/
public function get_all_comments()
{
$data = array();
$query = $this->db->get('comments');
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
// --------------------------------------------------------------------
/**
* get_all_comments_post()
*
* Description:
*
* @access public
* @param string
* @return void
*/
public function get_all_comments_post($post_id)
{
$data = array();
$this->db->where("post_id", $post_id);
$this->db->where('status', 'active');
$query = $this->db->get('comments');
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[] = $row;
}
}
$query->free_result();
return $data;
}
// --------------------------------------------------------------------
/**
* add_comment()
*
* Description:
*
* @access public
* @return void
*/
public function add_comment()
{
$now = date("Y-m-d H:i:s");
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'body' => strip_tags(substr($this->input->post('body'), 0, 255)),
'post_id' => $this->input->post('post_id'),
'pub_date' => $now,
);
$this->db->insert('comments', $data);
}
// --------------------------------------------------------------------
/**
* update_comment()
*
* Description:
*
* @access public
* @return void
*/
public function update_comment()
{
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'body' => $this->input->post('body'),
'post_id' => $this->input->post('post_id'),
'pub_date' => $this->input->post('pub_date'),
'status' => $this->input->post('status'),
);
$this->db->where('id', $this->input->post('id'));
$this->db->update('comments', $data);
//return $data;
}
// --------------------------------------------------------------------
/**
* delete_comment()
*
* Description:
*
* @access public
* @param string
* @return void
*/
public function delete_comment($id)
{
$this->db->where('id', $id);
$this->db->delete('comments');
// this will delete - remark out or delete the top 2 lines
$this->db->delete('comments', array('id' => $id));
}
}
// ------------------------------------------------------------------------
/* End of file category_model.php */
/* Location: ./application/models/category_model.php */