Commit efcf6b1b5b7f24da567ac9b519ad6fed3c354030
1 parent
9ad39282
Initial revision. Object that represents group_unit_link table in database
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@376 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
198 additions
and
0 deletions
lib/groups/GroupUnitLink.inc
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | +* @package lib.groups | |
| 4 | +* | |
| 5 | +* Class GroupUnitLink | |
| 6 | +* Represents a group, unit link as per the database table groups_units_link | |
| 7 | +* | |
| 8 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 9 | +* @date 20 January 2003 | |
| 10 | +*/ | |
| 11 | + | |
| 12 | +class GroupUnitLink { | |
| 13 | + | |
| 14 | + /** primary key of object */ | |
| 15 | + var $iId; | |
| 16 | + /** primary key of group to which unit is linked */ | |
| 17 | + var $iGroupID; | |
| 18 | + /** primary key of unit to which group is linked */ | |
| 19 | + var $iUnitID; | |
| 20 | + | |
| 21 | + function GroupUnitLink($iNewGroupID, $iNewUnitID) { | |
| 22 | + //object not created in database yet | |
| 23 | + $this->iId = -1; | |
| 24 | + $this->iGroupID = $iNewGroupID; | |
| 25 | + $this->iUnitID = $iNewUnitID; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get the object's primary key | |
| 30 | + * | |
| 31 | + * @return int object's primary key | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + function getID() { | |
| 35 | + return $this->iId; | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Get the primary key of the group to which the unit is linked | |
| 40 | + * | |
| 41 | + * @return int primary key of group to which unit is linked | |
| 42 | + * | |
| 43 | + */ | |
| 44 | + function getGroupID() { | |
| 45 | + return $this->iGroupID; | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Set the primary key of the group to which the unit is linked | |
| 50 | + * | |
| 51 | + * @param int Primary key of group to which unit is ilinked | |
| 52 | + * | |
| 53 | + */ | |
| 54 | + function setGroupID($iNewValue) { | |
| 55 | + $this->iGroupID = $iNewValue; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Get the prijmary key of the unit to which the group is linked | |
| 60 | + * | |
| 61 | + * @return int primary key of unit to which the group is linked | |
| 62 | + * | |
| 63 | + */ | |
| 64 | + function getUnitID() { | |
| 65 | + return $this->iUnitID; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Set the primary key of the unit to which the group is linked | |
| 70 | + * | |
| 71 | + * @param int Primary key of unit to which the group is linked | |
| 72 | + * | |
| 73 | + */ | |
| 74 | + function setUnitID($iNewValue) { | |
| 75 | + $this->iUnitID = $iNewValue; | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Create the current object in the database | |
| 80 | + * | |
| 81 | + * @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"] | |
| 82 | + * | |
| 83 | + */ | |
| 84 | + function create() { | |
| 85 | + global $default, $lang_err_database, $lang_err_object_exists; | |
| 86 | + //if the object hasn't been created | |
| 87 | + if ($this->iId < 0) { | |
| 88 | + $sql = new Owl_DB(); | |
| 89 | + $result = $sql->query("INSERT INTO " . $default->owl_groups_units_table . " (group_id, unit_id) VALUES ($this->iGroupID, $this->iUnitID)"); | |
| 90 | + if ($result) { | |
| 91 | + $this->iId = $sql->insert_id(); | |
| 92 | + return true; | |
| 93 | + } | |
| 94 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 95 | + return false; | |
| 96 | + } | |
| 97 | + $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_groups_units_table"; | |
| 98 | + return false; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Update the values in the database table with the object's current values | |
| 103 | + * | |
| 104 | + * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | |
| 105 | + * | |
| 106 | + */ | |
| 107 | + function update() { | |
| 108 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 109 | + //only update if the object has been stored | |
| 110 | + if ($this->iId > 0) { | |
| 111 | + $sql = new Owl_DB(); | |
| 112 | + $result = $sql->query("UPDATE " . $default->owl_groups_units_table . " SET group_id = $this->iGroupID, unit_id = $this->iUnitID WHERE id = $this->iId"); | |
| 113 | + if ($result) { | |
| 114 | + return true; | |
| 115 | + } | |
| 116 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 117 | + return false; | |
| 118 | + } | |
| 119 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 120 | + return false; | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Delete the current object from the database | |
| 125 | + * | |
| 126 | + * @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"] | |
| 127 | + * | |
| 128 | + */ | |
| 129 | + function delete() { | |
| 130 | + global $default, $lang_err_database, $lang_err_object_key; | |
| 131 | + //only delete the object if it exists in the database | |
| 132 | + if ($this->iId >= 0) { | |
| 133 | + $sql = new Owl_DB(); | |
| 134 | + $result = $sql->query("DELETE FROM $default->owl_groups_units_table WHERE id = $this->iId"); | |
| 135 | + if ($result) { | |
| 136 | + return true; | |
| 137 | + } | |
| 138 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + $_SESSION["errorMessage"] = $lang_err_object_key; | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * Static function. | |
| 147 | + * Given a groups_units_link primary key it will create a | |
| 148 | + * GroupUnitsLink object and populate it with the | |
| 149 | + * corresponding database values | |
| 150 | + * | |
| 151 | + * @return GroupUnitsLink populated GroupUnitsLink object on successful query, false otherwise and set $_SESSION["errorMessage"] | |
| 152 | + */ | |
| 153 | + function & get($iGroupUnitLinkID) { | |
| 154 | + global $default; | |
| 155 | + $sql = new Owl_DB(); | |
| 156 | + $result = $sql->query("SELECT * FROM $default->owl_groups_units_table WHERE id = $iGroupUnitLinkID"); | |
| 157 | + if ($result) { | |
| 158 | + if ($sql->next_record()) { | |
| 159 | + $oGroupUnitLink = & new GroupUnitLink($sql->f("group_id"), $sql->f("unit_id")); | |
| 160 | + $oGroupUnitLink->iId = $iGroupUnitLinkID; | |
| 161 | + return $oGroupUnitLink; | |
| 162 | + } | |
| 163 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iGroupUnitLinkID . " table = $default->owl_groups_units_table"; | |
| 164 | + return false; | |
| 165 | + } | |
| 166 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 167 | + return false; | |
| 168 | + } | |
| 169 | + | |
| 170 | +/** | |
| 171 | + * Static function | |
| 172 | + * Get a list of web documents | |
| 173 | + * | |
| 174 | + * @param String Where clause (not required) | |
| 175 | + * | |
| 176 | + * @return Array array of GroupUnitLink objects, false otherwise and set $_SESSION["errorMessage"] | |
| 177 | + */ | |
| 178 | + function getList($sWhereClause = null) { | |
| 179 | + global $default, $lang_err_database; | |
| 180 | + $aGroupUnitLink; | |
| 181 | + settype($aGroupUnitLink, "array"); | |
| 182 | + $sql = new Owl_DB(); | |
| 183 | + $result = $sql->query("SELECT * FROM " . $default->owl_groups_units_table . (isset($sWhereClause) ? " " . $sWhereClause : "")); | |
| 184 | + if ($result) { | |
| 185 | + $iCount = 0; | |
| 186 | + while ($sql->next_record()) { | |
| 187 | + $oGroupUnitLink = & GroupUnitLink::get($sql->f("id")); | |
| 188 | + $aGroupUnitLink[$iCount] = $oGroupUnitLink; | |
| 189 | + $iCount++; | |
| 190 | + } | |
| 191 | + return $aGroupUnitLink; | |
| 192 | + } | |
| 193 | + $_SESSION["errorMessage"] = $lang_err_database; | |
| 194 | + return false; | |
| 195 | + } | |
| 196 | + | |
| 197 | +} | |
| 198 | +?> | ... | ... |