Merge branch 'master' into zodiac
commit
4f81dae2f5
@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('BASEPATH'))
|
||||||
|
exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Info_tags extends CI_Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->permission->is_admin();
|
||||||
|
//$this->output->enable_profiler(TRUE);
|
||||||
|
$this->load->model('Information_model');
|
||||||
|
$this->load->model('InfoTags_model');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加标签
|
||||||
|
*/
|
||||||
|
public function add_tag()
|
||||||
|
{
|
||||||
|
$this->InfoTags_model->it_title = $this->input->get_post('title');
|
||||||
|
$this->InfoTags_model->it_memo = $this->input->get_post('memo');
|
||||||
|
$return = $this->InfoTags_model->add_tag();
|
||||||
|
if ($return)
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 1,
|
||||||
|
'message' => $return
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => -1,
|
||||||
|
'message' => '添加标签失败'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标签
|
||||||
|
*/
|
||||||
|
public function remove_tag()
|
||||||
|
{
|
||||||
|
$this->InfoTags_model->it_title = $this->input->get_post('title');
|
||||||
|
$return = $this->InfoTags_model->remove_tag();
|
||||||
|
if ($return == 'success')
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 1,
|
||||||
|
'message' => '删除标签成功'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => -1,
|
||||||
|
'message' => '删除标签失败'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 展示标签
|
||||||
|
*/
|
||||||
|
public function list_tag($ic_id = '')
|
||||||
|
{
|
||||||
|
$ic_id ? $this->InfoTags_model->ic_id = $ic_id : $this->InfoTags_model->ic_id = $this->input->post('ic_id');
|
||||||
|
$return = $this->InfoTags_model->list_tag();
|
||||||
|
if ($return != 'fail')
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 1,
|
||||||
|
'data' => $return
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => -1,
|
||||||
|
'message' => '读出标签失败'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加关联信息+标签
|
||||||
|
*/
|
||||||
|
public function add_tag_to_content()
|
||||||
|
{
|
||||||
|
$this->InfoTags_model->ic_id = $this->input->get_post('ic_id');
|
||||||
|
$this->InfoTags_model->it_id = $this->input->get_post('it_id');
|
||||||
|
$return = $this->InfoTags_model->add_tag_to_content();
|
||||||
|
if ($return == 'success')
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 1,
|
||||||
|
'message' => '关联信息标签成功'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else if ($return == 'exist')
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 2,
|
||||||
|
'message' => '关联信息标签已存在'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => -1,
|
||||||
|
'message' => '关联信息标签失败'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除关联信息+标签
|
||||||
|
*/
|
||||||
|
public function remove_tag_to_content()
|
||||||
|
{
|
||||||
|
$this->InfoTags_model->ic_id = $this->input->get_post('ic_id');
|
||||||
|
$this->InfoTags_model->it_id = $this->input->get_post('it_id');
|
||||||
|
$return = $this->InfoTags_model->remove_tag_to_content();
|
||||||
|
if ($return == 'success')
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => 1,
|
||||||
|
'message' => '移除关联信息标签成功'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo(json_encode(array(
|
||||||
|
'status' => -1,
|
||||||
|
'message' => '移除关联信息标签失败'
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class InfoTags_model extends CI_Model
|
||||||
|
{
|
||||||
|
//信息标签表
|
||||||
|
var $it_title = '';
|
||||||
|
var $it_memo = '';
|
||||||
|
//信息标签关联表
|
||||||
|
var $ic_id = '';
|
||||||
|
var $it_id = '';
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->HT = $this->load->database('HT', TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加标签
|
||||||
|
*/
|
||||||
|
function add_tag()
|
||||||
|
{
|
||||||
|
if ($this->it_title)
|
||||||
|
{
|
||||||
|
//查看是否已存在标签
|
||||||
|
$sql = "SELECT TOP 1 * from infoTags WHERE it_title = N?";
|
||||||
|
$check = $this->HT->query($sql, array($this->it_title));
|
||||||
|
|
||||||
|
//添加标签
|
||||||
|
if ($check->num_rows() === 0)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO infoTags (it_title, it_memo) VALUES (N?, N?)";
|
||||||
|
$query = $this->HT->query($sql, array($this->it_title, $this->it_memo));
|
||||||
|
return $this->HT->insert_id();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$row = $check->row();
|
||||||
|
return $row->it_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标签
|
||||||
|
*/
|
||||||
|
function remove_tag()
|
||||||
|
{
|
||||||
|
if ($this->it_title)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM infoTags WHERE it_title = N?";
|
||||||
|
$query = $this->HT->query($sql, array($this->it_title));
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
return 'fail';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签列表
|
||||||
|
*/
|
||||||
|
function list_tag()
|
||||||
|
{
|
||||||
|
if ($this->ic_id)
|
||||||
|
{
|
||||||
|
//展示信息的标签
|
||||||
|
$sql = "SELECT * FROM infoContentToTag INNER JOIN infoTags ON icit_it_id = it_id WHERE icit_ic_id = ?";
|
||||||
|
$query = $this->HT->query($sql, array($this->ic_id));
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//全部展示
|
||||||
|
$sql = "SELECT * FROM infoTags ORDER BY it_title ASC, it_date DESC";
|
||||||
|
$query = $this->HT->query($sql);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
return 'fail';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加信息与标签的关联
|
||||||
|
*/
|
||||||
|
function add_tag_to_content()
|
||||||
|
{
|
||||||
|
if ($this->ic_id && $this->it_id)
|
||||||
|
{
|
||||||
|
//查看是否已存在关联
|
||||||
|
$sql = "SELECT TOP 1 * from infoContentToTag WHERE icit_ic_id = ? AND icit_it_id = ?";
|
||||||
|
$check = $this->HT->query($sql, array($this->ic_id, $this->it_id));
|
||||||
|
|
||||||
|
//添加关联
|
||||||
|
if ($check->num_rows() === 0)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO infoContentToTag (icit_ic_id, icit_it_id) VALUES (?, ?)";
|
||||||
|
$query = $this->HT->query($sql, array($this->ic_id, $this->it_id));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 'exist';
|
||||||
|
}
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
return 'fail';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解除信息与标签的关联
|
||||||
|
*/
|
||||||
|
function remove_tag_to_content()
|
||||||
|
{
|
||||||
|
if ($this->ic_id && $this->it_id)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM infoContentToTag WHERE icit_ic_id = ? and icit_it_id = ?";
|
||||||
|
$query = $this->HT->query($sql, array($this->ic_id, $this->it_id));
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
return 'fail';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue