/** * Delete connection * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_SQL; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $dt = time(); $this->load(); $xml = format_object('xml', $this); $params = array(); $params[0] = $this->connid; $res = $DB->delete($HUB_SQL->DATAMODEL_CONNECTION_DELETE, $params); if (!$res) { return database_error(); } if (!auditConnection($USER->userid, $this->connid, "", $this->from->nodeid, $this->to->nodeid, $this->linktype->linktypeid, $this->fromrole->roleid, $this->torole->roleid, $CFG->actionDelete, $xml)) { return database_error(); } return new Result("deleted", "true", "1"); }
/** * Delete this linktype and any of this users connections using it. * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_SQL, $HUB_CACHE; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } if (isset($HUB_CACHE)) { $HUB_CACHE->deleteData($this->linktypeid); } $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $params[0] = $this->linktypeid; $params[1] = $currentuser; $resArray = $DB->select($HUB_SQL->DATAMODEL_LINKTYPE_DELETE_CHECK, $params); if ($resArray !== false) { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $c = new Connection($array['TripleID']); $c = $c->load(); if (!auditConnection($USER->userid, $array['TripleID'], $array['Label'], $array['FromID'], $array['ToID'], $array['LinkTypeID'], $array['FromContextTypeID'], $array['ToContextTypeID'], $CFG->actionDelete, format_object('xml', $c))) { return database_error(); } } $res = $DB->delete($HUB_SQL->DATAMODEL_LINKTYPE_DELETE_TRIPLE, $params); if ($res) { $res1 = $DB->delete($HUB_SQL->DATAMODEL_LINKTYPE_DELETE, $params); if (!$res1) { return database_error(); } } else { return database_error(); } } else { return database_error(); } return new Result("deleted", "true"); }
/** * Delete this role * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_SQL, $HUB_CACHE; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } if (isset($HUB_CACHE)) { $HUB_CACHE->deleteData($this->roleid); } $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $params[0] = $this->roleid; $params[1] = $this->roleid; $params[2] = $currentuser; $resArray = $DB->select($HUB_SQL->DATAMODEL_ROLE_DELETE_CHECK, $params); if ($resArray !== false) { $count = count($resArray); // Get the default role for this user $defRoleID = getDefaultRoleID(); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $fromContextType = $array['FromContextTypeID']; $toContextType = $array['ToContextTypeID']; if ($fromContextType == $this->roleid) { $fromContextType = $defRoleID; } if ($toContextType == $this->roleid) { $toContextType = $defRoleID; } $c = new Connection($array['TripleID']); $c = $c->load(); if (!auditConnection($USER->userid, $array['TripleID'], $array['Label'], $array['FromID'], $array['ToID'], $array['LinkTypeID'], $fromContextType, $toContextType, $CFG->actionEdit, format_object('xml', $c))) { return database_error(); } } $params = array(); $params[0] = $defRoleID; $params[1] = $this->roleid; $params[2] = $currentuser; $res1 = $DB->insert($HUB_SQL->DATAMODEL_ROLE_DELETE_UPDATE_TRIPLE_FROM, $params); $params = array(); $params[0] = $defRoleID; $params[1] = $this->roleid; $params[2] = $currentuser; $res2 = $DB->insert($HUB_SQL->DATAMODEL_ROLE_DELETE_UPDATE_TRIPLE_TO, $params); if ($res1 && $res2) { $params = array(); $params[0] = $currentuser; $params[1] = $this->roleid; $res = $DB->delete($HUB_SQL->DATAMODEL_ROLE_DELETE, $params); if (!$res) { return database_error(); } else { //delete any associated user assigned icon if ($this->image != null && $this->image != "" && substr($this->image, 0, 7) == 'uploads') { unlink($CFG->dirAddress . $this->image); } } } else { return database_error(); } } else { return database_error(); } return new Result("deleted", "true"); }
/** * Delete node * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_FLM, $HUB_SQL; try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $this->load(); $xml = format_object('xml', $this); $dt = time(); //delete the associated topic, if this is a map node being deleted. $role = $this->role; $challengenode = ""; $deleteconnections = array(); if ($role->name == "Map") { $view = getView($this->nodeid); // find the challenge node in the map to delete afterwards. $viewnodes = $view->nodes; $count = count($viewnodes); for ($i = 0; $i < $count; $i++) { $next = $viewnodes[$i]; $nextnode = $next->node; if ($nextnode->role->name == "Challenge") { $challengenode = $nextnode; } } // get the Connections in the Map to delete afterwards $viewconns = $view->connections; $count = count($viewconns); for ($i = 0; $i < $count; $i++) { $next = $viewconns[$i]; $nextcon = $next->connection; array_push($deleteconnections, $nextcon); } } $params = array(); $params[0] = $this->nodeid; $res = $DB->delete($HUB_SQL->DATAMODEL_NODE_DELETE, $params); if ($res) { auditIdea($USER->userid, $this->nodeid, $this->name, $this->description, $CFG->actionDelete, $xml); // NOT SURE THIS IS REQUIRED NOW AS IT SHOULD HAPPEN ON CASCADE DELETE IN THE DATABASE // update the related connections (triples) $params = array(); $params[0] = $this->nodeid; $params[1] = $this->nodeid; $resArray = $DB->select($HUB_SQL->DATAMODEL_NODE_DELETE_TRIPLE, $params); if ($resArray !== false) { $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $conn = new Connection($array['TripleID']); $conn = $conn->delete(); } } else { return database_error(); } //update the related URLs $params = array(); $params[0] = $this->nodeid; $res3 = $DB->delete($HUB_SQL->DATAMODEL_NODE_DELETE_URLNODE, $params); if (!$res3) { return database_error(); } // Take this opportunity to delete any URLs if they are no longer connected to a node // Probably should do this in a more organized way! $params = array(); $res4Array = $DB->select($HUB_SQL->DATAMODEL_NODE_DELETE_URLS_CLEAN, $params); if ($res4Array !== false) { $count = count($res4Array); for ($i = 0; $i < $count; $i++) { $array = $res4Array[$i]; $url = new URL($array['URLID']); $url = $url->delete(); } } // Delete any associated challenge node if this node is a Map // and any associated map Connections if ($role->name == "Map" && $challengenode != "") { $challengenode->delete(); $count = count($deleteconnections); for ($i = 0; $i < $count; $i++) { $nextcon = $deleteconnections[$i]; // Need to bypass check. // If you own the map you can delete it and its connections need to be deleted. $conxml = format_object('xml', $nextcon); $innerparams = array(); $innerparams[0] = $nextcon->connid; $res5 = $DB->delete($HUB_SQL->DATAMODEL_CONNECTION_DELETE, $innerparams); if ($res5) { auditConnection($USER->userid, $nextcon->connid, "", $nextcon->from->nodeid, $nextcon->to->nodeid, $nextcon->linktype->linktypeid, $nextcon->fromrole->roleid, $nextcon->torole->roleid, $CFG->actionDelete, $conxml); } } } } else { return database_error(); } //remove old thumbnail if ($this->thumb != null && $this->thumb != "" && substr($this->thumb, 0, 7) == 'uploads') { unlink($HUB_FLM->createUploadsDirPath($this->thumb)); } return new Result("deleted", "true"); }
/** * Delete node * * @return Result object (or Error object) */ function delete() { global $DB, $CFG, $USER, $HUB_FLM, $HUB_SQL; $this->load(); try { $this->candelete(); } catch (Exception $e) { return access_denied_error(); } $dt = time(); $params = array(); $params[0] = $this->viewid; $params[1] = $this->userid; $params[2] = $this->connid; $res = $DB->delete($HUB_SQL->DATAMODEL_VIEWCONNECTION_DELETE, $params); if ($res) { // Need to bypass check. // If you can delete the viewconnection you can delete it's underlying connection which needs to be deleted. $xml = format_object('xml', $this->connection); $params = array(); $params[0] = $this->connection->connid; $res2 = $DB->delete($HUB_SQL->DATAMODEL_CONNECTION_DELETE, $params); if ($res2) { auditConnection($USER->userid, $this->connection->connid, "", $this->connection->from->nodeid, $this->connection->to->nodeid, $this->connection->linktype->linktypeid, $this->connection->fromrole->roleid, $this->connection->torole->roleid, $CFG->actionDelete, $xml); } auditViewTriple($USER->userid, $this->viewid, $this->connid, $CFG->actionDelete); } else { return database_error(); } return new Result("deleted", "true"); }