Exemple #1
0
 public static function add_new_scope($title, $description, $user)
 {
     $dbObj = new dbAPI();
     // get new UID
     $UID = $dbObj->get_latest_UID($dbObj->db_get_contentDB(), 'scope');
     $UID++;
     // add record to database
     $query = "INSERT INTO scope (UID, TITLE, DESCRIPTION, ENABLED, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $title . "', '" . $description . "', 1, " . $user . ",'" . date("Y-m-d H:i:s") . "')";
     $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     // returns an entity of recently added scope
     return scope::get_scope_by_UID($UID);
 }
Exemple #2
0
 public static function release_lock($UID, $entity_type, $user)
 {
     // add record to lock table in order to specify that the kbit is no longer locked
     // NOTE: it is recomended to implement the lock in separated class
     if (Lock::is_locked($UID, $entity_type) == false) {
         debugLog::log("<i>[Lock::release_lock]:</i> cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked");
         return false;
     }
     if (Lock::is_locked_by_user($UID, $entity_type, $user) == false) {
         debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because it is not locked by the same user");
         return false;
     }
     $dbObj = new dbAPI();
     // disable lock records
     $query = "UPDATE CONTENT_LOCK SET ENABLED = 0 WHERE LOCKED_UID = '" . $UID . "' AND ENTITY_TYPE = '" . $entity_type . "' AND LOCK_STATUS = 'LOCKED' AND ENABLED = 1 ";
     $results = $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     if ($results == false) {
         debugLog::log("<i>[Lock::release_lock]:</i>cannot release lock of [" . $entity_type . "]: " . $UID . " because of database update error");
         return false;
     }
     // add release record
     $query = "INSERT INTO CONTENT_LOCK (LOCKED_UID, ENTITY_TYPE, ENABLED, LOCK_STATUS, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $entity_type . "', 1, 'UNLOCKED', " . $user . ",'" . date("Y-m-d H:i:s") . "')";
     return $dbObj->run_query($dbObj->db_get_contentDB(), $query) == true;
 }
Exemple #3
0
 /**
  * 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);
 }
Exemple #4
0
 /**
  * Creates a copy of all records related to the specified Delivery into the content database and disables all records in user database then releases the lock
  * @param  {int} $UID  UID of the Delivery that is being published
  * @param  {int} $user The user that is publishing the Delivery
  * @return {bool}       true on success false otherwise
  */
 public static function publish_changes($UID, $user)
 {
     // add new record in content database for each data record and disable all data records in user database
     if (Lock::is_locked_by_user($UID, 'DELIVERY_BASE', $user) == false) {
         debugLog::log("<i>[delivery.php:publish_changes]</i> cannot publish Delivery (" . $UID . ") because the user is not locking it or is locked by someone else");
         return false;
     }
     // get selected Delivery
     $curr_Delivery = Delivery::get_edited_Delivery_by_UID($UID);
     if ($curr_Delivery == null) {
         debugLog::log("<i>[Delivery::publish_changes]:</i> Could not find Delivery of the base (" . $UID . ") in user");
         return false;
     }
     // disable all Delivery information
     Delivery::disable_all_Delivery_info($UID, 'content');
     // copy Delivery from user database into content database
     $dbObj = new dbAPI();
     $where_sttmnt = ' WHERE UID = ' . $UID . ' AND ENABLED = 1 ';
     // get columns names
     $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_contentDB(), "DELIVERY_BASE", true);
     // remove primary key (auto-increment) column (id)
     $columns_names = str_replace("id,", "", $columns_names);
     // copy record from user to content
     $query = "INSERT INTO " . $dbObj->db_get_contentDB() . ".DELIVERY_BASE (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_usersDB() . ".DELIVERY_BASE " . $where_sttmnt . "";
     $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     // get front Delivery table name
     $front_table_name = Delivery::get_front_table_name($curr_Delivery["FRONT_TYPE"]);
     if ($front_table_name == null) {
         debugLog::log("<i>[Delivery::publish_changes]:</i> Could not find front Delivery table name (" . $UID . ")");
         // roll back option here
         return false;
     }
     // get columns names
     $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_contentDB(), $front_table_name, true);
     // remove primary key (auto-increment) column (id)
     $columns_names = str_replace("id,", "", $columns_names);
     // copy front record from user to content
     $query = "INSERT INTO " . $dbObj->db_get_contentDB() . "." . $front_table_name . " (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_usersDB() . "." . $front_table_name . " " . $where_sttmnt . "";
     $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     // loop over links and copy records from user to content
     $links_tables_names = Delivery::get_relations_tables_names();
     for ($i = 0; $i < count($links_tables_names); $i++) {
         // prepare where statement
         if ($links_tables_names[$i] == 'R_LD2D') {
             $where_sttmnt = ' (PARENT_ID = ' . $UID . ' OR CHILD_ID = ' . $UID . ') ';
         } else {
             $where_sttmnt = ' (Delivery_BASE_ID = ' . $UID . ') ';
         }
         // get columns names
         $columns_names = $dbObj->db_get_columns_names($dbObj->db_get_contentDB(), $links_tables_names[$i], true);
         // remove primary key (auto-increment) column (id)
         $columns_names = str_replace("id,", "", $columns_names);
         // get all relevant relations
         $query = "SELECT id FROM " . $links_tables_names[$i] . " where " . $where_sttmnt . " AND ENABLED = '1'";
         $relations = $dbObj->db_select_query($dbObj->db_get_usersDB(), $query);
         // loop over all records and insert them
         for ($j = 0; $j < count($relations); $j++) {
             $where_sttmnt = ' id =' . $relations[$j]["id"] . ' ';
             $query = "INSERT INTO " . $dbObj->db_get_contentDB() . "." . $links_tables_names[$i] . " (" . $columns_names . ") SELECT " . $columns_names . " FROM " . $dbObj->db_get_usersDB() . "." . $links_tables_names[$i] . " where " . $where_sttmnt . "";
             $dbObj->run_query($dbObj->db_get_contentDB(), $query);
         }
     }
     // remove copies from user database
     Delivery::disable_all_Delivery_info($UID, 'user');
     // release lock off the Delivery
     if (Lock::release_lock($UID, 'DELIVERY_BASE', $user) == false) {
         debugLog::log("<i>[delivery.php:publish_changes]</i> Could not release lock off Delivery (" . $UID . ")");
         return false;
     }
     return true;
 }
Exemple #5
0
 private static function create_new_token($username)
 {
     try {
         $token = users::generateRandomString();
         $dbObj = new dbAPI();
         $query = "UPDATE users SET TOKEN = '" . $token . "' where USERNAME = '******'";
         $results = $dbObj->run_query($dbObj->db_get_usersDB(), $query);
         if ($results) {
             echo $results;
             return $token;
         }
         debugLog::debug_log("create token for user: "******" has failed");
         return null;
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
 }
Exemple #6
0
 public static function add_meaning($meaning, $lang, $user)
 {
     $dbObj = new dbAPI();
     // get new UID
     $UID = $dbObj->get_latest_UID($dbObj->db_get_contentDB(), 'TERM_MEAN');
     $UID++;
     // add record to database
     $query = "INSERT INTO TERM_MEAN (UID, TEXT, LANG, ENABLED, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $meaning . "', '" . $lang . "', 1, " . $user . ",'" . date("Y-m-d H:i:s") . "')";
     $dbObj->run_query($dbObj->db_get_contentDB(), $query);
     // returns an entity of recently added term meaning
     return term::get_term_meaning_by_UID($UID, $lang);
 }
Exemple #7
0
 public static function delete_all($dbArr)
 {
     $dbObj = new dbAPI();
     // $dbArr = array( $u.'.KBIT_BASE', $u.'.KBIT_FRONT', $c.'.KBIT_BASE', $c.'.KBIT_FRONT', $c.'.CONTENT_LOCK');
     for ($k = 0; $k < count($dbArr); $k++) {
         $dbObj->run_query($dbObj->db_get_usersDB(), "DELETE FROM " . $dbArr[$k]);
     }
 }