Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezapprovecollaborationhandler.php
Go to the documentation of this file.
1 <?php
24 class eZApproveCollaborationHandler extends eZCollaborationItemHandler
25 {
27 const MESSAGE_TYPE_APPROVE = 1;
28
30 const STATUS_WAITING = 0;
31
33 const STATUS_ACCEPTED = 1;
34
36 const STATUS_DENIED = 2;
37
39 const STATUS_DEFERRED = 3;
40
41 public function __construct()
42 {
43 parent::__construct(
44 'ezapprove',
45 ezpI18n::tr( 'kernel/classes', 'Approval' ),
46 array(
47 'use-messages' => true,
48 'notification-types' => true,
49 'notification-collection-handling' => eZCollaborationItemHandler::NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE
50 )
51 );
52 }
53
54 function title( $collaborationItem )
55 {
56 return ezpI18n::tr( 'kernel/classes', 'Approval' );
57 }
58
59 function content( $collaborationItem )
60 {
61 return array( "content_object_id" => $collaborationItem->attribute( "data_int1" ),
62 "content_object_version" => $collaborationItem->attribute( "data_int2" ),
63 "approval_status" => $collaborationItem->attribute( "data_int3" ) );
64 }
65
66 function notificationParticipantTemplate( $participantRole )
67 {
68 if ( $participantRole == eZCollaborationItemParticipantLink::ROLE_APPROVER )
69 {
70 return 'approve.tpl';
71 }
72 else if ( $participantRole == eZCollaborationItemParticipantLink::ROLE_AUTHOR )
73 {
74 return 'author.tpl';
75 }
76 else
77 return false;
78 }
79
83 static function contentObjectVersion( $collaborationItem )
84 {
85 $contentObjectID = $collaborationItem->contentAttribute( 'content_object_id' );
86 $contentObjectVersion = $collaborationItem->contentAttribute( 'content_object_version' );
87 return eZContentObjectVersion::fetchVersion( $contentObjectVersion, $contentObjectID );
88 }
89
93 function readItem( $collaborationItem, $viewMode = false )
94 {
95 $collaborationItem->setLastRead();
96 }
97
101 function messageCount( $collaborationItem )
102 {
103 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ) ) );
104 }
105
109 function unreadMessageCount( $collaborationItem )
110 {
111 $lastRead = 0;
112 $status = $collaborationItem->attribute( 'user_status' );
113 if ( $status )
114 $lastRead = $status->attribute( 'last_read' );
115 return eZCollaborationItemMessageLink::fetchItemCount( array( 'item_id' => $collaborationItem->attribute( 'id' ),
116 'conditions' => array( 'modified' => array( '>', $lastRead ) ) ) );
117 }
118
123 static function checkApproval( $approvalID )
124 {
125 $collaborationItem = eZCollaborationItem::fetch( $approvalID );
126 if ( $collaborationItem !== null )
127 {
128 return $collaborationItem->attribute( 'data_int3' );
129 }
130 return false;
131 }
132
137 static function activateApproval( $approvalID )
138 {
139 $collaborationItem = eZCollaborationItem::fetch( $approvalID );
140 if ( $collaborationItem !== null )
141 {
142 $collaborationItem->setAttribute( 'data_int3', self::STATUS_WAITING );
143 $collaborationItem->setAttribute( 'status', eZCollaborationItem::STATUS_ACTIVE );
144 $timestamp = time();
145 $collaborationItem->setAttribute( 'modified', $timestamp );
146 $collaborationItem->store();
147 $participantList = eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $approvalID ) );
148 foreach( $participantList as $participantLink )
149 {
150 $collaborationItem->setIsActive( true, $participantLink->attribute( 'participant_id' ) );
151 }
152 return true;
153 }
154 return false;
155 }
156
163 static function createApproval( $contentObjectID, $contentObjectVersion, $authorID, $approverIDArray )
164 {
165 $collaborationItem = eZCollaborationItem::create( 'ezapprove', $authorID );
166 $collaborationItem->setAttribute( 'data_int1', $contentObjectID );
167 $collaborationItem->setAttribute( 'data_int2', $contentObjectVersion );
168 $collaborationItem->setAttribute( 'data_int3', false );
169 $collaborationItem->store();
170 $collaborationID = $collaborationItem->attribute( 'id' );
171
172 $participantList = array( array( 'id' => array( $authorID ),
173 'role' => eZCollaborationItemParticipantLink::ROLE_AUTHOR ),
174 array( 'id' => $approverIDArray,
175 'role' => eZCollaborationItemParticipantLink::ROLE_APPROVER ) );
176 foreach ( $participantList as $participantItem )
177 {
178 foreach( $participantItem['id'] as $participantID )
179 {
180 $participantRole = $participantItem['role'];
181 $link = eZCollaborationItemParticipantLink::create( $collaborationID, $participantID,
182 $participantRole, eZCollaborationItemParticipantLink::TYPE_USER );
183 $link->store();
184
185 $profile = eZCollaborationProfile::instance( $participantID );
186 $groupID = $profile->attribute( 'main_group' );
187 eZCollaborationItemGroupLink::addItem( $groupID, $collaborationID, $participantID );
188 }
189 }
190
191 // Create the notification
192 $collaborationItem->createNotificationEvent();
193 return $collaborationItem;
194 }
195
199 function handleCustomAction( $module, $collaborationItem )
200 {
201 $redirectView = 'item';
202 $redirectParameters = array( 'full', $collaborationItem->attribute( 'id' ) );
203 $addComment = false;
204
205 if ( $this->isCustomAction( 'Comment' ) )
206 {
207 $addComment = true;
208 }
209 else if ( $this->isCustomAction( 'Accept' ) or
210 $this->isCustomAction( 'Deny' ) or
211 $this->isCustomAction( 'Defer' ) )
212 {
213 // check user's rights to approve
214 $user = eZUser::currentUser();
215 $userID = $user->attribute( 'contentobject_id' );
216 $participantList = eZCollaborationItemParticipantLink::fetchParticipantList( array( 'item_id' => $collaborationItem->attribute( 'id' ) ) );
217
218 $approveAllowed = false;
219 foreach( $participantList as $participant )
220 {
221 if ( $participant->ParticipantID == $userID &&
222 $participant->ParticipantRole == eZCollaborationItemParticipantLink::ROLE_APPROVER )
223 {
224 $approveAllowed = true;
225 break;
226 }
227 }
228 if ( !$approveAllowed )
229 {
230 return $module->redirectToView( $redirectView, $redirectParameters );
231 }
232
233 $contentObjectVersion = $this->contentObjectVersion( $collaborationItem );
234 $status = self::STATUS_DENIED;
235 if ( $this->isCustomAction( 'Accept' ) )
236 $status = self::STATUS_ACCEPTED;
237 // else if ( $this->isCustomAction( 'Defer' ) )
238 // $status = self::STATUS_DEFERRED;
239 // else if ( $this->isCustomAction( 'Deny' ) )
240 // $status = self::STATUS_DENIED;
241 else if ( $this->isCustomAction( 'Defer' ) or
242 $this->isCustomAction( 'Deny' ) )
243 $status = self::STATUS_DENIED;
244 $collaborationItem->setAttribute( 'data_int3', $status );
245 $collaborationItem->setAttribute( 'status', eZCollaborationItem::STATUS_INACTIVE );
246 $timestamp = time();
247 $collaborationItem->setAttribute( 'modified', $timestamp );
248 $collaborationItem->setIsActive( false );
249 $redirectView = 'view';
250 $redirectParameters = array( 'summary' );
251 $addComment = true;
252 }
253 if ( $addComment )
254 {
255 $messageText = $this->customInput( 'ApproveComment' );
256 if ( trim( $messageText ) != '' )
257 {
258 $message = eZCollaborationSimpleMessage::create( 'ezapprove_comment', $messageText );
259 $message->store();
260 eZCollaborationItemMessageLink::addMessage( $collaborationItem, $message, self::MESSAGE_TYPE_APPROVE );
261 }
262 }
263 $collaborationItem->sync();
264 return $module->redirectToView( $redirectView, $redirectParameters );
265 }
266
267 }
268
269 ?>
eZApproveCollaborationHandler
Handles approval communication using the collaboration system.
Definition: ezapprovecollaborationhandler.php:25
eZApproveCollaborationHandler\createApproval
static createApproval( $contentObjectID, $contentObjectVersion, $authorID, $approverIDArray)
Definition: ezapprovecollaborationhandler.php:163
eZApproveCollaborationHandler\STATUS_WAITING
const STATUS_WAITING
Default status, no approval decision has been made.
Definition: ezapprovecollaborationhandler.php:30
eZApproveCollaborationHandler\STATUS_ACCEPTED
const STATUS_ACCEPTED
The contentobject was approved and will be published.
Definition: ezapprovecollaborationhandler.php:33
eZApproveCollaborationHandler\readItem
readItem( $collaborationItem, $viewMode=false)
Definition: ezapprovecollaborationhandler.php:93
eZApproveCollaborationHandler\unreadMessageCount
unreadMessageCount( $collaborationItem)
Definition: ezapprovecollaborationhandler.php:109
eZApproveCollaborationHandler\STATUS_DENIED
const STATUS_DENIED
The contentobject was denied and will be archived.
Definition: ezapprovecollaborationhandler.php:36
eZApproveCollaborationHandler\title
title( $collaborationItem)
Definition: ezapprovecollaborationhandler.php:54
eZApproveCollaborationHandler\handleCustomAction
handleCustomAction( $module, $collaborationItem)
Definition: ezapprovecollaborationhandler.php:199
eZApproveCollaborationHandler\content
content( $collaborationItem)
Definition: ezapprovecollaborationhandler.php:59
eZApproveCollaborationHandler\contentObjectVersion
static contentObjectVersion( $collaborationItem)
Definition: ezapprovecollaborationhandler.php:83
eZApproveCollaborationHandler\checkApproval
static checkApproval( $approvalID)
Definition: ezapprovecollaborationhandler.php:123
eZApproveCollaborationHandler\__construct
__construct()
Definition: ezapprovecollaborationhandler.php:41
eZApproveCollaborationHandler\notificationParticipantTemplate
notificationParticipantTemplate( $participantRole)
Definition: ezapprovecollaborationhandler.php:66
eZApproveCollaborationHandler\messageCount
messageCount( $collaborationItem)
Definition: ezapprovecollaborationhandler.php:101
eZApproveCollaborationHandler\activateApproval
static activateApproval( $approvalID)
Definition: ezapprovecollaborationhandler.php:137
eZApproveCollaborationHandler\STATUS_DEFERRED
const STATUS_DEFERRED
The contentobject was deferred and will be a draft again for reediting.
Definition: ezapprovecollaborationhandler.php:39
eZApproveCollaborationHandler\MESSAGE_TYPE_APPROVE
const MESSAGE_TYPE_APPROVE
Approval message type.
Definition: ezapprovecollaborationhandler.php:27
eZCollaborationItemGroupLink\addItem
static addItem( $groupID, $collaborationID, $userID)
Definition: ezcollaborationitemgrouplink.php:86
eZCollaborationItemHandler
The class eZCollaborationItemHandler does.
Definition: ezcollaborationitemhandler.php:18
eZCollaborationItemHandler\customInput
customInput( $name)
Definition: ezcollaborationitemhandler.php:441
eZCollaborationItemHandler\NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE
const NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE
Definition: ezcollaborationitemhandler.php:26
eZCollaborationItemHandler\isCustomAction
isCustomAction( $name)
Definition: ezcollaborationitemhandler.php:421
eZCollaborationItemMessageLink\fetchItemCount
static fetchItemCount( $parameters)
Definition: ezcollaborationitemmessagelink.php:122
eZCollaborationItemMessageLink\addMessage
static addMessage( $collaborationItem, $message, $messageType, $participantID=false)
Definition: ezcollaborationitemmessagelink.php:84
eZCollaborationItemParticipantLink\fetchParticipantList
static fetchParticipantList( $parameters=array())
Definition: ezcollaborationitemparticipantlink.php:132
eZCollaborationItemParticipantLink\TYPE_USER
const TYPE_USER
Definition: ezcollaborationitemparticipantlink.php:20
eZCollaborationItemParticipantLink\ROLE_AUTHOR
const ROLE_AUTHOR
Definition: ezcollaborationitemparticipantlink.php:30
eZCollaborationItemParticipantLink\create
static create( $collaborationID, $participantID, $participantRole=self::ROLE_STANDARD, $participantType=self::TYPE_USER)
Definition: ezcollaborationitemparticipantlink.php:82
eZCollaborationItemParticipantLink\ROLE_APPROVER
const ROLE_APPROVER
Definition: ezcollaborationitemparticipantlink.php:29
eZCollaborationItem\STATUS_INACTIVE
const STATUS_INACTIVE
Definition: ezcollaborationitem.php:20
eZCollaborationItem\fetch
static fetch( $id, $creatorID=false, $asObject=true)
Definition: ezcollaborationitem.php:135
eZCollaborationItem\STATUS_ACTIVE
const STATUS_ACTIVE
Definition: ezcollaborationitem.php:19
eZCollaborationItem\create
static create( $typeIdentifier, $creatorID, $status=self::STATUS_ACTIVE)
Definition: ezcollaborationitem.php:105
eZCollaborationProfile\instance
static instance( $userID=false)
Definition: ezcollaborationprofile.php:96
eZCollaborationSimpleMessage\create
static create( $type, $text=false, $creatorID=false)
Definition: ezcollaborationsimplemessage.php:87
eZContentObjectVersion\fetchVersion
static fetchVersion( $version, $contentObjectID, $asObject=true)
Definition: ezcontentobjectversion.php:166
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.