예제 #1
0
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//
/*! \file add_approver.php
*/
include_once 'kernel/common/template.php';
#include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezxapprovestatus.php' );
#include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezapprove2event.php' );
$Module = $Params['Module'];
$approveStatusID = $Params['ApproveStatusID'];
$approveStatus = eZXApproveStatus::fetch($approveStatusID);
if (!$approveStatus) {
    eZDebug::writeError('Approve status not found.');
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
if (!$approveStatus->isApprover(eZUser::currentUserID())) {
    eZDebug::writeError('User is not allowed to add new approvers.');
    return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
$approveEvent = $approveStatus->attribute('approve2_event');
if (!$approveEvent) {
    eZDebug::writeDebug('Could not find approve event.');
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
if (!$approveEvent->attribute('allow_add_approver')) {
    eZDebug::writeError('User is not allowed to add new approvers.');
 static function approveStatusMap()
 {
     return array('result' => eZXApproveStatus::statusNameMap());
 }
예제 #3
0
 function execute($process, $event)
 {
     eZDebugSetting::writeDebug('kernel-workflow-approve', $process, 'eZApprove2Type::execute');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $event, 'eZApprove2Type::execute');
     $parameters = $process->attribute('parameter_list');
     $versionID = $parameters['version'];
     $object = eZContentObject::fetch($parameters['object_id']);
     if (!$object) {
         eZDebugSetting::writeError('kernel-workflow-approve', $parameters['object_id'], 'eZApprove2Type::execute');
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     /*
       If we run event first time ( when we click publish in admin ) we do not have user_id set in workflow process,
       so we take current user and store it in workflow process, so next time when we run event from cronjob we fetch
       user_id from there.
     */
     if ($process->attribute('user_id') == 0) {
         $user = eZUser::currentUser();
         $process->setAttribute('user_id', $user->id());
     } else {
         $user = eZUser::instance($process->attribute('user_id'));
     }
     $eventData = eZApprove2Event::fetch($event->attribute('id'), $event->attribute('version'));
     $userGroups = array_merge((array) $user->attribute('groups'), (array) $user->attribute('contentobject_id'));
     $workflowSections = explode(',', $eventData->attribute('selected_sections'));
     $workflowGroups = explode(',', $eventData->attribute('selected_usergroups'));
     $editors = explode(',', $eventData->attribute('approve_users'));
     $approveGroups = explode(',', $eventData->attribute('approve_groups'));
     eZDebugSetting::writeDebug('kernel-workflow-approve', $user, 'eZApprove2Type::execute::user');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $userGroups, 'eZApprove2Type::execute::userGroups');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $editors, 'eZApprove2Type::execute::editor');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $workflowSections, 'eZApprove2Type::execute::workflowSections');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $workflowGroups, 'eZApprove2Type::execute::workflowGroups');
     eZDebugSetting::writeDebug('kernel-workflow-approve', $object->attribute('section_id'), 'eZApprove2Type::execute::section_id');
     $section = $object->attribute('section_id');
     $correctSection = false;
     if (!in_array($section, $workflowSections) && !in_array(-1, $workflowSections)) {
         $assignedNodes = $object->attribute('assigned_nodes');
         if ($assignedNodes) {
             foreach ($assignedNodes as $assignedNode) {
                 $parent = $assignedNode->attribute('parent');
                 $parentObject = $parent->object();
                 $section = $parentObject->attribute('section_id');
                 if (in_array($section, $workflowSections)) {
                     $correctSection = true;
                     break;
                 }
             }
         }
     } else {
         $correctSection = true;
     }
     switch ($eventData->attribute('approve_type')) {
         case eZApprove2Event::ApproveTypeUser:
             $inExcludeGroups = false;
             $userIsEditor = false;
             break;
         default:
         case eZApprove2Event::ApproveTypePredefined:
             $inExcludeGroups = count(array_intersect($userGroups, $workflowGroups)) != 0;
             $userIsEditor = in_array($user->id(), $editors) || count(array_intersect($userGroups, $approveGroups)) != 0;
             break;
     }
     if (!$inExcludeGroups && !$userIsEditor && $correctSection) {
         switch ($eventData->attribute('approve_type')) {
             case eZApprove2Event::ApproveTypeUser:
                 $contentObjectVersionID = $parameters['version'];
                 $contentObjectID = $parameters['object_id'];
                 $approveStatus = eZXApproveStatus::fetchByContentObjectID($contentObjectID, $contentObjectVersionID);
                 if (!$approveStatus || $approveStatus->attribute('approve_status') == eZXApproveStatus::StatusSelectApprover) {
                     if (!$approveStatus) {
                         $approveStatus = eZXApproveStatus::create($contentObjectID, $contentObjectVersionID, $process->attribute('id'), $process->attribute('event_position'));
                         $approveStatus->store();
                         $approveStatus->setCreator($user->attribute('contentobject_id'));
                     }
                     $approveStatus->setAttribute('active_version', $contentObjectVersionID);
                     $approveStatus->sync();
                     $process->Template = array();
                     $process->Template['templateName'] = 'design:workflow/eventtype/ezapprove2/select_approver.tpl';
                     $process->Template['templateVars'] = array('event' => $event, 'approval_status' => $approveStatus, 'object' => $object);
                     // Set object version to draft untill approvers are selected successfully in case user exists in the wrong way.
                     #include_once( 'kernel/classes/ezcontentobjectversion.php' );
                     $contentObjectVersion = eZContentObjectVersion::fetchVersion($contentObjectVersionID, $contentObjectID);
                     $contentObjectVersion->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
                     $contentObjectVersion->sync();
                     return eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT;
                 } else {
                     switch ($approveStatus->attribute('approve_status')) {
                         case eZXApproveStatus::StatusSelectApprover:
                             // Do nothing, continue processing in next cronjob run.
                             return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
                             break;
                         case eZXApproveStatus::StatusInApproval:
                             // Check if enough users have approves the workflow, or any has discarded it.
                             $discardCount = $approveStatus->discardedUserCount();
                             $collaborationItem = $approveStatus->attribute('collaboration_item');
                             #include_once( eZExtension::baseDirectory() . '/ezapprove2/collaboration/ezapprove2/ezapprove2collaborationhandler.php' );
                             if ($discardCount > 0) {
                                 $approveStatus->cancel();
                                 $approveINI = eZINI::instance('ezapprove2.ini');
                                 if ($approveINI->variable('ApproveSettings', 'NodeCreationOnDraft') == 'true') {
                                     $db = eZDB::instance();
                                     $db->query('UPDATE ezcontentobject_version
                                                  SET status = ' . eZContentObjectVersion::STATUS_REJECTED . '
                                                  WHERE contentobject_id = ' . $approveStatus->attribute('contentobject_id') . '
                                                  AND version = ' . $approveStatus->attribute('active_version'));
                                     $db->query('DELETE FROM ezcontentobject_tree where contentobject_id = ' . $approveStatus->attribute('contentobject_id') . ' AND contentobject_version = ' . $approveStatus->attribute('active_version'));
                                     $db->query('DELETE FROM ezurlalias
                                                  WHERE destination_url=\'content/versionview/' . $approveStatus->attribute('contentobject_id') . '/' . $approveStatus->attribute('active_version') . '\'');
                                 }
                                 return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
                             }
                             $numRequired = $approveStatus->attribute('num_approve_required');
                             $numApproved = $approveStatus->attribute('num_approved');
                             if ($numApproved >= $numRequired) {
                                 $collaborationItem->setAttribute('data_int3', eZApprove2CollaborationHandler::STATUS_ACCEPTED);
                                 $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE);
                                 $timestamp = time();
                                 $collaborationItem->setAttribute('modified', $timestamp);
                                 $collaborationItem->setIsActive(false);
                                 $collaborationItem->sync();
                                 $approveStatus->setAttribute('approve_status', eZXApproveStatus::StatusApproved);
                                 $approveStatus->store();
                                 $approveINI = eZINI::instance('ezapprove2.ini');
                                 if ($approveINI->variable('ApproveSettings', 'ObjectLockOnEdit') == 'true') {
                                     // Unlock related objects
                                     $object = $approveStatus->attribute('contentobject');
                                     // #HACK#
                                     if ($object->attribute('contentclass_id') == 17) {
                                         foreach ($object->relatedContentObjectList($approveStatus->attribute('active_version'), false, false) as $relatedObject) {
                                             $relatedObject->setAttribute('flags', $relatedObject->attribute('flags') ^ EZ_CONTENT_OBJECT_FLAG_LOCK_EDIT ^ EZ_CONTENT_OBJECT_FLAG_LOCK_REMOVE);
                                             $relatedObject->sync();
                                         }
                                     }
                                 }
                                 return eZWorkflowType::STATUS_ACCEPTED;
                             } else {
                                 // Still need more approvers.
                                 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
                             }
                             break;
                         case eZXApproveStatus::StatusDiscarded:
                             $approveINI = eZINI::instance('ezapprove2.ini');
                             if ($approveINI->variable('ApproveSettings', 'NodeCreationOnDraft') == 'true') {
                                 $db = eZDB::instance();
                                 $db->arrayQuery('DELETE FROM ezcontentobject_tree where contentobject_id = ' . $approveStatus->attribute('contentobject_id') . ' AND contentobject_version = ' . $approveStatus->attribute('active_version'));
                             }
                             return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
                             break;
                         case eZXApproveStatus::StatusApproved:
                         case eZXApproveStatus::StatusFinnished:
                             // Nothing special to do.
                             break;
                     }
                 }
                 break;
             case eZApprove2Event::ApproveTypePredefined:
                 $approveStatus = eZXApproveStatus::fetchByWorkflowProcessID($process->attribute('id'), $process->attribute('event_position'));
                 if (!$approveStatus) {
                     $contentObjectVersionID = $parameters['version'];
                     $contentObjectID = $parameters['object_id'];
                     $db = eZDB::instance();
                     $db->begin();
                     // CREATE APPROVE STATUS
                     $approveStatus = eZXApproveStatus::create($contentObjectID, $contentObjectVersionID, $process->attribute('id'), $process->attribute('event_position'));
                     $approveStatus->store();
                     $approveStatus->setCreator($user->attribute('contentobject_id'));
                     // ADD APPROVERS
                     foreach ($approveGroups as $userGroupID) {
                         $userGroupObject = eZContentObject::fetch($userGroupID);
                         if ($userGroupObject) {
                             $userGroupNode = $userGroupObject->attribute('main_node');
                             if ($userGroupNode) {
                                 foreach ($userGroupNode->subTree(array('Depth' => 1, 'DepthOperator' => 'eq', 'Limitation' => array())) as $userNode) {
                                     $approveStatus->addApproveUser($userNode->attribute('contentobject_id'));
                                 }
                             }
                         }
                     }
                     foreach ($editors as $userID) {
                         $approveStatus->addApproveUser($userID);
                     }
                     $approveStatus->setAttribute('approve_status', eZXApproveStatus::StatusInApproval);
                     $approveStatus->store();
                     $approveStatus->createCollaboration(false, $user->attribute('contentobject_id'));
                     $approveStatus->store();
                     $db->commit();
                 }
                 $discardCount = $approveStatus->discardedUserCount();
                 $collaborationItem = $approveStatus->attribute('collaboration_item');
                 #include_once( eZExtension::baseDirectory() . '/ezapprove2/collaboration/ezapprove2/ezapprove2collaborationhandler.php' );
                 if ($discardCount > 0) {
                     $approveStatus->cancel();
                     return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
                 }
                 $numApproved = $approveStatus->attribute('num_approved');
                 if ($numApproved >= 1) {
                     $collaborationItem->setAttribute('data_int3', eZApprove2CollaborationHandler::STATUS_ACCEPTED);
                     $collaborationItem->setAttribute('status', eZCollaborationItem::STATUS_INACTIVE);
                     $timestamp = time();
                     $collaborationItem->setAttribute('modified', $timestamp);
                     $collaborationItem->setIsActive(false);
                     $collaborationItem->sync();
                     $approveStatus->setAttribute('approve_status', eZXApproveStatus::StatusApproved);
                     $approveStatus->store();
                     return eZWorkflowType::STATUS_ACCEPTED;
                 } else {
                     // Still need more approvers.
                     return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
                 }
                 break;
         }
     } else {
         eZDebugSetting::writeDebug('kernel-workflow-approve', $workflowSections, "we are not going to create approval " . $object->attribute('section_id'));
         eZDebugSetting::writeDebug('kernel-workflow-approve', $userGroups, "we are not going to create approval");
         eZDebugSetting::writeDebug('kernel-workflow-approve', $workflowGroups, "we are not going to create approval");
         eZDebugSetting::writeDebug('kernel-workflow-approve', $user->id(), "we are not going to create approval ");
         return eZWorkflowType::STATUS_ACCEPTED;
     }
 }
 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);
 }
예제 #5
0
*/
include_once 'kernel/common/template.php';
#include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezxapprovestatus.php' );
#include_once( eZExtension::baseDirectory() . '/ezapprove2/classes/ezapprove2event.php' );
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
$userParameters = $Params['UserParameters'];
$statusFilter = isset($userParameters['statusFilter']) ? explode(',', $userParameters['statusFilter']) : array(-1);
$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();
예제 #6
0
 static function fetchByWorkflowProcessID($processID, $position, $asObject = true)
 {
     return eZPersistentObject::fetchObject(eZXApproveStatus::definition(), null, array('workflowprocess_id' => $processID, 'event_position' => $position), $asObject);
 }