PluginRank.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 PluginRank extends \We7Table {
  8. protected $tableName = 'modules_plugin_rank';
  9. protected $primaryKey = 'id';
  10. protected $field = array(
  11. 'uniacid',
  12. 'uid',
  13. 'rank',
  14. 'plugin_name',
  15. 'main_module_name',
  16. );
  17. protected $default = array(
  18. 'uniacid' => '0',
  19. 'uid' => '0',
  20. 'rank' => '0',
  21. 'plugin_name' => '',
  22. 'main_module_name' => '',
  23. );
  24. public function getByPluginNameAndUniacid($plugin_name, $uniacid) {
  25. global $_W;
  26. return $this->query->where('uid', $_W['uid'])->where(array('plugin_name' => $plugin_name, 'uniacid' => $uniacid))->get();
  27. }
  28. public function getMaxRank() {
  29. global $_W;
  30. $rank_info = $this->query->select('max(rank)')->where('uid', $_W['uid'])->getcolumn();
  31. return $rank_info;
  32. }
  33. public function setTop($plugin_name, $main_module_name, $uniacid) {
  34. global $_W;
  35. if (empty($plugin_name) || empty($uniacid)) {
  36. return false;
  37. }
  38. $max_rank = $this->getMaxRank();
  39. $exist = $this->getByPluginNameAndUniacid($plugin_name, $uniacid);
  40. if (!empty($exist)) {
  41. pdo_update($this->tableName, array('rank' => ($max_rank + 1)), array('plugin_name' => $plugin_name, 'uid' => $_W['uid'], 'uniacid' => $uniacid));
  42. } else {
  43. pdo_insert($this->tableName, array('uid' => $_W['uid'], 'plugin_name' => $plugin_name, 'main_module_name' => $main_module_name, 'uniacid' => $uniacid, 'rank' => ($max_rank + 1)));
  44. }
  45. return true;
  46. }
  47. public function searchWithUid($uid) {
  48. return $this->query->where('r.uid', $uid);
  49. }
  50. public function getPluginRankList($main_module, $uniacid) {
  51. return $this->query
  52. ->select('p.name, r.uid, r.uniacid, r.rank')
  53. ->from('modules_plugin', 'p')
  54. ->leftjoin('modules_plugin_rank', 'r')
  55. ->on(array('p.name' => 'r.plugin_name'))
  56. ->where('p.main_module', $main_module)
  57. ->where('r.uniacid', $uniacid)
  58. ->orderby('r.rank', 'DESC')
  59. ->getall('name');
  60. }
  61. }