/** * Editor k přidávání členů skupiny * * @param IEServices $service */ public function __construct($service) { $hostsAssigned = array(); parent::__construct(); $fieldName = $this->getmyKeyColumn(); $initialContent = new EaseTWBPanel(_('Sledované hosty služby'), 'default'); $initialContent->setTagCss(array('width' => '100%')); if (is_null($service->getMyKey())) { $initialContent->addItem(_('Nejprve je potřeba uložit záznam')); } else { $serviceName = $service->getName(); $host = new IEHost(); if (EaseShared::user()->getSettingValue('admin')) { $allHosts = $host->getAllFromMySQL(NULL, array($host->myKeyColumn, $host->nameColumn, 'platform', 'register'), null, $host->nameColumn, $host->myKeyColumn); } else { $allHosts = $host->getListing(null, true, array('platform', 'register')); } if ($service->getDataValue('host_name')) { foreach ($service->getDataValue('host_name') as $hostId => $hostName) { if (isset($allHosts[$hostId])) { $hostsAssigned[$hostId] = $allHosts[$hostId]; } } } foreach ($allHosts as $hostID => $hostInfo) { if ($hostInfo['register'] != 1) { unset($allHosts[$hostID]); } if ($hostInfo['platform'] != 'generic' && $hostInfo['platform'] != $service->getDataValue('platform')) { unset($allHosts[$hostID]); } } foreach ($hostsAssigned as $hostID => $hostInfo) { unset($allHosts[$hostID]); } if (count($allHosts)) { foreach ($allHosts as $hostID => $hostInfo) { $initialContent->addItem(new EaseTWBButtonDropdown($hostInfo[$host->nameColumn], 'inverse', 'xs', array(new EaseHtmlATag('host.php?host_id=' . $hostID . '&service_id=' . $service->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace')), new EaseHtmlATag('?addhost=' . $hostInfo[$host->nameColumn] . '&host_id=' . $hostID . '&' . $service->getmyKeyColumn() . '=' . $service->getMyKey() . '&' . $service->nameColumn . '=' . $service->getName(), EaseTWBPart::GlyphIcon('plus') . ' ' . _('Začít sledovat'))))); } } if (count($hostsAssigned)) { $initialContent->addItem('<br/>'); foreach ($hostsAssigned as $hostID => $hostInfo) { $initialContent->addItem(new EaseTWBButtonDropdown($hostInfo[$host->nameColumn], 'success', 'xs', array(new EaseHtmlATag('?delhost=' . $hostInfo[$host->nameColumn] . '&host_id=' . $hostID . '&' . $service->getmyKeyColumn() . '=' . $service->getMyKey() . '&' . $service->nameColumn . '=' . $service->getName(), EaseTWBPart::GlyphIcon('remove') . ' ' . _('Přestat sledovat')), new EaseHtmlATag('host.php?host_id=' . $hostID . '&service_id=' . $service->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace'))))); } } } $this->addItem($initialContent); }
/** * Přehodí * @param type $swapToID * @return boolean */ public function swapTo($swapToID) { $newService = new IEService($swapToID); $thisName = $this->getName(); $hostsOK = array(); $hostsErr = array(); $hostsAssigned = array(); $host = new IEHost(); if (EaseShared::user()->getSettingValue('admin')) { $allHosts = $host->getAllFromMySQL(NULL, array($host->myKeyColumn, $host->nameColumn, 'platform', 'register'), null, $host->nameColumn, $host->myKeyColumn); } else { $allHosts = $host->getListing(null, true, array('platform', 'register')); } $hosts = $this->getDataValue('host_name'); foreach ($hosts as $hostId => $hostName) { if (isset($allHosts[$hostId])) { $hostsAssigned[$hostId] = $allHosts[$hostId]; } } foreach ($hostsAssigned as $host_id => $hostAssigned) { if ($this->delMember('host_name', $host_id, $hostAssigned['host_name']) && $newService->addMember('host_name', $host_id, $hostAssigned['host_name'])) { $hostsOK[] = $hostAssigned['host_name']; } else { $hostsErr[] = $hostAssigned['host_name']; } } if ($this->saveToMySQL() && $newService->saveToMySQL() && count($hostsOK)) { $this->addStatusMessage(sprintf(_('%s byl přesunut z %s/%s do %s'), implode(',', $hostsOK), $this->keyword, $this->getName(), $newService->getName()), 'success'); return true; } else { $this->addStatusMessage(sprintf(_(' %s nebyl přesunut z %s/%s do %s'), implode(',', $hostsErr), $this->keyword, $this->getName(), $newService->getName()), 'warning'); return false; } }