public function addCategoryToAllowedRoots($categoryId)
    {
        if (null === ($roots = $this->getUserAllowedRoots())) {
            return;
        }

        $categoryId = (int) $categoryId;
        $user = $this->getUser();

        /** @var StringUtil $stringUtil */
        $stringUtil = $this->framework->getAdapter(StringUtil::class);

        // Add the permissions on group level
        if ('custom' !== $user->inherit) {
            $groups = $this->db->fetchAll('SELECT id, newscategories, newscategories_roots FROM tl_user_group WHERE id IN('.\implode(',', \array_map('intval', $user->groups)).')');

            foreach ($groups as $group) {
                $permissions = $stringUtil->deserialize($group['newscategories'], true);

                if (\in_array('manage', $permissions, true)) {
                    $categoryIds = $stringUtil->deserialize($group['newscategories_roots'], true);
                    $categoryIds[] = $categoryId;

                    $this->db->update('tl_user_group', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $group['id']]);
                }
            }
        }

        // Add the permissions on user level
        if ('group' !== $user->inherit) {
            $userData = $this->db->fetchAssoc('SELECT newscategories, newscategories_roots FROM tl_user WHERE id=?', [$user->id]);
            $permissions = $stringUtil->deserialize($userData['newscategories'], true);

            if (\in_array('manage', $permissions, true)) {
                $categoryIds = $stringUtil->deserialize($userData['newscategories_roots'], true);
                $categoryIds[] = $categoryId;

                $this->db->update('tl_user', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $user->id]);
            }
        }

        // Add the new element to the user object
        $user->newscategories_roots = \array_merge($roots, [$categoryId]);
    }
public function addCategoryToAllowedRoots($categoryId)
    {
        if (null === ($roots = $this->getUserAllowedRoots())) {
            return;
        }

        $categoryId = (int) $categoryId;
        $user = $this->getUser();

        /** @var StringUtil $stringUtil */
        $stringUtil = $this->framework->getAdapter(StringUtil::class);

        // Add the permissions on group level
        if ('custom' !== $user->inherit) {
            $groups = $this->db->fetchAll('SELECT id, newscategories, newscategories_roots FROM tl_user_group WHERE id IN('.\implode(',', \array_map('intval', $user->groups)).')');

            foreach ($groups as $group) {
                $permissions = $stringUtil->deserialize($group['newscategories'], true);

                if (\in_array('manage', $permissions, true)) {
                    $categoryIds = $stringUtil->deserialize($group['newscategories_roots'], true);
                    $categoryIds[] = $categoryId;

                    $this->db->update('tl_user_group', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $group['id']]);
                }
            }
        }

        // Add the permissions on user level
        if ('group' !== $user->inherit) {
            $userData = $this->db->fetchAssoc('SELECT newscategories, newscategories_roots FROM tl_user WHERE id=?', [$user->id]);
            $permissions = $stringUtil->deserialize($userData['newscategories'], true);

            if (\in_array('manage', $permissions, true)) {
                $categoryIds = $stringUtil->deserialize($userData['newscategories_roots'], true);
                $categoryIds[] = $categoryId;

                $this->db->update('tl_user', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $user->id]);
            }
        }

        // Add the new element to the user object
        $user->newscategories_roots = \array_merge($roots, [$categoryId]);
    }
public function addCategoryToAllowedRoots ( $ categoryId ) { if ( null === ( $ roots = $ this -> getUserAllowedRoots ( ) ) ) { return ; } $ categoryId = ( int ) $ categoryId ; $ user = $ this -> getUser ( ) ; /** @var StringUtil $stringUtil */ $ stringUtil = $ this -> framework -> getAdapter ( StringUtil :: class ) ; // Add the permissions on group level if ( 'custom' !== $ user -> inherit ) { $ groups = $ this -> db -> fetchAll ( 'SELECT id, newscategories, newscategories_roots FROM tl_user_group WHERE id IN(' . \ implode ( ',' , \ array_map ( 'intval' , $ user -> groups ) ) . ')' ) ; foreach ( $ groups as $ group ) { $ permissions = $ stringUtil -> deserialize ( $ group [ 'newscategories' ] , true ) ; if ( \ in_array ( 'manage' , $ permissions , true ) ) { $ categoryIds = $ stringUtil -> deserialize ( $ group [ 'newscategories_roots' ] , true ) ; $ categoryIds [ ] = $ categoryId ; $ this -> db -> update ( 'tl_user_group' , [ 'newscategories_roots' => \ serialize ( $ categoryIds ) ] , [ 'id' => $ group [ 'id' ] ] ) ; } } } // Add the permissions on user level if ( 'group' !== $ user -> inherit ) { $ userData = $ this -> db -> fetchAssoc ( 'SELECT newscategories, newscategories_roots FROM tl_user WHERE id=?' , [ $ user -> id ] ) ; $ permissions = $ stringUtil -> deserialize ( $ userData [ 'newscategories' ] , true ) ; if ( \ in_array ( 'manage' , $ permissions , true ) ) { $ categoryIds = $ stringUtil -> deserialize ( $ userData [ 'newscategories_roots' ] , true ) ; $ categoryIds [ ] = $ categoryId ; $ this -> db -> update ( 'tl_user' , [ 'newscategories_roots' => \ serialize ( $ categoryIds ) ] , [ 'id' => $ user -> id ] ) ; } } // Add the new element to the user object $ user -> newscategories_roots = \ array_merge ( $ roots , [ $ categoryId ] ) ; }
Add the category to allowed roots.

@param int $categoryId
Add the category to allowed roots .