function haveSetStatus($collabItemID, $approveStatusID, $userID)
 {
     $result = false;
     if ($collabItemID !== false) {
         $approveUserLink = eZXApproveStatusUserLink::fetchByCollaborationID($userID, $collabItemID, false);
     }
     if ($approveStatusID !== false) {
         $approveUserLink = eZXApproveStatusUserLink::fetchByUserID($userID, $approveStatusID, false);
     }
     if ($approveUserLink) {
         if ($approveUserLink->attribute('approve_status') != eZXApproveStatusUserLink::StatusNone) {
             $result = true;
         }
     }
     return array('result' => $result);
 }
 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);
 }
Example #3
0
 function addApproveUser($userID, $hash = false)
 {
     if ($this->isCreator($userID) || !$userID) {
         return false;
     }
     $hashCond = false;
     if ($hash !== false) {
         $hashCond = array(array($hash, ''));
     }
     $approveUserLink = eZXApproveStatusUserLink::fetchByUserID($userID, $this->attribute('id'), eZXApproveStatusUserLink::RoleApprover, $hashCond);
     if (!$approveUserLink) {
         $approveUserLink = eZXApproveStatusUserLink::create($userID, $this->attribute('id'), eZXApproveStatusUserLink::RoleApprover, $hash);
         $approveUserLink->store();
     }
 }