/** * connect Kbit to Delivery (add relation) * @param {int} $Kbit_UID kbit UID * @param {int} $delivery_UID delivery UID * @param {string} $link_type The link type e.g. NEEDED, PROVIDED * @param {float} $link_weight The wight of the link * @param {int} $user user's id that is performing the operation * @param {string} $database_name database name e.g. 'content', 'user' * @return {D2KRelation} The relation that was just created */ public static function add_D2K_relation($Kbit_UID, $delivery_UID, $link_type, $link_weight, $user, $database_name) { $database_name = dbAPI::get_db_name($database_name); // disable old relation D2KRelation::remove_D2K_relation($Kbit_UID, $delivery_UID, $link_type, $database_name); // get latest revision number $dbObj = new dbAPI(); $where_sttmnt = " KBIT_BASE_ID = " . $Kbit_UID . " AND DELIVERY_BASE_ID = " . $delivery_UID . " AND LINK_TYPE = '" . $link_type . "' AND ENABLED = 1 "; $old_rev = $dbObj->get_latest_Rivision_ID($database_name, 'R_LD2K', $where_sttmnt); if ($old_rev == null) { $old_rev = 0; } // add new relation $query = "INSERT INTO R_LD2K (REVISION, KBIT_BASE_ID, DELIVERY_BASE_ID, LINK_TYPE, LINK_WEIGHT, ENABLED, USER_ID, CREATION_DATE) VALUES (" . ($old_rev + 1) . ", " . $Kbit_UID . ", " . $delivery_UID . ", '" . $link_type . "'," . $link_weight . ", 1, " . $user . ",'" . date("Y-m-d H:i:s") . "')"; $dbObj->run_query($database_name, $query); // return recently created relation return D2KRelation::get_D2K_relation($Kbit_UID, $delivery_UID, $link_type, $database_name); }
public static function remove_Kbit_from_delivery($Kbit_UID, $Delivery_UID, $link_type, $user) { if (Lock::is_locked_by_user($Delivery_UID, 'DELIVERY_BASE', $user) == false) { debugLog::log("<i>[delivery.php:remove_term_from_Delivery]</i> Delivery (" . $Delivery_UID . ") is not locked by the user (" . $user . ")"); return null; } $locking_user = Lock::get_locking_user($UID, 'KBIT_BASE'); if ($locking_user != null && $locking_user["UID"] != $user) { debugLog::log("<i>[delivery.php:add_Kbit_to_delivery]</i> Kbit(" . $Kbit_UID . ") is locked by other user(" . $locking_user["UID"] . ")"); return null; } return D2KRelation::remove_D2K_relation($Kbit_UID, $Delivery_UID, $link_type, 'user'); }