1
0

BxDolModuleQuery.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolDb');
  10. class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton {
  11. function BxDolModuleQuery() {
  12. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  13. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  14. parent::BxDolDb();
  15. }
  16. /**
  17. * Prevent cloning the instance
  18. */
  19. public function __clone() {
  20. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  21. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  22. }
  23. /**
  24. * Get singleton instance of the class
  25. */
  26. public static function getInstance() {
  27. $sClass = __CLASS__;
  28. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  29. $GLOBALS['bxDolClasses'][__CLASS__] = new $sClass();
  30. return $GLOBALS['bxDolClasses'][__CLASS__];
  31. }
  32. function getModuleById($iId) {
  33. $sSql = $this->prepare("SELECT `id`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` WHERE `id`=? LIMIT 1", $iId);
  34. return $this->fromMemory('sys_modules_' . $iId, 'getRow', $sSql);
  35. }
  36. function getModuleByName($sName) {
  37. $sSql = $this->prepare("SELECT `id`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` WHERE `name`=? LIMIT 1", $sName);
  38. return $this->fromMemory('sys_modules_' . $sName, 'getRow', $sSql);
  39. }
  40. function getModuleByUri($sUri) {
  41. $sSql = $this->prepare("SELECT `id`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` WHERE `uri`=? LIMIT 1", $sUri);
  42. return $this->fromMemory('sys_modules_' . $sUri, 'getRow', $sSql);
  43. }
  44. function enableModuleByUri($sUri) {
  45. $sSql = $this->prepare("UPDATE `sys_modules` SET `enabled`='1' WHERE `uri`=? LIMIT 1", $sUri);
  46. return (int)$this->query($sSql) > 0;
  47. }
  48. function disableModuleByUri($sUri) {
  49. $sSql = $this->prepare("UPDATE `sys_modules` SET `enabled`='0' WHERE `uri`=? LIMIT 1", $sUri);
  50. return (int)$this->query($sSql) > 0;
  51. }
  52. function isModule($sUri) {
  53. $sSql = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `uri`=? LIMIT 1", $sUri);
  54. return (int)$this->getOne($sSql) > 0;
  55. }
  56. function isModuleByName($sName) {
  57. $sSql = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `name`=? LIMIT 1", $sName);
  58. return (int)$this->getOne($sSql) > 0;
  59. }
  60. function isModuleParamsUsed($sUri, $sPath, $sPrefixDb, $sPrefixClass) {
  61. $sSql = "SELECT `id` FROM `sys_modules` WHERE `uri`='" . $sUri . "' || `path`='" . $sPath . "' || `db_prefix`='" . $sPrefixDb . "' || `class_prefix`='" . $sPrefixClass . "' LIMIT 1";
  62. return (int)$this->getOne($sSql) > 0;
  63. }
  64. function isEnabled($sUri) {
  65. $sSql = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `uri`=? AND `enabled`='1' LIMIT 1", $sUri);
  66. return (int)$this->getOne($sSql) > 0;
  67. }
  68. function isEnabledByName($sName) {
  69. $sSql = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `name`=? AND `enabled`='1' LIMIT 1", $sName);
  70. return (int)$this->getOne($sSql) > 0;
  71. }
  72. function getModules() {
  73. $sSql = "SELECT `id`, `type`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` ORDER BY `title`";
  74. return $this->fromMemory('sys_modules', 'getAll', $sSql);
  75. }
  76. function getModulesBy($aParams = array()) {
  77. $sPostfix = $sWhereClause = "";
  78. switch($aParams['type']) {
  79. case 'modules':
  80. $sPostfix .= '_modules';
  81. $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_MODULE);
  82. break;
  83. case 'languages':
  84. $sPostfix .= '_languages';
  85. $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_LANGUAGE);
  86. break;
  87. case 'templates':
  88. $sPostfix .= '_templates';
  89. $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_TEMPLATE);
  90. break;
  91. }
  92. if(isset($aParams['active'])) {
  93. $sPostfix .= "_active";
  94. $sWhereClause .= $this->prepare(" AND `enabled`=?", (int)$aParams['active']);
  95. }
  96. $sSql = "SELECT
  97. `id`,
  98. `type`,
  99. `name`,
  100. `title`,
  101. `vendor`,
  102. `version`,
  103. `product_url`,
  104. `update_url`,
  105. `path`,
  106. `uri`,
  107. `class_prefix`,
  108. `db_prefix`,
  109. `lang_category`,
  110. `date`,
  111. `enabled`
  112. FROM `sys_modules`
  113. WHERE 1" . $sWhereClause . "
  114. ORDER BY `title`";
  115. return $this->fromMemory('sys_modules' . $sPostfix, 'getAll', $sSql);
  116. }
  117. function getModulesUri() {
  118. $sSql = "SELECT `uri` FROM `sys_modules` ORDER BY `uri`";
  119. return $this->fromMemory('sys_modules_uri', 'getColumn', $sSql);
  120. }
  121. function getDependent($sUri) {
  122. $sSql = "SELECT `id`, `title` FROM `sys_modules` WHERE `dependencies` LIKE '%" . $this->escape($sUri) . "%'";
  123. return $this->getAll($sSql);
  124. }
  125. }
  126. /** @} */