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