Ejemplo n.º 1
0
 /**
  * Add new Kbit (users database)
  * @param {string} $title The title of the Kbit
  * @param {string} $desc  The description of the Kbit
  * @param {int} $user  The user's id who added the Kbit
  * @param {frontKbit} $front array of key value pair in FRONT format
  * @return {Kbit}
  */
 public static function add_new_edit_for_kbit($UID, $title, $desc, $user, $front)
 {
     // check if Kbit is locked by user
     if (Lock::is_locked_by_user($UID, 'KBIT_BASE', $user) == false) {
         debugLog::log("<i>[Kbits.php:add_new_edit_for_kbit]</i>The kbit (" . $UID . ") is not locked by user (" . $user . ")");
         return null;
     }
     $dbObj = new dbAPI();
     // get front type
     if ($front == null) {
         debugLog::log("<i>[Kbits.php:add_new_edit_for_kbit]</i> FRONT Kbit of (" . $title . ") is missing!");
         return null;
     }
     if ($front["FRONT_TYPE"] == null) {
         debugLog::log("<i>[Kbits.php:add_new_edit_for_kbit]</i> FRONT Kbit type of (" . $title . ") is missing!");
         return null;
     }
     // disable all kbit information
     Kbit::disable_all_kbit_info($UID, 'content');
     $front_type = $front["FRONT_TYPE"];
     // add record to database
     $query = "INSERT INTO KBIT_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 KBIT_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 kbit
     $recent_kbit = Kbit::get_base_Kbit($UID, 'user');
     if ($front != null) {
         // add front data to database
         $front_kbit = Kbit::add_new_front($UID, $front, $user);
         // check if the front was created successfully
         if ($front_kbit == null) {
             debugLog::log("<i>[Kbits.php:add_new_edit_for_kbit]</i> FRONT Kbit (" . $title . ") faild to create!");
             // option to rollback
             // example: remove the base kbit due to this error.
             return $recent_kbit;
         }
         // merge front kbit with base
         $recent_kbit["FRONT_KBIT"] = $front_kbit;
     }
     return $recent_kbit;
 }