This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/**
 * @package Workflow
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2012 concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
 
class Concrete5_Model_ChangePagePermissionsPageWorkflowRequest extends PageWorkflowRequest {
    
    protected $wrStatusNum = 30;

    public function __construct() {
        $pk = PermissionKey::getByHandle('edit_page_permissions');
        parent::__construct($pk);
    }
    
    public function setPagePermissionSet(PermissionSet $set) {
        $this->permissionSet = $set;
    }

    public function getPagePermissionSet() {
        return $this->permissionSet;
    }

    public function getWorkflowRequestDescriptionObject() {
        $d = new WorkflowDescription();
        $c = Page::getByID($this->cID, 'ACTIVE');
        $link = Loader::helper('navigation')->getLinkToCollection($c, true);
        $d->setEmailDescription(t("\"%s\" has pending permission changes. View the page here: %s.", $c->getCollectionName(), $link));
        $d->setInContextDescription(t("Page Submitted for Permission Changes."));
        $d->setDescription(t("<a href=\"%s\">%s</a> submitted for Permission Changes.", $link, $c->getCollectionName()));
        $d->setShortStatus(t("Permission Changes"));
        return $d;
    }
    
    public function getWorkflowRequestStyleClass() {
        return 'info';
    }
    
    public function getWorkflowRequestApproveButtonClass() {
        return 'success';
    }
    
    public function getWorkflowRequestApproveButtonInnerButtonRightHTML() {
        return '<i class="icon-white icon-thumbs-up"></i>';
    }       
    
    public function getWorkflowRequestApproveButtonText() {
        return t('Change Permissions');
    }
    
    public function getWorkflowRequestAdditionalActions(WorkflowProgress $wp) {
        $buttons = array();
        $w = $wp->getWorkflowObject();
        if ($w->canApproveWorkflowProgressObject($wp)) {
            $c = Page::getByID($this->cID, 'ACTIVE');
            $button = new WorkflowProgressAction();
            $button->setWorkflowProgressActionLabel(t('View Pending Permissions'));
            $button->addWorkflowProgressActionButtonParameter('dialog-title', t('Pending Permissions'));
            $button->addWorkflowProgressActionButtonParameter('dialog-width', '400');
            $button->addWorkflowProgressActionButtonParameter('dialog-height', '360');
            $button->setWorkflowProgressActionStyleInnerButtonLeftHTML('<i class="icon-eye-open"></i>');
            $button->setWorkflowProgressActionURL(REL_DIR_FILES_TOOLS_REQUIRED . '/workflow/dialogs/change_page_permissions?wpID=' . $wp->getWorkflowProgressID());
            $button->setWorkflowProgressActionStyleClass('dialog-launch');
            $buttons[] = $button;
        }
        return $buttons;
    }

    public function approve(WorkflowProgress $wp) {
        $c = Page::getByID($this->getRequestedPageID());
        $ps = $this->getPagePermissionSet();
        $assignments = $ps->getPermissionAssignments();     
        foreach($assignments as $pkID => $paID) {
            $pk = PermissionKey::getByID($pkID);
            $pk->setPermissionObject($c);
            $pt = $pk->getPermissionAssignmentObject();
            $pt->clearPermissionAssignment();
            if ($paID > 0) {
                $pa = PermissionAccess::getByID($paID, $pk);
                if (is_object($pa)) {
                    $pt->assignPermissionAccess($pa);
                }           
            }           
        }
        $c->refreshCache();
        $wpr = new WorkflowProgressResponse();
        $wpr->setWorkflowProgressResponseURL(BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $c->getCollectionID());
        return $wpr;
    }

    
}