/core/class/table/table_comment.php

https://github.com/zyx0814/dzzoffice · PHP · 172 lines · 143 code · 14 blank · 15 comment · 22 complexity · f81faa6eeab5ebe1bb9430e6a4a8d3c9 MD5 · raw file

  1. <?php
  2. /*
  3. * @copyright Leyun internet Technology(Shanghai)Co.,Ltd
  4. * @license http://www.dzzoffice.com/licenses/license.txt
  5. * @package DzzOffice
  6. * @link http://www.dzzoffice.com
  7. * @author zyx(zyx@dzz.cc)
  8. */
  9. if(!defined('IN_DZZ')) {
  10. exit('Access Denied');
  11. }
  12. class table_comment extends dzz_table
  13. {
  14. public function __construct() {
  15. $this->_table = 'comment';
  16. $this->_pk = 'cid';
  17. $this->_pre_cache_key = 'comment_';
  18. $this->_cache_ttl = 60*60;
  19. parent::__construct();
  20. }
  21. public function insert_by_cid($arr,$ats,$attach){
  22. if($arr['cid']=parent::insert($arr,1)){
  23. /*if($arr['rcid'] && $rdata=parent::fetch($arr['rcid']) && !in_array($rdata['authorid'],$ats)){
  24. $ats[]=$rdata['authorid'];
  25. }*/
  26. if($ats){
  27. C::t('comment_at')->insert_by_cid($arr['cid'],($ats));
  28. }
  29. if($attach) C::t('comment_attach')->insert_by_cid($arr['cid'],$attach);
  30. if($arr['module']){
  31. @include_once DZZ_ROOT.'./dzz/'.$arr['module'].'/class/table/table_'.$arr['idtype'].'.php';
  32. }else{
  33. @include_once DZZ_ROOT.'./core/class/table/table_'.$arr['idtype'].'.php';
  34. }
  35. if(class_exists('table_'.$arr['idtype']) && method_exists('table_'.$arr['idtype'],'callback_by_comment')){
  36. $arr['message']=dzzcode($arr['message']);
  37. C::t($arr['idtype'])->callback_by_comment($arr,'add',$ats);
  38. }
  39. }
  40. return $arr['cid'];
  41. }
  42. public function update_by_cid($cid,$message,$rcid,$attach){
  43. $ret=0;
  44. $ret+=parent::update($cid,array('message'=>$message,'rcid'=>$rcid,'edituid'=>getglobal('uid'),'edittime'=>TIMESTAMP));
  45. $ret+=C::t('comment_attach')->update_by_cid($cid,$attach);
  46. return $ret;
  47. }
  48. public function delete_by_cid($cid){
  49. if(!$data=parent::fetch($cid)) return false;
  50. $delcids=array($cid);
  51. foreach(DB::fetch_all("select cid from %t where pcid=%d ",array($this->_table,$cid)) as $value){
  52. $delcids[]=$value['cid'];
  53. }
  54. if($return=parent::delete($delcids)){
  55. //删除@
  56. C::t('comment_at')->delete_by_cid($delcids);
  57. //删除附件
  58. C::t('comment_attach')->delete_by_cid($delcids);
  59. if($data['module']){
  60. @include_once DZZ_ROOT.'dzz/'.$data['module'].'/class/table/table_'.$data['idtype'].'.php';
  61. }else{
  62. @include_once DZZ_ROOT.'core/class/table/table_'.$data['idtype'].'.php';
  63. }
  64. if(class_exists('table_'.$data['idtype']) && method_exists('table_'.$data['idtype'],'callback_by_comment')){
  65. C::t($data['idtype'])->callback_by_comment($data,'delete');
  66. }
  67. return $return;
  68. }else{
  69. return false;
  70. }
  71. }
  72. public function delete_by_id_idtype($ids,$idtype){
  73. $ids=(array)$ids;
  74. $dels=array();
  75. foreach(DB::fetch_all("select * from %t where id IN (%n) and idtype=%s",array($this->_table,$ids,$idtype)) as $value){
  76. $dels[]=$value['cid'];
  77. }
  78. if($return=parent::delete($dels)){
  79. //删除@
  80. C::t('comment_at')->delete_by_cid($dels);
  81. //删除附件
  82. C::t('comment_attach')->delete_by_cid($dels);
  83. }
  84. return parent::delete($dels);
  85. }
  86. public function fetch_all_by_idtype($id,$idtype,$limit,$iscount=false){
  87. $limitsql='';
  88. if($limit){
  89. $limit=explode('-',$limit);
  90. if(count($limit)>1){
  91. $limitsql.=" limit ".intval($limit[0]).",".intval($limit[1]);
  92. }else{
  93. $limitsql.=" limit ".intval($limit[0]);
  94. }
  95. }
  96. if($iscount) return DB::result_first("select COUNT(*) from %t where id=%s and idtype=%s and pcid=0",array($this->_table,$id,$idtype));
  97. $data=array();
  98. foreach(DB::fetch_all("select * from %t where id=%s and idtype=%s and pcid=0 order by dateline DESC $limitsql",array($this->_table,$id,$idtype)) as $value){
  99. $value['message']=dzzcode($value['message']);
  100. $value['dateline']=dgmdate($value['dateline'],'u');
  101. $value['replies']=DB::result_first("select COUNT(*) from %t where pcid=%d",array($this->_table,$value['cid']));
  102. $value['replys']=self::fetch_all_by_pcid($value['cid'],5);
  103. $value['attachs']=C::t('comment_attach')->fetch_all_by_cid($value['cid']);
  104. $data[]=$value;
  105. }
  106. return $data;
  107. }
  108. public function fetch_all_by_pcid($pcid,$limit,$iscount=false){
  109. $limitsql='';
  110. if($limit){
  111. $limit=explode('-',$limit);
  112. if(count($limit)>1){
  113. $limitsql.=" limit ".intval($limit[0]).",".intval($limit[1]);
  114. }else{
  115. $limitsql.=" limit ".intval($limit[0]);
  116. }
  117. }
  118. if($iscount) return DB::result_first("select COUNT(*) from %t where pcid=%d ",array($this->_table,$pcid));
  119. $data=array();
  120. foreach(DB::fetch_all("select * from %t where pcid=%d order by dateline DESC $limitsql",array($this->_table,$pcid)) as $value){
  121. $value['message']=dzzcode($value['message']);
  122. $value['dateline']=dgmdate($value['dateline'],'u');
  123. $value['attachs']=C::t('comment_attach')->fetch_all_by_cid($value['cid']);
  124. if($value['rcid']){
  125. $value['rpost']=parent::fetch($value['rcid']);
  126. }
  127. $data[]=$value;
  128. }
  129. return $data;
  130. }
  131. public function copy_by_id_idtype($oid,$id,$idtype){
  132. $return=0;
  133. foreach(DB::fetch_all("select * from %t where id=%s and idtype=%s and pcid='0'",array($this->_table,$oid,$idtype)) as $value){
  134. $ocid=$value['cid'];
  135. unset($value['cid']);
  136. $value['id']=$id;
  137. if($value['cid']=parent::insert($value,1)){
  138. C::t('comment_at')->copy_by_cid($ocid,$value['cid']);
  139. C::t('comment_attach')->copy_by_cid($ocid,$value['cid']);
  140. $return+=1;
  141. //拷贝子评论
  142. foreach(DB::fetch_all("select * from %t where pcid=%d ",array($this->_table,$ocid)) as $value1){
  143. $ocid=$value1['cid'];
  144. unset($value1['cid']);
  145. $value1['pcid']=$value['cid'];
  146. $value1['id']=$id;
  147. $value1['rcid']=0;
  148. if(parent::insert($value1,1)){
  149. C::t('comment_at')->copy_by_cid($ocid,$value['cid']);
  150. C::t('comment_attach')->copy_by_cid($ocid,$value['cid']);
  151. }
  152. }
  153. }
  154. }
  155. return $return;
  156. }
  157. }
  158. ?>