Modules.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\Uni;
  7. class Modules extends \We7Table {
  8. protected $tableName = 'uni_modules';
  9. protected $primaryKey = 'id';
  10. protected $field = array(
  11. 'uniacid',
  12. 'module_name',
  13. );
  14. protected $default = array(
  15. 'uniacid' => '',
  16. 'module_name' => '',
  17. );
  18. public function getAllByModuleName($module_name) {
  19. return $this->query->select('uniacid')->where('module_name', $module_name)->getall('uniacid');
  20. }
  21. public function getallByUniacid($uniacid) {
  22. return $this->query->where('uniacid', $uniacid)->getall();
  23. }
  24. public function searchLikeModuleTitle($module_title) {
  25. return $this->query->where('m.title LIKE', "%{$module_title}%");
  26. }
  27. public function searchWithModuleLetter($module_letter) {
  28. return $this->query->where('m.title_initial', $module_letter);
  29. }
  30. public function searchWithModuleName($module_name) {
  31. $this->query->where('u.module_name', $module_name);
  32. }
  33. public function searchGroupbyModuleName() {
  34. return $this->query->groupby('u.module_name');
  35. }
  36. public function getModulesByUid($uid, $uniacid = 0) {
  37. global $_W;
  38. if (empty($uid)) {
  39. $uid = $_W['uid'];
  40. }
  41. if (!empty($uniacid)) {
  42. $this->where('u.uniacid', $uniacid);
  43. } else {
  44. $this->where('u.uniacid <>', 0);
  45. }
  46. $select_fields = "
  47. u.uniacid,
  48. u.module_name
  49. ";
  50. if (!user_is_founder($uid) && $_W['highest_role'] != ACCOUNT_MANAGE_NAME_CLERK || user_is_vice_founder($uid)) {
  51. $select_fields .= ", uau.role";
  52. $this->where('uau.uid', $uid);
  53. $this->query->from('uni_account_users', 'uau')
  54. ->leftjoin('uni_modules', 'u')
  55. ->on(array('uau.uniacid' => 'u.uniacid'));
  56. } elseif ($_W['highest_role'] == ACCOUNT_MANAGE_NAME_CLERK) {
  57. $select_fields .= ", up.uniacid as permission_uniacid";
  58. $this->where('up.uid', $uid);
  59. $this->query->from('users_permission', 'up')
  60. ->leftjoin('uni_modules', 'u')
  61. ->on(array('up.type' => 'u.module_name', 'up.uniacid' => 'u.uniacid'));
  62. } else {
  63. $this->query->from('uni_modules', 'u');
  64. }
  65. $modules = $this->query
  66. ->select($select_fields)
  67. ->getall();
  68. $total = $this->getLastQueryTotal();
  69. return array('modules' => $modules, 'total' => $total);
  70. }
  71. public function deleteUniModules($module_name, $uniacid) {
  72. $this->query->where('module_name', $module_name)->where('uniacid', $uniacid)->delete();
  73. }
  74. public function searchWithUsersOperateStar($uid) {
  75. $this->query->from('uni_modules', 'u');
  76. $this->query
  77. ->leftjoin('users_operate_star', 's')
  78. ->on(array('u.uniacid' => 's.uniacid', 'u.module_name' => 's.module_name', 's.type' => 2, 's.uid' => $uid));
  79. $this->query
  80. ->select('u.*, s.rank')
  81. ->orderby('s.rank', 'desc');
  82. return $this;
  83. }
  84. }