PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/b2b/core/model/comment/mdl.comment.php

http://phpfor.googlecode.com/
PHP | 249 lines | 208 code | 32 blank | 9 comment | 28 complexity | 8c9341496e1b4c5e017b6b54f1f8f682 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.time,aComment.author,aComment.goods_id,aComment.comment 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" 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. $this->db->exec('DELETE FROM sdb_comments WHERE comment_id = '.intval($comment_id).' OR for_comment_id = '.intval($comment_id));
  25. return true;
  26. }
  27. function toDisplay($comment_id, $status){
  28. $this->db->exec('UPDATE sdb_comments SET display = \''.$status.'\' WHERE comment_id = '.intval($comment_id));
  29. return true;
  30. }
  31. function toReply($data){
  32. $this->toInsert($data);
  33. if($this->system->getConf('comment.display.'.$data['object_type']) == 'reply'){
  34. $aUpdate['display'] = 'true';
  35. }
  36. $aUpdate['comment_id'] = $data['for_comment_id'];
  37. $aUpdate['lastreply'] = $data['time'];
  38. $aUpdate['reply_name'] = $data['author'];
  39. $aUpdate['mem_read_status'] = 'false';
  40. $this->toUpdate($aUpdate);
  41. $objGoods = $this->system->loadModel('trading/goods');
  42. $objGoods->updateRank($data['goods_id'], 'comments_count', 1); //??????
  43. $status = $this->system->loadModel('system/status');
  44. $status->count_gdiscuss();
  45. $status->count_gask();
  46. return true;
  47. }
  48. function toComment($data, $item, &$message){
  49. $this->toInsert($data);
  50. if($this->system->getConf('comment.display.'.$item) == 'soon'){
  51. $message = $this->system->getConf('comment.submit_display_notice.'.$item);
  52. }else{
  53. $message = $this->system->getConf('comment.submit_hidden_notice.'.$item);
  54. }
  55. $objGoods = $this->system->loadModel('trading/goods');
  56. $objGoods->updateRank($data['goods_id'], 'comments_count', 1); //??????
  57. $status = $this->system->loadModel('system/status');
  58. $status->count_gdiscuss();
  59. $status->count_gask();
  60. return true;
  61. }
  62. function toInsert(&$data){
  63. $data['title'] = $data['title'];
  64. $data['comment'] = safeHtml($data['comment']);
  65. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE 0=1');
  66. $sql = $this->db->GetInsertSQL($rs, $data);
  67. return $this->db->exec($sql);
  68. }
  69. function toUpdate(&$data){
  70. if(!empty($data['comment'])){
  71. $data['comment'] = safeHtml($data['comment']);
  72. }
  73. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($data['comment_id']));
  74. $sql = $this->db->getUpdateSQL($rs, $data);
  75. return (!$sql || $this->db->exec($sql));
  76. }
  77. //???????
  78. function setReaded($comment_id){
  79. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($comment_id));
  80. $aUpdate['adm_read_status'] = 'true';
  81. $sql = $this->db->getUpdateSQL($rs, $aUpdate);
  82. if($sql){
  83. if($this->db->exec($sql)){
  84. $status = &$this->system->loadModel('system/status');
  85. $status->count_gdiscuss();
  86. $status->count_gask();
  87. return 1;
  88. }else{
  89. return false;
  90. }
  91. }else{
  92. return true;
  93. }
  94. }
  95. //????????
  96. function setIndexOrder($comment_id){
  97. $aRet = $this->getFieldById($comment_id, array('p_index'));
  98. if($aRet['p_index'] == 1){
  99. $aRet['p_index'] = 0;
  100. }else{
  101. $aRet['p_index'] = 1;
  102. }
  103. $rs = $this->db->query('SELECT * FROM sdb_comments WHERE comment_id='.intval($comment_id));
  104. $sql = $this->db->getUpdateSQL($rs, $aRet);
  105. return (!$sql || $this->db->exec($sql));
  106. }
  107. //??????????
  108. function getGoodsIndexComments($goods_id, $item='ask'){
  109. $sql = "SELECT * FROM sdb_comments WHERE goods_id = ".intval($goods_id)
  110. ." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true'";
  111. $aRet['total'] = $this->db->_count($sql);
  112. $sql = "SELECT * FROM sdb_comments WHERE goods_id = ".intval($goods_id)
  113. ." AND for_comment_id IS NULL AND object_type = '".$item."' and disabled='false' AND display = 'true' ORDER BY p_index DESC, time DESC LIMIT ".$this->system->getConf('comment.index.listnum');
  114. $aRet['data'] = $this->db->select($sql);
  115. return $aRet;
  116. }
  117. //??????????
  118. function getCommentsReply($aId, $display=false){
  119. if($display) $sql = ' AND display = \'true\'';
  120. return $this->db->select("SELECT * FROM sdb_comments WHERE for_comment_id IN (".implode(",", $aId).")".$sql." and disabled='false' ORDER BY time");
  121. }
  122. //????????
  123. function getGoodsCommentList($goods_id, $item='ask', $page=1){
  124. if($page < 1) $page = 1;
  125. $pagenum = $this->system->getConf('comment.list.listnum');
  126. $sql = "SELECT * FROM sdb_comments
  127. WHERE goods_id = ".intval($goods_id)." AND for_comment_id IS NULL AND object_type = '".$item
  128. ."' and disabled='false' AND display = 'true'";
  129. $aRet['total'] = $this->db->_count($sql);
  130. $maxPage = ceil($aRet['total'] / $pagenum);
  131. if($page > $maxPage) $page = $maxPage;
  132. $start = ($page-1) * $pagenum;
  133. $start = $start<0 ? 0 : $start;
  134. $sql = "SELECT * FROM sdb_comments
  135. WHERE goods_id = ".intval($goods_id)." AND for_comment_id IS NULL AND object_type = '".$item
  136. ."' AND display = 'true' and disabled='false' ORDER BY time DESC LIMIT $start,".$pagenum;
  137. $aRet['page'] = $maxPage;
  138. $aRet['data'] = $this->db->select($sql);
  139. return $aRet;
  140. }
  141. //?????????
  142. function getMemberCommentList($member_id, $page=1){
  143. if($page < 1) $page = 1;
  144. $pagenum = $this->system->getConf('comment.list.listnum');
  145. $sql = "SELECT * FROM sdb_comments
  146. WHERE author_id = ".intval($member_id)." AND for_comment_id IS NULL AND display = 'true' and disabled='false' ORDER BY time DESC";
  147. $aRet['total'] = $this->db->_count($sql);
  148. $maxPage = ceil($aRet['total'] / $pagenum);
  149. if($page > $maxPage) $page = $maxPage;
  150. $start = ($page-1) * $pagenum;
  151. $start = $start<0 ? 0 : $start;
  152. $sql = "SELECT * FROM sdb_comments
  153. 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;
  154. $aRet['page'] = $maxPage;
  155. $aRet['data'] = $this->db->select($sql);
  156. return $aRet;
  157. }
  158. function toValidate($item, $gid, $memInfo, &$message){
  159. if($this->system->getConf('comment.switch.'.$item) != 'on'){
  160. $this->system->error(404);
  161. return false;
  162. exit;
  163. }
  164. if($this->system->getConf('comment.power.'.$item) != 'null' && !isset($memInfo['member_id'])){
  165. $message = __('???????!');
  166. return false;
  167. exit;
  168. }
  169. if($this->system->getConf('comment.power.'.$item) == 'buyer' && $memInfo['member_id']){
  170. $aRet = $this->db->selectrow('SELECT count(*) AS countRows FROM sdb_order_items i
  171. LEFT JOIN sdb_orders o ON i.order_id = o.order_id
  172. LEFT JOIN sdb_products p ON i.product_id = p.product_id
  173. WHERE o.version_id=0 and i.version_id=0 and o.member_id='.intval($memInfo['member_id']).' AND p.goods_id='.intval($gid).' AND (o.pay_status>0 OR o.ship_status>0)');
  174. if($aRet['countRows'] == 0){
  175. $message = __('???????????!');
  176. return false;
  177. exit;
  178. }
  179. }
  180. return true;
  181. }
  182. function getSetting($item){
  183. $aOut['switch'][$item] = $this->system->getConf('comment.switch.'.$item);
  184. $aOut['display'][$item] = $this->system->getConf('comment.display.'.$item);
  185. $aOut['power'][$item] = $this->system->getConf('comment.power.'.$item);
  186. $aOut['null_notice'][$item] = $this->system->getConf('comment.null_notice.'.$item);
  187. $aOut['submit_display_notice'][$item] = $this->system->getConf('comment.submit_display_notice.'.$item);
  188. $aOut['submit_hidden_notice'][$item] = $this->system->getConf('comment.submit_hidden_notice.'.$item);
  189. $aOut['index'] = intval($this->system->getConf('comment.index.listnum'));
  190. $aOut['list'] = intval($this->system->getConf('comment.list.listnum'));
  191. $aOut['verifyCode'][$item] = $this->system->getConf('comment.verifyCode.'.$item);
  192. return $aOut;
  193. }
  194. function setSetting($item, $aData){
  195. $this->system->setConf('comment.switch.'.$item, $aData['switch'][$item]);
  196. $this->system->setConf('comment.display.'.$item, $aData['display'][$item]);
  197. $this->system->setConf('comment.power.'.$item, $aData['power'][$item]);
  198. $this->system->setConf('comment.null_notice.'.$item, $aData['null_notice'][$item]);
  199. $this->system->setConf('comment.submit_display_notice.'.$item, $aData['submit_display_notice'][$item]);
  200. $this->system->setConf('comment.submit_hidden_notice.'.$item, $aData['submit_hidden_notice'][$item]);
  201. $this->system->setConf('comment.index.listnum', $aData['indexnum']);
  202. $this->system->setConf('comment.list.listnum', $aData['listnum']);
  203. $this->system->setConf('comment.verifyCode.'.$item, $aData['verifyCode'][$item]);
  204. }
  205. //????????
  206. function getTotalNum($nMId, $item=''){
  207. if($item) $sql = ' AND object_type=\''.$item.'\'';
  208. $aRow = $this->db->selectrow('SELECT count(*) AS num FROM sdb_comments WHERE disabled="false" and author_id='.$nMId.$sql);
  209. return $aRow['num'];
  210. }
  211. //???id??????
  212. function getCommListByMemId($nMId,$item){
  213. if($item) $sql = ' AND object_type=\''.$item.'\'';
  214. return $this->db->select_b("SELECT comment_id,author,contact,title,comment,time FROM sdb_comments WHERE author_id=".$nMId.$sql." ORDER BY time DESC");
  215. }
  216. }
  217. ?>