添加 infoTags 模型 v2

hotfix/远程访问多媒体中心
lmr@hainatravel.com 8 years ago
parent f37b965cc4
commit 1c33404c45

@ -0,0 +1,128 @@
<?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 == '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()
{
$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 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' => '移除关联信息标签失败'
)));
}
}
}

@ -4,7 +4,7 @@ class InfoTags_model extends CI_Model
{
//信息标签表
var $it_title = '';
var $it_memu = '';
var $it_memo = '';
//信息标签关联表
var $ic_id = '';
var $it_id = '';
@ -23,18 +23,22 @@ class InfoTags_model extends CI_Model
if ($this->it_title)
{
//查看是否已存在标签
$sql = "SELECT TOP 1 * from infoTags WHERE ic_title = N?";
$sql = "SELECT TOP 1 * from infoTags WHERE it_title = N?";
$check = $this->HT->query($sql, array($this->it_title));
//添加标签
if ($query->num_rows() === 0)
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_memu));
$query = $this->HT->query($sql, array($this->it_title, $this->it_memo));
}
else
{
return 'exist';
}
return true;
return 'success';
}
return false;
return 'fail';
}
/**
@ -46,9 +50,9 @@ class InfoTags_model extends CI_Model
{
$sql = "DELETE FROM infoTags WHERE it_title = N?";
$query = $this->HT->query($sql, array($this->it_title));
return true;
return 'success';
}
return false;
return 'fail';
}
/**
@ -68,9 +72,13 @@ class InfoTags_model extends CI_Model
$sql = "INSERT INTO infoContentToTag (ic_id, it_id) VALUES (?, ?)";
$query = $this->HT->query($sql, array($this->ic_id, $this->it_id));
}
return true;
else
{
return 'exist';
}
return 'success';
}
return false;
return 'fail';
}
/**
@ -82,9 +90,9 @@ class InfoTags_model extends CI_Model
{
$sql = "DELETE FROM infoContentToTag WHERE ic_id = ? and it_id = ?";
$query = $this->HT->query($sql, array($this->ic_id, $this->it_id));
return true;
return 'success';
}
return false;
return 'fail';
}
}
Loading…
Cancel
Save