Modules.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 Modules extends \We7Table {
  8. protected $tableName = 'modules';
  9. protected $primaryKey = 'mid';
  10. protected $templateFields = array('mid', 'name', 'version', 'title', 'description', 'type', 'sections');
  11. protected $field = array(
  12. 'name',
  13. 'type',
  14. 'title',
  15. 'title_initial',
  16. 'version',
  17. 'ability',
  18. 'description',
  19. 'author',
  20. 'url',
  21. 'settings',
  22. 'subscribes',
  23. 'handles',
  24. 'isrulefields',
  25. 'issystem',
  26. 'target',
  27. 'iscard',
  28. 'permissions',
  29. 'wxapp_support',
  30. 'account_support',
  31. 'welcome_support',
  32. 'webapp_support',
  33. 'oauth_type',
  34. 'phoneapp_support',
  35. 'xzapp_support',
  36. 'aliapp_support',
  37. 'logo',
  38. 'baiduapp_support',
  39. 'toutiaoapp_support',
  40. 'cloud_record',
  41. 'sections',
  42. 'application_type',
  43. );
  44. protected $default = array(
  45. 'name' => '',
  46. 'type' => '',
  47. 'title' => '',
  48. 'title_initial' => '',
  49. 'version' => '',
  50. 'ability' => '',
  51. 'description' => '',
  52. 'author' => '',
  53. 'url' => '',
  54. 'settings' => '0',
  55. 'subscribes' => '',
  56. 'handles' => '',
  57. 'isrulefields' => '0',
  58. 'issystem' => '0',
  59. 'target' => '0',
  60. 'iscard' => '0',
  61. 'permissions' => '',
  62. 'wxapp_support' => '1',
  63. 'account_support' => '1',
  64. 'welcome_support' => '1',
  65. 'webapp_support' => '1',
  66. 'oauth_type' => '1',
  67. 'phoneapp_support' => '1',
  68. 'xzapp_support' => '1',
  69. 'aliapp_support' => '1',
  70. 'logo' => '',
  71. 'baiduapp_support' => '1',
  72. 'toutiaoapp_support' => '1',
  73. 'cloud_record' => 0,
  74. 'sectinos' => 0,
  75. 'application_type' => 1,
  76. );
  77. public function bindings() {
  78. return $this->hasMany('modules_bindings', 'module', 'name');
  79. }
  80. public function getByName($module_name) {
  81. $result = $this->query->where('name', $module_name)->get();
  82. if (!empty($result['subscribes'])) {
  83. $result['subscribes'] = iunserializer($result['subscribes']);
  84. }
  85. if (!empty($result['handles'])) {
  86. $result['handles'] = iunserializer($result['handles']);
  87. }
  88. return $result;
  89. }
  90. protected function templatesMidToId($result) {
  91. if (empty($result) || !is_array($result)) {
  92. return array();
  93. }
  94. foreach ($result as $key => $template) {
  95. $result[$key] = $this->templateMidToId($template);
  96. }
  97. return $result;
  98. }
  99. protected function templateMidToId($result) {
  100. global $_W;
  101. if (empty($result) || !is_array($result)) {
  102. return array();
  103. }
  104. $result['id'] = $result['mid'];
  105. if (file_exists('../app/themes/'.$result['name'].'/preview.jpg')) {
  106. $result['logo'] = $_W['siteroot'].'app/themes/'.$result['name'].'/preview.jpg';
  107. } else {
  108. $result['logo'] = $_W['siteroot'].'web/resource/images/nopic-203.png';
  109. }
  110. return $result;
  111. }
  112. public function searchTemplateWithName($module_name) {
  113. return $this->query->where('name', $module_name);
  114. }
  115. public function getAllTemplates($keyfields = '') {
  116. $fields = array('mid', 'name', 'version', 'title', 'description', 'type', 'sections');
  117. $result = $this->query->select($fields)->where(array('application_type' => APPLICATION_TYPE_TEMPLATES, 'account_support' => MODULE_SUPPORT_ACCOUNT))->orderby('mid', 'DESC')->getall($keyfields);
  118. return $this->templatesMidToId($result);
  119. }
  120. public function getTemplateByName($module_name) {
  121. $result = $this->query->select($this->templateFields)->where('name', $module_name)->where('application_type', APPLICATION_TYPE_TEMPLATES)->get();
  122. return $this->templateMidToId($result);
  123. }
  124. public function getTemplateByNames($module_names, $keyfields = '') {
  125. $result = $this->query->select($this->templateFields)->where('name', $module_names)->where('application_type', APPLICATION_TYPE_TEMPLATES)->getall($keyfields);
  126. return $this->templatesMidToId($result);
  127. }
  128. public function getTemplateById($id) {
  129. $result = $this->query->select($this->templateFields)->where('mid', $id)->where('application_type', APPLICATION_TYPE_TEMPLATES)->get();
  130. return $this->templateMidToId($result);
  131. }
  132. public function getAllTemplateByIds($ids, $keyfields = '') {
  133. $result = $this->query->select($this->templateFields)->where('mid', $ids)->where('application_type', APPLICATION_TYPE_TEMPLATES)->orderby('mid', 'DESC')->getall($keyfields);
  134. return $this->templatesMidToId($result);
  135. }
  136. public function getByNameList($modulename_list, $get_system = false) {
  137. $this->query->whereor('name', $modulename_list)->orderby('mid', 'desc');
  138. if (!empty($get_system)) {
  139. $this->whereor('issystem', 1);
  140. }
  141. return $this->query->getall('name');
  142. }
  143. public function deleteByName($module_name) {
  144. return $this->query->where('name', $module_name)->delete();
  145. }
  146. public function getByHasSubscribes() {
  147. return $this->query->select('name', 'subscribes')->where('subscribes !=', '')->getall();
  148. }
  149. public function getSupportWxappList() {
  150. return $this->query->where('wxapp_support', MODULE_SUPPORT_WXAPP)->getall('mid');
  151. }
  152. public function searchWithType($type, $method = '=') {
  153. if ($method == '=') {
  154. $this->query->where('type', $type);
  155. } else {
  156. $this->query->where('type <>', $type);
  157. }
  158. return $this;
  159. }
  160. public function getNonRecycleModules() {
  161. load()->model('module');
  162. $modules = $this->where('issystem' , 0)->orderby('mid', 'DESC')->getall('name');
  163. if (empty($modules)) {
  164. return array();
  165. }
  166. foreach ($modules as &$module) {
  167. $module_info = module_fetch($module['name']);
  168. if (empty($module_info)) {
  169. unset($module);
  170. }
  171. if (!empty($module_info['recycle_info'])) {
  172. foreach (module_support_type() as $support => $value) {
  173. if ($module_info['recycle_info'][$support] > 0 && $module_info[$support] == $value['support']) {
  174. $module[$support] = $value['not_support'];
  175. }
  176. }
  177. }
  178. }
  179. return $modules;
  180. }
  181. public function getInstalled() {
  182. load()->model('module');
  183. $fields = array_keys(module_support_type());
  184. $fields = array_merge(array('name', 'version', 'cloud_record'), $fields);
  185. return $this->query->select($fields)->where(array('issystem' => '0'))->getall('name');
  186. }
  187. }