Code Duplication    Length = 47-48 lines in 2 locations

module/Admin/src/Admin/Controller/AclController.php 2 locations

@@ 637-684 (lines=48) @@
634
     * delete role item
635
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
636
     */
637
    public function deleteroleAction()
638
    {
639
        $tmplVars = $this->getTemplateVars( 
640
            array(
641
            'acldata' => $this->getAclTable()->fetchAll(),
642
            'roles' => $this->getAclroleTable()->fetchAll(),
643
            'resources' => $this->getAclresourceTable()->fetchAll(),
644
            'showForm' => true,
645
            )
646
        );
647
        $id = (int) $this->params()->fromRoute('acl_id', 0);
648
        if (!$id) {
649
            $this->flashMessenger()->addWarningMessage($this->translate("missing parameters"));
650
            return $this->redirect()->toRoute('admin/acledit', array('action' => 'roles'));
651
        }
652
653
        $tmplVars["acl_id"] = $id;
654
        try {
655
            $Aclrole = $this->getAclroleTable()->getAclrole($id);
656
        } catch (\Exception $e) {
657
            $this->flashMessenger()->addWarningMessage($this->translate("invalid parameters"));
658
            return $this->redirect()->toRoute('admin/acledit', array('action' => 'roles'));
659
        }
660
        $tmplVars["aclrole"] = $Aclrole;
661
        $request = $this->getRequest();
662
        if ($request->isPost()) {
663
            $del = $request->getPost('del', '');
664
665
            if (!empty($del)) {
666
                $id = (int) $request->getPost('id');
667
                $this->getAclroleTable()->deleteAclrole($id);
668
                $this->flashMessenger()->addSuccessMessage($this->translate("role has been deleted"));
669
            
670
                $this->reinitACLCache();
671
            }
672
673
            // Redirect to list of albums
674
            if ( $this->isXHR() ) {
675
                $tmplVars["showForm"] = false;
676
            } else {
677
                return $this->redirect()->toRoute('admin/acledit', array('action' => 'roles'));
678
            }
679
            
680
        }
681
682
        $tmplVars["roles"] = $this->getAclroleTable()->fetchAll();
683
        return new ViewModel($tmplVars);
684
    }
685
686
    /**
687
     * add resource item
@@ 790-836 (lines=47) @@
787
     * delete resource item
788
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
789
     */
790
    public function deleteresourceAction()
791
    {
792
        $tmplVars = $this->getTemplateVars( 
793
            array(
794
            'acldata' => $this->getAclTable()->fetchAll(),
795
            'roles' => $this->getAclroleTable()->fetchAll(),
796
            'resources' => $this->getAclresourceTable()->fetchAll(),
797
            'showForm' => true,
798
            )
799
        );
800
        $id = (int) $this->params()->fromRoute('acl_id', 0);
801
        if (!$id) {
802
            $this->flashMessenger()->addWarningMessage($this->translate("missing parameters"));
803
            return $this->redirect()->toRoute('admin/acledit', array('action' => 'resources'));
804
        }
805
806
        $tmplVars["acl_id"] = $id;
807
        try {
808
            $Aclresource = $this->getAclresourceTable()->getAclresource($id);
809
        } catch (\Exception $e) {
810
            $this->flashMessenger()->addWarningMessage($this->translate("invalid parameters"));
811
            return $this->redirect()->toRoute('admin/acledit', array('action' => 'resources'));
812
        }
813
        $tmplVars["aclresource"] = $Aclresource;
814
        $request = $this->getRequest();
815
        if ($request->isPost()) {
816
            $del = $request->getPost('del', '');
817
818
            if (!empty($del)) {
819
                $id = (int) $request->getPost('id');
820
                $this->getAclresourceTable()->deleteAclresource($id);
821
                $this->flashMessenger()->addSuccessMessage($this->translate("resource has been deleted"));
822
823
                $this->reinitACLCache();
824
            }
825
            
826
            // Redirect to list of albums
827
            if ( $this->isXHR() ) {
828
                $tmplVars["showForm"] = false;
829
            } else {
830
                return $this->redirect()->toRoute('admin/acledit', array('action' => 'resources'));
831
            }
832
        }
833
834
        $tmplVars["resources"] = $this->getAclresourceTable()->fetchAll();
835
        return new ViewModel($tmplVars);
836
    }
837
    
838
    /**
839
     * re-initialize, respectively clear ACL cache entries