예제 #1
0
파일: Ajax.php 프로젝트: projectesIF/Sirius
    /**
     * togglesubscriberareastatus
     * This function attaches/detaches a subscriber area to a provider area
     *
     * @param subscriberarea string area to be attached/detached
     * @param providerarea   string area to attach/detach
     * @return mixed Ajax response
     */
    public function togglesubscriberareastatus()
    {
        $this->checkAjaxToken();

        // get subscriberarea from POST
        $subscriberArea = $this->request->request->get('subscriberarea','');
        if (empty($subscriberArea)) {
            throw new Zikula_Exception_Fatal($this->__('No subscriber area passed.'));
        }

        // get subscriber module based on area and do some checks
        $subscriber = HookUtil::getOwnerByArea($subscriberArea);
        if (empty($subscriber)) {
            throw new Zikula_Exception_Fatal($this->__f('Module "%s" is not a valid subscriber.', $subscriber));
        }
        if (!ModUtil::available($subscriber)) {
            throw new Zikula_Exception_Fatal($this->__f('Subscriber module "%s" is not available.', $subscriber));
        }
        $this->throwForbiddenUnless(SecurityUtil::checkPermission($subscriber.'::', '::', ACCESS_ADMIN));

        // get providerarea from POST
        $providerArea = $this->request->request->get('providerarea','');
        if (empty($providerArea)) {
            throw new Zikula_Exception_Fatal($this->__('No provider area passed.'));
        }

        // get provider module based on area and do some checks
        $provider = HookUtil::getOwnerByArea($providerArea);
        if (empty($provider)) {
            throw new Zikula_Exception_Fatal($this->__f('Module "%s" is not a valid provider.', $provider));
        }
        if (!ModUtil::available($provider)) {
            throw new Zikula_Exception_Fatal($this->__f('Provider module "%s" is not available.', $provider));
        }
        $this->throwForbiddenUnless(SecurityUtil::checkPermission($provider.'::', '::', ACCESS_ADMIN));

        // get hookmanager
        $hookManager = $this->serviceManager->getService('zikula.hookmanager');

        // check if binding between areas exists
        $binding = HookUtil::getBindingBetweenAreas($subscriberArea, $providerArea);
        if (!$binding) {
            $hookManager->bindSubscriber($subscriberArea, $providerArea);
        } else {
            $hookManager->unbindSubscriber($subscriberArea, $providerArea);
        }

        // ajax response
        $response = array(
            'result' => true,
            'action' => $binding ? 'unbind' : 'bind',
            'subscriberarea' => $subscriberArea,
            'subscriberarea_id' => md5($subscriberArea),
            'providerarea' => $providerArea,
            'providerarea_id' => md5($providerArea),
            'isSubscriberSelfCapable' => (HookUtil::isSubscriberSelfCapable($subscriber) ? true : false)
        );

        return new Zikula_Response_Ajax($response);
    }