public static function add_relation_to_scope($parent_scope_UID, $child_scope_UID, $is_hier, $user) { // create relation between two terms if (refRelation::add_relation_to_object($parent_scope_UID, $child_scope_UID, $is_hier, $user, 'R_Ls2s') == null) { debugLog::log("parent scope (" . $parent_scope_UID . ") and child (" . $child_scope_UID . ") scope cannot be the same"); return null; } // return recently created relation return refRelation::get_objects_relation($parent_scope_UID, $child_scope_UID, 'R_Ls2s'); }
/** * Relate object to object of the same type * @param {int} $parent_UID parent/first object UID * @param {int} $child_UID child/second object UID * @param {bool} $is_hier true if relation is parent/child false otherwise * @param {int} $user the user id that is performing the operation * @param {string} $tableName table name of the relation, e.g. R_LT2T, R_LS2S.. * @return {refRelation} the relation that was just created */ public static function add_relation_to_object($parent_UID, $child_UID, $is_hier, $user, $tableName, $database_name = 'content') { $database_name = dbAPI::get_db_name($database_name); if ($parent_UID == $child_UID) { debugLog::log("<i>[relations.php:add_relation_to_object]</i> parent " . $tableName . " (" . $parent_UID . ") and child (" . $child_UID . ") " . $tableName . " cannot be the same"); return null; } // disable old relation refRelation::remove_relation($parent_UID, $child_UID, $tableName, $database_name); // get latest revision number $dbObj = new dbAPI(); // where statement $where_sttmnt = " (PARENT_ID = " . $parent_UID . " AND CHILD_ID = " . $child_UID . ") OR (CHILD_ID = " . $parent_UID . " AND PARENT_ID = " . $child_UID . ")"; $old_rel = $dbObj->get_latest_Rivision_ID($database_name, $tableName, $where_sttmnt); if ($old_rel == null) { $old_rel = 0; } // add new relation $query = "INSERT INTO " . $tableName . " (REVISION, HIER, PARENT_ID, CHILD_ID, ENABLED, USER_ID, CREATION_DATE) VALUES (" . ($old_rel + 1) . ", " . $is_hier . ", " . $parent_UID . ", " . $child_UID . ", 1, " . $user . ",'" . date("Y-m-d H:i:s") . "')"; $dbObj->run_query($database_name, $query); // return recently created relation return refRelation::get_objects_relation($parent_UID, $child_UID, $tableName, $database_name); }
public static function add_D2D_relation($first_UID, $second_UID, $is_hier, $user) { // check if delivery is locked by user if (Lock::is_locked_by_user($first_UID, 'DELIVERY_BASE', $user) == false && Lock::is_locked_by_user($second_UID, 'DELIVERY_BASE', $user) == false) { debugLog::log("<i>[delivery.php:add_D2D_relation]</i> Non of the deliveries (" . $first_UID . ", " . $second_UID . ") are locked by user (" . $user . ")"); return null; } // check soft lock $locking_user = Lock::get_locking_user($first_UID, 'DELIVERY_BASE'); if ($locking_user != null && $locking_user["UID"] != $user) { debugLog::log("<i>[delivery.php:add_D2D_relation]</i> one of the deliveries (" . $first_UID . ") is locked by other user(" . $locking_user["UID"] . ")"); return null; } $locking_user = Lock::get_locking_user($second_UID, 'DELIVERY_BASE'); if ($locking_user != null && $locking_user["UID"] != $user) { debugLog::log("<i>[delivery.php:add_D2D_relation]</i> one of the deliveries (" . $first_UID . ") is locked by other user(" . $locking_user["UID"] . ")"); return null; } if (refRelation::add_relation_to_object($first_UID, $second_UID, $is_hier, $user, 'R_LD2D', 'user') == null) { debugLog::log("<i>[delivery.php:add_D2D_relation]</i> parent Delivery (" . $first_UID . ") and child (" . $second_UID . ") Delivery cannot be the same"); return null; } // return recently created relation return refRelation::get_objects_relation($first_UID, $second_UID, 'R_LD2D', 'user'); }