00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( 'kernel/classes/ezpersistentobject.php' );
00041 include_once( 'kernel/classes/ezcollaborationitem.php' );
00042
00043 class eZCollaborationGroup extends eZPersistentObject
00044 {
00045
00046
00047
00048 function eZCollaborationGroup( $row )
00049 {
00050 $this->eZPersistentObject( $row );
00051 }
00052
00053 function definition()
00054 {
00055 return array( 'fields' => array( 'id' => array( 'name' => 'ID',
00056 'datatype' => 'integer',
00057 'default' => 0,
00058 'required' => true ),
00059 'parent_group_id' => array( 'name' => 'ParentGroupID',
00060 'datatype' => 'integer',
00061 'default' => 0,
00062 'required' => true,
00063 'foreign_class' => 'eZCollaborationGroup',
00064 'foreign_attribute' => 'id',
00065 'multiplicity' => '1..*' ),
00066 'depth' => array( 'name' => 'Depth',
00067 'datatype' => 'integer',
00068 'default' => 0,
00069 'required' => true ),
00070 'path_string' => array( 'name' => 'PathString',
00071 'datatype' => 'string',
00072 'default' => '',
00073 'required' => true ),
00074 'is_open' => array( 'name' => 'IsOpen',
00075 'datatype' => 'integer',
00076 'default' => '1',
00077 'required' => true ),
00078 'user_id' => array( 'name' => 'UserID',
00079 'datatype' => 'integer',
00080 'default' => '0',
00081 'required' => true,
00082 'foreign_class' => 'eZUser',
00083 'foreign_attribute' => 'contentobject_id',
00084 'multiplicity' => '1..*' ),
00085 'title' => array( 'name' => 'Title',
00086 'datatype' => 'string',
00087 'default' => '',
00088 'required' => true ),
00089 'created' => array( 'name' => 'Created',
00090 'datatype' => 'integer',
00091 'default' => '0',
00092 'required' => true ),
00093 'modified' => array( 'name' => 'Modified',
00094 'datatype' => 'integer',
00095 'default' => '0',
00096 'required' => true ) ),
00097 'keys' => array( 'id' ),
00098 "function_attributes" => array( 'user' => 'user',
00099 'parent_group' => 'parentGroup',
00100 'item_list' => 'itemList',
00101 'item_count' => 'itemCount' ),
00102 'increment_key' => 'id',
00103 'class_name' => 'eZCollaborationGroup',
00104 'sort' => array( 'title' => 'asc' ),
00105 'name' => 'ezcollab_group' );
00106 }
00107
00108
00109
00110
00111
00112 function addChild( &$group, $store = true )
00113 {
00114 $pathString = $this->PathString;
00115 if ( $pathString != '' )
00116 $pathString .= '/';
00117 $pathString .= $this->ID;
00118 $depth = $this->Depth + 1;
00119 $parentGroupID = $this->ID;
00120 $group->setAttribute( 'path_string', $pathString );
00121 $group->setAttribute( 'parent_group_id', $parentGroupID );
00122 $group->setAttribute( 'depth', $depth );
00123 if ( $store )
00124 $group->sync();
00125 }
00126
00127
00128
00129
00130
00131 function &instantiate( $userID, $title, $parentGroupID = 0, $isOpen = true )
00132 {
00133 $depth = 0;
00134 $pathString = '';
00135 if ( $parentGroupID > 0 )
00136 {
00137 $parentGroup = eZCollaborationGroup::fetch( $parentGroupID, $userID );
00138 $depth = $parentGroup->attribute( 'depth' ) + 1;
00139 $pathString = $parentGroup->attribute( 'path_string' );
00140 }
00141 $group = eZCollaborationGroup::create( $userID, $title, '', $depth, $parentGroupID, $isOpen );
00142
00143 $db =& eZDB::instance();
00144 $db->begin();
00145
00146 $group->store();
00147 if ( $pathString == '' )
00148 $pathString = $group->attribute( 'id' );
00149 else
00150 $pathString .= '/' . $group->attribute( 'id' );
00151 $group->setAttribute( 'path_string', $pathString );
00152 $group->sync();
00153
00154 $db->commit();
00155 return $group;
00156 }
00157
00158 function create( $userID, $title, $pathString = '', $depth = 0, $parentGroupID = 0, $isOpen = true )
00159 {
00160 $date_time = time();
00161 $row = array(
00162 'id' => null,
00163 'parent_group_id' => $parentGroupID,
00164 'path_string' => $pathString,
00165 'depth' => $depth,
00166 'is_open' => $isOpen,
00167 'user_id' => $userID,
00168 'title' => $title,
00169 'created' => $date_time,
00170 'modified' => $date_time );
00171 return new eZCollaborationGroup( $row );
00172 }
00173
00174 function fetch( $id, $userID = false, $asObject = true )
00175 {
00176 $conditions = array( "id" => $id );
00177 if ( $userID !== false )
00178 $conditions['user_id'] = $userID;
00179 return eZPersistentObject::fetchObject( eZCollaborationGroup::definition(),
00180 null,
00181 $conditions,
00182 $asObject );
00183 }
00184
00185
00186
00187
00188 function &itemList( $parameters = array() )
00189 {
00190 $itemList = eZCollaborationItem::fetchList( array_merge( array( 'parent_group_id' => $this->ID ),
00191 $parameters ) );
00192 return $itemList;
00193 }
00194
00195 function &subTree( $parameters = array() )
00196 {
00197 $parameters = array_merge( array( 'parent_group_id' => false,
00198 'depth' => false,
00199 'sort_by' => false,
00200 'as_object' => true,
00201 'offset' => false,
00202 'limit' => false ),
00203 $parameters );
00204 $parentGroupID = $parameters['parent_group_id'];
00205 $depth = $parameters['depth'];
00206 $asObject = $parameters['as_object'];
00207 $offset = $parameters['offset'];
00208 $limit = $parameters['limit'];
00209
00210 $group = null;
00211 if ( $parentGroupID > 0 )
00212 $group = eZCollaborationGroup::fetch( $parentGroupID );
00213
00214 $sortCount = 0;
00215 $sortList = $parameters['sort_by'];
00216 if ( is_array( $sortList ) and
00217 count( $sortList ) > 0 )
00218 {
00219 if ( count( $sortList ) > 1 and
00220 !is_array( $sortList[0] ) )
00221 {
00222 $sortList = array( $sortList );
00223 }
00224 }
00225 if ( $sortList !== false )
00226 {
00227 $sortingFields = '';
00228 foreach ( $sortList as $sortBy )
00229 {
00230 if ( is_array( $sortBy ) and count( $sortBy ) > 0 )
00231 {
00232 if ( $sortCount > 0 )
00233 $sortingFields .= ', ';
00234 $sortField = $sortBy[0];
00235 switch ( $sortField )
00236 {
00237 case 'path':
00238 {
00239 $sortingFields .= 'path_string';
00240 } break;
00241 case 'created':
00242 {
00243 $sortingFields .= 'created';
00244 } break;
00245 case 'modified':
00246 {
00247 $sortingFields .= 'modified';
00248 } break;
00249 case 'depth':
00250 {
00251 $sortingFields .= 'depth';
00252 } break;
00253 case 'priority':
00254 {
00255 $sortingFields .= 'priority';
00256 } break;
00257 case 'title':
00258 {
00259 $sortingFields .= 'title';
00260 } break;
00261 default:
00262 {
00263 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZCollaboration::subTree' );
00264 continue;
00265 };
00266 }
00267 $sortOrder = true;
00268 if ( isset( $sortBy[1] ) )
00269 $sortOrder = $sortBy[1];
00270 $sortingFields .= $sortOrder ? " ASC" : " DESC";
00271 ++$sortCount;
00272 }
00273 }
00274 }
00275 if ( $sortCount == 0 )
00276 {
00277 $sortingFields = " path_string ASC";
00278 }
00279
00280 $pathString = '';
00281 if ( $group !== null )
00282 $pathString = $group->attribute( 'path_string' );
00283
00284 $depthSQL = "";
00285 if ( $depth !== false )
00286 $depthSQL = "depth <= '$depth' AND";
00287 $pathSQL = '';
00288 if ( $pathString != '' )
00289 $pathSQL = "path_string like '$pathString%' AND";
00290
00291 $user =& eZUser::currentUser();
00292 $userID =& $user->attribute( 'contentobject_id' );
00293
00294 $sql = "SELECT *
00295 FROM
00296 ezcollab_group
00297 WHERE
00298 $pathSQL
00299 $depthSQL
00300 id != '$parentGroupID' AND
00301 user_id = '$userID'
00302 ORDER BY $sortingFields";
00303
00304 $db =& eZDB::instance();
00305 $sqlParameters = array();
00306 if ( $offset !== false and $limit !== false )
00307 {
00308 $sqlParameters['offset'] = $offset;
00309 $sqlParameters['limit'] = $limit;
00310 }
00311 $groupListArray = $db->arrayQuery( $sql, $sqlParameters );
00312 $returnGroupList = eZPersistentObject::handleRows( $groupListArray, 'eZCollaborationGroup', $asObject );
00313 eZDebugSetting::writeDebug( 'collaboration-group-tree', $returnGroupList );
00314 return $returnGroupList;
00315 }
00316
00317 function &itemCount( $parameters = array() )
00318 {
00319 $parameters = array_merge( array( 'as_object' => true ),
00320 $parameters );
00321 $asObject = $parameters['as_object'];
00322
00323 $user =& eZUser::currentUser();
00324 $userID =& $user->attribute( 'contentobject_id' );
00325
00326 $groupID = $this->ID;
00327
00328 $db =& eZDB::instance();
00329 $sql = "SELECT count( collaboration_id ) as count
00330 FROM ezcollab_item_group_link
00331 WHERE user_id = '$userID' AND
00332 group_id = '$groupID'";
00333 $countArray = $db->arrayQuery( $sql );
00334 return $countArray[0]['count'];
00335 }
00336
00337 function &user()
00338 {
00339 if ( isset( $this->UserID ) and $this->UserID )
00340 {
00341 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00342 $user = eZUser::fetch( $this->UserID );
00343 }
00344 else
00345 $user = null;
00346 return $user;
00347 }
00348
00349 function &parentGroup()
00350 {
00351 if ( isset( $this->ParentGroupID ) and $this->ParentGroupID )
00352 $parentGroup = eZCollaborationGroup::fetch( $this->ParentGroupID );
00353 else
00354 $parentGroup = null;
00355 return $parentGroup;
00356 }
00357
00358
00359 var $ID;
00360 var $ParentGroupID;
00361 var $UserID;
00362 var $Title;
00363 var $Created;
00364 var $Modified;
00365 }
00366
00367 ?>