mbmodule.php
来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 751 行 · 第 1/2 页
PHP
751 行
<?php/*********************************************************************************
* 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". ********************************************************************************/define ( 'MB_TEMPLATES', 'include/SugarObjects/templates' ) ;define ( 'MB_IMPLEMENTS', 'include/SugarObjects/implements' ) ;require_once ('modules/ModuleBuilder/MB/MBVardefs.php') ;require_once ('modules/ModuleBuilder/MB/MBRelationship.php') ;require_once ('modules/ModuleBuilder/MB/MBLanguage.php') ;class MBModule{ var $name = '' ; var $config = array ( 'assignable' => 1 , 'acl' => 1 , 'has_tab' => 1 , 'studio' => 1 , 'audit' => 1 ) ; var $mbvardefs ; var $errors = array ( ) ; var $path = '' ; var $implementable = array ( 'has_tab' => 'Navigation Tab' ) ; var $always_implement = array ( 'assignable' => 'Assignable' , 'acl' => 'Access Controls' , 'studio' => 'Studio Support' , 'audit' => 'Audit Table' ) ; var $iTemplate = array ( 'assignable' ) ; var $config_md5 = null ; function getDBName ($name) { return preg_replace ( "/[^\w]+/", "_", $name ) ; } function MBModule ($name , $path , $package , $package_key) { $this->config [ 'templates' ] = array ( 'basic' => 1 ) ; $this->name = MBModule::getDBName ( $name ) ; $this->key_name = $package_key . '_' . $name ; $this->package = $package ; $this->package_key = $package_key ; $this->package_path = $path ; $this->implementable = array ( 'has_tab' => $GLOBALS [ 'mod_strings' ] [ 'LBL_NAV_TAB' ] ) ; $this->path = $this->getModuleDir () ; // $this->mbrelationship = new MBRelationship($this->name, $this->path, $this->key_name); $this->relationships = new UndeployedRelationships ( $this->path ) ; $this->mbvardefs = new MBVardefs ( $this->name, $this->path, $this->key_name ) ; $this->load () ; } function getModuleName() { return $this->name; } function getPackageName() { return $this->package; } function getRelationships() { return $this->relationships; } /**
* Loads the module based on the module name
*
*/ function load () { if (file_exists ( $this->path . '/config.php' )) { include ($this->path . '/config.php') ; $this->config = $config ; } $label = (! empty ( $this->config [ 'label' ] )) ? $this->config [ 'label' ] : $this->name ; $this->mblanguage = new MBLanguage ( $this->name, $this->path, $label, $this->key_name ) ; foreach ( $this->iTemplate as $temp ) { if (! empty ( $this->config [ $temp ] )) { $this->mbvardefs->iTemplates [ $temp ] = 1 ; $this->mblanguage->iTemplates [ $temp ] = $temp ; } } $this->mbvardefs->templates = $this->config [ 'templates' ] ; $this->mblanguage->templates = $this->config [ 'templates' ] ; $this->mbvardefs->load () ; $this->mblanguage->load () ; } /**
* Enter description here...
*
* @param unknown_type $template
*/ function addTemplate ($template) { $this->config [ 'templates' ] [ $template ] = 1 ; } function getModuleDir () { return $this->package_path . '/modules/' . $this->name ; } function removeTemplate ($template) { unset ( $this->config [ 'templates' ] [ $template ] ) ; } function getVardefs ($by_group = false) { $this->mbvardefs->updateVardefs ( $by_group ) ; return $this->mbvardefs->getVardefs () ; } function addField ($vardef) { $this->mbvardefs->addFieldVardef ( $vardef ) ; } function addFieldObject ($field) { $vardef = $field->get_field_def () ; if (! empty ( $vardef [ 'source' ] ) && $vardef [ 'source' ] == 'custom_fields') unset ( $vardef [ 'source' ] ) ; $this->addField ( $vardef ) ; } function deleteField ($name) { $this->mbvardefs->deleteField ( $name ) ; } function fieldExists ($name = '' , $type = '') { $vardefs = $this->mbvardefs->getVardefs () ; if (! empty ( $vardefs )) { if (empty ( $type ) && empty ( $name )) return false ; else if (empty ( $type )) return ! empty ( $vardefs [ 'fields' ] [ $name ] ) ; else if (empty ( $name )) { foreach ( $vardefs [ 'fields' ] as $def ) { if ($def [ 'type' ] == $type) return true ; } return false ; } else return (! empty ( $vardefs [ 'fields' ] [ $name ] ) && ($vardefs [ 'fields' ] [ $name ] [ 'type' ] == $type)) ; } else { return false ; } } function getModStrings ($language = 'en_us') { $language .= '.lang.php' ; return $this->mblanguage->getModStrings ( $language ) ; } function setModStrings ($language = 'en_us' , $mod_strings) { $language .= '.lang.php' ; $this->mblanguage->strings [ $language ] = $mod_strings ; } function setLabel ($language = 'en_us' , $key , $value) { $language .= '.lang.php' ; $this->mblanguage->strings [ $language ] [ $key ] = $value ; } function deleteLabel ($language = 'en_us' , $key) { $language .= '.lang.php' ; unset ( $this->mblanguage->strings [ $language ] [ $key ] ) ; }
/**
* Required for an MB module to work with Dynamic fields
*/
function addLabel ( $displayLabel)
{
$this->setLabel('en_us', $this->getDBName($displayLabel, false), translate($displayLabel));
$this->save();
}
function getLabel ($language = 'en_us' , $key) { $language .= '.lang.php' ; if (empty ( $this->mblanguage->strings [ $language ] [ $key ] )) { return '' ; } return $this->mblanguage->strings [ $language ] [ $key ] ; } function getAppListStrings ($language = 'en_us') { return $this->mblanguage->getAppListStrings ( $language ) ; } function setAppListStrings ($language = 'en_us' , $app_list_strings) { $language .= '.lang.php' ; $this->mblanguage->appListStrings [ $language ] = $app_list_strings ; } function setDropDown ($language = 'en_us' , $key , $value) { $language .= '.lang.php' ; $this->mblanguage->appListStrings [ $language ] [ $key ] = $value ; } function deleteDropDown ($language = 'en_us' , $key) { $language .= '.lang.php' ; unset ( $this->mblanguage->appListStrings [ $language ] [ $key ] ) ; } function save () { $this->path = $this->getModuleDir () ; if (mkdir_recursive ( $this->path )) { $this->setConfigMD5 () ; $old_config_md5 = $this->config_md5 ; $this->saveConfig () ; $this->getVardefs () ; $this->mbvardefs->save ( $this->key_name ) ; // $this->mbrelationship->save ( $this->key_name ) ; $this->relationships->save () ; $this->copyMetaData () ; $this->copyDashlet () ; if (0 != strcmp ( $old_config_md5, $this->config_md5 )) { $this->mblanguage->reload () ; } $this->mblanguage->label = $this->config [ 'label' ] ; //pass in the key_name incase it has changed mblanguage will check if it is different and handle it accordingly
$this->mblanguage->save ( $this->key_name ) ; if (! file_exists ( $this->package_path . "/icons/icon_" . ucfirst ( $this->key_name ) . ".gif" )) { $this->createIcon () ; } $this->errors = array_merge ( $this->errors, $this->mbvardefs->errors ) ; } } function copyDashlet() { $templates = array_reverse ( $this->config [ 'templates' ], true ) ; foreach ( $templates as $template => $a ) { if (file_exists ( MB_TEMPLATES . '/' . $template . '/Dashlets/Dashlet' )) { $this->copyMetaRecursive ( MB_TEMPLATES . '/' . $template . '/Dashlets/Dashlet', $this->path . '/Dashlets/' . $this->key_name . 'Dashlet/' ) ; } } } function copyMetaData () { $templates = array_reverse ( $this->config [ 'templates' ], true ) ; foreach ( $templates as $template => $a ) { if (file_exists ( MB_TEMPLATES . '/' . $template . '/metadata' )) { $this->copyMetaRecursive ( MB_TEMPLATES . '/' . $template . '/metadata', $this->path . '/metadata/' ) ; } } } function copyMetaRecursive ($from , $to , $overwrite = false) { if (! file_exists ( $from )) return ; if (is_dir ( $from )) { $findArray = array ( '<module_name>' , '<_module_name>' , '<MODULE_NAME>' , '<object_name>' , '<_object_name>' , '<OBJECT_NAME>' ); $replaceArray = array ( $this->key_name , strtolower ( $this->key_name ) , strtoupper ( $this->key_name ) , $this->key_name , strtolower ( $this->key_name ) , strtoupper ( $this->key_name ) ); mkdir_recursive ( $to ) ; $d = dir ( $from ) ; while ( $e = $d->read () ) { if (substr ( $e, 0, 1 ) == '.') continue ; $nfrom = $from . '/' . $e ; $nto = $to . '/' . str_replace ( 'm-n-', $this->key_name, $e ) ; if (is_dir ( $nfrom )) { $this->copyMetaRecursive ( $nfrom, $nto, $overwrite ) ; } else { if ($overwrite || ! file_exists ( $nto )) { $contents = file_get_contents ( $nfrom ) ; $contents = str_replace ( $findArray, $replaceArray, $contents ) ; $fw = sugar_fopen ( $nto, 'w' ) ; fwrite ( $fw, $contents ) ; fclose ( $fw ) ; } } } } } function saveConfig () { $header = file_get_contents ( 'modules/ModuleBuilder/MB/header.php' ) ; if (! write_array_to_file ( 'config', $this->config, $this->path . '/config.php', 'w', $header )) { $this->errors [] = 'Could not save config to ' . $this->path . '/config.php' ; } $this->setConfigMD5 () ; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?