public static function createPermissions($permissions, $id)
    {
        $query = [];

        if($permissions) {
            // create other permissions
            foreach($permissions as $appName => $app){
                foreach ($app as $permissionType => $permission){
                    if($permissionType == 'defaultPermissionsValues') {
                        foreach ($permission as $key){
                            $query[] = array(
                                'groupID' => $id,
                                'app' => $appName,
                                'key' => $key,
                                'value' => true,
                                'ids' => null,
                                'hasAll' => false,
                            );
                        }
                    }else if ($permissionType == 'customPermissionsValues') {
                        foreach($permission as $key => $object){
                            if (is_array($object)) {

                                if(count($object)) {
                                    $IDs = array();
                                    $c = 0;
                                    foreach($object as $value){
                                        $class = "App\\Models\\".$appName;
                                        $model = new $class();
                                        $IDs['ID'.$c] = $value[$model->getKeyName()];
                                        $c++;
                                    }
                                    $query[] = array(
                                        'groupID' => $id,
                                        'app' => $appName,
                                        'key' => $key,
                                        'value' => true,
                                        'ids' => json_encode($IDs),
                                        'hasAll' => false,
                                    );
                                }
                            }else{
                                if ($object) {
                                    $query[] = array(
                                        'groupID' => $id,
                                        'app' => $appName,
                                        'key' => $key,
                                        'value' => true,
                                        'ids' => null,
                                        'hasAll' => false,
                                    );
                                }
                            }
                        }
                    }else if ($permissionType == 'categoriesValues') {
                        if ($app['hasAll']) {
                            $query[] = array(
                                'groupID' => $id,
                                'app' => $appName,
                                'key' => 'categories',
                                'value' => true,
                                'ids' => null,
                                'hasAll' => true,
                            );
                        }else{
                            $IDs = array();
                            $c=0;
                            foreach ($permission as $category){
                                $IDs['ID'.$c] = $category['categoryID'];
                                $c++;
                            }
                            if (count($IDs)) {
                                $query[] = array(
                                    'groupID' => $id,
                                    'app' => $appName,
                                    'key' => 'categories',
                                    'value' => true,
                                    'ids' => json_encode($IDs),
                                    'hasAll' => false,
                                );
                            }
                        }
                    }
                }
            }
        }

        return $query;
    }
public static function createPermissions($permissions, $id)
    {
        $query = [];

        if($permissions) {
            // create other permissions
            foreach($permissions as $appName => $app){
                foreach ($app as $permissionType => $permission){
                    if($permissionType == 'defaultPermissionsValues') {
                        foreach ($permission as $key){
                            $query[] = array(
                                'groupID' => $id,
                                'app' => $appName,
                                'key' => $key,
                                'value' => true,
                                'ids' => null,
                                'hasAll' => false,
                            );
                        }
                    }else if ($permissionType == 'customPermissionsValues') {
                        foreach($permission as $key => $object){
                            if (is_array($object)) {

                                if(count($object)) {
                                    $IDs = array();
                                    $c = 0;
                                    foreach($object as $value){
                                        $class = "App\\Models\\".$appName;
                                        $model = new $class();
                                        $IDs['ID'.$c] = $value[$model->getKeyName()];
                                        $c++;
                                    }
                                    $query[] = array(
                                        'groupID' => $id,
                                        'app' => $appName,
                                        'key' => $key,
                                        'value' => true,
                                        'ids' => json_encode($IDs),
                                        'hasAll' => false,
                                    );
                                }
                            }else{
                                if ($object) {
                                    $query[] = array(
                                        'groupID' => $id,
                                        'app' => $appName,
                                        'key' => $key,
                                        'value' => true,
                                        'ids' => null,
                                        'hasAll' => false,
                                    );
                                }
                            }
                        }
                    }else if ($permissionType == 'categoriesValues') {
                        if ($app['hasAll']) {
                            $query[] = array(
                                'groupID' => $id,
                                'app' => $appName,
                                'key' => 'categories',
                                'value' => true,
                                'ids' => null,
                                'hasAll' => true,
                            );
                        }else{
                            $IDs = array();
                            $c=0;
                            foreach ($permission as $category){
                                $IDs['ID'.$c] = $category['categoryID'];
                                $c++;
                            }
                            if (count($IDs)) {
                                $query[] = array(
                                    'groupID' => $id,
                                    'app' => $appName,
                                    'key' => 'categories',
                                    'value' => true,
                                    'ids' => json_encode($IDs),
                                    'hasAll' => false,
                                );
                            }
                        }
                    }
                }
            }
        }

        return $query;
    }
public static function createPermissions ( $ permissions , $ id ) { $ query = [ ] ; if ( $ permissions ) { // create other permissions foreach ( $ permissions as $ appName => $ app ) { foreach ( $ app as $ permissionType => $ permission ) { if ( $ permissionType == 'defaultPermissionsValues' ) { foreach ( $ permission as $ key ) { $ query [ ] = array ( 'groupID' => $ id , 'app' => $ appName , 'key' => $ key , 'value' => true , 'ids' => null , 'hasAll' => false , ) ; } } else if ( $ permissionType == 'customPermissionsValues' ) { foreach ( $ permission as $ key => $ object ) { if ( is_array ( $ object ) ) { if ( count ( $ object ) ) { $ IDs = array ( ) ; $ c = 0 ; foreach ( $ object as $ value ) { $ class = "App\\Models\\" . $ appName ; $ model = new $ class ( ) ; $ IDs [ 'ID' . $ c ] = $ value [ $ model -> getKeyName ( ) ] ; $ c ++ ; } $ query [ ] = array ( 'groupID' => $ id , 'app' => $ appName , 'key' => $ key , 'value' => true , 'ids' => json_encode ( $ IDs ) , 'hasAll' => false , ) ; } } else { if ( $ object ) { $ query [ ] = array ( 'groupID' => $ id , 'app' => $ appName , 'key' => $ key , 'value' => true , 'ids' => null , 'hasAll' => false , ) ; } } } } else if ( $ permissionType == 'categoriesValues' ) { if ( $ app [ 'hasAll' ] ) { $ query [ ] = array ( 'groupID' => $ id , 'app' => $ appName , 'key' => 'categories' , 'value' => true , 'ids' => null , 'hasAll' => true , ) ; } else { $ IDs = array ( ) ; $ c = 0 ; foreach ( $ permission as $ category ) { $ IDs [ 'ID' . $ c ] = $ category [ 'categoryID' ] ; $ c ++ ; } if ( count ( $ IDs ) ) { $ query [ ] = array ( 'groupID' => $ id , 'app' => $ appName , 'key' => 'categories' , 'value' => true , 'ids' => json_encode ( $ IDs ) , 'hasAll' => false , ) ; } } } } } } return $ query ; }
Prepare custom and default permission array to be stored on database.
Gets input from the front-end and customizes object to be stored as JSON in DB.

@param  array $permissions
@param  int   $id
@return array
Prepare custom and default permission array to be stored on database . Gets input from the front - end and customizes object to be stored as JSON in DB .