/** * 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); }
/** * Disables all the old instances of the specific front Delivery and generates a new Rivision number * @param {int} $UID The UID of requested Delivery * @param {string} $tableName The table name of a specific front format (front Delivery, e.g. YOUTUBE) * @param {string} $source The table name of a specific front format (front Delivery, e.g. YOUTUBE) * @return {int} The new revision that should be used */ private static function get_new_Revision_and_disbale_old_ones($UID, $tableName, $source = 'content') { $dbObj = new dbAPI(); // determines the database name which the {Delivery} should be imported from $database_source = dbAPI::get_db_name($source); // prepare where statement $where_sttmnt = " ( UID = " . $UID . " ) "; // remove old instances of the specific front $dbObj->disable_revision($database_source, $tableName, $where_sttmnt); // get a new revision number for front Delivery $latest_revision = $dbObj->get_latest_Rivision_ID($database_source, $tableName, $where_sttmnt); if ($latest_revision == null) { $latest_revision = 0; } return $latest_revision; }