Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanSort.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 RedBeanSort extends CSort
38  {
39  private $sortAttribute;
40 
41  private $sortDescending;
42 
49  public function resolveAttribute($attribute)
50  {
51  if ($this->attributes !== array())
52  {
53  $attributes = $this->attributes;
54  }
55  elseif ($attribute == 'id')
56  {
57  return $attribute;
58  }
59  elseif ($this->modelClass !== null)
60  {
61  $modelClassName = $this->modelClass;
62  $attributes = $modelClassName::getAttributeNames();
63  }
64  else
65  {
66  return false;
67  }
68  foreach ($attributes as $name => $definition)
69  {
70  if (is_string($name))
71  {
72  if ($name === $attribute)
73  {
74  return $definition;
75  }
76  }
77  elseif ($definition === '*')
78  {
79  if ($this->modelClass !== null)
80  {
81  $modelClassName = $this->modelClass;
82  if ($modelClassName::isAnAttribute($attribute))
83  {
84  return $attribute;
85  }
86  }
87  }
88  elseif ($definition === $attribute)
89  {
90  return $attribute;
91  }
92  }
93  return false;
94  }
95 
100  public function resolveLabel($attribute)
101  {
102  $definition = $this->resolveAttribute($attribute);
103  if (is_array($definition))
104  {
105  if (isset($definition['label']))
106  {
107  return $definition['label'];
108  }
109  }
110  elseif (is_string($definition))
111  {
112  $attribute = $definition;
113  }
114  if ($this->modelClass !== null)
115  {
116  $modelClassName = $this->modelClass;
117  if ($modelClassName::getAbbreviatedAttributeLabel($attribute) != null)
118  {
119  return $modelClassName::getAbbreviatedAttributeLabel($attribute);
120  }
121  else
122  {
123  return $modelClassName::getAnAttributeLabel($attribute);
124  }
125  }
126  else
127  {
128  return $attribute;
129  }
130  }
131 
138  public function getDirections()
139  {
140  $directions = parent::getDirections();
141  if (empty($directions))
142  {
143  $attributes = explode($this->separators[0], $this->sortAttribute . $this->sortDescending);
144  foreach ($attributes as $attribute)
145  {
146  if (($pos = strrpos($attribute, $this->separators[1])) !== false)
147  {
148  $descending = substr($attribute, $pos + 1) === $this->descTag;
149  if ($descending)
150  {
151  $attribute = substr($attribute, 0, $pos);
152  }
153  }
154  else
155  {
156  $descending = false;
157  }
158  if (($this->resolveAttribute($attribute)) !== false)
159  {
160  $directions[$attribute] = $descending;
161  if (!$this->multiSort)
162  {
163  return $directions;
164  }
165  }
166  }
167  if ($directions === array() && is_array($this->defaultOrder))
168  {
169  $directions = $this->defaultOrder;
170  }
171  }
172 
173  return $directions;
174  }
175 
176  public function getSortAttribute()
177  {
178  return $this->sortAttribute;
179  }
180 
181  public function setSortAttribute($sortAttribute)
182  {
183  $this->sortAttribute = $sortAttribute;
184  }
185 
186  public function getSortDescending()
187  {
188  return $this->sortDescending;
189  }
190 
191  public function setSortDescending($sortDescending)
192  {
193  if ($sortDescending === true)
194  {
195  $this->sortDescending = ".desc";
196  }
197  }
198  }
199 ?>
resolveAttribute($attribute)
Definition: RedBeanSort.php:49
resolveLabel($attribute)
Generated on Sun Jul 12 2020 07:10:27
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.