Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezusergroup.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezusergroup.php 8704 2001-12-07 17:07:01Z br $
5 //
6 // Definition of eZCompany class
7 //
8 // Created on: <26-Sep-2000 18:45:40 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
65 class eZUserGroup
66 {
67
74 function __construct( $id = -1, $fetch = true )
75 {
76 if ( is_array( $id ) )
77 {
78 $this->fill( $id );
79 }
80 else if ( $id != -1 )
81 {
82 $this->ID = $id;
83 if ( $fetch == true )
84 {
85 $this->get( $this->ID );
86 }
87 }
88 }
89
93 function store()
94 {
95 $db =& eZDB::globalDatabase();
96
97 $dbError = false;
98 $db->begin();
99
100 $name = $db->escapeString( $this->Name );
101 $description = $db->escapeString( $this->Description );
102
103 if ( !isset( $this->ID ) )
104 {
105 $db->lock( "eZUser_Group" );
106
107 $nextID = $db->nextID( "eZUser_Group", "ID" );
108 $query = "INSERT INTO eZUser_Group
109 (ID, Name, Description, SessionTimeout, IsRoot, GroupURL)
110 VALUES
111 ('$nextID', '$name', '$description', '$this->SessionTimeout', '$this->IsRoot', '$this->GroupURL')";
112
113 $db->query( $query );
114
115 $this->ID = $nextID;
116
117 }
118 else
119 {
120 $db->query( "UPDATE eZUser_Group SET
121 Name='$name',
122 Description='$description',
123 SessionTimeout='$this->SessionTimeout',
124 IsRoot='$this->IsRoot',
125 GroupURL='$this->GroupURL'
126 WHERE ID='$this->ID'" );
127 }
128
129 $db->unlock();
130
131 if ( $dbError == true )
132 $db->rollback( );
133 else
134 $db->commit();
135
136 return true;
137 }
138
142 function delete( $id = false )
143 {
144 $db =& eZDB::globalDatabase();
145
146 if ( !$id )
147 $id = $this->ID;
148
149 if ( isset( $id ) )
150 {
151 $db->query( "DELETE FROM eZUser_UserGroupLink WHERE GroupID='$id'" );
152 $db->query( "DELETE FROM eZUser_GroupPermissionLink WHERE GroupID='$id'" );
153 $db->query( "DELETE FROM eZUser_Group WHERE ID='$id'" );
154 }
155
156 return true;
157 }
158
162 function get( $id=-1 )
163 {
164 $db =& eZDB::globalDatabase();
165
166 if ( $id != "" )
167 {
168 $db->array_query( $user_group_array, "SELECT * FROM eZUser_Group WHERE ID='$id'",
169 array( "Offset" => 0, "Limit" => 1 ) );
170 if ( count( $user_group_array ) == 1 )
171 {
172 $this->fill( $user_group_array[0] );
173 }
174 }
175 }
176
180 function fill( &$user_group_array )
181 {
182 $db =& eZDB::globalDatabase();
183
184 $this->ID = $user_group_array[$db->fieldName( "ID" )];
185 $this->Name = $user_group_array[$db->fieldName( "Name" )];
186 $this->Description = $user_group_array[$db->fieldName( "Description" )];
187 $this->GroupURL = $user_group_array[$db->fieldName( "GroupURL" )];
188 $this->SessionTimeout = $user_group_array[$db->fieldName("SessionTimeout")];
189 $this->IsRoot = $user_group_array[$db->fieldName("IsRoot")];
190 }
191
197 static public function &getAll( $as_object = true )
198 {
199 $db =& eZDB::globalDatabase();
200
201 $return_array = array();
202 $group_array = array();
203
204 if ( $as_object )
205 $select = "*";
206 else
207 $select = "ID,Name";
208
209 $db->array_query( $group_array, "SELECT $select FROM eZUser_Group ORDER By Name" );
210
211 if ( $as_object )
212 {
213 for ( $i = 0; $i < count( $group_array ); $i++ )
214 {
215 $return_array[$i] = new eZUserGroup( $group_array[$i] );
216 }
217 }
218 else
219 {
220 for ( $i = 0; $i < count( $group_array ); $i++ )
221 {
222 $return_array[$i] =& $group_array[$db->fieldName( "ID" )];
223 }
224 }
225
226 return $return_array;
227 }
228
236 static public function getByUser( $user )
237 {
238 $return_array = array();
239
240 if ( is_a( $user, "eZUser" ) )
241 {
242 $db =& eZDB::globalDatabase();
243
244 $group_array = array();
245
246 $userID = $user->id();
247
248 $db->array_query( $group_array, "SELECT GroupID FROM eZUser_UserGroupLink WHERE UserID='$userID'" );
249
250 for ( $i = 0; $i < count( $group_array ); $i++ )
251 {
252 $return_array[$i] = new eZUserGroup( $group_array[$i][$db->fieldName( "GroupID" )], 0 );
253 }
254 }
255 return $return_array;
256 }
257
262 static public function isMember( $user )
263 {
264 if ( is_a( $user, "eZUser" ) )
265 {
266 $userTemp = new eZUserGroup();
267 $userList = $userTemp->users( );
268 if ( count( $userList ) > 0 )
269 {
270 foreach ( $userList as $usr )
271 {
272 if ( $user->id() == $usr->id() )
273 return true;
274 }
275 }
276 }
277 return false;
278 }
279
283 function id()
284 {
285 return $this->ID;
286 }
287
291 static public function users( $GroupID = false, $order = "Login", $search = false )
292 {
293 switch ( $order )
294 {
295 case "name" :
296 {
297 $orderBy = "U.LastName, U.FirstName";
298 }
299 break;
300
301 case "lastname" :
302 {
303 $orderBy = "U.LastName";
304 }
305 break;
306
307 case "firstname" :
308 {
309 $orderBy = "U.FirstName";
310 }
311 break;
312
313 case "email" :
314 {
315 $orderBy = "U.Email";
316 }
317 break;
318
319 default :
320 $orderBy = "U.Login";
321 break;
322 }
323
324 if ( is_array( $GroupID ) )
325 {
326 $first = true;
327 foreach ( $GroupID as $item )
328 {
329 if ( $first )
330 $userSQL = "UGL.GroupID='$item' ";
331 else
332 $userSQL .= "OR UGL.GroupID='$item' ";
333 $first = false;
334 }
335 }
336 else if ( !is_numeric( $GroupID ) )
337 {
338 $userSQL = "UGL.GroupID='$GroupID'";
339 }
340 else
341 {
342 $userSQL = "UGL.GroupID='$GroupID'";
343 }
344
345
346 $ret = array();
347 $db =& eZDB::globalDatabase();
348
349 if ( $search )
350 {
351 $query = new eZQuery( array( "U.FirstName", "U.LastName",
352 "U.Login", "U.Email" ), $search );
353
354
355 $db->array_query( $user_array, "SELECT UGL.UserID FROM eZUser_UserGroupLink AS UGL,
356 eZUser_User AS U
357 WHERE ( $userSQL ) AND UGL.UserID=U.ID
358 AND ( " . $query->buildQuery() . " )
359 GROUP BY UGL.UserID, U.Login
360 ORDER By $orderBy" );
361 }
362 else
363 {
364 $db->array_query( $user_array, "SELECT UGL.UserID FROM eZUser_UserGroupLink AS UGL,
365 eZUser_User AS U
366 WHERE ( $userSQL ) AND UGL.UserID=U.ID
367 GROUP BY UGL.UserID, U.Login
368 ORDER By $orderBy" );
369
370 }
371
372 foreach ( $user_array as $user )
373 {
374 $ret[] = new eZUser( $user[$db->fieldName( "UserID" )] );
375 }
376
377 return $ret;
378 }
379
383 function userEmails()
384 {
385 $db =& eZDB::globalDatabase();
386 $mail_array = array();
387 $db->array_query( $mail_array, "SELECT Email from eZUser_UserGroupLink, eZUser_User WHERE eZUser_User.ID=eZUser_UserGroupLink.UserID AND eZUser_UserGroupLink.GroupID='$this->ID'",
388 0, -1, "Email" );
389 return $mail_array;
390 }
391
395 function isRoot()
396 {
397 return $this->IsRoot;
398 }
399
403 function setIsRoot( $value )
404 {
405 $this->IsRoot = $value;
406 }
407
411 function name( $html = true )
412 {
413 if( $html && !is_null( $this->Name ) )
414 return htmlspecialchars( $this->Name );
415 else
416 return $this->Name;
417 }
418
422 function description( $html = true )
423 {
424 if( $html )
425 return htmlspecialchars( $this->Description );
426 return $this->Description;
427 }
428
432 function groupURL()
433 {
434 return $this->GroupURL;
435 }
436
440 function sessionTimeout()
441 {
442 return $this->SessionTimeout;
443 }
444
448 function setName( $value )
449 {
450 $this->Name = $value;
451 }
452
456 function setDescription( $value )
457 {
458 $this->Description = $value;
459 }
460
461 function setGroupURL( $url )
462 {
463 $this->GroupURL = $url;
464 }
465
469 function setSessionTimeout( $value )
470 {
471 $this->SessionTimeout = $value;
472
473 setType( $this->SessionTimeout, "integer" );
474 }
475
481 function addUser( $user )
482 {
483 $ret = false;
484
485 if ( is_a( $user, "eZUser" ) )
486 {
487 $db =& eZDB::globalDatabase();
488
489 $dbError = false;
490 $db->begin( );
491
492 $userID = $user->id();
493 $db->lock( "eZUser_UserGroupLink" );
494 $nextID = $db->nextID( "eZUser_UserGroupLink", "ID" );
495
496 // if ( $this->ID > 1 )
497 {
498 $res = $db->query( "INSERT INTO eZUser_UserGroupLink
499 ( ID, UserID, GroupID )
500 VALUES
501 ( '$nextID', '$userID', '$this->ID' )" );
502
503
504 if ( $res == false )
505 $dbError = true;
506 $ret = true;
507 }
508
509 $db->unlock();
510 if ( $dbError == true )
511 $db->rollback( );
512 else
513 $db->commit();
514
515 }
516 return $ret;
517 }
518
519 var $ID;
520 var $Name;
521 var $Description;
522 var $GroupURL;
523 var $SessionTimeout;
524 var $IsRoot;
525 }
526
527 ?>
$i
$i
Definition: admin/adlist.php:91
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZQuery
Definition: ezquery.php:54
eZUserGroup
Definition: ezusergroup.php:66
eZUserGroup\$IsRoot
$IsRoot
Definition: ezusergroup.php:524
eZUserGroup\setSessionTimeout
setSessionTimeout( $value)
Definition: ezusergroup.php:469
eZUserGroup\isRoot
isRoot()
Definition: ezusergroup.php:395
eZUserGroup\$GroupURL
$GroupURL
Definition: ezusergroup.php:522
eZUserGroup\setDescription
setDescription( $value)
Definition: ezusergroup.php:456
eZUserGroup\groupURL
groupURL()
Definition: ezusergroup.php:432
eZUserGroup\$SessionTimeout
$SessionTimeout
Definition: ezusergroup.php:523
eZUserGroup\sessionTimeout
sessionTimeout()
Definition: ezusergroup.php:440
eZUserGroup\$Name
$Name
Definition: ezusergroup.php:520
eZUserGroup\users
static users( $GroupID=false, $order="Login", $search=false)
Definition: ezusergroup.php:291
eZUserGroup\$Description
$Description
Definition: ezusergroup.php:521
eZUserGroup\$ID
$ID
Definition: ezusergroup.php:519
eZUserGroup\fill
fill(&$user_group_array)
Definition: ezusergroup.php:180
eZUserGroup\isMember
static isMember( $user)
Definition: ezusergroup.php:262
eZUserGroup\setName
setName( $value)
Definition: ezusergroup.php:448
eZUserGroup\description
description( $html=true)
Definition: ezusergroup.php:422
eZUserGroup\store
store()
Definition: ezusergroup.php:93
eZUserGroup\__construct
__construct( $id=-1, $fetch=true)
Definition: ezusergroup.php:74
eZUserGroup\name
name( $html=true)
Definition: ezusergroup.php:411
eZUserGroup\getByUser
static getByUser( $user)
Definition: ezusergroup.php:236
eZUserGroup\setGroupURL
setGroupURL( $url)
Definition: ezusergroup.php:461
eZUserGroup\getAll
static & getAll( $as_object=true)
Definition: ezusergroup.php:197
eZUserGroup\id
id()
Definition: ezusergroup.php:283
eZUserGroup\setIsRoot
setIsRoot( $value)
Definition: ezusergroup.php:403
eZUserGroup\addUser
addUser( $user)
Definition: ezusergroup.php:481
eZUserGroup\userEmails
userEmails()
Definition: ezusergroup.php:383
eZUser
Definition: ezuser.php:76
$item
$item
Definition: classes/admin/linklist.php:228
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$search
$search
Definition: export_froogle.php:153
$db
$db
Definition: ezarticle/user/authorlist.php:53
$mail_array
$mail_array
Definition: ezbug/admin/cron.php:42
$user_array
while( $tmpTime->isGreater( $stopTime)) $user_array
Definition: ezcalendar/user/dayview.php:495
$group_array
$group_array
Definition: ezgroupeventcalendar/user/dayview.php:836
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$url
$url
Definition: messagereviewlist.php:153
$order
$order
Definition: productreport.php:182
$GroupID
$GroupID
Definition: rssheadlines.php:51
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$userList
$userList
Definition: trustees.php:80
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.