Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Portlet.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 
44  class Portlet extends RedBeanModel
45  {
46  protected $view;
47 
51  public $params;
52 
53  public static function getByLayoutIdAndUserSortedByColumnIdAndPosition($layoutId, $userId, $params)
54  {
55  $portletCollection = array();
56  assert('is_integer($userId) && $userId >= 1');
58  $sql = "select id, {$quote}column$quote, position " .
59  'from portlet ' .
60  "where layoutid = '" . DatabaseCompatibilityUtil::escape($layoutId) . "' and _user_id = " .
61  DatabaseCompatibilityUtil::escape($userId) .
62  " order by {$quote}column$quote, position;";
63  $rows = ZurmoRedBean::getAll($sql);
64  if (!empty($rows))
65  {
66  foreach ($rows as $row)
67  {
68  $portlet = Portlet::getById(intval($row['id']));
69  $portlet->params = $params;
70  $portletCollection[intval($row['column'])][intval($row['position'])] = $portlet;
71  }
72  }
73  return $portletCollection;
74  }
75 
76  public static function getByLayoutIdAndUserSortedById($layoutId, $userId)
77  {
78  $portletCollection = array();
79  assert('is_integer($userId) && $userId >= 1');
81  $sql = "select id, {$quote}column$quote, position " .
82  'from portlet ' .
83  "where layoutid = '" . DatabaseCompatibilityUtil::escape($layoutId) .
84  "' and _user_id = " . DatabaseCompatibilityUtil::escape($userId) .
85  ' order by id;';
86  foreach (ZurmoRedBean::getAll($sql) as $row)
87  {
88  $portlet = Portlet::getById(intval($row['id']));
89  $portletCollection[$row['id']] = $portlet;
90  }
91  return $portletCollection;
92  }
93 
94  public static function makePortletsUsingMetadataSortedByColumnIdAndPosition($layoutId, $metadata, $user, $params)
95  {
96  $portletCollection = array();
97  foreach ($metadata['global']['columns'] as $column => $columns)
98  {
99  foreach ($columns['rows'] as $position => $portletMetadata)
100  {
101  $portlet = new Portlet();
102  $portlet->params = $params;
103  $portlet->column = $column + 1;
104  $portlet->position = $position + 1;
105  $portlet->layoutId = $layoutId;
106  $portlet->collapsed = false;
107  $portlet->viewType = $portletMetadata['type'];
108  $portlet->user = $user;
109  $portletCollection[$column + 1][$position + 1] = $portlet;
110  }
111  }
112  return $portletCollection;
113  }
114 
115  public static function savePortlets($portletCollection)
116  {
117  foreach ($portletCollection as $column => $columns)
118  {
119  foreach ($columns as $position => $portlet)
120  {
121  $saved = $portlet->save();
122  assert('$saved'); // Not Coding Standard // TODO - deal with this properly.
123  }
124  }
125  }
126 
127  public static function shiftPositionsBasedOnColumnReduction($portletCollection, $newColumnCount)
128  {
129  //Current column count is determined by the max key of all collection items, instead of count($items)
130  $currentColumnCount = max(array_keys($portletCollection));
131  if (!empty($portletCollection[1]))
132  {
133  $maxPositionInColumn1 = count($portletCollection[1]);
134  }
135  else
136  {
137  $maxPositionInColumn1 = 0;
138  }
139  $shiftToPosition = $maxPositionInColumn1 + 1;
140  for ($i = ($newColumnCount + 1); $i <= $currentColumnCount; $i++)
141  {
142  foreach ($portletCollection[$i] as $position => $portlet)
143  {
144  $portlet->column = 1;
145  $portlet->position = $shiftToPosition;
146  $portlet->save();
147  $shiftToPosition++;
148  }
149  }
150  }
151 
160  public static function makePortletUsingViewType($viewType, $uniqueLayoutId, $user, $numberOfColumns)
161  {
162  $portlet = new Portlet();
163  $portlet->column = $numberOfColumns;
164  $portlet->position = 1;
165  $portlet->layoutId = $uniqueLayoutId;
166  $portlet->collapsed = false;
167  $portlet->viewType = $viewType;
168  $portlet->user = $user;
169  $portlet->save();
170  }
171 
172  public static function getDefaultMetadata()
173  {
174  $metadata[__CLASS__] = array(
175  'members' => array(
176  'column',
177  'position',
178  'layoutId',
179  'viewType',
180  'serializedViewData',
181  'collapsed',
182  ),
183  'relations' => array(
184  'user' => array(static::HAS_ONE, 'User'),
185  ),
186  'rules' => array(
187  array('column', 'required'),
188  array('column', 'type', 'type' => 'integer'),
189  array('position', 'required'),
190  array('position', 'type', 'type' => 'integer'),
191  array('layoutId', 'required'),
192  array('layoutId', 'type', 'type' => 'string'),
193  array('layoutId', 'length', 'max' => 100),
194  array('viewType', 'required'),
195  array('viewType', 'type', 'type' => 'string'),
196  array('serializedViewData', 'type', 'type' => 'string'),
197  array('collapsed', 'boolean'),
198  )
199  );
200  return $metadata;
201  }
202 
203  public function getView()
204  {
205  $className = $this->viewType . 'View';
206  $this->params['portletId'] = $this->id;
207  $this->params['layoutId'] = $this->layoutId;
208  $this->view = new $className(unserialize($this->serializedViewData), $this->params, $this->getUniquePortletPageId());
209  return $this->view;
210  }
211 
216  public function getUniquePortletPageId()
217  {
218  return $this->layoutId . "_" . $this->id;
219  }
220 
221  public function getCssClasses()
222  {
223  return $this->getView()->getCssClasses();
224  }
225 
226  public function getTitle()
227  {
228  return $this->getView()->getTitle();
229  }
230 
231  public function renderContent()
232  {
233  //return '<div>test</div>';
234  return $this->getView()->render();
235  }
236 
237  public function renderHeadContent()
238  {
239  return $this->getView()->renderPortletHeadContent();
240  }
241 
242  public function getPortletParams()
243  {
244  return $this->getView()->getPortletParams();
245  }
246 
247  public function isEditable()
248  {
249  $className = get_class($this->getView());
250  return $className::canUserConfigure();
251  }
252 
253  public function beforeDelete()
254  {
255  $className = $this->viewType . 'View';
256  if (@class_exists($className))
257  {
258  $class = new ReflectionClass($className);
259  if ($class->implementsInterface('UserPersistentSettingsCleanupForPortletInterface'))
260  {
261  $className::processBeforeDelete($this->id);
262  }
263  }
264  return parent::beforeDelete();
265  }
266 
276  public static function doesPortletExistByViewTypeLayoutIdAndUser($viewType, $uniqueLayoutId, $userId)
277  {
278  assert('is_integer($userId) && $userId >= 1');
279  $sql = "select count(*) as count " .
280  'from portlet ' .
281  "where layoutid = '" . DatabaseCompatibilityUtil::escape($uniqueLayoutId) .
282  "' and viewtype = '" . DatabaseCompatibilityUtil::escape($viewType) .
283  "' and _user_id = " . DatabaseCompatibilityUtil::escape($userId);
284  $row = ZurmoRedBean::getRow($sql);
285  if ($row['count'] > 0)
286  {
287  return true;
288  }
289  else
290  {
291  return false;
292  }
293  }
294 
295  public static function getPlacedViewTypesByLayoutIdAndUser($uniqueLayoutId, $userId)
296  {
297  $portlets = static::getByLayoutIdAndUserSortedById($uniqueLayoutId,
298  $userId);
299  $placedViewTypes = array();
300  foreach ($portlets as $portlet)
301  {
302  $placedViewTypes[] = $portlet->viewType;
303  }
304  return $placedViewTypes;
305  }
306 
312  public static function resolvePortletCollectionColumnIndexes($layoutId)
313  {
314  $uniqueLayoutId = 'HomeDashboard' . $layoutId;
315  $portletCollection = self::getByLayoutIdAndUserSortedByColumnIdAndPosition($uniqueLayoutId,
316  Yii::app()->user->userModel->id, array());
317  if (count($portletCollection) > 0)
318  {
319  $totalColumns = max(array_keys($portletCollection));
320  }
321  else
322  {
323  $totalColumns = 0;
324  }
325  if (count($portletCollection) < $totalColumns)
326  {
327  $columnIndex = 1;
328  foreach ($portletCollection as $portletItem)
329  {
330  foreach ($portletItem as $position => $portlet)
331  {
332  $portlet->column = $columnIndex;
333  $portlet->save();
334  }
335  $columnIndex++;
336  }
337  }
338  }
339  }
340 ?>
static makePortletUsingViewType($viewType, $uniqueLayoutId, $user, $numberOfColumns)
Definition: Portlet.php:160
static resolvePortletCollectionColumnIndexes($layoutId)
Definition: Portlet.php:312
static doesPortletExistByViewTypeLayoutIdAndUser($viewType, $uniqueLayoutId, $userId)
Definition: Portlet.php:276
getUniquePortletPageId()
Definition: Portlet.php:216
static getById($id, $modelClassName=null)
Generated on Thu Jul 9 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.