Commit 3985a4d7592dd5e363386b90abf771ebc1e7489c

Authored by nbm
1 parent c0358a40

Use KTEntityUtil::get() for simplified get function, and perform ID -> Id

conversion


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4742 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 30 additions and 41 deletions
lib/groups/Group.inc
... ... @@ -37,6 +37,8 @@ class Group extends KTEntity {
37 37 var $bIsUnitAdmin;
38 38 /** is the group a sys admin */
39 39 var $bIsSysAdmin;
  40 + /** which unit the group belongs to */
  41 + var $iUnitId;;
40 42  
41 43  
42 44 function Group($sNewName = null, $bNewIsUnitAdmin = false, $bNewIsSysAdmin = false) {
... ... @@ -47,12 +49,12 @@ class Group extends KTEntity {
47 49 }
48 50  
49 51 var $_aFieldToSelect = array(
50   - 'iId' => 'id',
51   - 'sName' => 'name',
52   - 'bIsUnitAdmin' => 'is_unit_admin',
53   - 'bIsSysAdmin' => 'is_sys_admin',
54   - 'iUnitId' => 'unit_id',
55   - );
  52 + 'iId' => 'id',
  53 + 'sName' => 'name',
  54 + 'bIsUnitAdmin' => 'is_unit_admin',
  55 + 'bIsSysAdmin' => 'is_sys_admin',
  56 + 'iUnitId' => 'unit_id',
  57 + );
56 58  
57 59 function _table () {
58 60 global $default;
... ... @@ -99,21 +101,8 @@ class Group extends KTEntity {
99 101 *
100 102 * @return Group populated Group object on successful query, false otherwise and set $_SESSION["errorMessage"]
101 103 */
102   - function & get($iGroupID) {
103   - global $default;
104   - $sql = $default->db;
105   - $result = $sql->query(array("SELECT * FROM $default->groups_table WHERE id = ?", $iGroupID));/*ok*/
106   - if ($result) {
107   - if ($sql->next_record()) {
108   - $oGroup = & new Group($sql->f("name"), $sql->f("is_unit_admin"), $sql->f("is_sys_admin"));
109   - $oGroup->iId = $iGroupID;
110   - return $oGroup;
111   - }
112   - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iGroupID . " table = $default->groups_table";
113   - return false;
114   - }
115   - $_SESSION["errorMessage"] = $lang_err_database;
116   - return false;
  104 + function & get($iId) {
  105 + return KTEntityUtil::get('Group', $iId);
117 106 }
118 107  
119 108 /**
... ... @@ -150,11 +139,11 @@ class Group extends KTEntity {
150 139 global $default;
151 140 require_once(KT_LIB_DIR . '/users/User.inc');
152 141 $sQuery = "SELECT user_id FROM $default->users_groups_table WHERE group_id = ?";
153   - $aParams = array($this->getID());
154   - $aUserIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), "user_id");
  142 + $aParams = array($this->getId());
  143 + $aUserIds = DBUtil::getResultArrayKey(array($sQuery, $aParams), "user_id");
155 144 $aMembers = array();
156   - foreach ($aUserIDs as $iUserID) {
157   - $oUser = User::get($iUserID);
  145 + foreach ($aUserIds as $iUserId) {
  146 + $oUser = User::get($iUserId);
158 147 if ($oUser !== false) {
159 148 $aMembers[] = $oUser;
160 149 }
... ... @@ -165,11 +154,11 @@ class Group extends KTEntity {
165 154 function &getMemberGroups() {
166 155 global $default;
167 156 $sQuery = "SELECT member_group_id FROM $default->groups_groups_table WHERE parent_group_id = ?";
168   - $aParams = array($this->getID());
169   - $aGroupIDs = DBUtil::getResultArrayKey(array($sQuery, $aParams), "member_group_id");
  157 + $aParams = array($this->getId());
  158 + $aGroupIds = DBUtil::getResultArrayKey(array($sQuery, $aParams), "member_group_id");
170 159 $aMembers = array();
171   - foreach ($aGroupIDs as $iGroupID) {
172   - $oGroup = Group::get($iGroupID);
  160 + foreach ($aGroupIds as $iGroupId) {
  161 + $oGroup = Group::get($iGroupId);
173 162 if ($oGroup !== false) {
174 163 $aMembers[] = $oGroup;
175 164 }
... ... @@ -182,11 +171,11 @@ class Group extends KTEntity {
182 171 global $default;
183 172  
184 173 $sQuery = "DELETE FROM $default->users_groups_table WHERE group_id = ?";
185   - $aParams = array($this->getID());
  174 + $aParams = array($this->getId());
186 175 DBUtil::runQuery(array($sQuery, $aParams));
187 176  
188 177 $sQuery = "DELETE FROM $default->groups_units_table WHERE group_id = ?";
189   - $aParams = array($this->getID());
  178 + $aParams = array($this->getId());
190 179 DBUtil::runQuery(array($sQuery, $aParams));
191 180  
192 181 return parent::delete();
... ... @@ -199,7 +188,7 @@ class Group extends KTEntity {
199 188  
200 189 $sQuery = "SELECT COUNT(*) AS number_of_entries FROM $default->users_groups_table
201 190 WHERE group_id = ? AND user_id = ?";
202   - $aParams = array($this->getID(), $iUserId);
  191 + $aParams = array($this->getId(), $iUserId);
203 192 $res = (int)DBUtil::getOneResultKey(array($sQuery, $aParams), "number_of_entries");
204 193 if (PEAR::isError($res)) {
205 194 return $res;
... ... @@ -218,8 +207,8 @@ class Group extends KTEntity {
218 207 return true;
219 208 }
220 209 $aParams = array(
221   - "user_id" => $oUser->getID(),
222   - "group_id" => $this->getID(),
  210 + "user_id" => $oUser->getId(),
  211 + "group_id" => $this->getId(),
223 212 );
224 213 $res = DBUtil::autoInsert($default->users_groups_table, $aParams);
225 214 if (PEAR::isError($res)) {
... ... @@ -236,8 +225,8 @@ class Group extends KTEntity {
236 225 return true;
237 226 }
238 227 $aParams = array(
239   - "user_id" => $oUser->getID(),
240   - "group_id" => $this->getID(),
  228 + "user_id" => $oUser->getId(),
  229 + "group_id" => $this->getId(),
241 230 );
242 231 $res = DBUtil::whereDelete($default->users_groups_table, $aParams);
243 232 if (PEAR::isError($res)) {
... ... @@ -257,8 +246,8 @@ class Group extends KTEntity {
257 246 return true;
258 247 }
259 248 $aParams = array(
260   - "parent_group_id" => $this->getID(),
261   - "member_group_id" => $oGroup->getID(),
  249 + "parent_group_id" => $this->getId(),
  250 + "member_group_id" => $oGroup->getId(),
262 251 );
263 252 $res = DBUtil::autoInsert($default->groups_groups_table, $aParams);
264 253 if (PEAR::isError($res)) {
... ... @@ -275,8 +264,8 @@ class Group extends KTEntity {
275 264 return true;
276 265 }
277 266 $aParams = array(
278   - "parent_group_id" => $this->getID(),
279   - "member_group_id" => $oGroup->getID(),
  267 + "parent_group_id" => $this->getId(),
  268 + "member_group_id" => $oGroup->getId(),
280 269 );
281 270 $res = DBUtil::whereDelete($default->groups_groups_table, $aParams);
282 271 if (PEAR::isError($res)) {
... ... @@ -295,7 +284,7 @@ class Group extends KTEntity {
295 284  
296 285 $sQuery = "SELECT COUNT(*) AS number_of_entries FROM $default->groups_groups_table
297 286 WHERE parent_group_id = ? AND member_group_id = ?";
298   - $aParams = array($this->getID(), $oGroup->getID());
  287 + $aParams = array($this->getId(), $oGroup->getId());
299 288 $res = (int)DBUtil::getOneResultKey(array($sQuery, $aParams), "number_of_entries");
300 289 if (PEAR::isError($res)) {
301 290 return $res;
... ...