PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/include/MVC/View/views/view.metadata.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 375 lines | 258 code | 79 blank | 38 comment | 61 complexity | 633f61d9530455aec4be753d94fdada1 MD5 | raw file
  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM Community Edition is a customer relationship management program developed by
  4. * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
  5. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  6. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under
  9. * the terms of the GNU Affero General Public License version 3 as published by the
  10. * Free Software Foundation with the addition of the following permission added
  11. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  12. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  13. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  14. *
  15. * This program is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License along with
  21. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  22. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  23. * 02110-1301 USA.
  24. *
  25. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  26. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  27. *
  28. * The interactive user interfaces in modified source and object code versions
  29. * of this program must display Appropriate Legal Notices, as required under
  30. * Section 5 of the GNU Affero General Public License version 3.
  31. *
  32. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  33. * these Appropriate Legal Notices must retain the display of the "Powered by
  34. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  35. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  36. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  37. ********************************************************************************/
  38. require_once('include/DetailView/DetailView2.php');
  39. class ViewMetadata extends SugarView{
  40. var $type ='detail';
  41. var $dv;
  42. function displayCheckBoxes($name,$values, $selected =array(), $attr=''){
  43. echo "<div $attr style='overflow:auto;float:left;width:200px;height:200px' >";
  44. foreach($values as $value){
  45. $checked = in_array($value, $selected)? " checked=checked ": " ";
  46. echo "<div style='padding:2px'><input type='checkbox' name='$name' value='$value' $checked> $value</div>";
  47. }
  48. echo "</div>";
  49. }
  50. function displaySelect($name,$values, $selected ='', $attr=''){
  51. echo "<select name='$name' $attr>";
  52. foreach($values as $value){
  53. $checked = $value == $selected? " selected=selected ": " ";
  54. echo "<option value='$value' $checked> $value</option>";
  55. }
  56. echo "</select>";
  57. }
  58. function displayTextBoxes($values, $attr=''){
  59. echo "<div $attr style='overflow:auto;float:left;width:400px;height:200px' >";
  60. foreach($values as $value){
  61. $postvalue = !empty($_POST[$value])? $_POST[$value]: '';
  62. echo "<div style='padding:2px;width:150px;float:left'>$value</div> <input type='text' name='$value' value='$postvalue'> ";
  63. }
  64. echo "</div>";
  65. }
  66. function printValue($value, $depth=0){
  67. echo "<pre>";
  68. print_r($value);
  69. echo "</pre>";
  70. }
  71. function display(){
  72. $do = !empty($_REQUEST['do'])?$_REQUEST['do']:'';
  73. echo "<form method='post'>";
  74. echo "<div><h2>I want to learn about ";
  75. $this->displaySelect('do', array('Nothing', 'Modules','Fields', 'Field Attributes', 'Relationships'), $do, 'onchange="toggleLearn(this.value)"');
  76. echo "<input type='submit' value='Learn' class='button'></h2></div>";
  77. $modules = !empty($_REQUEST['modules'])?$_REQUEST['modules']:array();
  78. if(empty($modules) && !empty($_REQUEST['module']) && $_REQUEST['module'] != 'Home'){
  79. $modules = array( $_REQUEST['module']);
  80. }
  81. $this->displayCheckBoxes('modules[]', VardefBrowser::getModules(), $modules, ' id="_modules" ');
  82. $attributes = !empty($_REQUEST['attributes'])?$_REQUEST['attributes']:array();
  83. $allAttributes = array_keys(VardefBrowser::findFieldAttributes());
  84. sort($allAttributes);
  85. $this->displayCheckBoxes('attributes[]', $allAttributes, $attributes, ' id="_attributes" ');
  86. $this->displayTextBoxes($allAttributes, ' id="_fields" ');
  87. echo "</form>";
  88. echo <<<EOQ
  89. <script>
  90. function toggleLearn(value){
  91. document.getElementById('_modules').style.display = 'None';
  92. document.getElementById('_attributes').style.display = 'None';
  93. document.getElementById('_fields').style.display = 'None';
  94. if(value == 'Modules' || value == 'Relationships'){
  95. document.getElementById('_modules').style.display = '';
  96. }
  97. if(value == 'Fields'){
  98. document.getElementById('_modules').style.display = '';
  99. document.getElementById('_fields').style.display = '';
  100. }
  101. if(value == 'Field Attributes'){
  102. document.getElementById('_modules').style.display = '';
  103. document.getElementById('_attributes').style.display = '';
  104. }
  105. }
  106. toggleLearn('$do');
  107. </script>
  108. EOQ;
  109. echo "<div width='100%'></div><div><div style='float:left'>";
  110. switch ($do){
  111. case 'Modules':
  112. $this->printValue(VardefBrowser::findVardefs( $modules));
  113. break;
  114. case 'Field Attributes':
  115. $this->printValue(VardefBrowser::findFieldAttributes($attributes, $modules));
  116. break;
  117. case 'Fields':
  118. $searchFor = array();
  119. foreach($allAttributes as $at){
  120. if(!empty($_POST[$at])){
  121. $searchFor[$at] = $_POST[$at];
  122. }
  123. }
  124. $this->printValue(VardefBrowser::findFieldsWithAttributes($searchFor, $modules));
  125. break;
  126. default:
  127. echo <<<EOQ
  128. <div style='border:1px solid;width:100%;text-align:center;-moz-border-radius: 5px;border-radius: 5px;'>
  129. <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardefs in 30 minutes</h2>
  130. <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields and Relationships in 30 minutes</h1>
  131. <h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields in 30 minutes</h2>
  132. <h2 >Something about Vardefs in 30 minutes</h2>
  133. </div>
  134. <div style='border:1px solid;width:100%;-moz-border-radius: 5px;border-radius: 5px;'>
  135. <h4>What you need to know</h4>
  136. <pre>
  137. Vardefs are where we define information about the fields for a module.
  138. It also specifies 75% of the information on relationships.
  139. There are also special attributes that can enable additional functionality for a module.
  140. It's broken down into:
  141. <b>fields:</b> The fields of a module (most of these are stored in the database)
  142. <b>indices:</b> The indicies on the database
  143. <b>relationships:</b> The relationships for this module
  144. <b>templates:</b> the functionality/fields this module inherits from SugarObjects(located in include/SugarObjects).
  145. In a vardef these are specified by the third argument in VardefManager::createVardef
  146. For Example - <b>VardefManager::createVardef('Contacts','Contact', array('default', 'assignable','team_security','person'));</b>
  147. would add the fields for team security to contacts and make it an object that can be assigned to users.
  148. The 'person' value would indicate that that Contacts subclasses Person and gains all the fields/attributes that 'Person'
  149. would get. Since person extends basic it would also gain all the fields/attributes of basic as well.
  150. The SugarObjects that a module can extend are <b>'basic', 'company', 'file', 'issue', 'person'</b>.
  151. These are the same objects you can build off of in ModuleBuilder.
  152. Adding a new SugarObject to include/SugarObjects/templates is the way
  153. to add modules to ModuleBuilder
  154. Besides extending base objects, a module can also implement functionality defined in SugarObjects.
  155. You can currenty implement <b>'assignable' and 'team_security'</b>.
  156. <b>attributes:</b>
  157. <b>[table] (string) (required)</b> The database table where this module stores it's data - any custom fields will be stored in a new table
  158. with '_cstm' appended to the table name. The field id_c in the custom table will be the same value as id in the primary table
  159. allowing us to join the two tables together.
  160. <b>[comment] (string) (optional)</b> is a description of the module
  161. <b>[unified_search] (bool)(optional)</b> is global search (the search in the upper right corner on the screen) available for this module
  162. <b>[unified_search_default_enabled] (bool)(optional)</b> is this module available by default in global search
  163. <b>[optimistic_locking] (bool) (optional)</b> optimistic locking is the concept that on save if the record modifiy time (date_modified)
  164. is newer than the the modify time of the record when it was loaded to edit (this time is stored in the session).
  165. <b>[favorites] (bool) (optional)</b> should favorites be enabled for this module. Favorites are indicated by the stars next to a record
  166. on lists and deail views. It makes it easier for users to indicate what is important to them right now. It also allows them to filter
  167. by favorites.
  168. <b>[duplicate_merge] (bool) (optional)</b> is systematic merging allowed between records of this module or not. This option is available from
  169. the menu on list views. A user needs to select 2 records on the list view using the checkboxes, and then they can select merge from the actions
  170. menu.
  171. <b>[audited] (bool) (optional)</b> auditing allows for the tracking of any changes to specified fields. In order to enable auditing you need to enable
  172. it at both the module level and the field level. It will create an audit table for the module with the '_audit' appended to the table name.
  173. <b>[custom_fields] (bool) (automatic) </b> if the module has custom fields this will be set to true
  174. </pre>
  175. </div>
  176. <div>
  177. </div>
  178. EOQ;
  179. }
  180. echo "</div><div style='float:right'>Help Text</div></div>";
  181. //$this->printValue(VardefBrowser::findFieldsWithAttributes(array('type'=>'id'), $modules));
  182. }
  183. }
  184. class VardefBrowser{
  185. function __construct(){
  186. }
  187. static function getModules(){
  188. $modules = array();
  189. foreach($GLOBALS['beanList'] as $module=>$object){
  190. $object = BeanFactory::getObjectName($module);
  191. VardefManager::loadVardef($module, $object);
  192. if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
  193. $modules[] = $module;
  194. }
  195. sort($modules);
  196. return $modules;
  197. }
  198. static function findFieldsWithAttributes($attributes, $modules=null){
  199. $fields = array();
  200. if(empty($modules))$modules = VardefBrowser::getModules();
  201. foreach($modules as $module){
  202. if(!empty($GLOBALS['beanList'][$module])){
  203. $object = $GLOBALS['beanList'][$module];
  204. if($object == 'aCase')$object = 'Case';
  205. VardefManager::loadVardef($module, $object);
  206. if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
  207. foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){
  208. $match = true;
  209. foreach($attributes as $k=>$v){
  210. $alt = false;
  211. if($k == 'type'){
  212. $alt = 'dbType';
  213. }
  214. if($v == 'true' && !empty($def[$k])){
  215. continue;
  216. }
  217. if((empty($def[$k]) || $def[$k] != $v) && (empty($alt) || empty($def[$alt]) || $def[$alt] != $v )){
  218. $match = false;
  219. }
  220. }
  221. if($match){
  222. $fields[$module][$object][$name] = $def;
  223. }
  224. }
  225. }
  226. }
  227. return $fields;
  228. }
  229. static function findVardefs($modules=null){
  230. $defs = array();
  231. if(empty($modules))$modules = VardefBrowser::getModules();
  232. foreach($modules as $module){
  233. if(!empty($GLOBALS['beanList'][$module])){
  234. $object = $GLOBALS['beanList'][$module];
  235. if($object == 'aCase')$object = 'Case';
  236. VardefManager::loadVardef($module, $object);
  237. if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
  238. $defs[$module][$object] = $GLOBALS['dictionary'][$object];
  239. }
  240. }
  241. return $defs;
  242. }
  243. static function findFieldAttributes($attributes=array(), $modules=null, $byModule=false, $byType=false){
  244. $fields = array();
  245. if(empty($modules))$modules = VardefBrowser::getModules();
  246. foreach($modules as $module){
  247. if(!empty($GLOBALS['beanList'][$module])){
  248. $object = $GLOBALS['beanList'][$module];
  249. if($object == 'aCase')$object = 'Case';
  250. VardefManager::loadVardef($module, $object);
  251. if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue;
  252. foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){
  253. $fieldAttributes = (!empty($attributes))? $attributes:array_keys($def);
  254. foreach($fieldAttributes as $k){
  255. if(isset($def[$k])){
  256. $v = var_export($def[$k], true);
  257. $key = is_array($def[$k])?null:$def[$k];
  258. if($k == 'type'){
  259. if(isset($def['dbType'])){
  260. $v = var_export($def['dbType'], true);
  261. }
  262. }
  263. if($byModule){
  264. $fields[$module][$object][$def['type']][$k][$key] = $v;
  265. }else{
  266. if($byType){
  267. $fields[$def['type']][$k][$key] = $v;
  268. }else{
  269. if(!is_array($def[$k])){
  270. if(isset($fields[$k][$key])){
  271. $fields[$k][$key]['refs']++;
  272. }else{
  273. $fields[$k][$key] = array('attribute'=>$v, 'refs'=>1);
  274. }
  275. }else{
  276. $fields[$k]['_array'][] = $def[$k];
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. return $fields;
  286. }
  287. }