function fetchMessageList($itemID, $sortBy, $offset, $limit)
 {
     $itemParameters = array('item_id' => $itemID, 'offset' => $offset, 'limit' => $limit, 'sort_by' => $sortBy);
     $children = eZCollaborationItemMessageLink::fetchItemList($itemParameters);
     if ($children === null) {
         $resultArray = array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND));
     } else {
         $resultArray = array('result' => $children);
     }
     return $resultArray;
 }
 static function fetchItemList($parameters)
 {
     $parameters = array_merge(array('as_object' => true, 'item_id' => false, 'offset' => false, 'limit' => false, 'sort_by' => false), $parameters);
     $itemID = $parameters['item_id'];
     $asObject = $parameters['as_object'];
     $offset = $parameters['offset'];
     $limit = $parameters['limit'];
     $limitArray = null;
     if ($offset and $limit) {
         $limitArray = array('offset' => $offset, 'limit' => $limit);
     }
     return eZPersistentObject::fetchObjectList(eZCollaborationItemMessageLink::definition(), null, array("collaboration_id" => $itemID), null, $limitArray, $asObject);
 }
 function handleCustomAction($module, $collaborationItem)
 {
     $redirectView = 'item';
     $redirectParameters = array('full', $collaborationItem->attribute('id'));
     $addComment = false;
     if ($this->isCustomAction('Comment')) {
         $addComment = true;
     } else {
         if ($this->isCustomAction('Accept') or $this->isCustomAction('Deny') or $this->isCustomAction('Defer')) {
             // check user's rights to approve
             $user = eZUser::currentUser();
             $userID = $user->attribute('contentobject_id');
             $participantList = eZCollaborationItemParticipantLink::fetchParticipantList(array('item_id' => $collaborationItem->attribute('id')));
             $approveAllowed = false;
             foreach ($participantList as $participant) {
                 if ($participant->ParticipantID == $userID && $participant->ParticipantRole == eZCollaborationItemParticipantLink::ROLE_APPROVER) {
                     $approveAllowed = true;
                     break;
                 }
             }
             if (!$approveAllowed) {
                 return $module->redirectToView($redirectView, $redirectParameters);
             }
             $contentObjectVersion = $this->contentObjectVersion($collaborationItem);
             $status = self::STATUS_DENIED;
             if ($this->isCustomAction('Accept')) {
                 $status = self::STATUS_ACCEPTED;
             } else {
                 if ($this->isCustomAction('Defer') or $this->isCustomAction('Deny')) {
                     $status = self::STATUS_DENIED;
                 }
             }
             $collaborationItem->setAttribute('data_int3', $status);
             $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE);
             $timestamp = time();
             $collaborationItem->setAttribute('modified', $timestamp);
             $collaborationItem->setIsActive(false);
             $redirectView = 'view';
             $redirectParameters = array('summary');
             $addComment = true;
         }
     }
     if ($addComment) {
         $messageText = $this->customInput('ApproveComment');
         if (trim($messageText) != '') {
             $message = eZCollaborationSimpleMessage::create('ezapprove_comment', $messageText);
             $message->store();
             eZCollaborationItemMessageLink::addMessage($collaborationItem, $message, self::MESSAGE_TYPE_APPROVE);
         }
     }
     $collaborationItem->sync();
     return $module->redirectToView($redirectView, $redirectParameters);
 }
 function handleCustomAction(&$module, &$collaborationItem)
 {
     $redirectView = 'item';
     $redirectParameters = array('full', $collaborationItem->attribute('id'));
     $addComment = false;
     if ($this->isCustomAction('Comment')) {
         $addComment = true;
     } else {
         if ($this->isCustomAction('Accept') || $this->isCustomAction('Deny')) {
             #include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezxapprovestatus.php' );
             $approveStatus = eZXApproveStatus::fetchByCollaborationItem($collaborationItem->attribute('id'));
             if (!$approveStatus) {
                 eZDebug::writeError('Could not fetch approve status for collaboration id : ' . $collaborationItem->attribute('id'));
                 return false;
             }
             $approveStatusUserLink = eZXApproveStatusUserLink::fetchByUserID(eZUser::currentUserID(), $approveStatus->attribute('id'), eZXApproveStatusUserLink::RoleApprover);
             if (!$approveStatusUserLink) {
                 eZDebug::writeDebug('User is not approver for approve status : ' . $approveStatus->attribute('id') . ', user ID : ' . eZUser::currentUserID());
                 return false;
             }
             $contentObjectVersion = $this->contentObjectVersion($collaborationItem);
             if ($this->isCustomAction('Accept')) {
                 $approveStatusUserLink->setAttribute('approve_status', eZXApproveStatusUserLink::StatusApproved);
             } else {
                 if ($this->isCustomAction('Deny')) {
                     $collaborationItem->setIsActive(false);
                     $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE);
                     $approveStatusUserLink->setAttribute('approve_status', eZXApproveStatusUserLink::StatusDiscarded);
                 }
             }
             $approveStatusUserLink->sync();
             $redirectView = 'view';
             $redirectParameters = array('summary');
             $addComment = true;
         } else {
             if ($this->isCustomAction('Edit')) {
                 #include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezxapprovestatus.php' );
                 $approveStatus = eZXApproveStatus::fetchByCollaborationItem($collaborationItem->attribute('id'));
                 $contentObject = $approveStatus->attribute('contentobject');
                 // Check if user can edit object
                 if (!$contentObject || !$contentObject->attribute('can_edit')) {
                     eZDebug::writeError('insufficient access to edit object : ' . $contentObject->attribute('id'));
                     return false;
                 }
                 // 1. Lock workflow, and abort all previous pending elements.
                 $db = eZDB::instance();
                 if (!$approveStatus) {
                     eZDebug::writeError('Could not fetch approve status for collaboration id : ' . $collaborationItem->attribute('id'));
                     return false;
                 }
                 $db->begin();
                 $approveStatus->cancel();
                 // 2. Create new version based in the pending one.
                 $newVersion = $contentObject->createNewVersion($approveStatus->attribute('active_version'));
                 // If the Object has never been published we have to copy the node
                 // assignment(s) acorss from the initial version to avoid the user
                 // being prompted for a location when publishing.
                 //
                 // It would appear that isn't done in the model for non published items.
                 if ($contentObject->attribute('published') == 0) {
                     $version = $contentObject->attribute('current');
                     $nodeAssignmentList = $version->attribute('node_assignments');
                     $contentObjectID = $contentObject->attribute('id');
                     $newVersionNumber = $newVersion->attribute('version');
                     foreach (array_keys($nodeAssignmentList) as $key) {
                         $nodeAssignment = $nodeAssignmentList[$key];
                         $clonedAssignment = $nodeAssignment->cloneNodeAssignment($newVersionNumber, $contentObjectID);
                         $clonedAssignment->store();
                     }
                 }
                 // 3. Set pending version to rejected.
                 $oldVersion = $approveStatus->attribute('object_version');
                 $oldVersion->setAttribute('status', eZContentObjectVersion::STATUS_REJECTED);
                 $oldVersion->sync();
                 // Abort collaboration item. Added by KK
                 $collaborationItem->setIsActive(false);
                 $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE);
                 $db->commit();
                 // 4. Redirect user to new object.
                 return $module->redirect('content', 'edit', array($contentObject->attribute('id'), $newVersion->attribute('version')));
             } else {
                 if ($this->isCustomAction('AddApprover')) {
                     #include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezxapprovestatus.php' );
                     $approveStatus = eZXApproveStatus::fetchByCollaborationItem($collaborationItem->attribute('id'));
                     if (!$approveStatus) {
                         eZDebug::writeError('Could not find eZXApproveStatus, ' . $collaborationItem->attribute('id'));
                         return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
                     }
                     return $module->redirect('ezapprove2', 'add_approver', array($approveStatus->attribute('id')));
                 }
             }
         }
     }
     if ($addComment) {
         $messageText = $this->customInput('ApproveComment');
         if (trim($messageText) != '') {
             $message = eZCollaborationSimpleMessage::create('ezapprove2_comment', $messageText);
             $message->store();
             eZCollaborationItemMessageLink::addMessage($collaborationItem, $message, eZApprove2CollaborationHandler::MESSAGE_TYPE_APPROVE2);
         }
     }
     $collaborationItem->setAttribute('modified', time());
     $collaborationItem->sync();
     return $module->redirectToView($redirectView, $redirectParameters);
 }