undeployedrelationships.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 423 行 · 第 1/2 页
PHP
423 行
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');/********************************************************************************* * SugarCRM is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". *********************************************************************************/require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php' ;require_once 'modules/ModuleBuilder/parsers/relationships/RelationshipsInterface.php' ;require_once 'modules/ModuleBuilder/parsers/relationships/RelationshipFactory.php' ;class UndeployedRelationships extends AbstractRelationships implements RelationshipsInterface{ protected $basepath ; // Base directory for the lhs_module protected $packageName ; private $activitiesToAdd ; // if we need to add in the composite Activities and History subpanels to the module during the build /* * Constructor * Automatically loads in any saved relationships * @param string $path The pathname of the base module directory */ function __construct ($path) { $this->basepath = $path ; // pull the module and package names out of the path $this->moduleName = basename ( $path, "/" ) ; // just in case there are any trailing / $this->packageName = basename (dirname ( dirname ($path ) ) ) ; // simpler than explode :) $this->load () ; } /* * Find all modules, deployed and undeployed, that can participate in a relationship * @return array Array of [$module][$subpanel] */ static function findRelatableModules () { // first find all deployed modules that we might participate in a relationship $relatableModules = parent::findRelatableModules ( false ) ; // now add in the undeployed modules - those in custom/modulebuilder // note that if a module exists in both deployed and undeployed forms, the subpanels from the undeployed form are used... require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ; $mb = new ModuleBuilder ( ) ; $mb->getPackages () ; foreach ( $mb->getPackageList () as $packageName ) { $package = $mb->packages [ $packageName ] ; foreach ( $package->modules as $module ) { $relatableModules [$package->key . "_" . $module->name ] = $module->getProvidedSubpanels() ; } } return $relatableModules ; } /* * Add a relationship to the set * For undeployed relationships we always make the fields in the relationship visible in the layouts now, rather than waiting until build time, so * that the admin may move them around or otherwise edit them before the module is deployed * @param AbstractRelationship $relationship The relationship to add */ function add ($relationship) { parent::add ( $relationship ) ; $this->addFieldsToUndeployedLayouts ( $relationship ) ; // must come after parent::add as we need the relationship_name in the relationships getFieldsToLayouts() which is called by addFieldsToUndeployedLayouts() } /* * Delete a relationship by name * In future, if we need to actually track deleted relationships then just call $relationship->delete() instead * @param string $relationshipName The unique name for this relationship, as returned by $relationship->getName() */ function delete ($relationshipName) { if ($relationship = $this->get ( $relationshipName )) { $this->removeFieldsFromUndeployedLayouts ( $relationship ) ; unset ( $this->relationships [ $relationshipName ] ) ; } } /* * Load the saved relationship definitions for this module */ function load () { $this->relationships = array ( ) ; $this->relationships = parent::_load ( $this->basepath ) ; } /* * Save this modules relationship definitions out to a working file */ function save () { parent::_save ( $this->relationships, $this->basepath ) ; } /* * Implementation of getAllRelationships() for Undeployed modules * The set of all relevant relationships for undeployed modules is the superset of that for deployed modules and all of the relationships known to ModuleBuilder * @return array Set of all relevant relationships */ protected function getAllRelationships () { // start with the set of relationships known to this module plus those already deployed $allRelationships = array_merge ( $this->relationships, parent::getDeployedRelationships () ) ; // add in the relationships known to ModuleBuilder require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ; $mb = new ModuleBuilder ( ) ; $mb->getPackages () ; foreach ( $mb->getPackageList () as $packageName ) { $package = $mb->packages [ $packageName ] ; foreach ( $package->modules as $module ) { foreach ( $module->relationships->getRelationshipList () as $relationshipName ) { $relationship = $module->relationships->get ( $relationshipName ) ; $allRelationships [ $relationship->getName () ] = $relationship->getDefinition () ; } } } return $allRelationships ; } /* * As of SugarCRM 5.1 the subpanel code and the widgets have difficulty handling multiple subpanels or relate fields from the same module * Until this is fixed, we new relationships which will trigger this problem must be flagged as "relationship_only" and built without a UI component * This function is called from the view when constructing a new relationship * @param AbstractRelationship $relationship The relationship to be enforced */ public function enforceRelationshipOnly ( $relationship ) { // if we already have a relationship between this lhs_module and this rhs_module then set RelationshipOnly flag foreach ( $this->relationships as $rel ) { if ( $rel->lhs_module == $relationship->lhs_module && $rel->rhs_module == $relationship->rhs_module) { $rel->setRelationship_only () ; break; } } } /* * BUILD FUNCTIONS */ /* * Translate the set of relationship objects into files that the Module Loader can work with * @param $basepath string Pathname of the directory to contain the build */ function build ($basepath) { // first expand out any reference to Activities to its submodules // we do this here rather than in the subcomponents of the build as most of those subcomponents make use of elements of the definition, such // as the relationship name, that must be unique // the only special case is the subpanel for Activities, which is a composite, and is applied only once for all the submodules - this is handled in saveSubpanelDefinitions() for Undeployed modules $relationships = array () ; $this->activitiesToAdd = false ; foreach ( $this->relationships as $relationshipName => $relationship ) { $definition = $relationship->getDefinition() ; // activities will always appear on the rhs only - lhs will be always be this module in MB if (strtolower ( $definition [ 'rhs_module' ] ) == 'activities') { $this->activitiesToAdd = true ; $relationshipName = $definition [ 'relationship_name'] ; foreach ( self::$activities as $activitiesSubModuleName )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?