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
00041
00042
00043
00044
00045
00046
00047 include_once( 'kernel/classes/ezcollaborationitemhandler.php' );
00048 include_once( 'kernel/classes/ezcollaborationitem.php' );
00049 include_once( 'kernel/classes/ezcollaborationitemmessagelink.php' );
00050 include_once( 'kernel/classes/ezcollaborationitemparticipantlink.php' );
00051 include_once( 'kernel/classes/ezcollaborationitemgrouplink.php' );
00052 include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
00053 include_once( 'kernel/classes/ezcollaborationprofile.php' );
00054 include_once( 'kernel/classes/ezcollaborationsimplemessage.php' );
00055 include_once( 'kernel/classes/ezcontentobjectversion.php' );
00056 include_once( 'kernel/common/i18n.php' );
00057
00058
00059 define( "EZ_COLLABORATION_MESSAGE_TYPE_APPROVE", 1 );
00060
00061
00062 define( "EZ_COLLABORATION_APPROVE_STATUS_WAITING", 0 );
00063
00064 define( "EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED", 1 );
00065
00066 define( "EZ_COLLABORATION_APPROVE_STATUS_DENIED", 2 );
00067
00068 define( "EZ_COLLABORATION_APPROVE_STATUS_DEFERRED", 3 );
00069
00070 class eZApproveCollaborationHandler extends eZCollaborationItemHandler
00071 {
00072
00073
00074
00075 function eZApproveCollaborationHandler()
00076 {
00077 $this->eZCollaborationItemHandler( 'ezapprove',
00078 ezi18n( 'kernel/classes', 'Approval' ),
00079 array( 'use-messages' => true,
00080 'notification-types' => true,
00081 'notification-collection-handling' => EZ_COLLABORATION_NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE ) );
00082 }
00083
00084
00085
00086
00087 function title( &$collaborationItem )
00088 {
00089 return ezi18n( 'kernel/classes', 'Approval' );
00090 }
00091
00092
00093
00094
00095 function &content( &$collaborationItem )
00096 {
00097 $content = array( "content_object_id" => $collaborationItem->attribute( "data_int1" ),
00098 "content_object_version" => $collaborationItem->attribute( "data_int2" ),
00099 "approval_status" => $collaborationItem->attribute( "data_int3" ) );
00100 return $content;
00101 }
00102
00103 function notificationParticipantTemplate( $participantRole )
00104 {
00105 if ( $participantRole == EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER )
00106 {
00107 return 'approve.tpl';
00108 }
00109 else if ( $participantRole == EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR )
00110 {
00111 return 'author.tpl';
00112 }
00113 else
00114 return false;
00115 }
00116
00117
00118
00119
00120 function contentObjectVersion( &$collaborationItem )
00121 {
00122 $contentObjectID = $collaborationItem->contentAttribute( 'content_object_id' );
00123 $contentObjectVersion = $collaborationItem->contentAttribute( 'content_object_version' );
00124 return eZContentObjectVersion::fetchVersion( $contentObjectVersion, $contentObjectID );
00125 }
00126
00127
00128
00129
00130
00131 function readItem( &$collaborationItem )
00132 {
00133 $collaborationItem->setLastRead();
00134 }
00135
00136
00137
00138
00139
00140 function messageCount( &$collaborationItem )
00141 {
00142 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ) ) );
00143 }
00144
00145
00146
00147
00148
00149 function unreadMessageCount( &$collaborationItem )
00150 {
00151 $lastRead = 0;
00152 $status =& $collaborationItem->attribute( 'user_status' );
00153 if ( $status )
00154 $lastRead = $status->attribute( 'last_read' );
00155 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ),
00156 'conditions' => array( 'modified' => array( '>', $lastRead ) ) ) );
00157 }
00158
00159
00160
00161
00162
00163 function checkApproval( $approvalID )
00164 {
00165 $collaborationItem = eZCollaborationItem::fetch( $approvalID );
00166 if ( $collaborationItem !== null )
00167 {
00168 return $collaborationItem->attribute( 'data_int3' );
00169 }
00170 return false;
00171 }
00172
00173
00174
00175
00176
00177 function activateApproval( $approvalID )
00178 {
00179 $collaborationItem = eZCollaborationItem::fetch( $approvalID );
00180 if ( $collaborationItem !== null )
00181 {
00182
00183 $collaborationItem->setAttribute( 'data_int3', EZ_COLLABORATION_APPROVE_STATUS_WAITING );
00184 $collaborationItem->setAttribute( 'status', EZ_COLLABORATION_STATUS_ACTIVE );
00185 $timestamp = time();
00186 $collaborationItem->setAttribute( 'modified', $timestamp );
00187 $collaborationItem->store();
00188 $participantList =& eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $approvalID ) );
00189 for ( $i = 0; $i < count( $participantList ); ++$i )
00190 {
00191 $participantLink =& $participantList[$i];
00192 $collaborationItem->setIsActive( true, $participantLink->attribute( 'participant_id' ) );
00193 }
00194 return true;
00195 }
00196 return false;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205 function createApproval( $contentObjectID, $contentObjectVersion, $authorID, $approverIDArray )
00206 {
00207 $collaborationItem = eZCollaborationItem::create( 'ezapprove', $authorID );
00208 $collaborationItem->setAttribute( 'data_int1', $contentObjectID );
00209 $collaborationItem->setAttribute( 'data_int2', $contentObjectVersion );
00210 $collaborationItem->setAttribute( 'data_int3', false );
00211 $collaborationItem->store();
00212 $collaborationID = $collaborationItem->attribute( 'id' );
00213
00214 $participantList = array( array( 'id' => array( $authorID ),
00215 'role' => EZ_COLLABORATION_PARTICIPANT_ROLE_AUTHOR ),
00216 array( 'id' => $approverIDArray,
00217 'role' => EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER ) );
00218 foreach ( $participantList as $participantItem )
00219 {
00220 foreach( $participantItem['id'] as $participantID )
00221 {
00222 $participantRole = $participantItem['role'];
00223 $link = eZCollaborationItemParticipantLink::create( $collaborationID, $participantID,
00224 $participantRole, EZ_COLLABORATION_PARTICIPANT_TYPE_USER );
00225 $link->store();
00226
00227 $profile =& eZCollaborationProfile::instance( $participantID );
00228 $groupID =& $profile->attribute( 'main_group' );
00229 eZCollaborationItemGroupLink::addItem( $groupID, $collaborationID, $participantID );
00230 }
00231 }
00232
00233
00234 $collaborationItem->createNotificationEvent();
00235 return $collaborationItem;
00236 }
00237
00238
00239
00240
00241
00242 function handleCustomAction( &$module, &$collaborationItem )
00243 {
00244 $redirectView = 'item';
00245 $redirectParameters = array( 'full', $collaborationItem->attribute( 'id' ) );
00246 $addComment = false;
00247
00248 if ( $this->isCustomAction( 'Comment' ) )
00249 {
00250 $addComment = true;
00251 }
00252 else if ( $this->isCustomAction( 'Accept' ) or
00253 $this->isCustomAction( 'Deny' ) or
00254 $this->isCustomAction( 'Defer' ) )
00255 {
00256
00257 $user =& eZUser::currentUser();
00258 $userID = $user->attribute( 'contentobject_id' );
00259 $participantList = eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $collaborationItem->attribute( 'id' ) ) );
00260
00261 $approveAllowed = false;
00262 foreach( $participantList as $participant )
00263 {
00264 if ( $participant->ParticipantID == $userID &&
00265 $participant->ParticipantRole == EZ_COLLABORATION_PARTICIPANT_ROLE_APPROVER )
00266 {
00267 $approveAllowed = true;
00268 break;
00269 }
00270 }
00271 if ( !$approveAllowed )
00272 {
00273 return $module->redirectToView( $redirectView, $redirectParameters );
00274 }
00275
00276 $contentObjectVersion = $this->contentObjectVersion( $collaborationItem );
00277 $status = EZ_COLLABORATION_APPROVE_STATUS_DENIED;
00278 if ( $this->isCustomAction( 'Accept' ) )
00279 $status = EZ_COLLABORATION_APPROVE_STATUS_ACCEPTED;
00280
00281
00282
00283
00284 else if ( $this->isCustomAction( 'Defer' ) or
00285 $this->isCustomAction( 'Deny' ) )
00286 $status = EZ_COLLABORATION_APPROVE_STATUS_DENIED;
00287 $collaborationItem->setAttribute( 'data_int3', $status );
00288 $collaborationItem->setAttribute( 'status', EZ_COLLABORATION_STATUS_INACTIVE );
00289 $timestamp = time();
00290 $collaborationItem->setAttribute( 'modified', $timestamp );
00291 $collaborationItem->setIsActive( false );
00292 $redirectView = 'view';
00293 $redirectParameters = array( 'summary' );
00294 $addComment = true;
00295 }
00296 if ( $addComment )
00297 {
00298 $messageText = $this->customInput( 'ApproveComment' );
00299 if ( trim( $messageText ) != '' )
00300 {
00301 $message = eZCollaborationSimpleMessage::create( 'ezapprove_comment', $messageText );
00302 $message->store();
00303
00304 eZCollaborationItemMessageLink::addMessage( $collaborationItem, $message, EZ_COLLABORATION_MESSAGE_TYPE_APPROVE );
00305 }
00306 }
00307 $collaborationItem->sync();
00308 return $module->redirectToView( $redirectView, $redirectParameters );
00309 }
00310
00311 }
00312
00313 ?>