Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MultiSelectRelatedModelsAutoCompleteElement.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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 Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
42  abstract protected function getFormName();
43 
47  abstract protected function getUnqualifiedNameForIdField();
48 
52  abstract protected function getUnqualifiedIdForIdField();
53 
57  abstract protected function assertModelType();
58 
63  abstract protected function getWidgetSourceUrl();
64 
69  abstract protected function getRelationName();
70 
75  abstract protected function getWidgetHintText();
76 
82  public static function getModelAttributeNames()
83  {
84  return array();
85  }
86 
87  protected function getEditableInputId($attributeName = null, $relationAttributeName = null)
88  {
89  return $this->getFormName() . $this->getUnqualifiedIdForIdField();
90  }
91 
92  protected function getEditableInputName($attributeName = null, $relationAttributeName = null)
93  {
94  return $this->getFormName() . $this->getUnqualifiedNameForIdField();
95  }
96 
101  protected function renderControlNonEditable()
102  {
103  $content = null;
104  $existingRecords = $this->getExistingIdsAndLabels();
105  foreach ($existingRecords as $existingRecord)
106  {
107  if ($content != null)
108  {
109  $content .= ', ';
110  }
111  $content .= $existingRecord[$this->getWidgetPropertyToSearch()];
112  }
113  return $content;
114  }
115 
120  protected function getClipName()
121  {
122  return get_class($this);
123  }
124 
129  protected function getWidgetPathAlias()
130  {
131  return 'application.core.widgets.MultiSelectAutoComplete';
132  }
133 
138  protected function getWidgetOptions()
139  {
140  return array();
141  }
142 
147  protected function getWidgetDefaultHtmlOptions()
148  {
149  return array('disabled' => $this->getDisabledValue());
150  }
151 
156  protected function getJsonEncodedIdsAndLabels()
157  {
158  return CJSON::encode($this->getExistingIdsAndLabels());
159  }
160 
165  protected function getWidgetPropertyToSearch()
166  {
167  return 'name';
168  }
169 
175  protected final function getDefaultWidgetOptions()
176  {
177  return array(
178  'hintText' => $this->getWidgetHintText(),
179  'htmlOptions' => $this->getHtmlOptions(),
180  'id' => $this->getEditableInputId(),
181  'jsonEncodedIdsAndLabels' => $this->getJsonEncodedIdsAndLabels(),
182  'name' => $this->getEditableInputName(),
183  'onAdd' => $this->getOnAddContent(),
184  'onDelete' => $this->getOnDeleteContent(),
185  'sourceUrl' => $this->getWidgetSourceUrl(),
186  'propertyToSearch' => $this->getWidgetPropertyToSearch(),
187  );
188  }
189 
194  protected function renderControlEditable()
195  {
196  $this->assertModelType();
197  $cClipWidget = new CClipWidget();
198  $clipName = $this->getClipName();
199  $widgetPath = $this->getWidgetPathAlias();
200  $defaultWidgetOptions = $this->getDefaultWidgetOptions();
201  $customWidgetOptions = $this->getWidgetOptions();
202  $widgetOptions = CMap::mergeArray($defaultWidgetOptions, $customWidgetOptions);
203  $cClipWidget->beginClip($clipName);
204  $cClipWidget->widget($widgetPath, $widgetOptions);
205  $cClipWidget->endClip();
206  $content = $cClipWidget->getController()->clips[$clipName];
207  return $content;
208  }
209 
214  protected function getOnAddContent()
215  {
216  return null;
217  }
218 
223  protected function getOnDeleteContent()
224  {
225  return null;
226  }
227 
232  protected function renderError()
233  {
234  return null;
235  }
236 
241  protected function renderLabel()
242  {
243  return $this->resolveNonActiveFormFormattedLabel($this->getFormattedAttributeLabel());
244  }
245 
250  protected function getFormattedAttributeLabel()
251  {
252  return Yii::app()->format->text($this->getDisplayName());
253  }
254 
259  protected function getDefaultExistingIdsAndLabel()
260  {
261  return array();
262  }
263 
269  protected function resolveIdAndNameByModel(RedBeanModel $model)
270  {
271  return array(
272  'id' => $model->id,
273  $this->getWidgetPropertyToSearch() => $this->resolveModelNameForRendering($model),
274  );
275  }
276 
282  protected function resolveModelNameForRendering(RedBeanModel $model)
283  {
284  return strval($model);
285  }
286 
291  protected function getRelatedRecords()
292  {
293  $relation = $this->getRelationName();
294  $relatedRecords = $this->model->$relation;
295  return $relatedRecords;
296  }
297 
302  protected function getExistingIdsAndLabels()
303  {
304  $relatedRecords = $this->getRelatedRecords();
305  $existingRecords = array();
306  $default = $this->getDefaultExistingIdsAndLabel();
307  if (!empty($default))
308  {
309  $existingRecords[] = $default;
310  }
311  foreach ($relatedRecords as $relatedRecord)
312  {
313  $existingRecord = $this->resolveIdAndNameByModel($relatedRecord);
314  if (!empty($existingRecord))
315  {
316  $existingRecords[] = $existingRecord;
317  }
318  }
319  return $existingRecords;
320  }
321  }
322 ?>
Generated on Thu Jul 9 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.