]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/ParserFactory.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / ParserFactory.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3     die ( 'Not A Valid Entry Point' ) ;
4
5 /*********************************************************************************
6  * SugarCRM Community Edition is a customer relationship management program developed by
7  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8  * 
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Affero General Public License version 3 as published by the
11  * Free Software Foundation with the addition of the following permission added
12  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15  * 
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19  * details.
20  * 
21  * You should have received a copy of the GNU Affero General Public License along with
22  * this program; if not, see http://www.gnu.org/licenses or write to the Free
23  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24  * 02110-1301 USA.
25  * 
26  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28  * 
29  * The interactive user interfaces in modified source and object code versions
30  * of this program must display Appropriate Legal Notices, as required under
31  * Section 5 of the GNU Affero General Public License version 3.
32  * 
33  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34  * these Appropriate Legal Notices must retain the display of the "Powered by
35  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
36  * technical reasons, the Appropriate Legal Notices must display the words
37  * "Powered by SugarCRM".
38  ********************************************************************************/
39
40
41 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
42
43 class ParserFactory
44 {
45
46     /*
47      * Create a new parser
48      *
49      * @param string $view          The view, for example EditView or ListView. For search views, use advanced_search or basic_search
50      * @param string $moduleName    Module name
51      * @param string $packageName   Package name. If present implies that we are being called from ModuleBuilder
52      * @return AbstractMetaDataParser
53      */
54
55     public static function getParser ( $view , $moduleName , $packageName = null , $subpanelName = null )
56     {
57         $GLOBALS [ 'log' ]->info ( "ParserFactory->getParser($view,$moduleName,$packageName,$subpanelName )" ) ;
58                 $sm = null;
59         $lView = strtolower ( $view );
60         if ( empty ( $packageName ) || ( $packageName == 'studio' ) )
61         {
62             $packageName = null ;
63             //For studio modules, check for view parser overrides
64             $parser = self::checkForStudioParserOverride($view, $moduleName, $packageName);
65             if ($parser) return $parser;
66             $sm = StudioModuleFactory::getStudioModule($moduleName);
67             //If we didn't find a specofic parser, see if there is a view to type mapping
68             foreach($sm->sources as $file => $def)
69             {
70                 if (!empty($def['view']) && $def['view'] == $view && !empty($def['type']))
71                 {
72                     $lView = strtolower($def['type']);
73                     break;
74                 }
75             }
76         }
77
78         switch ( $lView)
79         {
80             case MB_EDITVIEW :
81             case MB_DETAILVIEW :
82             case MB_QUICKCREATE :
83                 require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ;
84                 return new GridLayoutMetaDataParser ( $view, $moduleName, $packageName ) ;
85             case MB_BASICSEARCH :
86             case MB_ADVANCEDSEARCH :
87                 require_once 'modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php' ;
88                 return new SearchViewMetaDataParser ( $view, $moduleName, $packageName ) ;
89             case MB_LISTVIEW :
90                 if ($subpanelName == null)
91                 {
92                     require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php' ;
93                     return new ListLayoutMetaDataParser ( MB_LISTVIEW, $moduleName, $packageName ) ;
94                 } else
95                 {
96                     require_once 'modules/ModuleBuilder/parsers/views/SubpanelMetaDataParser.php' ;
97                     return new SubpanelMetaDataParser ( $subpanelName, $moduleName, $packageName ) ;
98                 }
99             case MB_DASHLET :
100             case MB_DASHLETSEARCH :
101                 require_once 'modules/ModuleBuilder/parsers/views/DashletMetaDataParser.php' ;
102                 return new DashletMetaDataParser($view, $moduleName, $packageName  );
103             case MB_POPUPLIST :
104             case MB_POPUPSEARCH :
105                 require_once 'modules/ModuleBuilder/parsers/views/PopupMetaDataParser.php' ;
106                 return new PopupMetaDataParser($view, $moduleName, $packageName  );
107             case MB_LABEL :
108                 require_once 'modules/ModuleBuilder/parsers/parser.label.php' ;
109                 return new ParserLabel ( $moduleName, $packageName ) ;
110             case MB_VISIBILITY :
111                 require_once 'modules/ModuleBuilder/parsers/parser.visibility.php' ;
112                 return new ParserVisibility ( $moduleName, $packageName ) ;
113             default :
114                 $parser = self::checkForParserClass($view, $moduleName, $packageName);
115                 if ($parser)
116                     return $parser;
117
118         }
119
120         $GLOBALS [ 'log' ]->fatal ("ParserFactory: cannot create ModuleBuilder Parser $view" ) ;
121
122     }
123
124     protected static function checkForParserClass($view, $moduleName, $packageName, $nameOverride = false)
125     {
126         $prefix = '';
127         if(!is_null ( $packageName )){
128             $prefix = empty($packageName) ? 'build' :'modify';
129         }
130         $fileNames = array(
131             "custom/modules/$moduleName/parsers/parser." . strtolower ( $prefix . $view ) . ".php",
132             "modules/$moduleName/parsers/parser." . strtolower ( $prefix . $view ) . ".php",
133             "custom/modules/ModuleBuilder/parsers/parser." . strtolower ( $prefix . $view ) . ".php",
134             "modules/ModuleBuilder/parsers/parser." . strtolower ( $prefix . $view ) . ".php",
135         );
136         foreach($fileNames as $fileName)
137         {
138             if (file_exists ( $fileName ))
139             {
140                 require_once $fileName ;
141                 $class = 'Parser' . $prefix . ucfirst ( $view ) ;
142                 if (class_exists ( $class ))
143                 {
144                     $GLOBALS [ 'log' ]->debug ( 'Using ModuleBuilder Parser ' . $fileName ) ;
145                     $parser = new $class ( ) ;
146                     return $parser ;
147                 }
148             }
149         }
150         return false;
151     }
152
153     protected static function checkForStudioParserOverride($view, $moduleName, $packageName)
154     {
155         require_once('modules/ModuleBuilder/Module/StudioModuleFactory.php');
156         $sm = StudioModuleFactory::getStudioModule($moduleName);
157         foreach($sm->sources as $file => $def)
158         {
159             if (!empty($def['view']) && $def['view'] == strtolower($view) && !empty($def['parser']))
160             {
161                 $pName = $def['parser'];
162                 $path = "module/ModuleBuilder/parsers/views/{$pName}.php";
163                 if (file_exists("custom/$path"))
164                     require_once("custom/$path");
165                 else if (file_exists($path))
166                     require_once($path);
167                 if (class_exists ( $pName ))
168                     return new $pName($view, $moduleName, $packageName);
169                 //If it wasn't defined directly, check for a generic parser name for the view
170                 $parser = self::checkForParserClass($view, $moduleName, $packageName);
171                 if ($parser)
172                     return $parser;
173             }
174         }
175         return false;
176     }
177
178 }
179 ?>