PageRenderTime 314ms CodeModel.GetById 20ms RepoModel.GetById 2ms app.codeStats 0ms

/include/SugarFields/Fields/Enum/SugarFieldEnum.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 147 lines | 85 code | 21 blank | 41 comment | 23 complexity | f20e65f73f58126986b4fdc04a70c3e0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, LGPL-2.1
  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM is a customer relationship management program developed by
  4. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  24. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  25. *
  26. * The interactive user interfaces in modified source and object code versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the "Powered by
  32. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  33. * technical reasons, the Appropriate Legal Notices must display the words
  34. * "Powered by SugarCRM".
  35. ********************************************************************************/
  36. require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
  37. class SugarFieldEnum extends SugarFieldBase {
  38. function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
  39. if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html')
  40. {
  41. $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
  42. return "<span id='{$vardef['name']}'>" . $this->fetch($this->findTemplate('DetailViewFunction')) . "</span>";
  43. } else {
  44. return parent::getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
  45. }
  46. }
  47. function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
  48. if(empty($displayParams['size'])) {
  49. $displayParams['size'] = 6;
  50. }
  51. if(isset($vardef['function']) && !empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
  52. $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
  53. return $this->fetch($this->findTemplate('EditViewFunction'));
  54. }else{
  55. return parent::getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
  56. }
  57. }
  58. function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
  59. if(empty($displayParams['size'])) {
  60. $displayParams['size'] = 6;
  61. }
  62. if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
  63. $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
  64. return $this->fetch($this->findTemplate('EditViewFunction'));
  65. }else{
  66. $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
  67. return $this->fetch($this->findTemplate('SearchView'));
  68. }
  69. }
  70. function displayFromFunc( $displayType, $parentFieldArray, $vardef, $displayParams, $tabindex ) {
  71. if ( isset($vardef['function']['returns']) && $vardef['function']['returns'] == 'html' ) {
  72. return parent::displayFromFunc($displayType, $parentFieldArray, $vardef, $displayParams, $tabindex);
  73. }
  74. $displayTypeFunc = 'get'.$displayType.'Smarty';
  75. return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
  76. }
  77. /**
  78. * @see SugarFieldBase::importSanitize()
  79. */
  80. public function importSanitize(
  81. $value,
  82. $vardef,
  83. $focus,
  84. ImportFieldSanitize $settings
  85. )
  86. {
  87. global $app_list_strings;
  88. // Bug 27467 - Trim the value given
  89. $value = trim($value);
  90. if ( isset($app_list_strings[$vardef['options']])
  91. && !isset($app_list_strings[$vardef['options']][$value]) ) {
  92. // Bug 23485/23198 - Check to see if the value passed matches the display value
  93. if ( in_array($value,$app_list_strings[$vardef['options']]) )
  94. $value = array_search($value,$app_list_strings[$vardef['options']]);
  95. // Bug 33328 - Check for a matching key in a different case
  96. elseif ( in_array(strtolower($value), array_keys(array_change_key_case($app_list_strings[$vardef['options']]))) ) {
  97. foreach ( $app_list_strings[$vardef['options']] as $optionkey => $optionvalue )
  98. if ( strtolower($value) == strtolower($optionkey) )
  99. $value = $optionkey;
  100. }
  101. // Bug 33328 - Check for a matching value in a different case
  102. elseif ( in_array(strtolower($value), array_map('strtolower', $app_list_strings[$vardef['options']])) ) {
  103. foreach ( $app_list_strings[$vardef['options']] as $optionkey => $optionvalue )
  104. if ( strtolower($value) == strtolower($optionvalue) )
  105. $value = $optionkey;
  106. }
  107. else
  108. return false;
  109. }
  110. return $value;
  111. }
  112. public function formatField($rawField, $vardef){
  113. global $app_list_strings;
  114. if(!empty($vardef['options'])){
  115. $option_array_name = $vardef['options'];
  116. if(!empty($app_list_strings[$option_array_name][$rawField])){
  117. return $app_list_strings[$option_array_name][$rawField];
  118. }else {
  119. return $rawField;
  120. }
  121. } else {
  122. return $rawField;
  123. }
  124. }
  125. }
  126. ?>