All Data Structures Functions Variables Pages
MyListConfigView.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 
41  {
46  private $searchAttributes;
47 
48  public function __construct(ConfigurableMetadataModel $model, $searchModel, $params)
49  {
50  assert('$searchModel instanceof SearchForm || $searchModel instanceof RedBeanModel');
51  $this->model = $model;
52  $this->searchModel = $searchModel;
53  $this->modelClassName = get_class($model);
54  $this->modelId = null;
55  $this->params = $params;
56  }
57 
62  protected static function getActiveFormClassName()
63  {
64  return 'NoRequiredsActiveForm';
65  }
66 
71  public function validate()
72  {
73  $this->model->setAttributes(ArrayUtil::getArrayValue($_POST, $this->getPostArrayName()));
74  $this->searchModel->setAttributes(ArrayUtil::getArrayValue($_POST, $this->getSearchModelPostArrayName()));
75  echo NoRequiredsActiveForm::validate(array($this->model, $this->searchModel), null, false);
76  }
77 
82  public function setMetadataFromPost($postArray)
83  {
84  parent::setMetadataFromPost($postArray);
86  $this->searchModel,
87  ArrayUtil::getArrayValue($_POST, $this->getSearchModelPostArrayName()));
88 
89  $searchAttributes = SearchUtil::
91  ($sanitizedPostArray);
92  $searchAttributesAdaptedToSetInModel = SearchUtil::adaptSearchAttributesToSetInRedBeanModel(
93  $searchAttributes, $this->searchModel);
94  $this->searchAttributes = $searchAttributesAdaptedToSetInModel;
95  }
96 
101  public function getViewMetadata()
102  {
103  $viewMetadata = array();
104  if ($this->searchAttributes != null)
105  {
106  $viewMetadata['searchAttributes'] = $this->searchAttributes;
107  }
108  $viewMetadata = array_merge($viewMetadata, $this->model->getAttributes());
109  return $viewMetadata;
110  }
111 
112  public function getSearchModelPostArrayName()
113  {
114  return get_class($this->searchModel);
115  }
116 
117  public static function getDesignerRulesType()
118  {
119  return 'MyListConfigView';
120  }
121 
126  protected function getModel()
127  {
128  return $this->searchModel;
129  }
130 
138  protected function afterResolveMetadataWithRenderedElements(& $metadataWithRenderedElements, $form)
139  {
140  assert('is_array($metadataWithRenderedElements)');
141  assert('$form == null || $form instanceof ZurmoActiveForm');
142  $element = new CheckBoxElement($this->model, 'sortDescending', $form);
143  $sortDescendingData = array();
144  $sortDescendingData['rows'][0]['cells'][0]['elements'][0] = $element->render();
145  array_unshift($metadataWithRenderedElements['global']['panels'], $sortDescendingData);
146  $element = new PortletSortAttributesStaticDropDownElement($this->model, 'sortAttribute', $form);
147  $element->setDropDownArray($this->getSortAttributeNames());
148  $sortAttributeData = array();
149  $sortAttributeData['rows'][0]['cells'][0]['elements'][0] = $element->render();
150  array_unshift($metadataWithRenderedElements['global']['panels'], $sortAttributeData);
151  $element = new TextElement($this->model, 'title', $form);
152  $titleData = array();
153  $titleData['rows'][0]['cells'][0]['elements'][0] = $element->render();
154  array_unshift($metadataWithRenderedElements['global']['panels'], $titleData);
155  }
156 
162  public static function getDisplayDescription()
163  {
164  return null;
165  }
166 
167  private function getSortAttributeNames()
168  {
169  $defaultAttributeNames = array('id'=>'id');
170  $redBeanModelClassName = $this->getRedBeanModelClassName();
171  if ($redBeanModelClassName === null)
172  {
173  return array();
174  }
175  $metadata = $redBeanModelClassName::getMetadata();
176  foreach ($metadata as $className => $perClassMetadata)
177  {
178  foreach ($perClassMetadata as $key => $value)
179  {
180  if ($key == 'members')
181  {
182  $defaultAttributeNames = array_merge($defaultAttributeNames, array_combine($value,$value));
183  }
184  elseif ($key == 'customFields')
185  {
186  $defaultAttributeNames = array_merge($defaultAttributeNames, array_combine(array_keys($value),array_keys($value)));
187  }
188  }
189  }
190  return $defaultAttributeNames;
191  }
192 
193  protected function getRedBeanModelClassName()
194  {
195  return null;
196  }
197  }
198 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static getSearchAttributesFromSearchArrayForSavingExistingSearchCriteria($searchArray)
Definition: SearchUtil.php:342
afterResolveMetadataWithRenderedElements(&$metadataWithRenderedElements, $form)
setMetadataFromPost($postArray)
static getActiveFormClassName()
static getDisplayDescription()
static sanitizePostByDesignerTypeForSavingModel($model, $postData)
Definition: PostUtil.php:94
Generated on Tue Feb 25 2020 07:10:38