fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

site.class.php
Go to the documentation of this file.
1 <?php
22 class Site extends FOGController
23 {
29  protected $databaseTable = 'site';
35  protected $databaseFields = array(
36  'id' => 'sID',
37  'name' => 'sName',
38  'description' => 'sDesc'
39  );
45  protected $databaseFieldsRequired = array(
46  'id',
47  'name',
48  );
54  protected $additionalFields = array(
55  'description',
56  'users',
57  'usersnotinme',
58  'hosts',
59  'hostsnotinme'
60  );
68  public function addUser($addArray)
69  {
70  return $this->addRemItem(
71  'users',
72  (array)$addArray,
73  'merge'
74  );
75  }
83  public function removeUser($removeArray)
84  {
85  return $this->addRemItem(
86  'users',
87  (array)$removeArray,
88  'diff'
89  );
90  }
98  public function addHost($addArray)
99  {
100  return $this->addRemItem(
101  'hosts',
102  (array)$addArray,
103  'merge'
104  );
105  }
113  public function removeHost($removeArray)
114  {
115  return $this->addRemItem(
116  'hosts',
117  (array)$removeArray,
118  'diff'
119  );
120  }
126  public function save()
127  {
128  parent::save();
129  return $this
130  ->assocSetter('SiteUserAssociation', 'user', true)
131  ->assocSetter('SiteHostAssociation', 'host', true)
132  ->load();
133  }
139  protected function loadUsers()
140  {
141  $associds = self::getSubObjectIDs(
142  'SiteUserAssociation',
143  array('siteID' => $this->get('id')),
144  'userID'
145  );
146  $userids = self::getSubObjectIDs(
147  'User',
148  array('id' => $associds)
149  );
150  $this->set('users', (array)$userids);
151  }
157  protected function loadUsersnotinme()
158  {
159  $userids = array_diff(
160  self::getSubObjectIDs('User'),
161  $this->get('users')
162  );
163  $types = array();
164  self::$HookManager->processEvent(
165  'USER_TYPES_FILTER',
166  array('types' => &$types)
167  );
168  $users = array();
169  foreach ((array)self::getClass('UserManager')
170  ->find(array('id' => $userids)) as &$User
171  ) {
172  if (in_array($User->get('type'), $types)) {
173  continue;
174  }
175  $users[] = $User->get('id');
176  unset($User);
177  }
178  unset($userids, $types);
179  $this->set('usersnotinme', (array)$users);
180  }
188  public function loadHosts($ids = null)
189  {
190  if (is_null($ids)) {
191  $siteIDs = $this->get('id');
192  } else {
193  $siteIDs = $ids;
194  }
195  $associds = self::getSubObjectIDs(
196  'SiteHostAssociation',
197  array('siteID' => $siteIDs),
198  'hostID'
199  );
200  $hostids = self::getSubObjectIDs(
201  'Host',
202  array('id' => $associds)
203  );
204  $this->set('hosts', (array)$hostids);
205  }
213  public function loadHostsnotinme($ids = null)
214  {
215  if (is_null($ids)) {
216  $siteIDs = $this->get('id');
217  } else {
218  $siteIDs = $ids;
219  }
220  $associds = self::getSubObjectIDs(
221  'SiteHostAssociation',
222  array('siteID' => $siteIDs),
223  'hostID'
224  );
225  $hostids = self::getSubObjectIDs(
226  'Host',
227  array('id' => $associds)
228  );
229  $hostids = array_diff(
230  self::getSubObjectIDs('Host'),
231  $hostids
232  );
233  $this->set('hostsnotinme', (array)$hostids);
234  }
245  public function assocSetter($assocItem, $alterItem = '', $implicitCall = false)
246  {
247  // Lower our item
248  $alterItem = strtolower($alterItem ?: $assocItem);
249  // Getter is pluralized
250  $plural = "{$alterItem}s";
251  // Class to call, if implicit leave off association.
252  $classCall = ($implicitCall ? $assocItem : "{$assocItem}Association");
253  // Main object and string setters.
254  $obj = strtolower(get_class($this));
255  $objstr = "{$obj}ID";
256  $assocstr = "{$alterItem}ID";
257 
258  // Don't work on item that isn't loaded yet.
259  if (!$this->isLoaded($plural)) {
260  return $this;
261  }
262 
263  // Get the current items.
264  $items = $this->get($plural);
265  Route::ids(
266  $classCall,
267  [$objstr => $this->get('id')],
268  $assocstr
269  );
270  $cur = json_decode(Route::getData(), true);
271 
272  // Get the items differing between the current and what we have associated.
273  // Remove the items if there's anything to remove.
274  // Take in account that the array_diff function returns different values depending the order of the factors. In this way:
275  // When we delete hosts or users from the webUI:
276  $delItems = array_diff($cur, $items);
277  // When we add hosts or users from the webUI:
278  $addItems = array_diff($items, $cur);
279  if (count($delItems)) {
281  $classCall,
282  [
283  $objstr => $this->get('id'),
284  $assocstr => $delItems,
285  ]
286  );
287  return $this;
288  }
289  if (count($addItems)) {
290  $items = $addItems;
291  // Setup our insert.
292  $insert_fields = [
293  $objstr,
294  $assocstr
295  ];
296  $insert_values = [];
297  if ($assocstr == 'moduleID') {
298  $insert_fields[] = 'state';
299  }
300  foreach ($items as &$id) {
301  $insert_val = [
302  $this->get('id'),
303  $id
304  ];
305  if ($assocstr == 'moduleID') {
306  $insert_val[] = 1;
307  }
308  $insert_values[] = $insert_val;
309  unset($insert_val, $id);
310  }
311  if (count($insert_values ?: []) > 0) {
312  self::getClass("{$classCall}manager")->insertBatch(
313  $insert_fields,
314  $insert_values
315  );
316  }
317  }
318  return $this;
319  }
320 }
Site\loadHosts
loadHosts($ids=null)
Definition: site.class.php:188
Site\$databaseFields
$databaseFields
Definition: site.class.php:35
FOGController\addRemItem
addRemItem($key, $array, $array_type)
Definition: fogcontroller.class.php:823
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
Site\loadUsersnotinme
loadUsersnotinme()
Definition: site.class.php:157
Site\loadUsers
loadUsers()
Definition: site.class.php:139
Site\removeUser
removeUser($removeArray)
Definition: site.class.php:83
Site\addHost
addHost($addArray)
Definition: site.class.php:98
$items
$items
Definition: boot.php:24
Route\deletemass
static deletemass($class, $whereItems=[])
Definition: route.class.php:1631
Route\ids
ids($class, $whereItems=[], $getField='id')
Definition: route.class.php:1567
Site
Definition: site.class.php:23
FOGController
Definition: fogcontroller.class.php:29
Route\getData
static getData()
Definition: route.class.php:1173
Site\$databaseFieldsRequired
$databaseFieldsRequired
Definition: site.class.php:45
Site\loadHostsnotinme
loadHostsnotinme($ids=null)
Definition: site.class.php:213
Site\$databaseTable
$databaseTable
Definition: site.class.php:29
Site\$additionalFields
$additionalFields
Definition: site.class.php:54
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
Site\removeHost
removeHost($removeArray)
Definition: site.class.php:113
FOGBase\isLoaded
isLoaded($key)
Definition: fogbase.class.php:969
Site\assocSetter
assocSetter($assocItem, $alterItem='', $implicitCall=false)
Definition: site.class.php:245
Site\save
save()
Definition: site.class.php:126
Site\addUser
addUser($addArray)
Definition: site.class.php:68