public function associateGroupAndNode($node_id, $group_id) { $assoc = new NodeGroupAssociation(); $assoc->group_id = $group_id; $assoc->node_id = $node_id; if ($assoc->save()) { return Response::json(array('success' => 'true', 'new_id' => $assoc->id, 'new_name' => NodeGroup::find($group_id)->name)); } else { return Response::json(array('success' => 'false')); } }
</div> </div> <div class="uk-width-1-6 node_base_image_id activatable"><div class="trim shift5"><?php echo $node->service_provider_base_image_id; ?> </div></div> <div class="uk-width-1-6 node_hostname activatable"><div class="trim_long shift5"><?php echo $node->hostname; ?> </div></div> <div class="uk-width-1-6 node_packages"><div class="shift5"> <?php foreach (NodeGroupAssociation::where('node_id', '=', $node->id)->get() as $grp) { ?> <?php $groupInfo = NodeGroup::find($grp->group_id); ?> <div class="nos-deletable" rel="<?php echo $grp->id; ?> "><span><?php echo $groupInfo->name; ?> </span><a href="#" class="remove">x</a></div> <?php } ?> </div></div> </div> <?php }
/** * Create a new Node group in the database * * @param string $ng_name The name of the new node group to create. If empty a dummy value will be set * @param object $network Network object. The node's network. If not * present, the current Network will be assigned * * @return mixed The newly created Node Group object, or null if there was * an error * * @static * @access public */ public static function createNewObject($ng_name = null, $network = null) { $db = AbstractDb::getObject(); if (empty($ng_name)) { $ng_name = $db->escapeString(_('New node group name')); } else { $ng_name = $db->escapeString($ng_name); } $node_group_id = get_guid(); if (empty($network)) { $network = Network::getCurrentNetwork(); } $network_id = $db->escapeString($network->getId()); $duplicate = null; try { $duplicate = NodeGroup::getObjectByName($ng_name); } catch (Exception $e) { } if ($duplicate) { throw new Exception(sprintf(_('Sorry, a node group with the name %s already exists.'), $ng_name)); } $sql = "INSERT INTO node_groups (node_group_id, name) VALUES ('{$node_group_id}', '{$ng_name}')"; if (!$db->execSqlUpdate($sql, false)) { throw new Exception(_('Unable to insert new node group into database!')); } HotspotGraphElement::createNewObject($node_group_id, 'NodeGroup', $network); $object = self::getObject($node_group_id); return $object; }