<?php
if(!defined('IN_DZZ')) {
exit('Access Denied');
}
class table_app_pic extends dzz_table
{
public function __construct() {
$this->_table = 'app_pic';
$this->_pk = 'picid';
parent::__construct();
}
public function delete_by_appid($appids){ if(!$appids) return;
if(!is_array($appids)){
$appids=array($appids);
}
$data=DB::fetch_all("SELECT * FROM %t WHERE appid IN(%n)",array($this->_table,$appids));
foreach($data as $value){
if($value['picid']) $this->delete_by_picid($value['picid']);
}
return true;
}
public function delete_by_picid($picid){ global $_G;
if(!$data=$this->fetch($picid)){
return false;
}
if($data['aid']){
C::t('attachment')->delete_by_aid($data['aid']);
$this->delete($picid);
}
return true;
}
public function fetch($picid,$force=false){ $picid = intval($picid);
$data = array();
if($force || ($picid && $data = $this->fetch_cache($picid) === false)) {
$data=DB::fetch_first("SELECT * FROM %t WHERE picid= %d ", array($this->_table,$picid));
$attachment= array();
if($data['aid']) $attachment=C::t('attachment')->fetch($data['aid']);
$data=array_merge($attachment,$data);
if(!empty($data)) $this->store_cache($picid, $data, $this->_cache_ttl);
}
return $data;
}
public function fetch_all_by_appid($appid,$iscount=false,$force=false){ $appid=intval($appid);
$data=array();
if($force || ($appid && ($data = $this->fetch_cache($appid,'app_pic_by_appid_')) === false)) {
foreach(DB::fetch_all("select picid from %t where appid= %d",array($this->_table,$appid)) as $value){
$data[$value['picid']]=$this->fetch($value['picid'],$force);
}
if(!empty($data)) $this->store_cache($appid, $data, 3600,'app_pic_by_appid_');
}
return $iscount?count($data):$data;
}
}
?>