You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/third_party/recommend/models/infoTips_model.php

98 lines
2.8 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
class infoTips_model extends CI_Model
{
var $topnum = false; //返回记录数
var $orderby = false;
var $where = false; //查询条件
function __construct()
{
parent::__construct();
$this->HT = $this->load->database('INFORMATION', TRUE);
}
public function init() {
$this->topnum = false;
$this->where = false;
$this->orderby = ' order by it_expires ASC ';
}
public function detail($it_id){
$this->init();
$this->topnum = 1;
$this->where = ' AND it.it_id=' . $this->HT->escape($it_id);
return $this->get_list();
}
public function get_list() {
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
$sql .= "
it.it_id
,it.it_title
,it.it_expires
,it.it_code
,it.it_content
,it.it_sitecode
,it.it_datetime
from infoTips it
where 1=1
AND it.it_sitecode=?
";
$this->where ? $sql.=$this->where : false;
$this->orderby ? $sql.=$this->orderby : false;
$query = $this->HT->query($sql,array($this->config->item('site_code')));
//print_r($this->INFO->queries);
if ($this->topnum === 1) {
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
} else {
return $query->result();
}
}
// keyword 可以是标题或者 URL使用空格分开
public function search($keywords, $byWhat) {
if ($byWhat == 'byTitle') {
$whereCodition .= " and it.it_title like '%" . $keyword . "%'";
} else if ($byWhat == 'byLabel') {
$whereCodition .= " and it.it_code like '%" . $keyword . "%'";
} else if ($byWhat == 'byContent') {
$whereCodition .= " and it.it_content like '%" . $keyword . "%'";
}
$searchText =
"select it.it_id ,it.it_title,it.it_expires,it.it_code,it.it_content,it.it_sitecode,it.it_datetime
from infoTips it
where it.it_sitecode=?"
. $whereCodition . ") "
. " order by it_expires ASC";
$query = $this->HT->query($searchText, array($this->config->item('site_code')));
return $query->result();
}
public function add($table, $data)
{
if ($this->HT->insert($table, $data)) {
return $this->HT->last_id($table);
} else {
return false;
}
}
public function update($table, $data, $where)
{
return $this->HT->update($table, $data, $where);
}
public function delete($table, $where)
{
return $this->HT->delete($table, $where);
}
}