Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcollaborationgroup.php
Go to the documentation of this file.
1 <?php
17 class eZCollaborationGroup extends eZPersistentObject
18 {
19 static function definition()
20 {
21 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
22 'datatype' => 'integer',
23 'default' => 0,
24 'required' => true ),
25 'parent_group_id' => array( 'name' => 'ParentGroupID',
26 'datatype' => 'integer',
27 'default' => 0,
28 'required' => true,
29 'foreign_class' => 'eZCollaborationGroup',
30 'foreign_attribute' => 'id',
31 'multiplicity' => '1..*' ),
32 'depth' => array( 'name' => 'Depth',
33 'datatype' => 'integer',
34 'default' => 0,
35 'required' => true ),
36 'path_string' => array( 'name' => 'PathString',
37 'datatype' => 'string',
38 'default' => '',
39 'required' => true ),
40 'is_open' => array( 'name' => 'IsOpen',
41 'datatype' => 'integer',
42 'default' => '1',
43 'required' => true ),
44 'user_id' => array( 'name' => 'UserID',
45 'datatype' => 'integer',
46 'default' => '0',
47 'required' => true,
48 'foreign_class' => 'eZUser',
49 'foreign_attribute' => 'contentobject_id',
50 'multiplicity' => '1..*' ),
51 'title' => array( 'name' => 'Title',
52 'datatype' => 'string',
53 'default' => '',
54 'required' => true ),
55 'created' => array( 'name' => 'Created',
56 'datatype' => 'integer',
57 'default' => '0',
58 'required' => true ),
59 'modified' => array( 'name' => 'Modified',
60 'datatype' => 'integer',
61 'default' => '0',
62 'required' => true ) ),
63 'keys' => array( 'id' ),
64 "function_attributes" => array( 'user' => 'user',
65 'parent_group' => 'parentGroup',
66 'item_list' => 'itemList',
67 'item_count' => 'itemCount' ),
68 'increment_key' => 'id',
69 'class_name' => 'eZCollaborationGroup',
70 'sort' => array( 'title' => 'asc' ),
71 'name' => 'ezcollab_group' );
72 }
73
78 function addChild( $group, $store = true )
79 {
80 $pathString = $this->PathString;
81 if ( $pathString != '' )
82 $pathString .= '/';
83 $pathString .= $this->ID;
84 $depth = $this->Depth + 1;
85 $parentGroupID = $this->ID;
86 $group->setAttribute( 'path_string', $pathString );
87 $group->setAttribute( 'parent_group_id', $parentGroupID );
88 $group->setAttribute( 'depth', $depth );
89 if ( $store )
90 $group->sync();
91 }
92
97 static function instantiate( $userID, $title, $parentGroupID = 0, $isOpen = true )
98 {
99 $depth = 0;
100 $pathString = '';
101 if ( $parentGroupID > 0 )
102 {
103 $parentGroup = eZCollaborationGroup::fetch( $parentGroupID, $userID );
104 $depth = $parentGroup->attribute( 'depth' ) + 1;
105 $pathString = $parentGroup->attribute( 'path_string' );
106 }
107 $group = eZCollaborationGroup::create( $userID, $title, '', $depth, $parentGroupID, $isOpen );
108
109 $db = eZDB::instance();
110 $db->begin();
111
112 $group->store();
113 if ( $pathString == '' )
114 $pathString = $group->attribute( 'id' );
115 else
116 $pathString .= '/' . $group->attribute( 'id' );
117 $group->setAttribute( 'path_string', $pathString );
118 $group->sync();
119
120 $db->commit();
121 return $group;
122 }
123
124 static function create( $userID, $title, $pathString = '', $depth = 0, $parentGroupID = 0, $isOpen = true )
125 {
126 $date_time = time();
127 $row = array(
128 'id' => null,
129 'parent_group_id' => $parentGroupID,
130 'path_string' => $pathString,
131 'depth' => $depth,
132 'is_open' => $isOpen,
133 'user_id' => $userID,
134 'title' => $title,
135 'created' => $date_time,
136 'modified' => $date_time );
137 return new eZCollaborationGroup( $row );
138 }
139
140 static function fetch( $id, $userID = false, $asObject = true )
141 {
142 $conditions = array( "id" => $id );
143 if ( $userID !== false )
144 $conditions['user_id'] = $userID;
145 return eZPersistentObject::fetchObject( eZCollaborationGroup::definition(),
146 null,
147 $conditions,
148 $asObject );
149 }
150
154 function itemList( $parameters = array() )
155 {
156 return eZCollaborationItem::fetchList( array_merge( array( 'parent_group_id' => $this->ID ),
157 $parameters ) );
158 }
159
160 static function subTree( $parameters = array() )
161 {
162 $parameters = array_merge( array( 'parent_group_id' => false,
163 'depth' => false,
164 'sort_by' => false,
165 'as_object' => true,
166 'offset' => false,
167 'limit' => false ),
168 $parameters );
169 $parentGroupID = $parameters['parent_group_id'];
170 $depth = $parameters['depth'];
171 $asObject = $parameters['as_object'];
172 $offset = $parameters['offset'];
173 $limit = $parameters['limit'];
174
175 $group = null;
176 if ( $parentGroupID > 0 )
177 $group = eZCollaborationGroup::fetch( $parentGroupID );
178
179 $sortCount = 0;
180 $sortList = $parameters['sort_by'];
181 if ( is_array( $sortList ) and
182 count( $sortList ) > 0 )
183 {
184 if ( count( $sortList ) > 1 and
185 !is_array( $sortList[0] ) )
186 {
187 $sortList = array( $sortList );
188 }
189 }
190 if ( $sortList !== false )
191 {
192 $sortingFields = '';
193 foreach ( $sortList as $sortBy )
194 {
195 if ( is_array( $sortBy ) and count( $sortBy ) > 0 )
196 {
197 if ( $sortCount > 0 )
198 $sortingFields .= ', ';
199 $sortField = $sortBy[0];
200 switch ( $sortField )
201 {
202 case 'path':
203 {
204 $sortingFields .= 'path_string';
205 } break;
206 case 'created':
207 {
208 $sortingFields .= 'created';
209 } break;
210 case 'modified':
211 {
212 $sortingFields .= 'modified';
213 } break;
214 case 'depth':
215 {
216 $sortingFields .= 'depth';
217 } break;
218 case 'priority':
219 {
220 $sortingFields .= 'priority';
221 } break;
222 case 'title':
223 {
224 $sortingFields .= 'title';
225 } break;
226 default:
227 {
228 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, __METHOD__ );
229 continue 2;
230 }
231 }
232 $sortOrder = true; // true is ascending
233 if ( isset( $sortBy[1] ) )
234 $sortOrder = $sortBy[1];
235 $sortingFields .= $sortOrder ? " ASC" : " DESC";
236 ++$sortCount;
237 }
238 }
239 }
240 if ( $sortCount == 0 )
241 {
242 $sortingFields = " path_string ASC";
243 }
244
245 $pathString = '';
246 if ( $group !== null )
247 $pathString = $group->attribute( 'path_string' );
248
249 $depthSQL = "";
250 if ( $depth !== false )
251 $depthSQL = "depth <= '$depth' AND";
252 $pathSQL = '';
253 if ( $pathString != '' )
254 $pathSQL = "path_string like '$pathString%' AND";
255
256 $user = eZUser::currentUser();
257 $userID = $user->attribute( 'contentobject_id' );
258
259 $sql = "SELECT *
260 FROM
261 ezcollab_group
262 WHERE
263 $pathSQL
264 $depthSQL
265 id != '$parentGroupID' AND
266 user_id = '$userID'
267 ORDER BY $sortingFields";
268
269 $db = eZDB::instance();
270 $sqlParameters = array();
271 if ( $offset !== false and $limit !== false )
272 {
273 $sqlParameters['offset'] = $offset;
274 $sqlParameters['limit'] = $limit;
275 }
276 $groupListArray = $db->arrayQuery( $sql, $sqlParameters );
277 $returnGroupList = eZPersistentObject::handleRows( $groupListArray, 'eZCollaborationGroup', $asObject );
278 eZDebugSetting::writeDebug( 'collaboration-group-tree', $returnGroupList );
279 return $returnGroupList;
280 }
281
282 function itemCount( $parameters = array() )
283 {
284 $parameters = array_merge( array( 'as_object' => true ),
285 $parameters );
286 $asObject = $parameters['as_object'];
287
288 $user = eZUser::currentUser();
289 $userID = $user->attribute( 'contentobject_id' );
290
291 $groupID = $this->ID;
292
293 $db = eZDB::instance();
294 $sql = "SELECT count( collaboration_id ) as count
295 FROM ezcollab_item_group_link
296 WHERE user_id = '$userID' AND
297 group_id = '$groupID'";
298 $countArray = $db->arrayQuery( $sql );
299 return $countArray[0]['count'];
300 }
301
302 function user()
303 {
304 if ( isset( $this->UserID ) and $this->UserID )
305 {
306 return eZUser::fetch( $this->UserID );
307 }
308 return null;
309 }
310
311 function parentGroup()
312 {
313 if ( isset( $this->ParentGroupID ) and $this->ParentGroupID )
314 {
315 return eZCollaborationGroup::fetch( $this->ParentGroupID );
316 }
317 return null;
318 }
319
321 public $ID;
322 public $ParentGroupID;
323 public $UserID;
324 public $Title;
325 public $Created;
326 public $Modified;
327 }
328
329 ?>
eZCollaborationGroup
The class eZCollaborationGroup does.
Definition: ezcollaborationgroup.php:18
eZCollaborationGroup\$UserID
$UserID
Definition: ezcollaborationgroup.php:323
eZCollaborationGroup\$Created
$Created
Definition: ezcollaborationgroup.php:325
eZCollaborationGroup\definition
static definition()
Definition: ezcollaborationgroup.php:19
eZCollaborationGroup\addChild
addChild( $group, $store=true)
Definition: ezcollaborationgroup.php:78
eZCollaborationGroup\instantiate
static instantiate( $userID, $title, $parentGroupID=0, $isOpen=true)
Definition: ezcollaborationgroup.php:97
eZCollaborationGroup\itemList
itemList( $parameters=array())
Definition: ezcollaborationgroup.php:154
eZCollaborationGroup\$Title
$Title
Definition: ezcollaborationgroup.php:324
eZCollaborationGroup\$Modified
$Modified
Definition: ezcollaborationgroup.php:326
eZCollaborationGroup\fetch
static fetch( $id, $userID=false, $asObject=true)
Definition: ezcollaborationgroup.php:140
eZCollaborationGroup\user
user()
Definition: ezcollaborationgroup.php:302
eZCollaborationGroup\parentGroup
parentGroup()
Definition: ezcollaborationgroup.php:311
eZCollaborationGroup\create
static create( $userID, $title, $pathString='', $depth=0, $parentGroupID=0, $isOpen=true)
Definition: ezcollaborationgroup.php:124
eZCollaborationGroup\subTree
static subTree( $parameters=array())
Definition: ezcollaborationgroup.php:160
eZCollaborationGroup\$ParentGroupID
$ParentGroupID
Definition: ezcollaborationgroup.php:322
eZCollaborationGroup\$ID
$ID
Definition: ezcollaborationgroup.php:321
eZCollaborationGroup\itemCount
itemCount( $parameters=array())
Definition: ezcollaborationgroup.php:282
eZCollaborationItem\fetchList
static fetchList( $parameters=array())
Definition: ezcollaborationitem.php:331
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\$PathString
$PathString
Definition: ezpersistentobject.php:1470
eZPersistentObject\handleRows
static handleRows( $rows, $class_name, $asObject)
Definition: ezpersistentobject.php:963
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.