Snippet to create sub-directories in URI but not sub-resource

So I inherited a website that uses a bunch of PHP with zero comments explaining things. I am stuck on a function that is supposed to create links that modify the URI to look like a sub-directory rather than creating a physical resource underneath.

Here’s the function:

function getTabParams($link, $name){
    global $modx;
    $params = array();
    $typeValue = !empty($_GET['type']) ? strip_tags($_GET['type']) : '';
    
    if(checkTabAvailability($link)){
        $params = array(
            'class' => ($typeValue == $link) ? 'active' : '',
            'name'  => $name,
            'link'  => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri')
        );
    }    
    return $params;
}

The line in question is this:

'link'  => !empty($link) ? $modx->resource->get('uri').($modx->resource->get('isfolder') == 1 ? '' : '/').$link : $modx->resource->get('uri')

Also, checkTabAvailability is a big block of code but here’s just one case for reference:

function checkTabAvailability($type){
    global $modx;
    switch($type){
        case 'people':
            $c = $modx->newQuery('modResource');
            $c->leftJoin('modTemplateVarResource','TV1','TV1.contentid=modResource.id'); 
            $c->where(array('template:IN' => [16,39,40], 'published' => 1, 'TV1.tmplvarid' => 81, 'TV1.value:LIKE' => '%'.$modx->resource->get('link_attributes').'%'));
            $c->select(array('modResource.id as id'));
            if(!$modx->getCount('modResource', $c)){
                return false;
            }
            return true;
            break;
        default: // all
            return true;
    }
}

For some reason only a handful of templates will successfully link to these “pages”. But if I’m building my own template or if I duplicate the template, it will not link properly. Just ends with a 404 page.

Anybody have any thoughts? Thanks

Might be well off but could it be this line that seems to list template id’s ?


$c->where(array('template:IN' => [16,39,40], 'published' => 1, 'TV1.tmplvarid' => 81, 'TV1.value:LIKE' => '%'.$modx->resource->get('link_attributes').'%'));

Unfortunately, these aren’t the templates that work with it. They are just the ids for the bio types for employees. This line just gathers all resources using those template ids, that have a string within TV 81 that matches the link_attributes field for the resource I’m currently viewing.

Here’s a different case for comparison:

    case 'experience':
        $_tv = $modx->newQuery('modTemplateVarResource');
        $_tv->where(array('modTemplateVarResource.contentid' => $modx->resource->get('id'),'modTemplateVarResource.tmplvarid' => 118)); // ServiceExperience
        $_tv->select(array('modTemplateVarResource.value as value'));
        $_tv->prepare();
        ///echo $_tv->toSQL();
        $_tv->stmt->execute();
        $_tv_res = $_tv->stmt->fetch(PDO::FETCH_ASSOC);
        if(empty($_tv_res) || empty($_tv_res['value'])){
            return false;
        }
        return true;
        break;

What is the $type value when the trouble occurs?