public function save() { parent::save(); if ($this->isLoaded('hosts')) { // Remove old rows $this->getClass('GroupAssociationManager')->destroy(array('groupID' => $this->get('id'))); // Create assoc foreach ((array) $this->get('hosts') as $Host) { if ($Host instanceof Host && $Host->isValid()) { $this->getClass('GroupAssociation')->set('hostID', $Host->get('id'))->set('groupID', $this->get('id'))->save(); } } } return $this; }
public function save() { parent::save(); if ($this->isLoaded('hosts')) { // Remove all old entries. $this->getClass('PrinterAssociationManager')->destroy(array('printerID' => $this->get('id'))); // Create new Assocs $i = 0; foreach ((array) $this->get('hosts') as $Host) { if ($Host instanceof Host && $Host->isValid()) { $NewPrinter = new PrinterAssociation(array('printerID' => $this->get('id'), 'hostID' => $Host->get('id'), 'isDefault' => $i === 0 ? '1' : '0')); $NewPrinter->save(); } $i++; } } return $this; }
public function save() { parent::save(); if ($this->isLoaded('mac')) { $this->getClass('MACAddressAssociationManager')->destroy(array('hostID' => $this->get('id'), 'primary' => 1)); if ($this->get('mac') instanceof MACAddress && $this->get('mac')->isValid()) { $this->getClass('MACAddressAssociation')->set('hostID', $this->get('id'))->set('mac', strtolower($this->get('mac')))->set('primary', 1)->set('clientIgnore', $this->get('mac')->isClientIgnored())->set('imageIgnore', $this->get('mac')->isImageIgnored())->save(); } } if ($this->isLoaded('additionalMACs')) { $this->getClass('MACAddressAssociationManager')->destroy(array('hostID' => $this->get('id'), 'primary' => 0, 'pending' => 0)); foreach ((array) $this->get('additionalMACs') as $me) { if ($me instanceof MACAddress && $me->isValid()) { $this->getClass('MACAddressAssociation')->set('hostID', $this->get('id'))->set('mac', strtolower($me))->set('primary', 0)->set('pending', 0)->set('clientIgnore', $me->isClientIgnored())->set('imageIgnore', $me->isImageIgnored())->save(); } } } if ($this->isLoaded('pendingMACs')) { $this->getClass('MACAddressAssociationManager')->destroy(array('hostID' => $this->get('id'), 'primary' => 0, 'pending' => 1)); foreach ((array) $this->get('pendingMACs') as $me) { if ($me instanceof MACAddress && $me->isValid()) { $this->getClass('MACAddressAssociation')->set('hostID', $this->get('id'))->set('mac', strtolower($me))->set('primary', 0)->set('pending', 1)->set('clientIgnore', $me->isClientIgnored())->set('imageIgnore', $me->isImageIgnored())->save(); } } } if ($this->isLoaded('modules')) { $this->getClass('ModuleAssociationManager')->destroy(array('hostID' => $this->get('id'))); foreach ((array) $this->get('modules') as $Module) { $moduleName = $this->getGlobalModuleStatus(); if ($Module instanceof Module && $Module->isValid()) { if ($moduleName[$Module->get('shortName')]) { $this->getClass('ModuleAssociation')->set('hostID', $this->get('id'))->set('moduleID', $Module->get('id'))->set('state', 1)->save(); } } } } if ($this->isLoaded('printers')) { $defPrint = current((array) $this->getClass('PrinterAssociationManager')->find(array('hostID' => $this->get('id'), 'isDefault' => 1))); $totalPrinters = $this->getClass('PrinterAssociationManager')->count(array('hostID' => $this->get('id'))); $this->getClass('PrinterAssociationManager')->destroy(array('hostID' => $this->get('id'))); $i = 0; foreach ((array) $this->get('printers') as $Printer) { if ($Printer instanceof Printer && $Printer->isValid()) { $PrinterAssoc = current((array) $this->getClass('PrinterAssociationManager')->find(array('hostID' => $this->get('id'), 'printerID' => $Printer->get('id')))); if (!$PrinterAssoc || !$PrinterAssoc->isValid()) { $this->getClass('PrinterAssociation')->set('printerID', $Printer->get('id'))->set('hostID', $this->get('id'))->set('isDefault', $defPrint && $defPrint->isValid() && $defPrint->get('printerID') == $Printer->get('id') ? 1 : ($totalPrinters ? 0 : ($i === 0 ? 1 : 0)))->save(); } } $i++; } } if ($this->isLoaded('snapins')) { $this->getClass('SnapinAssociationManager')->destroy(array('hostID' => $this->get('id'))); foreach ((array) $this->get('snapins') as $Snapin) { if ($Snapin instanceof Snapin && $Snapin->isValid()) { $this->getClass('SnapinAssociation')->set('hostID', $this->get('id'))->set('snapinID', $Snapin->get('id'))->save(); } } } if ($this->isLoaded('groups')) { // Remove old rows $this->getClass('GroupAssociationManager')->destroy(array('hostID' => $this->get('id'))); // Create assoc foreach ((array) $this->get('groups') as $Group) { if ($Group instanceof Group && $Group->isValid()) { $this->getClass('GroupAssociation')->set('hostID', $this->get('id'))->set('groupID', $Group->get('id'))->save(); } } } if ($this->isLoaded('users')) { $this->getClass('UserTrackingManager')->destroy(array('hostID' => $this->get('id'))); foreach ((array) $this->get('users') as $User) { if ($User instanceof UserTracking && $User->isValid()) { $this->getClass('UserTracking')->set('hostID', $this->get('id'))->set('username', $User->get('username'))->set('action', $User->get('action'))->set('datetime', $User->get('datetime'))->set('description', $User->get('description'))->set('date', $User->get('date'))->save(); } } } return $this; }
public function save() { parent::save(); if ($this->isLoaded('hosts')) { // Remove old rows $this->getClass('SnapinAssociationManager')->destroy(array('snapinID' => $this->get('id'))); // Create assoc foreach ((array) $this->get('hosts') as $Host) { if ($Host instanceof Host && $Host->isValid()) { $NewGroup = new SnapinAssociation(array('hostID' => $Host->get('id'), 'snapinID' => $this->get('id'))); $NewGroup->save(); } } } if ($this->isLoaded('storageGroups')) { // Remove old rows $this->getClass('SnapinGroupAssociationManager')->destroy(array('snapinID' => $this->get('id'))); // Create Assoc foreach ((array) $this->get('storageGroups') as $Group) { if ($Group instanceof StorageGroup && $Group->isValid()) { $NewGroup = new SnapinGroupAssociation(array('snapinID' => $this->get('id'), 'storageGroupID' => $Group->get('id'))); $NewGroup->save(); } } } return $this; }
public function save() { parent::save(); if ($this->isLoaded('hosts')) { // Unset all hosts foreach ($this->getClass('HostManager')->find(array('imageID' => $this->get('id'))) as $Host) { if ($Host instanceof Host && $Host->isValid()) { $Host->set('imageID', 0)->save(); } } // Reset the hosts necessary foreach ((array) $this->get('hosts') as $Host) { if ($Host instanceof Host && $Host->isValid()) { $Host->set('imageID', $this->get('id'))->save(); } } } if ($this->isLoaded('storageGroups')) { // Remove old rows $this->getClass('ImageAssociationManager')->destroy(array('imageID' => $this->get('id'))); // Create Assoc foreach ((array) $this->get('storageGroups') as $Group) { if ($Group instanceof StorageGroup && $Group->isValid()) { $NewGroup = new ImageAssociation(array('imageID' => $this->get('id'), 'storageGroupID' => $Group->get('id'))); $NewGroup->save(); } } } return $this; }