undeployedrelationships.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 423 行 · 第 1/2 页
PHP
423 行
{ $definition [ 'rhs_module' ] = $activitiesSubModuleName ; $definition [ 'relationship_name' ] = $relationshipName . '_' . $activitiesSubModuleName ; $relationships [ $definition [ 'relationship_name'] ] = RelationshipFactory::newRelationship( $definition ) ; } } else { $relationships [ $definition [ 'relationship_name' ] ] = $relationship ; } } require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php' ; $mb = new ModuleBuilder ( ) ; $module = $mb->getPackageModule( $this->packageName , $this->moduleName ) ; // use an installDefPrefix of <basepath>/SugarModules for compatibility with the rest of ModuleBuilder $this->installDefs = parent::build ( $basepath , "<basepath>/SugarModules" , $relationships , array_keys($module->config ['templates']) ) ; } /* * Translate a set of subpanelDefinitions into files for the Module Loader * @param string $basepath Basepath location for this module * @param $installDefPrefix Pathname prefix for the installdefs, for example for ModuleBuilder use "<basepath>/SugarModules" * @param array $subpanelDefinitions Set of subpanel definitions in the form $subpanelDefinitions[$for_module][] * @return array $installDefs Set of new installDefs */ protected function saveSubpanelDefinitions ($basepath , $installDefPrefix , $relationshipName , $subpanelDefinitions) { mkdir_recursive ( "$basepath/layoutdefs/" ) ; foreach ( $subpanelDefinitions as $moduleName => $definitions ) { $filename = "$basepath/layoutdefs/{$moduleName}.php" ; foreach ( $definitions as $definition ) { // add in the composite subpanel for Activities instead of individual subpanels, but only if we haven't added it before if (isset(parent::$activities[strtolower($definition['module'])])) { if ($this->activitiesToAdd) { $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveSubpanelDefinitions(): saving the composite Activities and History to {$filename}" ) ; write_array_to_file ( 'layout_defs["' . $moduleName . '"]["subpanel_setup"]["activities"]', $this->buildActivitiesSubpanelDefinition ( $relationshipName ), $filename, "a" ) ; write_array_to_file ( 'layout_defs["' . $moduleName . '"]["subpanel_setup"]["history"]', $this->buildHistorySubpanelDefinition ( $relationshipName ), $filename, "a" ) ; $this->activitiesToAdd = false; } } else { $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . "->saveSubpanelDefinitions(): saving the following to {$filename}" . print_r ( $definition, true ) ) ; write_array_to_file ( 'layout_defs["' . $moduleName . '"]["subpanel_setup"]["' . strtolower ( $definition [ 'module' ] ) . '"]', $definition, $filename, "a" ) ; } } $installDefs [ $moduleName ] = array ( 'from' => "{$installDefPrefix}/relationships/layoutdefs/{$moduleName}.php" , 'to_module' => $moduleName ) ; } return $installDefs ; } /* * Add the installDefs for this relationship to the definitions in the parameter * Required by MBModule * @param reference installDef Reference to the set of installDefs to which this relationship's installDefs should be added */ function addInstallDefs (&$installDef) { foreach ( $this->installDefs as $name => $def ) { if (! empty ( $def )) { foreach ( $def as $val ) { $installDef [ $name ] [] = $val ; } } } } private function addFieldsToUndeployedLayouts ($relationship) { return $this->updateUndeployedLayout ( $relationship, true ) ; } private function removeFieldsFromUndeployedLayouts ($relationship) { return $this->updateUndeployedLayout ( $relationship, false ) ; } /* * Add any relate fields to the DetailView and EditView of the appropriate module immediately (don't wait for a build) * @param AbstractRelationship $relationship The relationship whose fields we are to add or remove * @param boolean $actionAdd True if we are to add; false if to remove * return null */ private function updateUndeployedLayout ($relationship , $actionAdd = true) { // many-to-many relationships don't have fields so if we have a many-to-many we can just skip this... if ($relationship->getType () == MB_MANYTOMANY) return false ; $successful = true ; $layoutAdditions = $relationship->buildFieldsToLayouts () ; //$GLOBALS['log']->debug( get_class($this)."->updateUndeployedLayout(): layoutDefinitions to add:".print_r($layoutAdditions,true)); require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ; foreach ( $layoutAdditions as $deployedModuleName => $fieldName ) { if (strtolower ( $deployedModuleName ) != 'emails') // don't attempt to add or remove a field to the emails module! It uses a custom ajax front end... foreach ( array ( MB_EDITVIEW , MB_DETAILVIEW ) as $view ) { $parsedName = $this->parseDeployedModuleName ( $deployedModuleName ) ; if (isset ( $parsedName [ 'packageName' ] )) { $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . ": " . (($actionAdd) ? "adding" : "removing") . " $fieldName on $view layout for undeployed module {$parsedName [ 'moduleName' ]} in package {$parsedName [ 'packageName' ]}" ) ; $parser = new GridLayoutMetaDataParser ( $view, $parsedName [ 'moduleName' ], $parsedName [ 'packageName' ] ) ; if (($actionAdd) ? $parser->addField ( array ( 'name' => $fieldName ) ) : $parser->removeField ( $fieldName )) { $parser->handleSave ( false ) ; } else { $GLOBALS [ 'log' ]->debug ( get_class ( $this ) . ": couldn't " . (($actionAdd) ? "add" : "remove") . " $fieldName on $view layout for undeployed module $deployedModuleName" ) ; $successful = false ; } } } } return $successful ; } /* * Shortcut to construct an Activities collection subpanel * @param AbstractRelationship $relationship Source relationship to Activities module */ protected function buildActivitiesSubpanelDefinition ( $relationshipName ) { return array ( 'order' => 10 , 'sort_order' => 'desc' , 'sort_by' => 'date_start' , 'title_key' => 'lbl_activities' , 'type' => 'collection' , 'subpanel_name' => 'activities' , //this value is not associated with a physical file 'module' => 'Activities' , 'top_buttons' => array ( array ( 'widget_class' => 'SubPanelTopCreateTaskButton' ) , array ( 'widget_class' => 'SubPanelTopScheduleMeetingButton' ) , array ( 'widget_class' => 'SubPanelTopScheduleCallButton' ) , array ( 'widget_class' => 'SubPanelTopComposeEmailButton' ) ) , 'collection_list' => array ( 'meetings' => array ( 'module' => 'Meetings' , 'subpanel_name' => 'ForActivities' , 'get_subpanel_data' => $relationshipName. '_meetings' ) , 'tasks' => array ( 'module' => 'Tasks' , 'subpanel_name' => 'ForActivities' , 'get_subpanel_data' => $relationshipName. '_tasks' ) , 'calls' => array ( 'module' => 'Calls' , 'subpanel_name' => 'ForActivities' , 'get_subpanel_data' => $relationshipName. '_calls' ) ) ) ; } /* * Shortcut to construct a History collection subpanel * @param AbstractRelationship $relationship Source relationship to Activities module */ protected function buildHistorySubpanelDefinition ( $relationshipName ) { return array ( 'order' => 20 , 'sort_order' => 'desc' , 'sort_by' => 'date_modified' , 'title_key' => 'LBL_HISTORY' , 'type' => 'collection' , 'subpanel_name' => 'history' , //this values is not associated with a physical file. 'module' => 'History' , 'top_buttons' => array ( array ( 'widget_class' => 'SubPanelTopCreateNoteButton' ) , array ( 'widget_class' => 'SubPanelTopArchiveEmailButton' ) , array ( 'widget_class' => 'SubPanelTopSummaryButton' ) ) , 'collection_list' => array ( 'meetings' => array ( 'module' => 'Meetings' , 'subpanel_name' => 'ForHistory' , 'get_subpanel_data' => $relationshipName. '_meetings' ) , 'tasks' => array ( 'module' => 'Tasks' , 'subpanel_name' => 'ForHistory' , 'get_subpanel_data' => $relationshipName. '_tasks' ) , 'calls' => array ( 'module' => 'Calls' , 'subpanel_name' => 'ForHistory' , 'get_subpanel_data' => $relationshipName. '_calls' ) , 'notes' => array ( 'module' => 'Notes' , 'subpanel_name' => 'ForHistory' , 'get_subpanel_data' => $relationshipName. '_notes' ) , 'emails' => array ( 'module' => 'Emails' , 'subpanel_name' => 'ForHistory' , 'get_subpanel_data' => $relationshipName. '_emails' ) ) ) ; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?