BxDolStudioPage.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. defined('BX_DOL') or die('hack attempt');
  10. bx_import('BxDol');
  11. bx_import('BxDolStudioUtils');
  12. bx_import('BxDolStudioPageQuery');
  13. define('BX_DOL_STUDIO_PAGE_HOME', 'home');
  14. define('BX_DOL_STUDIO_PAGE_JS_OBJECT', 'oBxDolStudioPage');
  15. define('BX_DOL_STUDIO_MIT_CAPTION', 'caption');
  16. define('BX_DOL_STUDIO_MIT_ITEM', 'item');
  17. class BxDolStudioPage extends BxDol {
  18. protected $oDb;
  19. protected $aPage;
  20. protected $bPageMultiple;
  21. protected $sPageSelected;
  22. protected $aActions;
  23. function BxDolStudioPage($mixedPageName) {
  24. parent::BxDol();
  25. $this->oDb = new BxDolStudioPageQuery();
  26. $this->aPage = array();
  27. $this->bPageMultiple = false;
  28. $this->sPageSelected = '';
  29. $this->aActions = array();
  30. if(is_string($mixedPageName)) {
  31. $this->oDb->getPages(array('type' => 'by_page_name_full', 'value' => $mixedPageName), $this->aPage, false);
  32. if(empty($this->aPage) || !is_array($this->aPage))
  33. return;
  34. $this->aPage['bookmarked'] = $this->oDb->isBookmarked($this->aPage);
  35. }
  36. else if(is_array($mixedPageName)) {
  37. $aPages = array();
  38. $this->oDb->getPages(array('type' => 'by_page_names_full', 'value' => array_keys($mixedPageName)), $aPages, false);
  39. if(empty($this->aPage) || !is_array($this->aPage))
  40. return;
  41. $this->bPageMultiple = true;
  42. foreach($aPages as $aPage) {
  43. if((int)$mixedPageName[$aPage['name']] == 1)
  44. $this->sPageSelected = $aPage['name'];
  45. $aPage['bookmarked'] = $this->oDb->isBookmarked($aPage);
  46. $this->aPage[$aPage['name']] = $aPage;
  47. }
  48. }
  49. if(!$this->bPageMultiple)
  50. $this->addAction(array(
  51. 'type' => 'switcher',
  52. 'name' => 'bookmark',
  53. 'caption' => '_adm_txt_pca_favorite',
  54. 'checked' => $this->aPage['bookmarked'],
  55. 'onchange' => "javascript:" . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".bookmark('" . $this->aPage['name'] . "', this)"
  56. ));
  57. }
  58. function addAction($aAction, $bOnRight = true) {
  59. if($bOnRight)
  60. $this->aActions[] = $aAction;
  61. else
  62. $this->aActions = array_merge(array($aAction), $this->aActions);
  63. }
  64. function removeActions() {
  65. $this->aActions = array();
  66. }
  67. function bookmark() {
  68. $bResult = $this->oDb->bookmark($this->aPage);
  69. if(!$bResult)
  70. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  71. bx_import('BxDolStudioTemplate');
  72. $oTemplate = BxDolStudioTemplate::getInstance();
  73. $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  74. if($this->aPage['bookmarked']) {
  75. $aResult['icon'] = $oTemplate->getIconUrl('ics-star-act.png');
  76. $aResult['title'] = bx_js_string(_t('_adm_txt_favorites_remove'));
  77. }
  78. else {
  79. $aResult['icon'] = $oTemplate->getIconUrl('ics-star-pas.png');
  80. $aResult['title'] = bx_js_string(_t('_adm_txt_favorites_add'));
  81. }
  82. return $aResult;
  83. }
  84. protected function getSystemName($sValue) {
  85. return BxDolStudioUtils::getSystemName($sValue);
  86. }
  87. protected function getClassName($sValue) {
  88. return BxDolStudioUtils::getClassName($sValue);
  89. }
  90. protected function getModuleTitle($sName) {
  91. return BxDolStudioUtils::getModuleTitle($sName);
  92. }
  93. protected function getModuleIcon($sName, $sType = 'menu') {
  94. return BxDolStudioUtils::getModuleIcon($sName, $sType);
  95. }
  96. protected function getModules($bShowCustom = true, $bShowSystem = true) {
  97. return BxDolStudioUtils::getModules($bShowCustom, $bShowSystem);
  98. }
  99. }
  100. /** @} */