PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/aoliz/core/model/comment/mdl.comment.php

http://phpfor.googlecode.com/
PHP | 279 lines | 238 code | 32 blank | 9 comment | 36 complexity | 59c635d33b17a5dff43b36e82448ac99 MD5 | raw file
  1. <?php
  2. include_once('shopObject.php');
  3. class mdl_comment extends shopObject{
  4. function getFieldById($id, $aFeild){
  5. $sqlString = "SELECT ".implode(',', $aFeild)." FROM sdb_comments WHERE disabled='false' and comment_id = ".intval($id);
  6. return $this->db->selectrow($sqlString);
  7. }
  8. //?id??????
  9. function getCommentById($comment_id){
  10. $aRet = $this->db->selectrow("SELECT c.*, g.name AS goods_name FROM sdb_comments c
  11. LEFT JOIN sdb_goods g ON c.goods_id = g.goods_id
  12. WHERE comment_id = ".intval($comment_id));
  13. return $aRet;
  14. }
  15. function getTopComment($limit){
  16. return $this->db->select('SELECT aGoods.name,aComment.comment_id,aComment.author,aComment.goods_id,aComment.comment,aComment.time FROM sdb_comments as aComment
  17. left join sdb_goods as aGoods on aGoods.goods_id=aComment.goods_id
  18. WHERE aComment.for_comment_id is Null and aComment.display="true" and aComment.object_type = "discuss" and aComment.disabled = "false" ORDER BY aComment.comment_id desc limit 0,'.intval($limit));
  19. }
  20. function getCommentReply($comment_id){
  21. return $this->db->select('SELECT * FROM sdb_comments WHERE for_comment_id = '.intval($comment_id).' and disabled="false" ORDER BY time');
  22. }
  23. function toRemove($comment_id){
  24. $row = $this->getCommentById($comment_id);
  25. $this->db->exec('DELETE FROM sdb_comments WHERE comment_id = '.intval($comment_id).' OR for_comment_id = '.intval($comment_id));
  26. $this->modelName = 'member/account';
  27. $data['member_id'] = $row['author_id'];
  28. if($row['object_type'] == "discuss"){
  29. $this->fireEvent('discuzz_del',$data,$row['author_id']);
  30. }
  31. if($row['object_type'] == "ask"){
  32. $this->fireEvent('advisory_del',$data,$row['author_id']);
  33. }
  34. return true;
  35. }
  36. function toDisplay($comment_id, $status){
  37. $this->db->exec('UPDATE sdb_comments SET display = '.$this->db->quote($status).' WHERE comment_id = '.intval($comment_id));
  38. return true;
  39. }
  40. function toReply($data){
  41. $this->toInsert($data);
  42. if($this->system->getConf('comment.display.'.$data['object_type']) == 'reply'){
  43. $aUpdate['display'] = 'true';
  44. }
  45. $aUpdate['comment_id'] = $data['for_comment_id'];
  46. $aUpdate['lastreply'] = $data['time'];
  47. $aUpdate['reply_name'] = $data['author'];
  48. $aUpdate['mem_read_status'] = 'false';
  49. $this->toUpdate($aUpdate);
  50. $this->db->exec('UPDATE sdb_comments SET adm_read_status=\'false\' WHERE comment_id = '.$data['for_comment_id']);
  51. $objGoods = &$this->system->loadModel('trading/goods');
  52. $objGoods->updateRank($data['goods_id'], 'comments_count', 1); //??????
  53. $status = &$this->system->loadModel('system/status');
  54. $status->count_gdiscuss();
  55. $status->count_gask();
  56. $aTemp = $this->db->selectrow('SELECT * FROM sdb_comments WHERE comment_id='.$data['for_comment_id']);
  57. $data['member_id'] = $aTemp['author_id'];
  58. if ($data['object_type'] == "discuss")
  59. $type="discuzz_check";
  60. else
  61. $type="advisory_replay";
  62. $this->modelName="member/account";
  63. $this->fireEvent($type,$data,$data['member_id']);
  64. return true;
  65. }
  66. function toComment($data, $item, &$message){
  67. $this->toInsert($data);
  68. if($this->system->getConf('comment.display.'.$item) == 'soon'){
  69. $message = $this->system->getConf('comment.submit_display_notice.'.$item);
  70. }else{
  71. $message = $this->system->getConf('comment.submit_hidden_notice.'.$item);
  72. }
  73. $objGoods = &$this->system->loadModel('trading/goods');
  74. $objGoods->updateRank($data['goods_id'], 'comments_count', 1); //??????
  75. $status = &$this->system->loadModel('system/status');
  76. $status->count_gdiscuss();
  77. $status->count_gask();
  78. $data['member_id'] = substr($_COOKIE['MEMBER'],0,strpos($_COOKIE['MEMBER'],"-"));
  79. if ($item=="ask")
  80. $type='advisory_new';
  81. elseif ($item=="discuss")
  82. $type='discuzz_new';
  83. $this->modelName="member/account";
  84. $this->fireEvent($type,$data,$data['member_id']);
  85. return true;
  86. }
  87. function toInsert(&$data){
  88. $data['title'] = $data['title'];
  89. $data['comment'] = safeHtml($data['comment']);
  90. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE 0=1');
  91. $sql = $this->db->GetInsertSQL($rs, $data);
  92. return $this->db->exec($sql);
  93. }
  94. function toUpdate(&$data){
  95. if(!empty($data['comment'])){
  96. $data['comment'] = safeHtml($data['comment']);
  97. }
  98. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($data['comment_id']));
  99. $sql = $this->db->getUpdateSQL($rs, $data);
  100. return (!$sql || $this->db->exec($sql));
  101. }
  102. //???????
  103. function setReaded($comment_id){
  104. if(is_array($comment_id)){
  105. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id IN ('.implode(",",$comment_id).')');
  106. }
  107. else{
  108. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($comment_id));
  109. }
  110. $aUpdate['adm_read_status'] = 'true';
  111. $sql = $this->db->getUpdateSQL($rs, $aUpdate);
  112. if($sql){
  113. if($this->db->exec($sql)){
  114. $status = &$this->system->loadModel('system/status');
  115. $status->count_gdiscuss();
  116. $status->count_gask();
  117. return 1;
  118. }else{
  119. return false;
  120. }
  121. }else{
  122. return true;
  123. }
  124. }
  125. //????????
  126. function setIndexOrder($comment_id){
  127. $aRet = $this->getFieldById($comment_id, array('p_index'));
  128. if($aRet['p_index'] == 1){
  129. $aRet['p_index'] = 0;
  130. }else{
  131. $aRet['p_index'] = 1;
  132. }
  133. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($comment_id));
  134. $sql = $this->db->getUpdateSQL($rs, $aRet);
  135. return (!$sql || $this->db->exec($sql));
  136. }
  137. //??????????
  138. function getGoodsIndexComments($goods_id, $item='ask'){
  139. $sql = "SELECT * FROM sdb_comments WHERE goods_id = ".intval($goods_id)
  140. ." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true'";
  141. $aRet['total'] = $this->db->count($sql);
  142. $sql = "SELECT * FROM sdb_comments WHERE goods_id = ".intval($goods_id)
  143. ." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true' ORDER BY p_index ASC, time DESC LIMIT ".$this->system->getConf('comment.index.listnum');
  144. $aRet['data'] = $this->db->select($sql);
  145. return $aRet;
  146. }
  147. //??????????
  148. function getCommentsReply($aId, $display=false){
  149. if($display) $sql = ' AND display = \'true\'';
  150. return $this->db->select("SELECT * FROM sdb_comments WHERE for_comment_id IN (".implode(",", $aId).")".$sql." and disabled='false' ORDER BY time");
  151. }
  152. //????????
  153. function getGoodsCommentList($goods_id, $item='ask', $page=1){
  154. if($page < 1) $page = 1;
  155. $pagenum = $this->system->getConf('comment.list.listnum');
  156. $sql = "SELECT * FROM sdb_comments
  157. WHERE goods_id = ".intval($goods_id)." AND for_comment_id IS NULL AND object_type = '".$item
  158. ."' and disabled='false' AND display = 'true'";
  159. $aRet['total'] = $this->db->count($sql);
  160. $maxPage = ceil($aRet['total'] / $pagenum);
  161. if($page > $maxPage) $page = $maxPage;
  162. $start = ($page-1) * $pagenum;
  163. $start = $start<0 ? 0 : $start;
  164. $sql = "SELECT * FROM sdb_comments
  165. WHERE goods_id = ".intval($goods_id)." AND for_comment_id IS NULL AND object_type = '".$item
  166. ."' AND display = 'true' and disabled='false' ORDER BY time DESC LIMIT $start,".$pagenum;
  167. $aRet['page'] = $maxPage;
  168. $aRet['data'] = $this->db->select($sql);
  169. return $aRet;
  170. }
  171. //?????????
  172. function getMemberCommentList($member_id, $page=1){
  173. if($page < 1) $page = 1;
  174. $pagenum = $this->system->getConf('comment.list.listnum');
  175. $sql = "SELECT * FROM sdb_comments
  176. WHERE author_id = ".intval($member_id)." AND for_comment_id IS NULL AND display = 'true' and disabled='false' ORDER BY time DESC";
  177. $aRet['total'] = $this->db->count($sql);
  178. $maxPage = ceil($aRet['total'] / $pagenum);
  179. if($page > $maxPage) $page = $maxPage;
  180. $start = ($page-1) * $pagenum;
  181. $start = $start<0 ? 0 : $start;
  182. $sql = "SELECT * FROM sdb_comments
  183. WHERE author_id = ".intval($member_id)." AND for_comment_id IS NULL AND display = 'true' and disabled='false' ORDER BY time DESC LIMIT $start,".$pagenum;
  184. $aRet['page'] = $maxPage;
  185. $aRet['data'] = $this->db->select($sql);
  186. return $aRet;
  187. }
  188. function toValidate($item, $gid, $memInfo, &$message){
  189. if($this->system->getConf('comment.switch.'.$item) != 'on'){
  190. $this->system->error(404);
  191. return false;
  192. exit;
  193. }
  194. if($this->system->getConf('comment.power.'.$item) != 'null' && !isset($memInfo['member_id'])){
  195. $message = __('???????!');
  196. return false;
  197. exit;
  198. }
  199. if($this->system->getConf('comment.power.'.$item) == 'buyer' && $memInfo['member_id']){
  200. $aRet = $this->db->selectrow('SELECT count(*) AS countRows FROM sdb_order_items i
  201. LEFT JOIN sdb_orders o ON i.order_id = o.order_id
  202. LEFT JOIN sdb_products p ON i.product_id = p.product_id
  203. WHERE o.member_id='.intval($memInfo['member_id']).' AND p.goods_id='.intval($gid).' AND (o.pay_status>"0" OR o.ship_status>"0")');
  204. if($aRet['countRows'] == 0){
  205. $message = __('???????????!');
  206. return false;
  207. exit;
  208. }
  209. }
  210. return true;
  211. }
  212. function getSetting($item){
  213. $aOut['switch'][$item] = $this->system->getConf('comment.switch.'.$item);
  214. $aOut['display'][$item] = $this->system->getConf('comment.display.'.$item);
  215. $aOut['power'][$item] = $this->system->getConf('comment.power.'.$item);
  216. $aOut['null_notice'][$item] = $this->system->getConf('comment.null_notice.'.$item);
  217. $aOut['submit_display_notice'][$item] = $this->system->getConf('comment.submit_display_notice.'.$item);
  218. $aOut['submit_hidden_notice'][$item] = $this->system->getConf('comment.submit_hidden_notice.'.$item);
  219. $aOut['index'] = intval($this->system->getConf('comment.index.listnum'));
  220. $aOut['list'] = intval($this->system->getConf('comment.list.listnum'));
  221. $aOut['verifyCode'][$item] = $this->system->getConf('comment.verifyCode.'.$item);
  222. return $aOut;
  223. }
  224. function setSetting($item, $aData){
  225. $this->system->setConf('comment.switch.'.$item, $aData['switch'][$item]);
  226. $this->system->setConf('comment.display.'.$item, $aData['display'][$item]);
  227. $this->system->setConf('comment.power.'.$item, $aData['power'][$item]);
  228. $this->system->setConf('comment.null_notice.'.$item, $aData['null_notice'][$item]);
  229. $this->system->setConf('comment.submit_display_notice.'.$item, $aData['submit_display_notice'][$item]);
  230. $this->system->setConf('comment.submit_hidden_notice.'.$item, $aData['submit_hidden_notice'][$item]);
  231. $this->system->setConf('comment.index.listnum', $aData['indexnum']);
  232. $this->system->setConf('comment.list.listnum', $aData['listnum']);
  233. $this->system->setConf('comment.verifyCode.'.$item, $aData['verifyCode'][$item]);
  234. }
  235. //????????
  236. function getTotalNum($nMId, $item=''){
  237. if($item) $sql = ' AND object_type=\''.$item.'\'';
  238. $aRow = $this->db->selectrow('SELECT count(*) AS num FROM sdb_comments WHERE disabled="false" and author_id='.$nMId.$sql);
  239. return $aRow['num'];
  240. }
  241. //???id??????
  242. function getCommListByMemId($nMId,$item){
  243. if($item) $sql = ' AND object_type=\''.$item.'\'';
  244. return $this->db->select("SELECT comment_id,author,contact,title,comment,time FROM sdb_comments WHERE author_id=".$nMId.$sql." ORDER BY time DESC");
  245. }
  246. }
  247. ?>