Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 88
ExcludedMenuService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 6
702.00
0.00% covered (danger)
0.00%
0 / 88
 __construct
n/a
0 / 0
1
n/a
0 / 0
 __clone
n/a
0 / 0
1
n/a
0 / 0
 getInstance
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 5
 getExcludedMenu
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 11
 permissionToggleExcludedMenu
0.00% covered (danger)
0.00%
0 / 1
72.00
0.00% covered (danger)
0.00%
0 / 21
 settingsExcludedMenu
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 21
 inarrayExcludedMenu
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 15
 menuCanShow
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 15
<?php
    namespace com\linways\core\ams\professional\service;
    use com\linways\core\ams\professional\service\BaseService;
    use com\linways\core\ams\professional\constant\ExcludingMenuArray;
    use com\linways\core\ams\professional\toggles\PermissionToggle;
    use com\linways\core\ams\professional\dto\SettingsConstents;
    use com\linways\core\ams\professional\service\CommonService;
    use com\linways\core\ams\professional\service\MenuService;
    use ReflectionClass;
    class ExcludedMenuService extends BaseService {
        // /Condition 1 - Presence of a static member variable
        private static $_instance = null;
        
        // /Condition 2 - Locked down the constructor
        private function __construct() {}
        // Prevent any oustide instantiation of this class
        
        // /Condition 3 - Prevent any object or instance of that class to be cloned
        private function __clone() {}
        // Prevent any copy of this object
        
        // /Condition 4 - Have a single globally accessible static method
        public static function getInstance() {
            if (! is_object(self::$_instance)) {
                // or if( is_null(self::$_instance) ) or if( self::$_instance == null )
                self::$_instance = new self();
            }
            return self::$_instance;
        } 
        /**
         * @param String $type  - "ADMIN", "STAFF" etc
         * @return Array $excludedMenuArray
         * @author Vishnu M
         */
        public function getExcludedMenu ( $type ) {
            $type = $this->realEscapeString($type);
            $excludedMenuArray = [];
            $settingsExcludedMenu = [];
            $toggleExcludedMenu = [];
            $toggleExcludedMenu     = $this->permissionToggleExcludedMenu ( $type );
            $settingsExcludedMenu   = $this->settingsExcludedMenu ( $type );
            $inarrayExcludedMenu    = $this->inarrayExcludedMenu ( $type );
            $canShowExcludedMenu    = $this->menuCanShow ( $type );
            $excludedMenuArray = array_merge ( $toggleExcludedMenu, $settingsExcludedMenu, $inarrayExcludedMenu, $canShowExcludedMenu );
            
            return $excludedMenuArray;
        }
        /**
         * @param String $type  - "ADMIN", "STAFF" etc
         * @return Array $excludedMenuArray
         * @author Vishnu M
         */
        public function permissionToggleExcludedMenu ( $type ) {
            $type = $this->realEscapeString($type);
            $excludedMenuArray = [];
            if ( $type == "ADMIN" ) {
                $toggleExcludedMenu = ExcludingMenuArray::ADMIN_PERMISSION_TOGGLE_ENABLED;
                foreach ($toggleExcludedMenu as $key => $arr) {
                    if ( !PermissionToggle::isEnabled ( $key ) ) {
                        $excludedMenuArray = array_merge ( $excludedMenuArray, $arr );
                    }
                    if($key == "COURSE" || $key == "OPEN_COURSE"){
                        $excludedMenuArray = array_merge ( $excludedMenuArray, $arr );
                    }
                }
                $toggleExcludedMenu = ExcludingMenuArray::ADMIN_PERMISSION_TOGGLE_DISABLED;
                foreach ($toggleExcludedMenu as $key => $arr) {
                    if ( PermissionToggle::isEnabled ( $key ) ) {
                        $excludedMenuArray = array_merge ( $excludedMenuArray, $arr );
                    }
                }
            }
            return $excludedMenuArray;
        }
        /**
         * @param String $type  - "ADMIN", "STAFF" etc
         * @return Array $excludedMenuArray
         * @author Vishnu M
         */
        public function settingsExcludedMenu ( $type ) {
            $type = $this->realEscapeString($type);
            $reflectionClass = new ReflectionClass("com\linways\core\ams\professional\dto\SettingsConstents");
            $excludedMenuArray = [];
            $status = null;
            if ( $type == "ADMIN" ) {
                $settingsExcludedMenuArray = ExcludingMenuArray::ADMIN_SETTINGS;
                foreach ($settingsExcludedMenuArray as $key => $arr) {
                    list ( $settingsType, $settingsName ) = explode ( ":", $key );
                    $status = CommonService::getInstance()->getSettings ( $settingsType, $settingsName );
                    // To verify null ie; Settings is available in the 'SettingsConstents' class
                    if ( $status === null ) {
                        $settingsType = $reflectionClass->getConstant($settingsType);
                        $settingsName = $reflectionClass->getConstant($settingsName);
                        $status = CommonService::getInstance()->getSettings ( $settingsType, $settingsName );
                    }
                    if ( $status == 0 ) {
                        $excludedMenuArray = array_merge ( $excludedMenuArray, $arr );
                    }
                }
            }
            return $excludedMenuArray;
        }
        /**
         * @param String $type  - "ADMIN", "STAFF" etc
         * @return Array $excludedMenuArray
         * @author Vishnu M
         */
        public function inarrayExcludedMenu ( $type ) {
            $type = $this->realEscapeString($type);
            global $COLLEGE_CODE;
            global $messEnabled;
            global $NBAaccreditation;
            $excludedMenuArray = [];
            if ( $type == "ADMIN" ) {
                if ( !in_array ( $COLLEGE_CODE, $messEnabled ) ) {
                    $excludedMenuArray = array_merge ( $excludedMenuArray, ExcludingMenuArray::ADMIN_MESS_ENABLED );
                }
                if ( !in_array ( $COLLEGE_CODE, $NBAaccreditation ) ) {
                    $excludedMenuArray = array_merge ( $excludedMenuArray, ExcludingMenuArray::ADMIN_NBA_ACCREDITATION );
                }
            }
            return $excludedMenuArray;
        }
        /**
         * @param String $type  - "ADMIN", "STAFF" etc
         * @return Array $excludedMenuArray
         * @author Vishnu M
         */
        public function menuCanShow ( $type ) {
            $type = $this->realEscapeString($type);
            $menuService = Menuservice::getInstance();
            $excludedMenuArray = [];
            if ( $type == "ADMIN" ) {
                $reflectionClass = new ReflectionClass("com\linways\core\ams\professional\constant\AdminMenu");
                $canShowMenuArray = ExcludingMenuArray::ADMIN_MENU_CAN_SHOW;
                foreach ($canShowMenuArray as $key => $menuArray) {
                    $menuConstant = $reflectionClass->getConstant ( $key );
                    if ( !$menuService->canShow ( $menuConstant ) ) {
                        $excludedMenuArray = array_merge ( $excludedMenuArray, $menuArray );
                    }
                }
            }
            return $excludedMenuArray;
        }
    }
?>