| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup DolphinStudio Dolphin Studio
- * @{
- */
- defined('BX_DOL') or die('hack attempt');
- bx_import('BxDol');
- define('BX_DOL_STUDIO_MODULE_SYSTEM', 'system');
- define('BX_DOL_STUDIO_MODULE_CUSTOM', 'custom');
- define('BX_DOL_STUDIO_VISIBLE_ALL', 'all');
- define('BX_DOL_STUDIO_VISIBLE_SELECTED', 'selected');
- class BxDolStudioUtils extends BxDol {
- function __construct() {
- parent::BxDol();
- }
- public static function getSystemName($sValue) {
- return str_replace(' ', '_', strtolower($sValue));
- }
- public static function getClassName($sValue) {
- return str_replace(' ', '', ucwords(str_replace('_', ' ', $sValue)));
- }
- public static function getModuleIcon($sName, $sType = 'menu') {
- $aType2Prefix = array('menu' => 'mi', 'page' => 'pi');
- $oTemplate = BxDolStudioTemplate::getInstance();
- $sDefaultIcon = $oTemplate->getIconUrl($aType2Prefix[$sType] . '-mod-empty.png');
- bx_import('BxDolModuleQuery');
- $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sName);
- if(empty($aModule))
- return $sDefaultIcon;
- $sModuleIcon = isset($aModule['path']) ? $oTemplate->getIconUrl($aModule['name'] . '@modules/' . $aModule['path'] . '|std-' . $aType2Prefix[$sType] . '.png') : '';
- return !empty($sModuleIcon) ? $sModuleIcon : $sDefaultIcon;
- }
- public static function getModuleTitle($sName) {
- $sPrefix = '_adm_txt_module_';
-
- if(in_array($sName, array(BX_DOL_STUDIO_MODULE_SYSTEM, BX_DOL_STUDIO_MODULE_CUSTOM)))
- return _t($sPrefix . $sName);
-
- bx_import('BxDolModuleQuery');
- $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sName);
- if(!empty($aModule))
- return $aModule['title'];
-
- return _t($sPrefix . strtolower($sName));
- }
- public static function getModules($bShowCustom = true, $bShowSystem = true) {
- $aResult = array();
-
- if($bShowSystem)
- $aResult[BX_DOL_STUDIO_MODULE_SYSTEM] = self::getModuleTitle(BX_DOL_STUDIO_MODULE_SYSTEM);
-
- if($bShowCustom)
- $aResult[BX_DOL_STUDIO_MODULE_CUSTOM] = self::getModuleTitle(BX_DOL_STUDIO_MODULE_CUSTOM);
-
- bx_import('BxDolModuleQuery');
- $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
- foreach($aModules as $aModule)
- $aResult[$aModule['name']] = $aModule['title'];
-
- return $aResult;
- }
- public static function getVisibilityTitle($iValue) {
- $iCount = self::getVisibilityCount($iValue);
- $sResult = "";
- switch($iCount) {
- case 1:
- bx_import('BxDolAcl');
- $aLevel = BxDolAcl::getInstance()->getMembershipInfo(log($iValue, 2) + 1);
- $sResult = _t($aLevel['name']);
- break;
- case 0:
- $sResult = _t('_adm_prm_txt_visibility_items_nobody');
- break;
- case -1:
- $sResult = _t('_adm_prm_txt_visibility_items_anyone');
- break;
- default:
- $sResult = _t('_adm_prm_txt_visibility_items_n_user_levels', $iCount);
- }
- return $sResult;
- }
-
- public static function getVisibilityCount($iValue) {
- $iResult = 0;
- $iValue = (int)$iValue;
- if($iValue == 0)
- return $iResult;
- else if($iValue == BX_DOL_INT_MAX)
- return -1;
- bx_import('BxDolAcl');
- $aLevels = BxDolAcl::getInstance()->getMemberships(false, true);
- $iIndex = 1;
- do {
- if(array_key_exists($iIndex++, $aLevels))
- $iResult += $iValue & 1;
- } while(($iValue = $iValue >> 1) != 0);
- return $iResult;
- }
- public static function getVisibilityValue($sVisibleFor, $aVisibleForLevels) {
- if($sVisibleFor == BX_DOL_STUDIO_VISIBLE_ALL)
- return BX_DOL_INT_MAX;
- $iVisibleFor = 0;
- if(is_array($aVisibleForLevels))
- foreach($aVisibleForLevels as $iLevelId)
- $iVisibleFor += pow(2, (int)$iLevelId - 1);
- return $iVisibleFor;
- }
- public static function getVisibilityValues($iValue, &$aValuesAll, &$aValuesSelected) {
- bx_import('BxDolAcl');
- $aLevels = BxDolAcl::getInstance()->getMemberships(false, true);
- foreach($aLevels as $iKey => $sValue) {
- if(((int)$iValue & pow(2, (int)$iKey - 1)) != 0)
- $aValuesSelected[] = $iKey;
-
- $aValuesAll[$iKey] = _t($sValue);
- }
- }
- public static function addInArray($aInput, $sKey, $aValues) {
- reset($aInput);
- $iInput = count($aInput);
- for($i = 0; $i < $iInput; $i++, next($aInput))
- if(key($aInput) == $sKey)
- break;
-
- $aOutput = array_slice($aInput, 0, $i + 1);
- $aOutput = array_merge($aOutput, $aValues);
- $aOutput = array_merge($aOutput, array_slice($aInput, $i + 1));
-
- return $aOutput;
- }
- }
- /** @} */
|