diff --git a/application/controllers/info_tags.php b/application/controllers/info_tags.php index 0469102f..ff90be1e 100644 --- a/application/controllers/info_tags.php +++ b/application/controllers/info_tags.php @@ -23,27 +23,20 @@ class Info_tags extends CI_Controller $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') + if ($return) { echo(json_encode(array( 'status' => 1, - 'message' => '添加标签成功' - ))); - } - else if ($return == 'exist') - { - echo(json_encode(array( - 'status' => 2, - 'message' => '标签已存在' + 'message' => $return ))); - } - else + } + else { echo(json_encode(array( 'status' => -1, 'message' => '添加标签失败' ))); - } + } } /** @@ -69,6 +62,29 @@ class Info_tags extends CI_Controller } } + /** + * 展示标签 + */ + 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' => '读出标签失败' + ))); + } + } + /** * 添加关联信息+标签 */ diff --git a/application/controllers/information.php b/application/controllers/information.php index 662f3639..5f5c5475 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -20,6 +20,7 @@ class Information extends CI_Controller { $this->load->model('Infoauthors_model'); $this->load->model('InfoKeywordsanalytics_model', 'analytics_model'); $this->load->model('InfoSMS_model'); + $this->load->model('InfoTags_model'); $this->load->library('Accesscheck'); $this->accesscheck->check_access(); @@ -254,6 +255,25 @@ class Information extends CI_Controller { //所属导航栏目 $data['setting_website_nav'] = $this->InfoMetas_model->get_list(0, 'setting_website_nav_' . strtolower($this->config->item('site_code'))); + //信息标签 + $this->InfoTags_model->ic_id = null; + $data['all_tags'] = $this->InfoTags_model->list_tag(); + $this->InfoTags_model->ic_id = $data['information']->ic_id; + $data['my_tags'] = $this->InfoTags_model->list_tag(); + //差集 + foreach ($data['all_tags'] as &$it) + { + foreach ($data['my_tags'] as $it2) + { + if ($it->it_id == $it2->icit_it_id) + { + $it = null; + break; + } + } + } + $data['all_tags'] = array_filter($data['all_tags']); + $this->load->view('bootstrap3/header', $data); $this->load->view('bootstrap3/information_edit'); $this->load->view('bootstrap3/footer'); diff --git a/application/models/infoTags_model.php b/application/models/infoTags_model.php index 0768ca1b..6f6e2208 100644 --- a/application/models/infoTags_model.php +++ b/application/models/infoTags_model.php @@ -31,14 +31,16 @@ class InfoTags_model extends CI_Model { $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 { - return 'exist'; + $row = $check->row(); + return $row->it_id; } - return 'success'; + } - return 'fail'; + return FALSE; } /** @@ -55,6 +57,28 @@ class InfoTags_model extends CI_Model 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'; + } + /** * 添加信息与标签的关联 */ @@ -63,13 +87,13 @@ class InfoTags_model extends CI_Model if ($this->ic_id && $this->it_id) { //查看是否已存在关联 - $sql = "SELECT TOP 1 * from infoContentToTag WHERE ic_id = ? AND 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 ($query->num_rows() === 0) + if ($check->num_rows() === 0) { - $sql = "INSERT INTO infoContentToTag (ic_id, it_id) VALUES (?, ?)"; + $sql = "INSERT INTO infoContentToTag (icit_ic_id, icit_it_id) VALUES (?, ?)"; $query = $this->HT->query($sql, array($this->ic_id, $this->it_id)); } else @@ -88,7 +112,7 @@ class InfoTags_model extends CI_Model { if ($this->ic_id && $this->it_id) { - $sql = "DELETE FROM infoContentToTag WHERE ic_id = ? and 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'; } diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 40edd1fb..072cd03e 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -532,7 +532,12 @@
- +
@@ -1253,3 +1258,90 @@
+ + \ No newline at end of file