Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
BuilderElementEditableModelForm.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 
37  class BuilderElementEditableModelForm extends CModel
38  {
39  public $className;
40  public $content;
41  public $properties;
42 
43  public function __construct(array $content, array $properties)
44  {
45  $this->content = $content;
46  $this->properties = $properties;
47  }
48 
49  public function attributeNames()
50  {
51  array('content', 'properties');
52  }
53 
54  public function __get($name)
55  {
56  if (strpos($name, '['))
57  {
58  $basePropertyName = substr($name, 0, strpos($name, '['));
59  $index = substr($name, strpos($name, '[') + 1);
60  if (property_exists($this, $basePropertyName))
61  {
62  return ArrayUtil::getNestedValue($this->{$basePropertyName}, $index);
63  }
64  }
65  return parent::__get($name);
66  }
67 
68  public function rules()
69  {
70  return array_merge(parent::rules(), array(
71  array('className', 'safe'),
72  array('content', 'safe'),
73  array('content', 'validateContent'),
74  array('properties', 'safe'),
75  array('properties', 'validateProperties')
76  ));
77  }
78 
79  public function validateProperties($attribute, $params)
80  {
81  if (!isset($this->className))
82  {
83  throw new NotSupportedException();
84  }
85  $hasErrors = false;
86  $elementClassName = $this->className;
87  $element = new $elementClassName();
88  $prefix = 'properties';
89  $this->validatePropertiesByElement($this->$attribute, $element, $prefix, $hasErrors, $attribute, null);
90  return !$hasErrors;
91  }
92 
93  protected function validatePropertiesByElement($properties, $element, $prefix, & $hasErrors, $attribute, $key)
94  {
95  if (is_array($properties))
96  {
97  foreach ($properties as $key => $value)
98  {
99  $this->validatePropertiesByElement($value, $element, $prefix . '_' . $key, $hasErrors, $attribute, $key);
100  }
101  }
102  else
103  {
104  $error = $element->validate($key, $properties);
105  if (!($error === true))
106  {
107  $this->addError($prefix, $error);
108  $hasErrors = true;
109  }
110  }
111  }
112 
113  public function validateContent($attribute, $params)
114  {
115  if (!isset($this->className))
116  {
117  throw new NotSupportedException();
118  }
119  }
120  }
121 ?>
static getNestedValue(array $array, $key)
Definition: ArrayUtil.php:275
Generated on Sun Aug 9 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.