Răsfoiți Sursa

#5000 Workspaces module: global context

Alex Trofimov 1 an în urmă
părinte
comite
5c776c325d

+ 40 - 0
inc/utils.inc.php

@@ -2778,4 +2778,44 @@ function bx_is_serialized($string)
     return preg_match('/^([adObis]):[0-9]+:/', $string) === 1;
 }
 
+
+function bx_get_context_workspace($bFromCache = true)
+{
+    if ($bFromCache && !empty($GLOBALS['bxWorkspaceContext']))
+        return $GLOBALS['bxWorkspaceContext'];
+
+    $o = BxDolProfile::getInstance();
+    if (!$o) {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    $sModule = $o->getModule();
+    if ($sModule !== 'bx_workspaces') {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    $sModuleContext = getParam('bx_workspaces_context_module');
+    if (!$sModuleContext) {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    $oModuleContext = BxDolModule::getInstance($sModuleContext);
+    if (!$oModuleContext) {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    $CNF = $oModuleContext->_oConfig->CNF;
+    $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
+    if (!$oConnection) {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    $a = $oConnection->getConnectedContent ($o->id(), true, 0, 1);
+    if (!$a) {
+        return ($GLOBALS['bxWorkspaceContext'] = false);
+    }
+
+    return ($GLOBALS['bxWorkspaceContext'] = array_pop($a));
+}
+
 /** @} */

+ 13 - 0
modules/boonex/workspaces/classes/BxWorkspacesAlertsResponse.php

@@ -21,6 +21,19 @@ class BxWorkspacesAlertsResponse extends BxBaseModProfileAlertsResponse
     {
         $sContextModule = getParam('bx_workspaces_context_module');
 
+        // logo URL is refferring to the context when in workspace
+        if ('system' == $oAlert->sUnit && 'get_logo' == $oAlert->sAction && bx_get_context_workspace()) {
+            $o = BxDolProfile::getInstance(bx_get_context_workspace());
+            if ($o) {
+                $oAlert->aExtras['tmpl_vars']['attrs'] = preg_replace('/href="([^"]+)" title="([^"]+)"/', 'href="' . $o->getUrl() . '" title="' . $o->getDisplayName() . '"', $oAlert->aExtras['tmpl_vars']['attrs']);
+            }
+        }
+
+        // site menu is off when in workspace
+        if ($sContextModule && 'menu' == $oAlert->sUnit && 'get_code_before' == $oAlert->sAction && isset($oAlert->aExtras['object_name']) && $oAlert->aExtras['object_name'] == 'sys_site' && bx_get_context_workspace()) {
+            $oAlert->aExtras['override_result'] = "site menu is off when in workspace (" . bx_get_context_workspace() . ")";
+        }
+
         // TODO: replace 'bx_groups_fans' with proper connection object from $sContextModule
 
         if ($sContextModule && 'system' == $oAlert->sUnit && 'connection_before_add' == $oAlert->sAction && isset($oAlert->aExtras['object_name']) && $oAlert->aExtras['object_name'] == 'bx_groups_fans') {

+ 3 - 1
modules/boonex/workspaces/install/sql/enable.sql

@@ -544,7 +544,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_workspaces', 'timeline_pin', @iHandler),
 ('bx_workspaces', 'timeline_promote', @iHandler),
 ('system', 'connection_before_add', @iHandler),
-('system', 'connection_removed', @iHandler);
+('system', 'connection_removed', @iHandler),
+('menu', 'get_code_before', @iHandler),
+('system', 'get_logo', @iHandler);
 
 -- PRIVACY 
 INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `spaces`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES