$table
$table :
作品集model
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/**
* 作品集model
* @author Administrator
*
*/
class Protflio_model extends CI_Model{
private $table = 'protfolio';
public function __construct()
{
parent::__construct();
}
/**
* 得到当前作者所有作品集
* @param unknown $userId
*/
public function getuserProtflio($authorId,$select='*',$status='1',$limit=10,$start=0){
$this->db->select($select);
$this->db->where('authorId',$authorId);
if($status==1){
$this->db->where('status',$status);
}
$this->db->order_by('createtime','desc');
$this->db->limit($limit, $start);
return $this->db->get($this->table )->result_array();
}
/**
* 搜索模糊查询
*/
public function searchProtfolio($title,$limit=10,$start=0){
$param['Name like'] = '%'.strval($title).'%';
$this->db->where($param);
$this->db->where('status',1);
$this->db->order_by('collectNum','desc');
$this->db->limit($limit, $start);
return $this->db->get($this->table )->result_array();
}
/**
* 按分类获取作品集
* @param unknown $category
* @param string $select
* @param string $ststus
* @param number $limit
* @param number $start
*/
public function getcateProtflio($category,$select='*',$ststus='1',$limit=10,$start=0,$order="createtime"){
$this->db->select($select);
if (!empty($category)){
$this->db->where('category',$category);
}
$this->db->where('status',$ststus);
$this->db->order_by($order,'desc');
$this->db->limit($limit, $start);
return $this->db->get($this->table )->result_array();
}
/**
* 获取当前作品集信息
* @param unknown $ptotfolioId
* @param string $select
* @param string $status
*/
public function getProtflioinfo($ptotfolioId,$select='*'){
$this->db->select($select);
$this->db->where('id',$ptotfolioId);
$this->db->order_by('createtime','desc');
return $this->db->get($this->table )->row_array();
}
/**
* 获取分类文集数量
*/
public function getcateNum(){
$this->db->select('category');
$this->db->where('category');
return $this->db->count_all_results($this->table);
}
/**
* 得到作品集数量
*/
public function getProtfoliocount($where=array(),$stime=0,$etime=0){
if(!empty($stime)){
$this->db->where('createtime >' ,$stime);
}
if(!empty($etime)){
$this->db->where('createtime <' ,$etime);
}
$param = $this->_getWhere($where);
$this->db->where($param);
return $this->db->count_all_results( $this->table);
}
/**
* 得到符合条件的作品集信息
*/
public function getProtfoliolist($where=array(),$limit,$start){
$param = $this->_getWhere($where);
$this->db->where($param);
$this->db->limit($limit, $start);
$this->db->order_by('createtime','desc');
return $this->db->get($this->table )->result_array();
}
public function _getWhere( $where=array() )
{
$param = array();
if (!empty($where['Name']))
{
$param['Name like'] = '%'.strval($where['Name']).'%';
}
if (isset($where['dirction'])&&!empty($where['dirction']))
{
$param['dirction'] = '%'.strval($where['dirction']).'%';
}
if (isset($where['dirction'])&&!empty($where['dirction']))
{
$param['createtime'] = $where['createtime'];
}
if (isset($where['authorId']) && $where['authorId']!='-1')
{
$param['authorId'] = intval($where['authorId']);
}
if (isset($where['articleNum']) && $where['articleNum']!='-1')
{
$param['articleNum'] = intval($where['articleNum']);
}
if (isset($where['status']) && ($where['status'])!='-1')
{
$param['status'] = $where['status'];
}
//$param['issue'] = empty($where['issue'])?0:$where['issue'];
if (isset($where['collectNum']))
{
$param['collectNum'] = intval($where['collectNum']);
}
if (isset($where['category'])&&!empty($where['category']))
{
$param['category'] = intval($where['category']);
}
if (isset($where['cateId'])&&!empty($where['cateId']))
{
$param['cateId'] = intval($where['cateId']);
}
if (isset($where['finishstatus']))
{
$param['finishstatus'] = $where['finishstatus'];
}
//print_R($param);exit;
return $param;
}
/**
* 修改作品集信息
*/
public function updateNum($data,$ptotfolioId=0)
{
foreach ($data as $k => $v)
{
$this->db->set($k, $v, FALSE);
}
$this->db->where('id',$ptotfolioId)->update( $this->table );
return $this->db->affected_rows();
}
/**
* 创建作品集
*/
public function insertData($ProtflioData){
$res = $this->db->insert($this->table, $ProtflioData);
return $res;
}
/**
* 删除作品集
*/
public function delete($id){
$this->db->where( 'id', $id );
$query = $this->db->delete( $this->table);
return $query ? $id : false;
}
}