| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZApproveCollaborationHandler class 4 // 5 // Created on: <23-Jan-2003 11:57:11 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 ezapprovecollaborationhandler.php 30 */ 31 32 /*! 33 \class eZApproveCollaborationHandler ezapprovecollaborationhandler.php 34 \brief Handles approval communication using the collaboration system 35 36 The handler uses the fields data_int1, data_int2 and data_int3 to store 37 information on the contentobject and the approval status. 38 39 - data_int1 - The content object ID 40 - data_int2 - The content object version 41 - data_int3 - The status of the approval, see defines. 42 43 */ 44 45 include_once ( 'kernel/classes/ezcollaborationitemhandler.php' ); 46 include_once ( 'kernel/classes/ezcollaborationitem.php' ); 47 include_once ( 'kernel/classes/ezcollaborationitemmessagelink.php' ); 48 include_once ( 'kernel/classes/ezcollaborationitemparticipantlink.php' ); 49 include_once ( 'kernel/classes/ezcollaborationitemgrouplink.php' ); 50 include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' ); 51 include_once ( 'kernel/classes/ezcollaborationprofile.php' ); 52 include_once ( 'kernel/classes/ezcollaborationsimplemessage.php' ); 53 include_once ( 'kernel/classes/ezcontentobjectversion.php' ); 54 include_once ( 'kernel/common/i18n.php' ); 55 56 /// Approval message type 57 define( "EZ_COLLABORATION_MESSAGE_TYPE_APPROVE", 1 ); 58 59 /// Default status, no approval decision has been made 60 define( "EZ_COLLABORATION_APPROVE_STATUS_WAITING", 0 ); 61 /// The contentobject was approved and will be published. 62 define( "EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED", 1 ); 63 /// The contentobject was denied and will be archived. 64 define( "EZ_COLLABORATION_APPROVE_STATUS_DENIED", 2 ); 65 /// The contentobject was deferred and will be a draft again for reediting. 66 define( "EZ_COLLABORATION_APPROVE_STATUS_DEFERRED", 3 ); 67 68 class eZApproveCollaborationHandler extends eZCollaborationItemHandler 69 { 70 /*! 71 Initializes the handler 72 */ 73 function eZApproveCollaborationHandler() 74 { 75 $this->eZCollaborationItemHandler( 'ezapprove', 76 ezi18n( 'kernel/classes', 'Approval' ), 77 array( 'use-messages' => true, 78 'notification-types' => true, 79 'notification-collection-handling' => EZ_COLLABORATION_NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE ) ); 80 } 81 82 /*! 83 \reimp 84 */ 85 function title( &$collaborationItem ) 86 { 87 return ezi18n( 'kernel/classes', 'Approval' ); 88 } 89 90 /*! 91 \reimp 92 */ 93 function &content( &$collaborationItem ) 94 { 95 $content = array( "content_object_id" => $collaborationItem->attribute( "data_int1" ), 96 "content_object_version" => $collaborationItem->attribute( "data_int2" ), 97 "approval_status" => $collaborationItem->attribute( "data_int3" ) ); 98 return $content; 99 } 100 101 function notificationParticipantTemplate( $participantRole ) 102 { 103 if ( $participantRole == EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER ) 104 { 105 return 'approve.tpl'; 106 } 107 else if ( $participantRole == EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR ) 108 { 109 return 'author.tpl'; 110 } 111 else 112 return false; 113 } 114 115 /*! 116 \return the content object version object for the collaboration item \a $collaborationItem 117 */ 118 function contentObjectVersion( &$collaborationItem ) 119 { 120 $contentObjectID = $collaborationItem->contentAttribute( 'content_object_id' ); 121 $contentObjectVersion = $collaborationItem->contentAttribute( 'content_object_version' ); 122 return eZContentObjectVersion::fetchVersion( $contentObjectVersion, $contentObjectID ); 123 } 124 125 /*! 126 \reimp 127 Updates the last_read for the participant link. 128 */ 129 function readItem( &$collaborationItem ) 130 { 131 $collaborationItem->setLastRead(); 132 } 133 134 /*! 135 \reimp 136 \return the number of messages for the approve item. 137 */ 138 function messageCount( &$collaborationItem ) 139 { 140 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ) ) ); 141 } 142 143 /*! 144 \reimp 145 \return the number of unread messages for the approve item. 146 */ 147 function unreadMessageCount( &$collaborationItem ) 148 { 149 $lastRead = 0; 150 $status =& $collaborationItem->attribute( 'user_status' ); 151 if ( $status ) 152 $lastRead = $status->attribute( 'last_read' ); 153 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ), 154 'conditions' => array( 'modified' => array( '>', $lastRead ) ) ) ); 155 } 156 157 /*! 158 \static 159 \return the status of the approval collaboration item \a $approvalID. 160 */ 161 function checkApproval( $approvalID ) 162 { 163 $collaborationItem = eZCollaborationItem::fetch( $approvalID ); 164 if ( $collaborationItem !== null ) 165 { 166 return $collaborationItem->attribute( 'data_int3' ); 167 } 168 return false; 169 } 170 171 /*! 172 \static 173 \return makes sure the approval item is activated for all participants \a $approvalID. 174 */ 175 function activateApproval( $approvalID ) 176 { 177 $collaborationItem = eZCollaborationItem::fetch( $approvalID ); 178 if ( $collaborationItem !== null ) 179 { 180 // eZDebug::writeDebug( $collaborationItem, "reactivating approval $approvalID" ); 181 $collaborationItem->setAttribute( 'data_int3', EZ_COLLABORATION_APPROVE_STATUS_WAITING ); 182 $collaborationItem->setAttribute( 'status', EZ_COLLABORATION_STATUS_ACTIVE ); 183 $timestamp = time(); 184 $collaborationItem->setAttribute( 'modified', $timestamp ); 185 $collaborationItem->store(); 186 $participantList =& eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $approvalID ) ); 187 for ( $i = 0; $i < count( $participantList ); ++$i ) 188 { 189 $participantLink =& $participantList[$i]; 190 $collaborationItem->setIsActive( true, $participantLink->attribute( 'participant_id' ) ); 191 } 192 return true; 193 } 194 return false; 195 } 196 197 /*! 198 Creates a new approval collaboration item which will approve the content object \a $contentObjectID 199 with version \a $contentObjectVersion. 200 The item will be added to the author \a $authorID and the approver array \a $approverIDArray. 201 \return the collaboration item. 202 */ 203 function createApproval( $contentObjectID, $contentObjectVersion, $authorID, $approverIDArray ) 204 { 205 $collaborationItem = eZCollaborationItem::create( 'ezapprove', $authorID ); 206 $collaborationItem->setAttribute( 'data_int1', $contentObjectID ); 207 $collaborationItem->setAttribute( 'data_int2', $contentObjectVersion ); 208 $collaborationItem->setAttribute( 'data_int3', false ); 209 $collaborationItem->store(); 210 $collaborationID = $collaborationItem->attribute( 'id' ); 211 212 $participantList = array( array( 'id' => array( $authorID ), 213 'role' => EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR ), 214 array( 'id' => $approverIDArray, 215 'role' => EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER ) ); 216 foreach ( $participantList as $participantItem ) 217 { 218 foreach( $participantItem['id'] as $participantID ) 219 { 220 $participantRole = $participantItem['role']; 221 $link = eZCollaborationItemParticipantLink::create( $collaborationID, $participantID, 222 $participantRole, EZ_COLLABORATION_PARTICIPANT_TYPE_USER ); 223 $link->store(); 224 225 $profile =& eZCollaborationProfile::instance( $participantID ); 226 $groupID =& $profile->attribute( 'main_group' ); 227 eZCollaborationItemGroupLink::addItem( $groupID, $collaborationID, $participantID ); 228 } 229 } 230 231 // Create the notification 232 $collaborationItem->createNotificationEvent(); 233 return $collaborationItem; 234 } 235 236 /*! 237 \reimp 238 Adds a new comment, approves the item or denies the item. 239 */ 240 function handleCustomAction( &$module, &$collaborationItem ) 241 { 242 $redirectView = 'item'; 243 $redirectParameters = array( 'full', $collaborationItem->attribute( 'id' ) ); 244 $addComment = false; 245 246 if ( $this->isCustomAction( 'Comment' ) ) 247 { 248 $addComment = true; 249 } 250 else if ( $this->isCustomAction( 'Accept' ) or 251 $this->isCustomAction( 'Deny' ) or 252 $this->isCustomAction( 'Defer' ) ) 253 { 254 $contentObjectVersion = $this->contentObjectVersion( $collaborationItem ); 255 $status = EZ_COLLABORATION_APPROVE_STATUS_DENIED; 256 if ( $this->isCustomAction( 'Accept' ) ) 257 $status = EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED; 258 // else if ( $this->isCustomAction( 'Defer' ) ) 259 // $status = EZ_COLLABORATION_APPROVE_STATUS_DEFERRED; 260 // else if ( $this->isCustomAction( 'Deny' ) ) 261 // $status = EZ_COLLABORATION_APPROVE_STATUS_DENIED; 262 else if ( $this->isCustomAction( 'Defer' ) or 263 $this->isCustomAction( 'Deny' ) ) 264 $status = EZ_COLLABORATION_APPROVE_STATUS_DENIED; 265 $collaborationItem->setAttribute( 'data_int3', $status ); 266 $collaborationItem->setAttribute( 'status', EZ_COLLABORATION_STATUS_INACTIVE ); 267 $timestamp = time(); 268 $collaborationItem->setAttribute( 'modified', $timestamp ); 269 $collaborationItem->setIsActive( false ); 270 $redirectView = 'view'; 271 $redirectParameters = array( 'summary' ); 272 $addComment = true; 273 } 274 if ( $addComment ) 275 { 276 $messageText = $this->customInput( 'ApproveComment' ); 277 if ( trim( $messageText ) != '' ) 278 { 279 $message = eZCollaborationSimpleMessage::create( 'ezapprove_comment', $messageText ); 280 $message->store(); 281 // eZDebug::writeDebug( $message ); 282 eZCollaborationItemMessageLink::addMessage( $collaborationItem, $message, EZ_COLLABORATION_MESSAGE_TYPE_APPROVE ); 283 } 284 } 285 $collaborationItem->sync(); 286 return $module->redirectToView( $redirectView, $redirectParameters ); 287 } 288 289 } 290 291 ?>
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 |