<?php debugLog::included_log("Relation"); // reflexive relations class refRelation { /** * Relate object to object of the same type * @param {int} $parent_UID parent/first object UID * @param {int} $child_UID child/second object UID * @param {bool} $is_hier true if relation is parent/child false otherwise * @param {int} $user the user id that is performing the operation * @param {string} $tableName table name of the relation, e.g. R_LT2T, R_LS2S.. * @return {refRelation} the relation that was just created */ public static function add_relation_to_object($parent_UID, $child_UID, $is_hier, $user, $tableName, $database_name = 'content') { $database_name = dbAPI::get_db_name($database_name); if ($parent_UID == $child_UID) { debugLog::log("<i>[relations.php:add_relation_to_object]</i> parent " . $tableName . " (" . $parent_UID . ") and child (" . $child_UID . ") " . $tableName . " cannot be the same"); return null; } // disable old relation refRelation::remove_relation($parent_UID, $child_UID, $tableName, $database_name); // get latest revision number $dbObj = new dbAPI(); // where statement $where_sttmnt = " (PARENT_ID = " . $parent_UID . " AND CHILD_ID = " . $child_UID . ") OR (CHILD_ID = " . $parent_UID . " AND PARENT_ID = " . $child_UID . ")"; $old_rel = $dbObj->get_latest_Rivision_ID($database_name, $tableName, $where_sttmnt); if ($old_rel == null) { $old_rel = 0;
<?php debugLog::included_log("Lock"); /** * Lock class * @class Lock */ class Lock { public static function acquire_lock($UID, $entity_type, $user) { // add record to lock table in order to specify that the kbit is locked // NOTE: it is recomended to implement the lock in separated class if (Lock::is_locked($UID, $entity_type)) { debugLog::log("<i>[Lock::acquire_lock]:</i> cannot acquire lock on [" . $entity_type . "]: " . $UID . " because it is already locked"); return false; } $dbObj = new dbAPI(); // disable unlock records $query = "UPDATE CONTENT_LOCK SET ENABLED = 0 WHERE LOCKED_UID = '" . $UID . "' AND ENTITY_TYPE = '" . $entity_type . "' AND LOCK_STATUS = 'UNLOCKED' AND ENABLED = 1 "; $results = $dbObj->run_query($dbObj->db_get_contentDB(), $query); if ($results == false) { debugLog::log("<i>[Lock::acquire_lock]:</i> cannot acquire lock on [" . $entity_type . "]: " . $UID . " because of database update error"); return false; } // add lock record $query = "INSERT INTO CONTENT_LOCK (LOCKED_UID, ENTITY_TYPE, LOCK_STATUS, ENABLED, USER_ID, CREATION_DATE) VALUES (" . $UID . ", '" . $entity_type . "', 'LOCKED', 1, " . $user . ",'" . date("Y-m-d H:i:s") . "')"; return $dbObj->run_query($dbObj->db_get_contentDB(), $query) == true; } public static function release_lock($UID, $entity_type, $user) {
<?php debugLog::included_log("delivery"); /** * Delivery class * @class Delivery */ class Delivery { private static function get_relations_tables_names() { return array('R_LD2K', 'R_LD2T', 'R_LD2D'); } /** * Add new Delivery in edit mode (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_Delivery_in_edit_mode($title, $desc, $user, $front) { $dbObj = new dbAPI(); // get new UID from contents database to reseve the UID $UID = $dbObj->get_latest_UID($dbObj->db_get_contentDB(), 'DELIVERY_BASE'); $UID++; // try to acquire lock on the Delivery if (Lock::acquire_lock($UID, 'DELIVERY_BASE', $user) == false) { debugLog::log("<i>[delivery.php:add_new_Delivery_in_edit_mode]</i> Could not acquire lock on Delivery (" . $UID . "), check whether the Delivery is locked by other users"); return null;
<?php /* * PHP database connector */ //a basic API for database connector debugLog::included_log("Users"); // include 'DBobject.php'; class users { public $id; public $UID; public $first_name; public $last_name; public $username; private $password; public $email; public $creation_date; public $profile_picture; public $role; // add new user public static function add_new_user($first_name, $last_name, $username, $password, $email, $profile_picture, $role) { if (!users::is_username_available($username)) { return false; } $dbObj = new dbAPI(); $UID = $dbObj->get_latest_UID($dbObj->db_get_usersDB(), 'users'); $UID++; $query = "INSERT INTO users (UID, FIRST_NAME, LAST_NAME, USERNAME, PASSWORD, EMAIL, PROFILE_PICTURE, ROLE, CREATION_DATE) VALUES (" . $UID . ", '" . $first_name . "', '" . $last_name . "', '" . $username . "', '" . $password . "', '" . $email . "', '" . $profile_picture . "', " . $role . ",'" . date("Y-m-d H:i:s") . "')"; $dbObj->run_query($dbObj->db_get_usersDB(), $query);
<?php debugLog::included_log("Kbits"); /** * Kbit class * @class Kbit */ class Kbit { private static function get_relations_tables_names() { return array('R_LD2K', 'R_LK2T', 'R_LK2K'); } /** * Add new Kbit in edit mode (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_Kbit_in_edit_mode($title, $desc, $user, $front) { $dbObj = new dbAPI(); // get new UID from contents database to reseve the UID $UID = $dbObj->get_latest_UID($dbObj->db_get_contentDB(), 'KBIT_BASE'); $UID++; // try to acquire lock on the Kbit if (Lock::acquire_lock($UID, 'KBIT_BASE', $user) == false) { debugLog::log("<i>[Kbits.php:add_new_Kbit_in_edit_mode]</i> Could not acquire lock on kbit (" . $UID . "), check whether the Kbit is locked by other users"); return null;
<?php debugLog::included_log("Term"); class term { // 1) add a new term with scope and meaning, if no scope selected create term with 'general scope' and 'general meaning' public static function add_new_term_with_scope_and_meaning($term_text, $lang, $user, $scope_UID = '', $meaning_text = '') { // create single term $new_term = term::add_new_term($term_text, $lang, $user); // get selected scope // check if there is specific scope if ($scope_UID == '') { $scope_UID = '0'; // 0 means general scope // check if there is a general scope in database $selected_scope = scope::get_scope_by_UID(0); if ($selected_scope == null) { // create new general scope record in database $selected_scope = scope::add_new_scope("General", "General scope", $user); } } else { $selected_scope = scope::get_scope_by_UID($scope_UID); } if ($selected_scope == null) { debugLog::debug_log("could not locate scope \"" . $scope_UID . "\""); return null; } // check if a meaning is attached and add it to database if ($meaning_text == '') { // create new general meaning
<?php debugLog::included_log("Scope"); class scope { // add new scope 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); } // returns a scope by its UID public static function get_scope_by_UID($UID) { $dbObj = new dbAPI(); $query = "SELECT * FROM scope where UID = '" . $UID . "' AND ENABLED = '1'"; $results = $dbObj->db_select_query($dbObj->db_get_contentDB(), $query); if (count($results) == 0) { return null; } return $results[0]; } public static function get_scope_by_UID_with_relations($UID, $lang = '') {
<?php /* * PHP database connector */ //a basic API for database connector debugLog::included_log("dbAPI"); class dbAPI { //private $user = '******'; //private $password = '******'; //private $dbUsers = 'CMS_USERSdb'; //private $dbContent = 'CMSdb'; //private $host = 'localhost'; private $user = '******'; private $password = '******'; private $dbUsers = 'CMS_USERSdb'; private $dbContent = 'CMSdb'; private $host = '127.12.108.2:3306'; public function db_get_usersDB() { return $this->dbUsers; } public function db_get_contentDB() { return $this->dbContent; } public static function get_db_name($source) { $dbObj = new dbAPI(); if ($source == 'content' || $source == "CMSdb") {