Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModels.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  $basePath = Yii::app()->getBasePath();
38  require_once("$basePath/../../redbean/rb.php");
39 
46  abstract class RedBeanModels implements ArrayAccess, Iterator, Countable
47  {
48  protected $modelClassName;
49 
53  protected $bean;
54 
60  protected $relatedBeansAndModels = array();
61 
62  private $position;
63 
68  public function __toString()
69  {
70  return $this->count(). ' ' . Zurmo::t('Core', 'records') . '.';
71  }
72 
76  public function offsetSet($i, $value)
77  {
78  throw new NotSupportedException();
79  }
80 
84  public function offsetExists($i)
85  {
86  return $i < $this->count();
87  }
88 
92  public function offsetUnset($i)
93  {
94  throw new NotSupportedException();
95  }
96 
100  public function offsetGet($i)
101  {
102  if ($i < $this->count())
103  {
104  return $this->getByIndex($i);
105  }
106  else
107  {
108  return null;
109  }
110  }
111 
115  public function rewind()
116  {
117  $this->position = 0;
118  }
119 
123  function current()
124  {
125  return $this[$this->position];
126  }
127 
131  function key()
132  {
133  return $this->position;
134  }
135 
139  function next()
140  {
141  $this->position++;
142  }
143 
147  function valid()
148  {
149  return $this->position < $this->count();
150  }
151 
156  public function count()
157  {
158  return count($this->relatedBeansAndModels);
159  }
160 
164  public function contains(RedBeanModel $model)
165  {
166  foreach ($this as $containedModel)
167  {
168  if ($containedModel->isSame($model))
169  {
170  return true;
171  }
172  }
173  return false;
174  }
175 
180  protected function getByIndex($i)
181  {
182  assert('is_int($i)');
183  assert('$i >= 0');
184  assert('$i < $this->count()');
185  $beanOrModel = $this->relatedBeansAndModels[$i];
186  if ($beanOrModel instanceof RedBean_OODBBean)
187  {
188  $model = RedBeanModel::makeModel($beanOrModel, $this->modelClassName);
189  $this->relatedBeansAndModels[$i] = $model;
190  }
191  return $this->relatedBeansAndModels[$i];
192  }
193 
198  public function hasErrors($attributeNameOrNames)
199  {
200  assert('$attributeNameOrNames === null || ' .
201  'is_string($attributeNameOrNames) || ' .
202  'is_array ($attributeNameOrNames) && AssertUtil::all($attributeNameOrNames, "is_string")');
203  for ($i = 0; $i < $this->count(); $i++)
204  {
205  if ($this->relatedBeansAndModels[$i] instanceof RedBeanModel)
206  {
207  $model = $this->relatedBeansAndModels[$i];
208  if ($model->hasErrors($attributeNameOrNames))
209  {
210  return true;
211  }
212  }
213  }
214  return false;
215  }
216 
221  public function validate(array $attributeNames = null)
222  {
223  $hasErrors = false;
224  for ($i = 0; $i < $this->count(); $i++)
225  {
226  if ($this->relatedBeansAndModels[$i] instanceof RedBeanModel)
227  {
228  $model = $this->relatedBeansAndModels[$i];
229  if (!$model->validate($attributeNames))
230  {
231  $hasErrors = true;
232  }
233  }
234  }
235  return !$hasErrors;
236  }
237 
242  public function save($runValidation = true)
243  {
244  for ($i = 0; $i < $this->count(); $i++)
245  {
246  if ($this->relatedBeansAndModels[$i] instanceof RedBeanModel)
247  {
248  if (!$this->relatedBeansAndModels[$i]->save($runValidation))
249  {
250  return false;
251  }
252  }
253  }
254  return true;
255  }
256 
261  public function isModified()
262  {
263  for ($i = 0; $i < $this->count(); $i++)
264  {
265  if ($this->relatedBeansAndModels[$i] instanceof RedBeanModel)
266  {
267  $model = $this->relatedBeansAndModels[$i];
268  if ($model->isModified())
269  {
270  return true;
271  }
272  }
273  }
274  return false;
275  }
276  }
277 ?>
validate(array $attributeNames=null)
hasErrors($attributeNameOrNames)
contains(RedBeanModel $model)
offsetSet($i, $value)
save($runValidation=true)
static makeModel(RedBean_OODBBean $bean, $modelClassName=null)
Generated on Tue Jul 7 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.