Commit 79d83dff9e3a383f3f7e51fe6a8288e420d64625

Authored by rob
1 parent 4b80f06f

Initial revision. Object that represents folders_users_roles_link table in database


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@379 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 272 additions and 0 deletions
lib/roles/RoleFolderLink.inc 0 → 100644
  1 +<?php
  2 +/**
  3 +* @package lib.roles
  4 +*
  5 +* Class RoleFolderLink
  6 +* Represents a role, folder links as per the folders_users_role_link table
  7 +*
  8 +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  9 +* @date 20 January 2003
  10 +*/
  11 +
  12 +class RoleFolderLink {
  13 +
  14 + var $iId;
  15 + var $iUserID;
  16 + var $iFolderID;
  17 + var $iRoleTypeID;
  18 + var $dDateTime;
  19 + var $bDone;
  20 +
  21 + /**
  22 + * Default constructor
  23 + *
  24 + * @param int Primary key of user to which role is linked
  25 + * @param int Primary key of folder to which role is linked
  26 + * @param int Primary key of role type
  27 + *
  28 + */
  29 + function RoleFolderLink($iNewUserID, $iNewFolderID, $iNewRoleTypeID) {
  30 + //object not created in database yet
  31 + $this->iId = -1;
  32 + $this->iUserID = $iNewUserID;
  33 + $this->iFolderID = $iNewFolderID;
  34 + $this->iRoleTypeID = $iNewRoleTypeID;
  35 + //the date time is the time at which the task is finished, not the time
  36 + //at which the object is created
  37 + $this->dDateTime = null;
  38 + //task cannot be done yet
  39 + $this->bDone = false;
  40 + }
  41 +
  42 + /**
  43 + * Get the object's primary key
  44 + *
  45 + * @return int object's primary key
  46 + *
  47 + */
  48 + function getID() {
  49 + return $this->iId;
  50 + }
  51 +
  52 + /**
  53 + * Get the primary key of the user to which the role is linked
  54 + *
  55 + * @return int primary key of user to which role is linked
  56 + *
  57 + */
  58 + function getUserID() {
  59 + return $this->iUserID;;
  60 + }
  61 +
  62 + /**
  63 + * Set the primary key of the user to which the role is linked
  64 + *
  65 + * @param int Primary key of user to which role will be linked
  66 + *
  67 + */
  68 + function setUserID($iNewValue) {
  69 + $this->iUserID = $iNewValue;
  70 + }
  71 +
  72 + /**
  73 + * Get the primary key of the folder to which the role is linked
  74 + *
  75 + * @return int primary key of folder to which role is linked
  76 + *
  77 + */
  78 + function getFolderID() {
  79 + return $this->iFolderID;
  80 + }
  81 +
  82 + /**
  83 + * Set the primary key of the folder to which the role is linked
  84 + *
  85 + * @param int Primary key of folder to which role is linked
  86 + *
  87 + */
  88 + function setFolderID($iNewValue) {
  89 + $this->iFolderID = $iNewValue;
  90 + }
  91 +
  92 + /**
  93 + * Get the primary key of the role type
  94 + *
  95 + * @return int primary key of role type
  96 + *
  97 + */
  98 + function getRoleTypeID() {
  99 + return $this->iRoleTypeID;
  100 + }
  101 +
  102 + /**
  103 + * Set the primary key of the role type
  104 + *
  105 + * @param int Primary key of role type
  106 + *
  107 + */
  108 + function setRoleTypeID($iNewValue) {
  109 + $this->iRoleTypeID = $iNewValue;
  110 + }
  111 +
  112 + /**
  113 + * Get the date at which the function for this role was performed
  114 + *
  115 + * @return date date at which the function for this role was performed
  116 + *
  117 + */
  118 + function getDateTime() {
  119 + return $this->dDateTime;
  120 + }
  121 +
  122 + /**
  123 + * Set the date/time at which the function for this role was performed
  124 + *
  125 + * @param date/time Date/time at which the function for this role was performed
  126 + *
  127 + */
  128 + function setDateTime($dNewValue) {
  129 + $this->dDateTine = $dNewValue;
  130 + }
  131 +
  132 + /**
  133 + * Get the done status of the role/folder/user link
  134 + *
  135 + * @return boolean done status of this role/folder/user link
  136 + *
  137 + */
  138 + function getDone() {
  139 + return $this->bDone;
  140 + }
  141 +
  142 + /**
  143 + * Set the done status of this role/folder/user link
  144 + *
  145 + * @param boolean Done status of this role/folder/user link
  146 + *
  147 + */
  148 + function setDone($bNewValue) {
  149 + $this->bDone = $bNewValue;
  150 + }
  151 +
  152 + /**
  153 + * Create the current object in the database
  154 + *
  155 + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"]
  156 + *
  157 + */
  158 + function create() {
  159 + global $default, $lang_err_database, $lang_err_object_exists;
  160 + //if the object hasn't been created
  161 + if ($this->iId < 0) {
  162 + $sql = new Owl_DB();
  163 + $result = $sql->query("INSERT INTO " . $default->owl_folders_user_roles_table . " (user_id, folder_id, role_type_id, datetime, done) VALUES ($this->iUserID, $this->iFolderID, $this->iRoleTypeID, '$this->dDateTime', " . ($this->bDone ? 1 : 0) . ")");
  164 + if ($result) {
  165 + $this->iId = $sql->insert_id();
  166 + return true;
  167 + }
  168 + $_SESSION["errorMessage"] = $lang_err_database;
  169 + return false;
  170 + }
  171 + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_folder_user_roles_table";
  172 + return false;
  173 + }
  174 +
  175 + /**
  176 + * Update the values in the database table with the object's current values
  177 + *
  178 + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
  179 + *
  180 + */
  181 + function update() {
  182 + global $default, $lang_err_database, $lang_err_object_key;
  183 + //only update if the object has been stored
  184 + if ($this->iId > 0) {
  185 + $sql = new Owl_DB();
  186 + $result = $sql->query("UPDATE " . $default->owl_folders_user_roles_table . " SET user_id = $this->iUserID, folder_id = $this->iFolderID, role_type_id = $this->iRoleTypeID, datetime = '$this->dDateTime', done = " . ($this->bDone ? 1 : 0) . " WHERE id = $this->iId");
  187 + if ($result) {
  188 + return true;
  189 + }
  190 + $_SESSION["errorMessage"] = $lang_err_database;
  191 + return false;
  192 + }
  193 + $_SESSION["errorMessage"] = $lang_err_object_key;
  194 + return false;
  195 + }
  196 +
  197 + /**
  198 + * Delete the current object from the database
  199 + *
  200 + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]
  201 + *
  202 + */
  203 + function delete() {
  204 + global $default, $lang_err_database, $lang_err_object_key;
  205 + //only delete the object if it exists in the database
  206 + if ($this->iId >= 0) {
  207 + $sql = new Owl_DB();
  208 + $result = $sql->query("DELETE FROM $default->owl_folders_user_roles_table WHERE id = $this->iId");
  209 + if ($result) {
  210 + return true;
  211 + }
  212 + $_SESSION["errorMessage"] = $lang_err_database;
  213 + return false;
  214 + }
  215 + $_SESSION["errorMessage"] = $lang_err_object_key;
  216 + return false;
  217 + }
  218 +
  219 + /**
  220 + * Static function.
  221 + * Given a folders_users_roles_link primary key it will create a
  222 + * RolesFoldersLink object and populate it with the
  223 + * corresponding database values
  224 + *
  225 + * @return RolesFoldersLink populated RolesFoldersLink object on successful query, false otherwise and set $_SESSION["errorMessage"]
  226 + */
  227 + function & get($iRolesFoldersID) {
  228 + global $default;
  229 + $sql = new Owl_DB();
  230 + $result = $sql->query("SELECT * FROM $default->owl_folders_user_roles_table WHERE id = $iRolesFoldersID");
  231 + if ($result) {
  232 + if ($sql->next_record()) {
  233 + $oRolesFoldersLink = & new RoleFolderLink($sql->f("user_id"), $sql->f("folder_id"), $sql->f("role_type_id"), $sql->f("datetime"), $sql->f("done"));
  234 + $oRolesFoldersLink->iId = $iRolesFoldersID;
  235 + return $oRolesFoldersLink;
  236 + }
  237 + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iRolesFoldersID . " table = $default->owl_folders_user_roles_table";
  238 + return false;
  239 + }
  240 + $_SESSION["errorMessage"] = $lang_err_database;
  241 + return false;
  242 + }
  243 +
  244 +/**
  245 + * Static function
  246 + * Get a list of web documents
  247 + *
  248 + * @param String Where clause (not required)
  249 + *
  250 + * @return Array array of RolesFoldersLink objects, false otherwise and set $_SESSION["errorMessage"]
  251 + */
  252 + function getList($sWhereClause = null) {
  253 + global $default, $lang_err_database;
  254 + $aRolesFoldersLinkArray;
  255 + settype($aRolesFoldersLinkArray, "array");
  256 + $sql = new Owl_DB();
  257 + $result = $sql->query("SELECT * FROM " . $default->owl_folders_user_roles_table . (isset($sWhereClause) ? " " . $sWhereClause : ""));
  258 + if ($result) {
  259 + $iCount = 0;
  260 + while ($sql->next_record()) {
  261 + $oRolesFoldersLink = & RoleFolderLink::get($sql->f("id"));
  262 + $aRolesFoldersLinkArray[$iCount] = $oRolesFoldersLink;
  263 + $iCount++;
  264 + }
  265 + return $aRolesFoldersLinkArray;
  266 + }
  267 + $_SESSION["errorMessage"] = $lang_err_database;
  268 + return false;
  269 + }
  270 +
  271 +}
  272 +?>
... ...