人人商城

Rank.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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->select(array('rank', 'module_name'))->getall('module_name');
  27. }
  28. public function getByModuleName($module_name) {
  29. global $_W;
  30. return $this->query->where('uid', $_W['uid'])->where('module_name', $module_name)->get();
  31. }
  32. public function getMaxRank() {
  33. global $_W;
  34. $rank_info = $this->query->select('max(rank)')->where('uid', $_W['uid'])->getcolumn();
  35. return $rank_info;
  36. }
  37. public function setTop($module_name) {
  38. global $_W;
  39. if (empty($module_name)) {
  40. return false;
  41. }
  42. $max_rank = $this->getMaxRank();
  43. $exist = $this->getByModuleName($module_name);
  44. if (!empty($exist)) {
  45. pdo_update($this->tableName, array('rank' => ($max_rank + 1)), array('module_name' => $module_name, 'uid' => $_W['uid']));
  46. } else {
  47. pdo_insert($this->tableName, array('uid' => $_W['uid'], 'module_name' => $module_name, 'rank' => ($max_rank + 1)));
  48. }
  49. return true;
  50. }
  51. }