/** * Add new Delivery (users database) * @param {string} $title The title of the Delivery * @param {string} $desc The description of the Delivery * @param {int} $user The user's id who added the Delivery * @param {frontDelivery} $front array of key value pair in FRONT format * @return {Delivery} */ public static function add_new_edit_for_Delivery($UID, $title, $desc, $user, $front) { // check if Kbit is locked by user if (Lock::is_locked_by_user($UID, 'DELIVERY_BASE', $user) == false) { debugLog::log("<i>[delivery.php:add_new_edit_for_Delivery]</i>The Delivery (" . $UID . ") is not locked by user (" . $user . ")"); return null; } $dbObj = new dbAPI(); // get front type if ($front == null) { debugLog::log("<i>[delivery.php:add_new_edit_for_Delivery]</i> FRONT Delivery of (" . $title . ") is missing!"); return null; } if ($front["FRONT_TYPE"] == null) { debugLog::log("<i>[delivery.php:add_new_edit_for_Delivery]</i> FRONT Delivery type of (" . $title . ") is missing!"); return null; } // disable all Delivery information Delivery::disable_all_Delivery_info($UID, 'content'); $front_type = $front["FRONT_TYPE"]; // add record to database $query = "INSERT INTO DELIVERY_BASE (UID, REVISION, TITLE, DESCRIPTION, ENABLED, USER_ID, CREATION_DATE, FRONT_TYPE) VALUES (" . $UID . ", 1, '" . $title . "', '" . $desc . "', 1, " . $user . ",'" . date("Y-m-d H:i:s") . "','" . $front_type . "')"; $dbObj->run_query($dbObj->db_get_usersDB(), $query); $query = "INSERT INTO DELIVERY_BASE (UID, REVISION, TITLE, DESCRIPTION, ENABLED, USER_ID, CREATION_DATE, FRONT_TYPE) VALUES (" . $UID . ", 1, '" . $title . "', '" . $desc . "', 0, " . $user . ",'" . date("Y-m-d H:i:s") . "','" . $front_type . "')"; $dbObj->run_query('content', $query); // entity of recently added Delivery $recent_Delivery = Delivery::get_base_Delivery($UID, 'user'); if ($front != null) { // add front data to database $front_Delivery = Delivery::add_new_front($UID, $front, $user); // check if the front was created successfully if ($front_Delivery == null) { debugLog::log("<i>[delivery.php:add_new_edit_for_Delivery]</i> FRONT Delivery (" . $title . ") faild to create!"); // option to rollback // example: remove the base Delivery due to this error. return $recent_Delivery; } // merge front Delivery with base $recent_Delivery["FRONT_DELIVERY"] = $front_Delivery; } return $recent_Delivery; }