Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SecurityTreeListView.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  abstract class SecurityTreeListView extends MetadataView
42  {
43  protected $controllerId;
44 
45  protected $moduleId;
46 
47  protected $items;
48 
54  public function __construct($controllerId, $moduleId, $items)
55  {
56  assert('$controllerId != null');
57  assert('$moduleId != null');
58  assert('is_array($items)');
59  $this->controllerId = $controllerId;
60  $this->moduleId = $moduleId;
61  $this->items = $items;
62  }
63 
70  protected function renderTreeMenu($nodeRelationName, $nodesRelationName, $title)
71  {
72  $this->registerScripts();
73  $parentNode = array('text' => $title);
74  $itemNodes = array();
75  foreach ($this->items as $item)
76  {
77  if (empty($item->{$nodeRelationName}->id) || $item->{$nodeRelationName}->id < 1)
78  {
79  if ($this->resolveIsNodeLinkableById($item->id, strval($item)))
80  {
81  $text = $this->makeTreeMenuNodeLink(
82  strval($item),
83  'details',
84  $item->id);
85  $route = $this->makeTreeMenuNodeRoute('details', $item->id);
86  }
87  else
88  {
89  $text = strval($item);
90  $route = null;
91  }
92 
93  $userCount = $this->resolveUserCountForItem($item);
94  $node = array('link' => $text,
95  'userCount' => $userCount,
96  'route' => $route);
97  $node['children'] = $this->makeChildrenNodes($this->items, $item, $nodeRelationName);
98  $itemNodes[] = $node;
99  }
100  }
101  $dataTree = $itemNodes;
102  return $this->renderTreeListView($dataTree);
103  }
104 
105  protected function getModelRelationNameForUserCount()
106  {
107  return 'users';
108  }
109 
110  protected function renderTreeListView($data)
111  {
112  throw new NotImplementedException();
113  }
114 
115  protected static function renderTreeListViewNode(& $content, $data, $indent)
116  {
117  assert('is_string($content)');
118  assert('is_array($data)');
119  foreach ($data as $node)
120  {
121  $content .= '<tr>';
122  $content .= '<td class="level-' . $indent . '">';
123  $content .= $node['link'];
124  $content .= '</td>';
125  $content .= '<td>';
126  $content .= static::renderUserCount($node['userCount'], $node['route']);
127  $content .= '</td>';
128  $content .= '<td>';
129  if (isset($node['route']) && $node['route'] != null && static::shouldRenderConfigureLink())
130  {
131  $content .= ZurmoHtml::link(ZurmoHtml::wrapLabel(Zurmo::t('Core', 'Configure') ),
132  $node['route'], array('class' => 'white-button'));
133  }
134  $content .= '</td>';
135  $content .= '</tr>';
136  if (isset($node['children']))
137  {
138  static::renderTreeListViewNode($content, $node['children'], $indent + 1);
139  }
140  }
141  }
142 
149  protected function makeChildrenNodes($items, $parentItem, $nodeRelationName, $isLink = true)
150  {
151  assert('is_string($nodeRelationName)');
152  assert('is_bool($isLink)');
153  $itemNodes = array();
154  foreach ($items as $item)
155  {
156  if (isset($item->{$nodeRelationName}) &&
157  $item->{$nodeRelationName}->id == $parentItem->id &&
158  $parentItem->id > 0)
159  {
160  if ($isLink && !$this->resolveIsNodeLinkableById($item->id, strval($item)))
161  {
162  $isLink = false;
163  }
164  if ($isLink)
165  {
166  $text = $this->makeTreeMenuNodeLink(
167  strval($item),
168  'details',
169  $item->id);
170  $route = $this->makeTreeMenuNodeRoute('details', $item->id);
171  }
172  else
173  {
174  $text = strval($item);
175  $route = null;
176  }
177  $userCount = $this->resolveUserCountForItem($item);
178  $node = array('link' => $text,
179  'userCount' => $userCount,
180  'route' => $route);
181  $node['children'] = $this->makeChildrenNodes($items, $item, $nodeRelationName, $isLink);
182  $itemNodes[] = $node;
183  }
184  }
185  return $this->resolveNodeWithChildrenItems($itemNodes, $parentItem);
186  }
187 
192  protected function resolveNodeWithChildrenItems(array $itemNodes, $parentItem)
193  {
194  assert('$parentItem instanceof Item');
195  return $itemNodes;
196  }
197 
198  protected function makeTreeMenuNodeLink($label, $action, $id)
199  {
200  return ZurmoHtml::Link($label, $this->makeTreeMenuNodeRoute($action, $id));
201  }
202 
203  protected function makeTreeMenuNodeRoute($action, $id)
204  {
205  return Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/' . $action . '/', array('id' => $id));
206  }
207 
208  public static function getDefaultMetadata()
209  {
210  $metadata = array(
211  'global' => array(),
212  );
213  return $metadata;
214  }
215 
220  protected function resolveIsNodeLinkableById($id, $name)
221  {
222  return true;
223  }
224 
225  protected function resolveUserCountForItem(Item $item)
226  {
227  return $item->{$this->getModelRelationNameForUserCount()}->count();
228  }
229 
230  protected static function shouldRenderConfigureLink()
231  {
232  return true;
233  }
234 
235  protected static function resolveIdFromRoute($route)
236  {
237  return substr($route, strpos($route, 'id=') + 3); // Not Coding Standard
238  }
239 
240  protected static function renderUserCount($userCount, $route)
241  {
242  if ($userCount && static::resolveShouldShowLinkableUserCount())
243  {
244  $element = new UsersModalListLinkActionElement(Yii::app()->controller->id,
245  Yii::app()->controller->module->id,
246  static::resolveIdFromRoute($route),
247  array('label' => $userCount, 'htmlOptions' => array('class' => 'z-link'),
248  'routeAction' => static::resolveRouteAction()));
249  return $element->render();
250  }
251  else
252  {
253  return $userCount;
254  }
255  }
256 
257  protected static function resolveShouldShowLinkableUserCount()
258  {
259  return false;
260  }
261 
262  protected static function resolveRouteAction()
263  {
264  return '/usersInRoleModalList/';
265  }
266 
267  protected function registerScripts()
268  {
269  //Registered to make sure things work when debug mode is on. Otherwise this is missing.
270  Yii::app()->getClientScript()->registerCoreScript('bbq');
271  }
272  }
273 ?>
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
makeChildrenNodes($items, $parentItem, $nodeRelationName, $isLink=true)
__construct($controllerId, $moduleId, $items)
renderTreeMenu($nodeRelationName, $nodesRelationName, $title)
Definition: Item.php:37
resolveNodeWithChildrenItems(array $itemNodes, $parentItem)
Generated on Sat Nov 28 2020 07:10:48
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.