BxDolAclQuery.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for ACL
  11. * @see BxDolAcl
  12. */
  13. class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
  14. {
  15. protected function __construct()
  16. {
  17. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  18. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  19. parent::__construct();
  20. }
  21. /**
  22. * Prevent cloning the instance
  23. */
  24. public function __clone()
  25. {
  26. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  27. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  28. }
  29. /**
  30. * Get singleton instance of the class
  31. */
  32. static function getInstance()
  33. {
  34. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  35. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolAclQuery();
  36. return $GLOBALS['bxDolClasses'][__CLASS__];
  37. }
  38. function getLevels($aParams, &$aItems, $bReturnCount = true)
  39. {
  40. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  41. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  42. if(!isset($aParams['order']) || empty($aParams['order']))
  43. $sOrderClause = "ORDER BY `tal`.`Order` ASC";
  44. switch($aParams['type']) {
  45. case 'by_id':
  46. $aMethod['name'] = 'getRow';
  47. $aMethod['params'][1] = array(
  48. 'id' => $aParams['value']
  49. );
  50. $sWhereClause .= "AND `tal`.`ID`=:id";
  51. $sLimitClause .= "LIMIT 1";
  52. break;
  53. case 'all_active':
  54. $sWhereClause .= "AND `tal`.`Active`='yes'";
  55. break;
  56. case 'all_active_purchasble_pair':
  57. $aMethod['name'] = "getPairs";
  58. $aMethod['params'][1] = 'id';
  59. $aMethod['params'][2] = 'name';
  60. $sWhereClause .= "AND `tal`.`Active`='yes' AND `tal`.`Purchasable`='yes'";
  61. break;
  62. case 'all_active_pair':
  63. $aMethod['name'] = "getPairs";
  64. $aMethod['params'][1] = 'id';
  65. $aMethod['params'][2] = 'name';
  66. $sWhereClause .= "AND `tal`.`Active`='yes'";
  67. break;
  68. case 'all_active_not_automatic_pair':
  69. $aMethod['name'] = "getPairs";
  70. $aMethod['params'][1] = 'id';
  71. $aMethod['params'][2] = 'name';
  72. $sWhereClause .= "AND `tal`.`Active`='yes' AND `tal`.`ID` NOT IN (" . $this->implode_escape(array(
  73. MEMBERSHIP_ID_NON_MEMBER,
  74. MEMBERSHIP_ID_ACCOUNT,
  75. MEMBERSHIP_ID_UNCONFIRMED,
  76. MEMBERSHIP_ID_PENDING,
  77. MEMBERSHIP_ID_SUSPENDED
  78. )) . ")";
  79. break;
  80. case 'all_pair':
  81. $aMethod['name'] = "getPairs";
  82. $aMethod['params'][1] = 'id';
  83. $aMethod['params'][2] = 'name';
  84. break;
  85. case 'all_order_id':
  86. $sOrderClause = "ORDER BY `tal`.`ID` ASC";
  87. break;
  88. case 'password_can_expired':
  89. $sWhereClause .= "AND PasswordExpired <> 0";
  90. break;
  91. case 'all':
  92. break;
  93. }
  94. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  95. `tal`.`ID` AS `id`,
  96. `tal`.`Name` AS `name`,
  97. `tal`.`Icon` AS `icon`,
  98. `tal`.`Description` AS `description`,
  99. `tal`.`Active` AS `active`,
  100. `tal`.`Purchasable` AS `purchasable`,
  101. `tal`.`Removable` AS `removable`,
  102. `tal`.`QuotaSize` AS `quota_size`,
  103. `tal`.`QuotaNumber` AS `quota_number`,
  104. `tal`.`QuotaMaxFileSize` AS `quota_max_file_size`,
  105. `tal`.`PasswordExpired` AS `password_expired`,
  106. `tal`.`PasswordExpiredNotify` AS `password_expired_notify`,
  107. `tal`.`Order` AS `order`" . $sSelectClause . "
  108. FROM `sys_acl_levels` AS `tal` " . $sJoinClause . "
  109. WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
  110. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  111. if(!$bReturnCount)
  112. return !empty($aItems);
  113. return (int)$this->getOne("SELECT FOUND_ROWS()");
  114. }
  115. function getActions($aParams, &$aItems, $bReturnCount = true)
  116. {
  117. $sMemoryKey = '';
  118. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  119. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  120. if(!isset($aParams['order']) || empty($aParams['order']))
  121. $sOrderClause = "ORDER BY `taa`.`Title` ASC";
  122. switch($aParams['type']) {
  123. case 'by_names_and_module':
  124. $aMethod['params'][1] = array(
  125. 'module' => $aParams['module']
  126. );
  127. $sWhereClause .= " AND `taa`.`Name` IN(" . $this->implode_escape($aParams['value']) . ") AND `taa`.`Module` = :module ";
  128. $sMemoryKey = 'BxDolAclQuery::getActions' . $aParams['type'] . $aParams['module'] . $sWhereClause;
  129. break;
  130. case 'by_names':
  131. $sWhereClause .= " AND `taa`.`Name` IN(" . $this->implode_escape($aParams['value']) . ")";
  132. break;
  133. case 'by_level_id':
  134. $aMethod['params'][1] = array(
  135. 'level_id' => $aParams['value'],
  136. 'level_code' => pow(2, ($aParams['value'] - 1))
  137. );
  138. $sSelectClause .= ", `tam`.`AllowedCount` AS `allowed_count`, `tam`.`AllowedPeriodLen` AS `allowed_period_len`, `tam`.`AllowedPeriodStart` AS `allowed_period_start`, `tam`.`AllowedPeriodEnd` AS `allowed_period_end`, `tam`.`AdditionalParamValue` AS `additional_param_value` ";
  139. $sJoinClause .= "LEFT JOIN `sys_acl_matrix` AS `tam` ON `taa`.`ID`=`tam`.`IDAction` ";
  140. $sWhereClause .= "AND `tam`.`IDLevel`=:level_id AND (`taa`.`DisabledForLevels`='0' OR `taa`.`DisabledForLevels`&:level_code=0)";
  141. break;
  142. case 'by_level_id_key_id':
  143. $aMethod['name'] = 'getAllWithKey';
  144. $aMethod['params'][1] = 'id';
  145. $aMethod['params'][2] = array(
  146. 'level_id' => $aParams['value']
  147. );
  148. $sSelectClause .= ", `tam`.`AllowedCount` AS `allowed_count`, `tam`.`AllowedPeriodLen` AS `allowed_period_len` ";
  149. $sJoinClause .= "LEFT JOIN `sys_acl_matrix` AS `tam` ON `taa`.`ID`=`tam`.`IDAction` ";
  150. $sWhereClause .= "AND `tam`.`IDLevel`=:level_id";
  151. break;
  152. case 'counter_by_modules':
  153. $aMethod['name'] = 'getPairs';
  154. $aMethod['params'][1] = 'module';
  155. $aMethod['params'][2] = 'counter';
  156. $sSelectClause = ", COUNT(*) AS `counter`";
  157. $sGroupClause = "GROUP BY `taa`.`Module`";
  158. break;
  159. case 'counter_by_levels':
  160. $aMethod['name'] = 'getPairs';
  161. $aMethod['params'][1] = 'level_id';
  162. $aMethod['params'][2] = 'counter';
  163. $sSelectClause = ", `tam`.`IDLevel` AS `level_id`, COUNT(`tam`.`IDAction`) AS `counter`";
  164. $sJoinClause = "LEFT JOIN `sys_acl_matrix` AS `tam` ON `taa`.`ID`=`tam`.`IDAction` AND (`taa`.`DisabledForLevels`='0' OR `taa`.`DisabledForLevels`&POW(2, `tam`.`IDLevel`-1)=0) ";
  165. $sGroupClause = "GROUP BY `tam`.`IDLevel`";
  166. break;
  167. }
  168. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  169. `taa`.`ID` AS `id`,
  170. `taa`.`Module` AS `module`,
  171. `taa`.`Name` AS `name`,
  172. `taa`.`Title` AS `title`,
  173. `taa`.`Countable` AS `countable`,
  174. `taa`.`DisabledForLevels` AS `disabled_for_levels`" . $sSelectClause . "
  175. FROM `sys_acl_actions` AS `taa` " . $sJoinClause . "
  176. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  177. if ($sMemoryKey) {
  178. array_unshift($aMethod['params'], $sMemoryKey, $aMethod['name']);
  179. $aItems = call_user_func_array(array($this, 'fromMemory'), $aMethod['params']);
  180. return $bReturnCount ? count($aItems) : !empty($aItems);
  181. }
  182. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  183. if(!$bReturnCount)
  184. return !empty($aItems);
  185. return (int)$this->getOne("SELECT FOUND_ROWS()");
  186. }
  187. /**
  188. * Fetch the last purchased/assigned membership that is still active for the given profile.
  189. *
  190. * NOTE. Don't use cache here, because it's causing an error, if a number of memberrship levels are purchased at the same time.
  191. * fromMemory returns the same DateExpires because setMembership (old buyMembership) function is called in cycle in the same session.
  192. */
  193. function getLevelCurrent($iProfileId, $iTime = 0)
  194. {
  195. $iTime = $iTime == 0 ? time() : (int)$iTime;
  196. $sSql = $this->prepare("
  197. SELECT `sys_acl_levels_members`.`IDLevel` as `id`,
  198. `sys_acl_levels`.`Name` AS `name`,
  199. `sys_acl_levels`.`QuotaSize` AS `quota_size`,
  200. `sys_acl_levels`.`QuotaNumber` AS `quota_number`,
  201. `sys_acl_levels`.`QuotaMaxFileSize` AS `quota_max_file_size`,
  202. UNIX_TIMESTAMP(`sys_acl_levels_members`.`DateStarts`) as `date_starts`,
  203. UNIX_TIMESTAMP(`sys_acl_levels_members`.`DateExpires`) as `date_expires`,
  204. `sys_acl_levels_members`.`State` AS `state`,
  205. `sys_acl_levels_members`.`TransactionID` AS `transaction_id`,
  206. `sys_profiles`.`status`
  207. FROM `sys_acl_levels_members`
  208. RIGHT JOIN `sys_profiles` ON `sys_acl_levels_members`.IDMember = `sys_profiles`.`id`
  209. AND (`sys_acl_levels_members`.DateStarts IS NULL OR `sys_acl_levels_members`.DateStarts <= FROM_UNIXTIME(?))
  210. AND (`sys_acl_levels_members`.DateExpires IS NULL OR `sys_acl_levels_members`.DateExpires > FROM_UNIXTIME(?))
  211. LEFT JOIN `sys_acl_levels` ON `sys_acl_levels_members`.IDLevel = `sys_acl_levels`.ID
  212. WHERE `sys_profiles`.`id` = ?
  213. ORDER BY `sys_acl_levels_members`.DateStarts DESC
  214. LIMIT 1", $iTime, $iTime, $iProfileId);
  215. return $this->fromMemory('BxDolAclQuery::getLevelCurrent' . $iProfileId . $iTime, 'getRow', $sSql);
  216. }
  217. function getLevelByIdCached($iLevel)
  218. {
  219. $sQuery = $this->prepare("SELECT
  220. `tal`.`ID` AS `id`,
  221. `tal`.`Name` AS `name`,
  222. `tal`.`QuotaSize` AS `quota_size`,
  223. `tal`.`QuotaNumber` AS `quota_number`,
  224. `tal`.`QuotaMaxFileSize` AS `quota_max_file_size`
  225. FROM `sys_acl_levels` AS `tal`
  226. WHERE `tal`.`ID`=?
  227. LIMIT 1", $iLevel);
  228. return $this->fromCache('sys_acl_levels' . $iLevel, 'getRow', $sQuery);
  229. }
  230. function getAction($iMembershipId, $iActionId)
  231. {
  232. $sQuery = $this->prepare("SELECT
  233. `tam`.`IDAction` AS `id`,
  234. `taa`.`Name` AS `name`,
  235. `taa`.`Title` AS `title`,
  236. `tam`.`AllowedCount` AS `allowed_count`,
  237. `tam`.`AllowedPeriodLen` AS `allowed_period_len`,
  238. UNIX_TIMESTAMP(`tam`.`AllowedPeriodStart`) as `allowed_period_start`,
  239. UNIX_TIMESTAMP(`tam`.`AllowedPeriodEnd`) as `allowed_period_end`,
  240. `tam`.`AdditionalParamValue` AS `additional_param_value`
  241. FROM `sys_acl_actions` AS `taa`
  242. LEFT JOIN `sys_acl_matrix` AS `tam` ON `tam`.`IDAction` = `taa`.`ID` AND `tam`.`IDLevel` = ?
  243. WHERE `taa`.`ID` = ?", $iMembershipId, $iActionId);
  244. return $this->fromMemory('BxDolAclQuery::getAction' . $iMembershipId . $iActionId, 'getRow', $sQuery);
  245. }
  246. function getActionTrack($iActionId, $iProfileId)
  247. {
  248. $sQuery = $this->prepare("SELECT
  249. `taat`.`ActionsLeft` AS `actions_left`,
  250. UNIX_TIMESTAMP(`taat`.`ValidSince`) as `valid_since`
  251. FROM `sys_acl_actions_track` AS `taat`
  252. WHERE `taat`.`IDAction`=? AND `taat`.`IDMember`=?", $iActionId, $iProfileId);
  253. return $this->getRow($sQuery);
  254. }
  255. function insertActionTarck($iActionId, $iProfileId, $iActionsLeft, $iValidSince)
  256. {
  257. $sQuery = $this->prepare("INSERT INTO `sys_acl_actions_track`(`IDAction`, `IDMember`, `ActionsLeft`, `ValidSince`) VALUES (?, ?, ?, FROM_UNIXTIME(?))", $iActionId, $iProfileId, $iActionsLeft, $iValidSince);
  258. return (int)$this->query($sQuery) > 0;
  259. }
  260. function updateActionTrack($iActionId, $iProfileId, $iActionsLeft, $iValidSince = 0)
  261. {
  262. $aBindings = array(
  263. 'actions_left' => $iActionsLeft,
  264. 'action_id' => $iActionId,
  265. 'member_id' => $iProfileId
  266. );
  267. $sUpdateAddon = "";
  268. if($iValidSince != 0) {
  269. $aBindings['valid_since'] = $iValidSince;
  270. $sUpdateAddon = ", ValidSince=FROM_UNIXTIME(:valid_since)";
  271. }
  272. $sQuery = "UPDATE `sys_acl_actions_track` SET `ActionsLeft`=:actions_left" . $sUpdateAddon . " WHERE `IDAction`=:action_id AND `IDMember`=:member_id";
  273. return (int)$this->query($sQuery, $aBindings) > 0;
  274. }
  275. function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $aPeriod, $sTransactionId)
  276. {
  277. $aBindings = array(
  278. 'member_id' => $iProfileId,
  279. 'level_id' => $iMembershipId,
  280. 'transaction_id' => $sTransactionId,
  281. 'date_starts' => $iDateStarts
  282. );
  283. $sSetClause = '';
  284. if((int)$aPeriod['period'] != 0) {
  285. $aBindings['period'] = (int)$aPeriod['period'];
  286. switch($aPeriod['period_unit']) {
  287. case MEMBERSHIP_PERIOD_UNIT_DAY:
  288. case MEMBERSHIP_PERIOD_UNIT_WEEK:
  289. if($aPeriod['period_unit'] == MEMBERSHIP_PERIOD_UNIT_WEEK)
  290. $aBindings['period'] *= 7;
  291. $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period DAY)";
  292. break;
  293. case MEMBERSHIP_PERIOD_UNIT_MONTH:
  294. $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period MONTH)";
  295. break;
  296. case MEMBERSHIP_PERIOD_UNIT_YEAR:
  297. $sSetClause = "DATE_ADD(FROM_UNIXTIME(:date_starts), INTERVAL :period YEAR)";
  298. break;
  299. }
  300. if(!empty($sSetClause) && !empty($aPeriod['period_reserve'])) {
  301. $aBindings['reserve'] = (int)$aPeriod['period_reserve'];
  302. $sSetClause = "DATE_ADD(" . $sSetClause . ", INTERVAL :reserve DAY)";
  303. }
  304. if(!empty($sSetClause))
  305. $sSetClause = ", `DateExpires`=" . $sSetClause;
  306. if(isset($aPeriod['period_trial']) && $aPeriod['period_trial'] === true) {
  307. $aBindings['state'] = 'trial';
  308. $sSetClause .= ", `State`=:state";
  309. }
  310. }
  311. $sQuery = $this->prepare("INSERT `sys_acl_levels_members` SET `IDMember`=:member_id, `IDLevel`=:level_id, `DateStarts`=FROM_UNIXTIME(:date_starts), `TransactionID`=:transaction_id" . $sSetClause);
  312. return (int)$this->query($sQuery, $aBindings) > 0;
  313. }
  314. function deleteLevelByProfileId($iProfileId, $bAll = false)
  315. {
  316. $sQuery = $this->prepare("DELETE FROM `sys_acl_levels_members` WHERE `IDMember` = ? " . ($bAll ? "" : " AND (`DateExpires` IS NULL OR `DateExpires` > NOW())"), $iProfileId);
  317. return (int)$this->query($sQuery) > 0;
  318. }
  319. function deleteLevelBy($aWhere)
  320. {
  321. if(empty($aWhere))
  322. return false;
  323. $sQuery = "DELETE FROM `sys_acl_levels_members` WHERE " . $this->arrayToSQL($aWhere, ' AND ');
  324. return (int)$this->query($sQuery) > 0;
  325. }
  326. function maintenance($iDaysToCleanMemLevels = 0)
  327. {
  328. $sQuery = $this->prepare("DELETE FROM `sys_acl_levels_members` WHERE `DateExpires` < NOW() - INTERVAL ? DAY", $iDaysToCleanMemLevels);
  329. if ($iDeleteMemLevels = $this->query($sQuery))
  330. $this->query("OPTIMIZE TABLE `sys_acl_levels_members`");
  331. return $iDeleteMemLevels;
  332. }
  333. function clearActionsTracksForMember($iMemberId)
  334. {
  335. $sQuery = $this->prepare("DELETE FROM `sys_acl_actions_track` WHERE `IDMember` = ?", (int)$iMemberId);
  336. return $this->query($sQuery);
  337. }
  338. function getContentByLevelAsSQLPart($sContentTable, $sContentField, $mixedLevelId)
  339. {
  340. $sJoin = $sWhere = "";
  341. $iLevelId = !is_array($mixedLevelId) ? $mixedLevelId : 0;
  342. if (!$iLevelId && is_array($mixedLevelId) && 1 == count($mixedLevelId)) {
  343. $a = array_values($mixedLevelId);
  344. $iLevelId = array_shift($a);
  345. }
  346. // unconfirmed
  347. if (MEMBERSHIP_ID_UNCONFIRMED == $iLevelId) {
  348. return array(
  349. 'where' => " AND `cblasp_a`.`email_confirmed` = 0 ",
  350. 'join' => " INNER JOIN `sys_profiles` AS `cblasp_p` ON (`" . $sContentTable . "`.`" . $sContentField . "`=`cblasp_p`.`id`) INNER JOIN `sys_accounts` AS `cblasp_a` ON (`cblasp_a`.`id`=`cblasp_p`.`account_id`) ",
  351. );
  352. }
  353. // standard
  354. elseif (MEMBERSHIP_ID_STANDARD == $iLevelId) {
  355. $sWhere .= " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW()) AND `tlm`.`IDMember` IS NULL AND `cblasp_a`.`email_confirmed` != 0 ";
  356. $sJoin .= " LEFT JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember` INNER JOIN `sys_profiles` AS `cblasp_p` ON (`" . $sContentTable . "`.`" . $sContentField . "`=`cblasp_p`.`id`) INNER JOIN `sys_accounts` AS `cblasp_a` ON (`cblasp_a`.`id`=`cblasp_p`.`account_id`) ";
  357. return array(
  358. 'where' => $sWhere,
  359. 'join' => $sJoin
  360. );
  361. }
  362. // other levels
  363. else {
  364. if(is_array($mixedLevelId))
  365. $sWhere .= " AND `tlm`.`IDLevel` IN (" . $this->implode_escape($mixedLevelId) . ")";
  366. else
  367. $sWhere .= $this->prepareAsString(" AND `tlm`.`IDLevel` = ?", (int)$mixedLevelId);
  368. $sWhere .= " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW()) AND `cblasp_a`.`email_confirmed` != 0 ";
  369. $sJoin .= " INNER JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember` INNER JOIN `sys_profiles` AS `cblasp_p` ON (`" . $sContentTable . "`.`" . $sContentField . "`=`cblasp_p`.`id`) INNER JOIN `sys_accounts` AS `cblasp_a` ON (`cblasp_a`.`id`=`cblasp_p`.`account_id`) ";
  370. return array(
  371. 'where' => $sWhere,
  372. 'join' => $sJoin
  373. );
  374. }
  375. }
  376. function getContentByActionAsSQLPart($sContentTable, $sContentField, $mixedActionName, $aParams = [])
  377. {
  378. $sWhere = " AND (`tlm`.`DateStarts` IS NULL OR `tlm`.`DateStarts` <= NOW()) AND (`tlm`.`DateExpires` IS NULL OR `tlm`.`DateExpires` > NOW()) ";
  379. $sJoinWhere = "";
  380. if(is_array($mixedActionName))
  381. $sJoinWhere .= " AND `ta`.`Name` IN (" . $this->implode_escape($mixedActionName) . ")";
  382. else
  383. $sJoinWhere .= $this->prepareAsString(" AND `ta`.`Name` = ?", $mixedActionName);
  384. if(!empty($aParams['module']))
  385. $sJoinWhere .= $this->prepareAsString(" AND `ta`.`Module` = ?", $aParams['module']);
  386. $sJoin = " INNER JOIN `sys_acl_levels_members` AS `tlm` ON `" . $sContentTable . "`.`" . $sContentField . "`=`tlm`.`IDMember` INNER JOIN `sys_acl_matrix` AS `tm` ON `tlm`.`IDLevel`=`tm`.`IDLevel` INNER JOIN `sys_acl_actions` AS `ta` ON (`tm`.`IDAction`=`ta`.`ID` " . $sJoinWhere . ") ";
  387. return array(
  388. 'where' => $sWhere,
  389. 'join' => $sJoin
  390. );
  391. }
  392. function getProfilesByMembership($mixedLevelId)
  393. {
  394. $aSqlParts = $this->getContentByLevelAsSQLPart('sys_profiles', 'id', $mixedLevelId);
  395. return $this->getAll("SELECT `sys_profiles`.* FROM `sys_profiles`" . $aSqlParts['join'] . " WHERE 1" . $aSqlParts['where']);
  396. }
  397. function getProfilesByAction($mixedActionName, $aParams = [])
  398. {
  399. $sMethod = "getAll";
  400. $sSqlSelect = "`sys_profiles`.*";
  401. if(isset($aParams['ids_only']) && $aParams['ids_only'] === true) {
  402. $sMethod = "getColumn";
  403. $sSqlSelect = "`sys_profiles`.`id`";
  404. }
  405. $aSqlParts = $this->getContentByActionAsSQLPart('sys_profiles', 'id', $mixedActionName, $aParams);
  406. return $this->$sMethod("SELECT DISTINCT " . $sSqlSelect . " FROM `sys_profiles`" . $aSqlParts['join'] . " WHERE 1" . $aSqlParts['where']);
  407. }
  408. }
  409. /** @} */