static function fetchByUserID($userID, $approveID, $approveStatus, $hash = false, $asObject = true)
 {
     $cond = array('user_id' => $userID, 'approve_id' => $approveID);
     if ($approveStatus !== false) {
         $cond['approve_role'] = $approveStatus;
     }
     if ($hash !== false) {
         $cond['hash'] = $hash;
     }
     return eZPersistentObject::fetchObject(eZXApproveStatusUserLink::definition(), null, $cond, $asObject);
 }
 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);
 }
示例#4
0
$offset = isset($userParameters['offset']) ? $userParameters['offset'] : 0;
$limitKey = isset($userParameters['limit']) ? $userParameters['limit'] : '1';
$limitList = array('1' => 10, '2' => 25, '3' => 50);
$limit = $limitList[(string) $limitKey];
$viewParameters = array('offset' => $offset, 'limitkey' => $limitKey);
$userID = eZUser::currentUserID();
$approveStatusList = eZXApproveStatus::fetchListByUserID($userID, $offset, $limit);
$approveStatusCount = eZXApproveStatus::fetchCountByUserID($userID);
$allowedApproveStatusList = array(eZXApproveStatusUserLink::StatusApproved, eZXApproveStatusUserLink::StatusDiscarded);
if ($http->hasPostVariable('UpdateApproveStatusList')) {
    if (is_array($approveStatusList)) {
        foreach ($approveStatusList as $approveStatus) {
            if ($http->hasPostVariable('ApproveStatus_' . $approveStatus->attribute('id'))) {
                if (in_array($http->postVariable('ApproveStatus_' . $approveStatus->attribute('id')), $allowedApproveStatusList)) {
                    $userApproveStatus = $approveStatus->attribute('user_approve_status');
                    $userApproveStatus->setAttribute('approve_status', $http->postVariable('ApproveStatus_' . $approveStatus->attribute('id')));
                    $userApproveStatus->sync();
                }
            }
        }
    }
}
$tpl = templateInit();
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('approve_status_list', $approveStatusList);
$tpl->setVariable('approve_status_count', $approveStatusCount);
$tpl->setVariable('status_name_map', eZXApproveStatusUserLink::statusNameMap());
$tpl->setVariable('limit', $limit);
$Result = array();
$Result['content'] = $tpl->fetch("design:workflow/eventtype/ezapprove2/view_approve_list.tpl");
$Result['path'] = array(array('url' => false, 'text' => ezi18n('ezapprove2', 'Approve List')));
示例#5
0
 function removeUser($linkID, $hash = false)
 {
     $condArray = array('id' => $linkID);
     if ($hash !== false) {
         $condArray['hash'] = $hash;
     }
     eZPersistentObject::removeObject(eZXApproveStatusUserLink::definition(), $condArray);
 }