AntonLV 12 лет назад
Родитель
Сommit
542a3ce17c

+ 2 - 2
inc/classes/BxDolMenu.php

@@ -183,10 +183,10 @@ class BxDolMenu extends BxDol implements iBxDolFactoryObject, iBxDolReplaceable
         ));
 
         // get list of menu triggers
-        $aMenuItem = BxDolMenuQuery::getMenuTriggers($sMenuTriggerName);
+        $aMenuItems = BxDolMenuQuery::getMenuTriggers($sMenuTriggerName);
 
         // check each menu item trigger for all modules
-        foreach ($aMenuItem as $aMenuItem) {
+        foreach ($aMenuItems as $aMenuItem) {
             foreach ($aModules as $aModule) {
                 if (!BxDolRequest::serviceExists($aModule['name'], 'get_menu_set_name_for_menu_trigger'))
                     continue;

+ 38 - 0
inc/classes/BxDolPage.php

@@ -178,6 +178,44 @@ class BxDolPage extends BxDol implements iBxDolFactoryObject, iBxDolReplaceable
         return ($GLOBALS['bxDolClasses']['BxDolPage!'.$sObject] = $o);
     }
 
+	/**
+     * Process page triggers.
+     * Page triggers allow to automatically add page blocks to modules with no different if dependant module was install before or after the module page block belongs to.
+     * For example module "Notes" adds page blocks to all profiles modules (Persons, Organizations, etc)
+     * with no difference if persons module was installed before or after "Notes" module was installed.
+     * @param $sPageTriggerName trigger name to process, usually specified in module installer class - @see BxBaseModGeneralInstaller
+     * @return always true, always success
+     */
+    static public function processPageTrigger ($sPageTriggerName)
+    {
+        // get list of active modules
+        bx_import('BxDolModuleQuery');
+        $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array(
+            'type' => 'modules',
+            'active' => 1,
+        ));
+
+        // get list of menu triggers
+        $aPageBlocks = BxDolPageQuery::getPageTriggers($sPageTriggerName);
+
+        // check each menu item trigger for all modules
+        foreach ($aPageBlocks as $aPageBlock) {
+            foreach ($aModules as $aModule) {
+                if (!BxDolRequest::serviceExists($aModule['name'], 'get_page_object_for_page_trigger'))
+                    continue;
+
+				$sPageObject = BxDolService::call($aModule['name'], 'get_page_object_for_page_trigger', array($sPageTriggerName));
+                if (!$sPageObject)
+                    continue;
+
+                $aPageBlock['object'] = $sPageObject;
+                BxDolPageQuery::addPageBlockToPage($aPageBlock);
+            }
+        }
+
+        return true;
+    }
+
     /**
      * Add replace markers. Markers are replaced in raw, html, lang blocks and page title, description, keywords and block titles.
      * @param $a array of markers as key => value

+ 27 - 0
inc/classes/BxDolPageQuery.php

@@ -39,6 +39,33 @@ class BxDolPageQuery extends BxDolDb
         return $oDb->getOne($sQuery);
     }
 
+	static public function getPageTriggers($sTriggerName)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_pages_blocks` WHERE `object` = ? ORDER BY `id` ASC", $sTriggerName);
+        return $oDb->getAll($sQuery);
+    }
+
+    static public function addPageBlockToPage($aPageBlock)
+    {
+        $oDb = BxDolDb::getInstance();
+
+        if (empty($aPageBlock['object']))
+            return false;
+
+        if (empty($aPageBlock['order'])) {
+        	$iCellId = !empty($aPageBlock['cell_id']) ? (int)$aPageBlock['cell_id'] : 1;
+            $sQuery = $oDb->prepare("SELECT `order` FROM `sys_pages_blocks` WHERE `object` = ? AND `cell_id` = ? AND `active` = 1 ORDER BY `order` DESC LIMIT 1", $aPageBlock['object'], $iCellId);
+            $aPageBlock['order'] = (int)$oDb->getOne($sQuery) + 1;
+        }
+
+        $sQuery = $oDb->prepare("DELETE FROM `sys_pages_blocks` WHERE `object` = ? AND `type` = ? AND `title` = ?", $aPageBlock['object'], $aPageBlock['type'], $aPageBlock['title']);
+        $oDb->query($sQuery);
+
+        unset($aPageBlock['id']);
+        return $oDb->query("INSERT INTO `sys_pages_blocks` SET " . $oDb->arrayToSQL($aPageBlock));
+    }
+
     public function getPageBlocks()
     {
         $aRet = array ();

+ 8 - 0
modules/base/general/classes/BxBaseModGeneralInstaller.php

@@ -24,6 +24,8 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
     protected $_aMenuTriggers = array(); // list of menu triggers, it must be specified in the module which adds menu item and in modules where menu items are added, @see BxDolMenu::processMenuTrigger
 
+    protected $_aPageTriggers = array(); // list of page triggers, it must be specified in the module which adds page block and in modules where page blocks are added, @see BxDolMenu::processPageTrigger
+
     function __construct($aConfig)
     {
         parent::__construct($aConfig);
@@ -44,6 +46,12 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
                 BxDolMenu::processMenuTrigger($sMenuTriggerName);
         }
 
+	    if ($this->_aPageTriggers) {
+            bx_import('BxDolPage');
+            foreach ($this->_aPageTriggers as $sPageTriggerName)
+                BxDolPage::processPageTrigger($sPageTriggerName);
+        }
+
         return $aResult;
     }
 

+ 8 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -62,6 +62,14 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolPro
         return '';
     }
 
+	public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
+    {
+        if(isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
+        	return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
+
+        return '';
+    }
+
     public function serviceProfilesSearch ($sTerm, $iLimit)
     {
         $aRet = array();

+ 3 - 0
modules/boonex/organizations/classes/BxOrgsConfig.php

@@ -85,10 +85,13 @@ class BxOrgsConfig extends BxBaseModProfileConfig
             'OBJECT_MENU_SUBMENU_VIEW_ENTRY' => 'bx_organizations_view_submenu',  // view entry submenu
             'OBJECT_MENU_SUBMENU_VIEW_ENTRY_MAIN_SELECTION' => 'organizations-home', // first item in view entry submenu from main module submenu
             'OBJECT_MENU_MANAGE_TOOLS' => 'bx_organizations_menu_manage_tools', //manage menu in content administration tools
+            'OBJECT_PAGE_VIEW_ENTRY' => 'bx_organizations_view_profile',
             'OBJECT_GRID_ADMINISTRATION' => 'bx_organizations_administration',
         	'OBJECT_GRID_MODERATION' => 'bx_organizations_moderation',
         	'OBJECT_GRID_COMMON' => 'bx_organizations_common',
 
+        	'TRIGGER_PAGE_VIEW_ENTRY' => 'trigger_page_organizations_view_entry',
+
             // menu items which visibility depends on custom visibility checking
             'MENU_ITEM_TO_METHOD' => array (
                 'bx_organizations_view_actions' => $aMenuItems2Methods,

+ 1 - 0
modules/boonex/organizations/install/installer.php

@@ -23,6 +23,7 @@ class BxOrgsInstaller extends BxBaseModProfileInstaller
             'sys_profiles_subscriptions' => array ('type' => 'profiles'),
         );
         $this->_aMenuTriggers = array ('trigger_profile_view_submenu');
+        $this->_aPageTriggers = array ('trigger_page_organizations_view_entry');
     }
 }
 

+ 3 - 0
modules/boonex/persons/classes/BxPersonsConfig.php

@@ -85,10 +85,13 @@ class BxPersonsConfig extends BxBaseModProfileConfig
             'OBJECT_MENU_SUBMENU_VIEW_ENTRY' => 'bx_persons_view_submenu',  // view entry submenu
             'OBJECT_MENU_SUBMENU_VIEW_ENTRY_MAIN_SELECTION' => 'persons-home', // first item in view entry submenu from main module submenu
             'OBJECT_MENU_MANAGE_TOOLS' => 'bx_persons_menu_manage_tools', //manage menu in content administration tools
+            'OBJECT_PAGE_VIEW_ENTRY' => 'bx_persons_view_profile',
             'OBJECT_GRID_ADMINISTRATION' => 'bx_persons_administration',
         	'OBJECT_GRID_MODERATION' => 'bx_persons_moderation',
         	'OBJECT_GRID_COMMON' => 'bx_persons_common',
 
+        	'TRIGGER_PAGE_VIEW_ENTRY' => 'trigger_page_persons_view_entry',
+
             // menu items which visibility depends on custom visibility checking
             'MENU_ITEM_TO_METHOD' => array (
                 'bx_persons_view_actions' => $aMenuItems2Methods,

+ 1 - 0
modules/boonex/persons/install/installer.php

@@ -23,6 +23,7 @@ class BxPersonsInstaller extends BxBaseModProfileInstaller
             'sys_profiles_subscriptions' => array ('type' => 'profiles'),
         );
         $this->_aMenuTriggers = array ('trigger_profile_view_submenu', 'trigger_profile_view_actions');
+        $this->_aPageTriggers = array ('trigger_page_persons_view_entry');
     }
 }
 

+ 1 - 0
modules/boonex/timeline/install/installer.php

@@ -18,6 +18,7 @@ class BxTimelineInstaller extends BxBaseModNotificationsInstaller
         parent::__construct($aConfig);
         $this->_aTranscoders = array ('bx_timeline_photos_preview', 'bx_timeline_photos_view');
         $this->_aStorages = array ('bx_timeline_photos');
+        $this->_aPageTriggers = array ('trigger_page_persons_view_entry', 'trigger_page_organizations_view_entry');
     }
 }
 

+ 4 - 2
modules/boonex/timeline/install/langs/en.xml

@@ -52,8 +52,10 @@
 	<string name="_bx_timeline_page_title_account"><![CDATA[Timeline]]></string>
 	<string name="_bx_timeline_page_block_title_post"><![CDATA[Post to Timeline]]></string>
 	<string name="_bx_timeline_page_block_title_view"><![CDATA[Timeline]]></string>
-	<string name="_bx_timeline_page_block_title_post_profile"><![CDATA[Post to Timeline]]></string>
-	<string name="_bx_timeline_page_block_title_view_profile"><![CDATA[Timeline]]></string>
+	<string name="_bx_timeline_page_block_title_post_profile_persons"><![CDATA[Post to Timeline]]></string>
+	<string name="_bx_timeline_page_block_title_post_profile_organizations"><![CDATA[Post to Timeline]]></string>
+	<string name="_bx_timeline_page_block_title_view_profile_persons"><![CDATA[Timeline]]></string>
+	<string name="_bx_timeline_page_block_title_view_profile_organizations"><![CDATA[Timeline]]></string>
 	<string name="_bx_timeline_page_block_title_item"><![CDATA[Item]]></string>
 	<string name="_bx_timeline_page_block_title_view_account"><![CDATA[Subscriptions Timeline]]></string>
 	<string name="_bx_timeline_page_block_title_view_home"><![CDATA[Outline]]></string>

+ 11 - 7
modules/boonex/timeline/install/sql/enable.sql

@@ -3,29 +3,33 @@ INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `lay
 ('bx_timeline_view', '_bx_timeline_page_title_sys_view', '_bx_timeline_page_title_view', 'bx_timeline', 5, 2147483647, 1, 'timeline-view', 'page.php?i=timeline-view', '', '', '', 0, 1, 0, '', ''),
 ('bx_timeline_item', '_bx_timeline_page_title_sys_item', '_bx_timeline_page_title_item', 'bx_timeline', 5, 2147483647, 1, 'timeline-item', 'page.php?i=timeline-item', '', '', '', 0, 1, 0, '', '');
 
-
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
 ('bx_timeline_view', 1, 'bx_timeline', '_bx_timeline_page_block_title_post', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:14:"get_block_post";}', 0, 0, 1),
 ('bx_timeline_view', 1, 'bx_timeline', '_bx_timeline_page_block_title_view', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:14:"get_block_view";}', 0, 0, 2),
 
 ('bx_timeline_item', 1, 'bx_timeline', '_bx_timeline_page_block_title_item', 0, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:14:"get_block_item";}', 0, 0, 1);
 
-SET @iPBCellProfile = 4;
-SET @iPBOrderProfile = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_pages_blocks` WHERE `object`='bx_persons_view_profile' AND `cell_id` = @iPBCellProfile LIMIT 1);
-INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
-('bx_persons_view_profile', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_post_profile', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_post_profile";}', 0, 0, @iPBOrderProfile + 1),
-('bx_persons_view_profile', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_view_profile', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_view_profile";}', 0, 0, @iPBOrderProfile + 2);
-
+-- PAGES: add page block on dashboard
 SET @iPBCellDashboard = 1;
 SET @iPBOrderDashboard = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_pages_blocks` WHERE `object` = 'bx_persons_view_profile' AND `cell_id` = @iPBCellProfile LIMIT 1);
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
 ('sys_dashboard', @iPBCellDashboard, 'bx_timeline', '_bx_timeline_page_block_title_view_account', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_view_account";}', 0, 1, @iPBOrderDashboard + 1);
 
+-- PAGES: add page block on home
 SET @iPBCellHome = 1;
 SET @iPBOrderHome = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_pages_blocks` WHERE `object` = 'sys_home' AND `cell_id` = @iPBCellHome ORDER BY `order` DESC LIMIT 1);
 INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES 
 ('sys_home', @iPBCellHome, 'bx_timeline', '_bx_timeline_page_block_title_view_home', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:19:"get_block_view_home";}', 0, 1, @iPBOrderHome + 1);
 
+-- PAGES: add page block to profiles modules (trigger* page objects are processed separately upon modules enable/disable)
+SET @iPBCellProfile = 4;
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES
+('trigger_page_persons_view_entry', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_post_profile_persons', 11, 2147483647, 'service', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_post_profile";s:6:"params";a:1:{i:0;s:10:"bx_persons";}}', 0, 0, 0),
+('trigger_page_persons_view_entry', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_view_profile_persons', 11, 2147483647, 'service', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_view_profile";s:6:"params";a:1:{i:0;s:10:"bx_persons";}}', 0, 0, 0),
+
+('trigger_page_organizations_view_entry', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_post_profile_organizations', 11, 2147483647, 'service', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_post_profile";s:6:"params";a:1:{i:0;s:16:"bx_organizations";}}', 0, 0, 0),
+('trigger_page_organizations_view_entry', @iPBCellProfile, 'bx_timeline', '_bx_timeline_page_block_title_view_profile_organizations', 11, 2147483647, 'service', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:22:"get_block_view_profile";s:6:"params";a:1:{i:0;s:16:"bx_organizations";}}', 0, 0, 0);
+
 
 -- MENU: Item Manage (Delete)
 INSERT INTO `sys_objects_menu`(`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES