Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RelatedItemsElement.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 
43  {
44  public $editableTemplate = '<th class="hidden-element"></th><td class="hidden-element" colspan="{colspan}"></td></tr>{content}{error}<tr><th class="hidden-element"></th><td class="hidden-element" colspan="{colspan}"></td>';
45 
46  public $nonEditableTemplate = '<th class="hidden-element"></th><td class="hidden-element" colspan="{colspan}"></td></tr>{content}<tr><th class="hidden-element"></th><td class="hidden-element" colspan="{colspan}"></td>';
47 
48  protected static function getRelatedItemsModelClassNames()
49  {
50  throw new NotImplementedException();
51  }
52 
53  protected static function getRelatedItemFormClassName()
54  {
55  throw new NotImplementedException();
56  }
57 
58  protected function getRelatedItemsFromModel()
59  {
60  throw new NotImplementedException();
61  }
62 
63  protected function renderControlNonEditable()
64  {
65  return $this->renderNonEditableElementsForRelationsByRelationsData(static::getRelatedItemsModelClassNames());
66  }
67 
68  protected function renderControlEditable()
69  {
70  return $this->renderElementsForRelationsByRelationsData(static::getRelatedItemsModelClassNames());
71  }
72 
73  protected function renderElementsForRelationsByRelationsData($relationModelClassNames)
74  {
75  $content = null;
76  $formClassName = static::getRelatedItemFormClassName();
77  foreach ($relationModelClassNames as $relationModelClassName)
78  {
79  $relatedItemForm = null;
80  //ASSUMES ONLY A SINGLE ATTACHED RELATEDITEM PER RELATION TYPE.
81  foreach ($this->getRelatedItemsFromModel() as $item)
82  {
83  try
84  {
85  $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
86  $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
87  $relatedItemForm = new $formClassName($castedDownModel);
88  $relationModel = $castedDownModel;
89  break;
90  }
91  catch (NotFoundException $e)
92  {
93  }
94  }
95  if ($relatedItemForm == null)
96  {
97  $relationModel = new $relationModelClassName();
98  $relatedItemForm = new $formClassName($relationModel);
99  }
100  $canAccess = true;
102  $relationModelClassName, Yii::app()->user->userModel, $canAccess);
103  if ($canAccess)
104  {
105  $content .= $this->resolveAndRenderEditableInput($relationModel, $relatedItemForm,
106  $relationModelClassName, $modelElementType);
107  }
108  elseif ($relationModel->id > 0)
109  {
110  $content .= $this->renderEditableHiddenInput($relatedItemForm, $relationModelClassName, $modelElementType);
111  }
112  }
113  return $content;
114  }
115 
116  protected function resolveAndRenderEditableInput($relationModel, $relatedItemForm, $relationModelClassName, $modelElementType)
117  {
118  $elementInformation = array('attributeName' => $relationModelClassName,
119  'type' => $modelElementType);
120  FormLayoutSecurityUtil::resolveElementForEditableRender($relatedItemForm, $elementInformation, Yii::app()->user->userModel);
121  if ($elementInformation['attributeName'] != null)
122  {
123  $elementclassname = $elementInformation['type'] . 'Element';
124  $element = new $elementclassname($relatedItemForm, $elementInformation['attributeName'],
125  $this->form, array_slice($elementInformation, 2));
126  assert('$element instanceof ModelElement');
127  $element->editableTemplate = $this->getRelatedItemEditableTemplate();
128  return $element->render();
129  }
130  elseif ($relationModel->id > 0)
131  {
132  return $this->renderEditableHiddenInput($relatedItemForm, $relationModelClassName, $modelElementType);
133  }
134  }
135 
136  protected function renderEditableHiddenInput($relatedItemForm, $relationModelClassName, $modelElementType)
137  {
138  $elementInformation = array('attributeName' => $relationModelClassName,
139  'type' => $modelElementType,
140  'onlyHiddenInput' => true);
141  $elementclassname = $elementInformation['type'] . 'Element';
142  $element = new $elementclassname($relatedItemForm, $elementInformation['attributeName'],
143  $this->form, array_slice($elementInformation, 2));
144  assert('$element instanceof ModelElement');
145  $element->editableTemplate = $this->getRelatedItemEditableHiddenInputOnlyTemplate();
146  return $element->render();
147  }
148 
149  protected function renderNonEditableElementsForRelationsByRelationsData($relationModelClassNames)
150  {
151  $content = null;
152  $formClassName = static::getRelatedItemFormClassName();
153  foreach ($relationModelClassNames as $relationModelClassName)
154  {
155  $relatedItemForm = null;
156  //ASSUMES ONLY A SINGLE ATTACHED RELATEDITEM PER RELATION TYPE.
157  foreach ($this->getRelatedItemsFromModel() as $item)
158  {
159  try
160  {
161  $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem($relationModelClassName);
162  $castedDownModel = $item->castDown(array($modelDerivationPathToItem));
163  $relatedItemForm = new $formClassName($castedDownModel);
164  break;
165  }
166  catch (NotFoundException $e)
167  {
168  //do nothing
169  }
170  }
171  if ($relatedItemForm != null)
172  {
173  $canAccess = true;
175  $relationModelClassName, Yii::app()->user->userModel, $canAccess);
176  if ($canAccess)
177  {
178  $elementInformation = array('attributeName' => $relationModelClassName,
179  'type' => $modelElementType);
180  FormLayoutSecurityUtil::resolveElementForNonEditableRender($relatedItemForm, $elementInformation, Yii::app()->user->userModel);
181  if ($elementInformation['attributeName'] != null)
182  {
183  $elementclassname = $elementInformation['type'] . 'Element';
184  $element = new $elementclassname($relatedItemForm, $elementInformation['attributeName'],
185  $this->form, array_slice($elementInformation, 2));
186  assert('$element instanceof ModelElement');
187  $element->nonEditableTemplate = $this->getRelatedItemNonEditableTemplate();
188  $content .= $element->render();
189  }
190  }
191  }
192  }
193  return $content;
194  }
195 
196  protected function getRelatedItemEditableTemplate()
197  {
198  $template = "<tr><th>\n";
199  $template .= "{label}";
200  $template .= "</th><td colspan=\"" . $this->getColumnSpan() . "\">\n";
201  $template .= '{content}{error}';
202  $template .= "</td></tr>\n";
203  return $template;
204  }
205 
206  protected function getRelatedItemEditableHiddenInputOnlyTemplate()
207  {
208  $template = "<tr><th>\n";
209  $template .= "</th><td colspan=\"" . $this->getColumnSpan() . "\">\n";
210  $template .= '{content}{error}';
211  $template .= "</td></tr>\n";
212  return $template;
213  }
214 
215  protected function getRelatedItemNonEditableTemplate()
216  {
217  $template = "<tr><th>\n";
218  $template .= "{label}";
219  $template .= "</th><td colspan=\"" . $this->getColumnSpan() . "\">\n";
220  $template .= '{content}';
221  $template .= "</td></tr>\n";
222  return $template;
223  }
224 
225  protected function renderError()
226  {
227  }
228 
229  protected function renderLabel()
230  {
231  return ZurmoHtml::label(Zurmo::t('Core', 'Related to'), false);
232  }
233 
234  public static function getDisplayName()
235  {
236  $content = Zurmo::t('Core', 'Related') . '&#160;';
237  $relationContent = null;
238  foreach (static::getRelatedItemsModelClassNames() as $relationModelClassName)
239  {
240  if ($relationContent != null)
241  {
242  $relationContent .= ',&#160;';
243  }
244  $relationContent .= $relationModelClassName::getModelLabelByTypeAndLanguage('Plural');
245  }
246  return $content . $relationContent;
247  }
248 
254  public static function getModelAttributeNames()
255  {
256  return array();
257  }
258 
264  public static function getEditableActionType()
265  {
266  return static::$editableActionType;
267  }
268 
272  public static function getNonEditableActionType()
273  {
274  throw new NotImplementedException();
275  }
276  }
277 ?>
static resolveElementForNonEditableRender($model, &$elementInformation, $user)
getColumnSpan()
Definition: Element.php:195
static resolveElementForEditableRender($model, &$elementInformation, $user)
static getModelDerivationPathToItem($modelClassName)
Definition: RuntimeUtil.php:79
Generated on Sat Jul 4 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.