Rank.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. namespace We7\Table\Modules;
  7. class Rank extends \We7Table {
  8. protected $tableName = 'modules_rank';
  9. protected $primaryKey = 'id';
  10. protected $field = array(
  11. 'module_name',
  12. 'uid',
  13. 'rank',
  14. );
  15. protected $default = array(
  16. 'module_name' => '',
  17. 'uid' => '',
  18. 'rank' => '',
  19. );
  20. public function getByModuleNameList($modulename_list) {
  21. global $_W;
  22. $this->query->where('uid', $_W['uid']);
  23. if (!empty($modulename_list)) {
  24. $this->query->where('module_name', $modulename_list);
  25. }
  26. return $this->query->getall('module_name');
  27. }
  28. public function getAllByUid($uid) {
  29. global $_W;
  30. return $this->query
  31. ->select(array('module_name', 'rank'))
  32. ->where('uid', $_W['uid'])
  33. ->getall('module_name');
  34. }
  35. public function getByModuleName($module_name) {
  36. global $_W;
  37. return $this->query->where('uid', $_W['uid'])->where('module_name', $module_name)->get();
  38. }
  39. public function getByModuleNameAndUniacid($module_name, $uniacid) {
  40. global $_W;
  41. return $this->query->where('uid', $_W['uid'])->where(array('module_name' => $module_name, 'uniacid' => $uniacid))->get();
  42. }
  43. public function getMaxRank() {
  44. global $_W;
  45. $rank_info = $this->query->select('max(rank)')->where('uid', $_W['uid'])->getcolumn();
  46. return $rank_info;
  47. }
  48. public function setTop($module_name, $uniacid) {
  49. global $_W;
  50. if (empty($module_name) || empty($uniacid)) {
  51. return false;
  52. }
  53. $max_rank = $this->getMaxRank();
  54. $exist = $this->getByModuleNameAndUniacid($module_name, $uniacid);
  55. if (!empty($exist)) {
  56. pdo_update($this->tableName, array('rank' => ($max_rank + 1)), array('module_name' => $module_name, 'uid' => $_W['uid'], 'uniacid' => $uniacid));
  57. } else {
  58. pdo_insert($this->tableName, array('uid' => $_W['uid'], 'module_name' => $module_name, 'uniacid' => $uniacid, 'rank' => ($max_rank + 1)));
  59. }
  60. return true;
  61. }
  62. public function getModuleListByUidAndUniacid() {
  63. global $_W;
  64. return $this->query->where(array('uid' => $_W['uid'], 'uniacid' => $_W['uniacid']))->getall('module_name');
  65. }
  66. }