]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarFields/Fields/Multienum/SugarFieldMultienum.php
Release 6.5.0
[Github/sugarcrm.git] / include / SugarFields / Fields / Multienum / SugarFieldMultienum.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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
37 require_once('include/SugarFields/Fields/Enum/SugarFieldEnum.php');
38
39 class SugarFieldMultienum extends SugarFieldEnum
40 {
41     function setup($parentFieldArray, $vardef, $displayParams, $tabindex, $twopass=true) {
42         if ( !isset($vardef['options_list']) && isset($vardef['options']) && !is_array($vardef['options'])) {
43             $vardef['options_list'] = $GLOBALS['app_list_strings'][$vardef['options']];
44         }
45         return parent::setup($parentFieldArray, $vardef, $displayParams, $tabindex, $twopass);
46     }
47
48         function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
49         if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
50            $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
51            return $this->fetch($this->findTemplate('EditViewFunction'));
52         }else{
53            $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
54            return $this->fetch($this->findTemplate('SearchView'));
55         }
56     }
57
58     function displayFromFunc( $displayType, $parentFieldArray, $vardef, $displayParams, $tabindex ) {
59         if ( isset($vardef['function']['returns']) && $vardef['function']['returns'] == 'html' ) {
60             return parent::displayFromFunc($displayType, $parentFieldArray, $vardef, $displayParams, $tabindex);
61         }
62
63         $displayTypeFunc = 'get'.$displayType.'Smarty';
64         return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
65     }
66
67         public function save(&$bean, $params, $field, $properties, $prefix = ''){
68                 if ( isset($params[$prefix.$field]) ) {
69                         if($params[$prefix.$field][0] === '' && !empty($params[$prefix.$field][1]) ) {
70                                 unset($params[$prefix.$field][0]);
71                         }
72
73                         $bean->$field = encodeMultienumValue($params[$prefix.$field]);
74                 }
75         else  if (isset($params[$prefix.$field.'_multiselect']) && $params[$prefix.$field.'_multiselect']==true) {
76                         // if the value in db is not empty and
77                         // if the data is not set in params (means the user has deselected everything) and
78                         // if the corresponding multiselect flag is true
79                         // then set field to ''
80                         if (!empty($bean->$field)) {
81                                 $bean->$field = '';
82                         }
83                 }
84     }
85
86     /**
87      * @see SugarFieldBase::importSanitize()
88      */
89     public function importSanitize(
90         $value,
91         $vardef,
92         $focus,
93         ImportFieldSanitize $settings
94         )
95     {
96         if(!empty($value) && is_array($value)) {
97             $enum_list = $value;
98         }
99         else {
100             // If someone was using the old style multienum import technique
101             $value = str_replace("^","",$value);
102
103             // We will need to break it apart to put test it.
104             $enum_list = explode(",",$value);
105         }
106         // parse to see if all the values given are valid
107         foreach ( $enum_list as $key => $enum_value ) {
108             $enum_list[$key] = $enum_value = trim($enum_value);
109             $sanitizedValue = parent::importSanitize($enum_value,$vardef,$focus,$settings);
110             if ($sanitizedValue  === false ) {
111                 return false;
112             }
113             else {
114                 $enum_list[$key] = $sanitizedValue;
115             }
116         }
117         $value = encodeMultienumValue($enum_list);
118
119         return $value;
120     }
121 }