[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZCollaborationItem class 4 // 5 // Created on: <22-Jan-2003 15:44:48 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezcollaborationitem.php 30 */ 31 32 /*! 33 \class eZCollaborationItem ezcollaborationitem.php 34 \brief The class eZCollaborationItem does 35 36 */ 37 38 define( 'EZ_COLLABORATION_STATUS_ACTIVE', 1 ); 39 define( 'EZ_COLLABORATION_STATUS_INACTIVE', 2 ); 40 define( 'EZ_COLLABORATION_STATUS_ARCHIVE', 3 ); 41 42 include_once ( 'kernel/classes/ezpersistentobject.php' ); 43 include_once ( 'kernel/classes/ezcollaborationitemstatus.php' ); 44 45 class eZCollaborationItem extends eZPersistentObject 46 { 47 /*! 48 Constructor 49 */ 50 function eZCollaborationItem( $row ) 51 { 52 $this->eZPersistentObject( $row ); 53 } 54 55 function definition() 56 { 57 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 58 'datatype' => 'integer', 59 'default' => 0, 60 'required' => true ), 61 'type_identifier' => array( 'name' => 'TypeIdentifier', 62 'datatype' => 'string', 63 'default' => '', 64 'required' => true ), 65 'creator_id' => array( 'name' => 'CreatorID', 66 'datatype' => 'integer', 67 'default' => 0, 68 'required' => true, 69 'foreign_class' => 'eZUser', 70 'foreign_attribute' => 'contentobject_id', 71 'multiplicity' => '1..*' ), 72 'status' => array( 'name' => 'Status', 73 'datatype' => 'integer', 74 'default' => 1, 75 'required' => true ), 76 'data_text1' => array( 'name' => 'DataText1', 77 'datatype' => 'text', 78 'default' => '', 79 'required' => true ), 80 'data_text2' => array( 'name' => 'DataText2', 81 'datatype' => 'text', 82 'default' => '', 83 'required' => true ), 84 'data_text3' => array( 'name' => 'DataText3', 85 'datatype' => 'text', 86 'default' => '', 87 'required' => true ), 88 'data_int1' => array( 'name' => 'DataInt1', 89 'datatype' => 'integer', 90 'default' => 0, 91 'required' => true ), 92 'data_int2' => array( 'name' => 'DataInt2', 93 'datatype' => 'integer', 94 'default' => 0, 95 'required' => true ), 96 'data_int3' => array( 'name' => 'DataInt3', 97 'datatype' => 'integer', 98 'default' => 0, 99 'required' => true ), 100 'data_float1' => array( 'name' => 'DataFloat1', 101 'datatype' => 'float', 102 'default' => 0, 103 'required' => true ), 104 'data_float2' => array( 'name' => 'DataFloat2', 105 'datatype' => 'float', 106 'default' => 0, 107 'required' => true ), 108 'data_float3' => array( 'name' => 'DataFloat3', 109 'datatype' => 'float', 110 'default' => 0, 111 'required' => true ), 112 'created' => array( 'name' => 'Created', 113 'datatype' => 'integer', 114 'default' => 0, 115 'required' => true ), 116 'modified' => array( 'name' => 'Modified', 117 'datatype' => 'integer', 118 'default' => 0, 119 'required' => true ) ), 120 'keys' => array( 'id' ), 121 'function_attributes' => array( 'creator' => 'creator', 122 'is_creator' => 'isCreator', 123 'participant_list' => 'participantList', 124 'user_status' => 'userStatus', 125 'handler' => 'handler', 126 'use_messages' => 'useMessages', 127 'message_count' => 'messageCount', 128 'unread_message_count' => 'unreadMessageCount', 129 'content' => 'content', 130 'title' => 'title' ), 131 'increment_key' => 'id', 132 'class_name' => 'eZCollaborationItem', 133 'sort' => array( 'modified' => 'asc' ), 134 'name' => 'ezcollab_item' ); 135 } 136 137 function create( $typeIdentifier, $creatorID, $status = EZ_COLLABORATION_STATUS_ACTIVE ) 138 { 139 $date_time = time(); 140 $row = array( 141 'id' => null, 142 'type_identifier' => $typeIdentifier, 143 'creator_id' => $creatorID, 144 'status' => $status, 145 'created' => $date_time, 146 'modified' => $date_time ); 147 return new eZCollaborationItem( $row ); 148 } 149 150 /*! 151 Creates a collaboration notification event and stores it. 152 \a subType can be used to specify a sub type of this collaboration item. 153 */ 154 function createNotificationEvent( $subType = false ) 155 { 156 $handler =& $this->attribute( 'handler' ); 157 $info = $handler->attribute( 'info' ); 158 $type = $info['type-identifier']; 159 if ( $subType ) 160 $type .= '_' . $subType; 161 include_once ( 'kernel/classes/notification/eznotificationevent.php' ); 162 $event = eZNotificationEvent::create( 'ezcollaboration', array( 'collaboration_id' => $this->attribute( 'id' ), 163 'collaboration_identifier' => $type ) ); 164 $event->store(); 165 return $event; 166 } 167 168 function fetch( $id, $creatorID = false, $asObject = true ) 169 { 170 $conditions = array( 'id' => $id ); 171 if ( $creatorID !== false ) 172 $conditions['creator_id'] = $creatorID; 173 return eZPersistentObject::fetchObject( eZCollaborationItem::definition(), 174 null, 175 $conditions, 176 $asObject ); 177 } 178 179 function &creator() 180 { 181 if ( isset( $this->CreatorID ) and $this->CreatorID ) 182 { 183 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 184 $user = eZUser::fetch( $this->CreatorID ); 185 } 186 else 187 $user = null; 188 return $user; 189 } 190 191 function &isCreator() 192 { 193 if ( isset( $this->CreatorID ) and $this->CreatorID ) 194 { 195 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 196 $isCreator = ( eZUser::currentUserID() == $this->CreatorID ); 197 } 198 else 199 $isCreator = false; 200 return $isCreator; 201 } 202 203 function &participantList() 204 { 205 include_once ( 'kernel/classes/ezcollaborationitemparticipantlink.php' ); 206 $list =& eZCollaborationItemParticipantLink::fetchParticipantList( array('item_id' => $this->ID ) ); 207 return $list; 208 } 209 210 function &userStatus() 211 { 212 include_once ( 'kernel/classes/ezcollaborationitemstatus.php' ); 213 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 214 $userID = eZUser::currentUserID(); 215 return eZCollaborationItemStatus::fetch( $this->ID, $userID ); 216 } 217 218 function &handler() 219 { 220 include_once ( 'kernel/classes/ezcollaborationitemhandler.php' ); 221 $handler =& eZCollaborationItemHandler::instantiate( $this->attribute( 'type_identifier' ) ); 222 return $handler; 223 } 224 225 /*! 226 \return true if the item uses messages. 227 \note It's up to each handler to control this. 228 */ 229 function &useMessages() 230 { 231 $handler =& $this->handler(); 232 if ( !$handler ) 233 $useMessages = false; 234 else 235 $useMessages = $handler->useMessages( $this ); 236 return $useMessages; 237 } 238 239 /*! 240 \return the number of messages in this item. 241 \note The message count is purely abstract and it's up to each handler to return a valid count. 242 */ 243 function &messageCount() 244 { 245 $handler =& $this->handler(); 246 if ( !$handler ) 247 $messageCount = 0; 248 else 249 $messageCount = $handler->messageCount( $this ); 250 return $messageCount; 251 } 252 253 /*! 254 \return the number of unread messages in this item. 255 \note The message count is purely abstract and it's up to each handler to return a valid count. 256 It's also up the handler to keep track of which messages are read or not. 257 */ 258 function &unreadMessageCount() 259 { 260 $handler =& $this->handler(); 261 if ( !$handler ) 262 $unreadMessageCount = 0; 263 else 264 $unreadMessageCount = $handler->unreadMessageCount( $this ); 265 return $unreadMessageCount; 266 } 267 268 function &content() 269 { 270 $handler =& $this->handler(); 271 if ( !$handler ) 272 $content = null; 273 else 274 $content = $handler->content( $this ); 275 return $content; 276 } 277 278 function &title() 279 { 280 $handler =& $this->handler(); 281 if ( !$handler ) 282 $title = null; 283 else 284 $title = $handler->title( $this ); 285 return $title; 286 } 287 288 289 function hasContentAttribute( $attribute ) 290 { 291 $handler =& $this->handler(); 292 if ( !$handler ) 293 $hasContentAttribute = null; 294 else 295 $hasContentAttribute = $handler->hasContentAttribute( $this, $attribute ); 296 return $hasContentAttribute; 297 } 298 299 function &contentAttribute( $attribute ) 300 { 301 $handler =& $this->handler(); 302 if ( !$handler ) 303 $contentAttribute = null; 304 else 305 $contentAttribute = $handler->contentAttribute( $this, $attribute ); 306 return $contentAttribute; 307 } 308 309 /*! 310 \static 311 */ 312 function setIsActive( $active, $userID = false ) 313 { 314 $active = intval($active); 315 eZCollaborationItemStatus::updateFields( $this->attribute( 'id' ), $userID, array( 'is_active' => $active ) ); 316 } 317 318 function fetchListCount( $parameters = array() ) 319 { 320 return eZCollaborationItem::fetchListTool( $parameters, true ); 321 // $parameters = array_merge( array( 'status' => false 322 // 'is_active' => null, 323 // 'is_read' => null ), 324 // $parameters ); 325 // $statusTypes = $parameters['status']; 326 // $isRead = $parameters['is_read']; 327 // $isActive = $parameters['is_active']; 328 329 // $user =& eZUser::currentUser(); 330 // $userID =& $user->attribute( 'contentobject_id' ); 331 332 // $isReadText = ''; 333 // if ( $isRead !== null ) 334 // { 335 // $isReadValue = $isRead ? 1 : 0; 336 // $isReadText = "ezcollab_item_group_link.is_read = '$isReadValue' AND"; 337 // } 338 339 // $isActiveText = ''; 340 // if ( $isActive !== null ) 341 // { 342 // $isActiveValue = $isActive ? 1 : 0; 343 // $isActiveText = "ezcollab_item_group_link.is_active = '$isActiveValue' AND"; 344 // } 345 346 // $statusText = ''; 347 // if ( $statusTypes === false ) 348 // $statusTypes = array( EZ_COLLABORATION_STATUS_ACTIVE, 349 // EZ_COLLABORATION_STATUS_INACTIVE ); 350 // $statusText = implode( ', ', $statusTypes ); 351 352 // $sql = "SELECT count( ezcollab_item.id ) as count 353 // FROM 354 // ezcollab_item, 355 // ezcollab_item_group_link 356 // WHERE ezcollab_item.status IN ( $statusText ) AND 357 // $isReadText 358 // $isActiveText 359 // ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND 360 // ezcollab_item_group_link.user_id=$userID"; 361 362 // $db =& eZDB::instance(); 363 // $itemCount = $db->arrayQuery( $sql ); 364 // return $itemCount[0]['count']; 365 } 366 367 function setLastRead( $userID = false, $timestamp = false ) 368 { 369 if ( $userID === false ) 370 $userID = eZUser::currentUserID(); 371 if ( $timestamp === false ) 372 $timestamp = time(); 373 $collaborationID = $this->attribute( 'id' ); 374 375 eZCollaborationItemStatus::setLastRead( $collaborationID, $userID, $timestamp ); 376 eZCollaborationItemParticipantLink::setLastRead( $collaborationID, $userID, $timestamp ); 377 } 378 379 function fetchList( $parameters = array() ) 380 { 381 return eZCollaborationItem::fetchListTool( $parameters, false ); 382 } 383 384 function &fetchListTool( $parameters = array(), $asCount ) 385 { 386 $parameters = array_merge( array( 'as_object' => true, 387 'offset' => false, 388 'parent_group_id' => false, 389 'limit' => false, 390 'is_active' => null, 391 'is_read' => null, 392 'status' => false, 393 'sort_by' => false ), 394 $parameters ); 395 $asObject = $parameters['as_object']; 396 $offset = $parameters['offset']; 397 $limit = $parameters['limit']; 398 $statusTypes = $parameters['status']; 399 $isRead = $parameters['is_read']; 400 $isActive = $parameters['is_active']; 401 $parentGroupID = $parameters['parent_group_id']; 402 403 $sortText = ''; 404 if ( !$asCount ) 405 { 406 $sortCount = 0; 407 $sortList = $parameters['sort_by']; 408 if ( is_array( $sortList ) and 409 count( $sortList ) > 0 ) 410 { 411 if ( count( $sortList ) > 1 and 412 !is_array( $sortList[0] ) ) 413 { 414 $sortList = array( $sortList ); 415 } 416 } 417 if ( $sortList !== false ) 418 { 419 $sortingFields = ''; 420 foreach ( $sortList as $sortBy ) 421 { 422 if ( is_array( $sortBy ) and count( $sortBy ) > 0 ) 423 { 424 if ( $sortCount > 0 ) 425 $sortingFields .= ', '; 426 $sortField = $sortBy[0]; 427 switch ( $sortField ) 428 { 429 case 'created': 430 { 431 $sortingFields .= 'ezcollab_item_group_link.created'; 432 } break; 433 case 'modified': 434 { 435 $sortingFields .= 'ezcollab_item_group_link.modified'; 436 } break; 437 default: 438 { 439 eZDebug::writeWarning( 'Unknown sort field: ' . $sortField, 'eZCollaborationItem::fetchList' ); 440 continue; 441 }; 442 } 443 $sortOrder = true; // true is ascending 444 if ( isset( $sortBy[1] ) ) 445 $sortOrder = $sortBy[1]; 446 $sortingFields .= $sortOrder ? ' ASC' : ' DESC'; 447 ++$sortCount; 448 } 449 } 450 } 451 if ( $sortCount == 0 ) 452 { 453 $sortingFields = ' ezcollab_item_group_link.modified DESC'; 454 } 455 $sortText = "ORDER BY $sortingFields"; 456 } 457 458 $parentGroupText = ''; 459 if ( $parentGroupID > 0 ) 460 { 461 $parentGroupText = "ezcollab_item_group_link.group_id = '$parentGroupID' AND"; 462 } 463 464 $isReadText = ''; 465 if ( $isRead !== null ) 466 { 467 $isReadValue = $isRead ? 1 : 0; 468 $isReadText = "ezcollab_item_status.is_read = '$isReadValue' AND"; 469 } 470 471 $isActiveText = ''; 472 if ( $isActive !== null ) 473 { 474 $isActiveValue = $isActive ? 1 : 0; 475 $isActiveText = "ezcollab_item_status.is_active = '$isActiveValue' AND"; 476 } 477 478 $userID = eZUser::currentUserID(); 479 480 $statusText = ''; 481 if ( $statusTypes === false ) 482 $statusTypes = array( EZ_COLLABORATION_STATUS_ACTIVE, 483 EZ_COLLABORATION_STATUS_INACTIVE ); 484 $statusText = implode( ', ', $statusTypes ); 485 486 if ( $asCount ) 487 $selectText = 'count( ezcollab_item.id ) as count'; 488 else 489 $selectText = 'ezcollab_item.*, ezcollab_item_status.is_read, ezcollab_item_status.is_active, ezcollab_item_status.last_read'; 490 491 $sql = "SELECT $selectText 492 FROM 493 ezcollab_item, 494 ezcollab_item_status, 495 ezcollab_item_group_link 496 WHERE ezcollab_item.status IN ( $statusText ) AND 497 $isReadText 498 $isActiveText 499 ezcollab_item.id = ezcollab_item_status.collaboration_id AND 500 ezcollab_item.id = ezcollab_item_group_link.collaboration_id AND 501 $parentGroupText 502 ezcollab_item_status.user_id = '$userID' AND 503 ezcollab_item_group_link.user_id = '$userID' 504 $sortText"; 505 506 $db =& eZDB::instance(); 507 if ( !$asCount ) 508 { 509 $sqlParameters = array(); 510 if ( $offset !== false and $limit !== false ) 511 { 512 $sqlParameters['offset'] = $offset; 513 $sqlParameters['limit'] = $limit; 514 } 515 $itemListArray = $db->arrayQuery( $sql, $sqlParameters ); 516 517 foreach( $itemListArray as $key => $value ) 518 { 519 $itemData =& $itemListArray[$key]; 520 $statusObject = eZCollaborationItemStatus::create( $itemData['id'], $userID ); 521 $statusObject->setAttribute( 'is_read', $itemData['is_read'] ); 522 $statusObject->setAttribute( 'is_active', $itemData['is_active'] ); 523 $statusObject->setAttribute( 'last_read', $itemData['last_read'] ); 524 $statusObject->updateCache(); 525 } 526 $returnItemList = eZPersistentObject::handleRows( $itemListArray, 'eZCollaborationItem', $asObject ); 527 eZDebugSetting::writeDebug( 'collaboration-item-list', $returnItemList ); 528 return $returnItemList; 529 } 530 else 531 { 532 $itemCount = $db->arrayQuery( $sql ); 533 return $itemCount[0]['count']; 534 } 535 } 536 537 function handleView( $viewMode ) 538 { 539 $handler =& $this->handler(); 540 $handler->readItem( $this, $viewMode ); 541 return true; 542 } 543 544 /*! 545 \static 546 Removes all collaboration items by fetching them and calling remove on them. 547 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 548 the calls within a db transaction; thus within db->begin and db->commit. 549 */ 550 function cleanup() 551 { 552 $db =& eZDB::instance(); 553 $db->begin(); 554 $db->query( "DELETE FROM ezcollab_item" ); 555 $db->query( "DELETE FROM ezcollab_item_group_link" ); 556 $db->query( "DELETE FROM ezcollab_item_message_link" ); 557 $db->query( "DELETE FROM ezcollab_item_participant_link" ); 558 $db->query( "DELETE FROM ezcollab_item_status" ); 559 $db->query( "DELETE FROM ezcollab_notification_rule" ); 560 $db->query( "DELETE FROM ezcollab_profile" ); 561 $db->query( "DELETE FROM ezcollab_simple_message" ); 562 $db->commit(); 563 } 564 565 /// \privatesection 566 var $ID; 567 var $TypeIdentifier; 568 var $CreatorID; 569 var $Status; 570 var $Created; 571 var $Modified; 572 var $DataText1; 573 var $DataText2; 574 var $DataText3; 575 var $DataInt1; 576 var $DataInt2; 577 var $DataInt3; 578 var $DataFloat1; 579 var $DataFloat2; 580 var $DataFloat3; 581 } 582 583 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |