1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there a getThreads NOT IN thread.node_id

Discussion in 'XenForo Development Discussions' started by BamaStangGuy, Jan 27, 2015.

  1. BamaStangGuy

    BamaStangGuy Well-Known Member

    I am looking to exclude nodes from the getThreads method but this is the only Condition I see related to nodes. Is there not a way to do this using the getThreads method? I imagine I can work around it by getting a complete list of node ids and then removing the ones that I wish to include and then adding them to this... but that seems like overkill. Am I over looking something?

    PHP:
            if (!empty($conditions['node_id']))
            {
                if (
    is_array($conditions['node_id']))
                {
                    
    $sqlConditions[] = 'thread.node_id IN (' $db->quote($conditions['node_id']) . ')';
                }
                else
                {
                    
    $sqlConditions[] = 'thread.node_id = ' $db->quote($conditions['node_id']);
                }
            }
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    I think your workaround is a reasonable approach to be honest.

    It's also probably less effort than adding additional conditions which can sometimes be difficult to extend.

    It will probably cost an additional query to fetch all nose IDs first, but that shouldn't be a big problem.
     
    BamaStangGuy likes this.
  3. BamaStangGuy

    BamaStangGuy Well-Known Member

    Thanks Chris. Still navigating my way through XenForo code and wanted to make sure I wasn't overlooking something.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Great auto correct in my post there... nose IDs...
     
    The Forum Heroes and batpool52! like this.
  5. BamaStangGuy

    BamaStangGuy Well-Known Member

    Haha didn't even see that until you pointed it out.
     
  6. BamaStangGuy

    BamaStangGuy Well-Known Member

    Might not be the prettiest way but it works

    PHP:
                $nodeModel $this->_getNodeModel();
                
    $nodes $nodeModel->getAllNodes();
               
                
    $cleanNodeIds '';
                foreach (
    $nodes AS $node)
                {
                    
    $cleanNodeIds .= $node['node_id'] . ',';
                }
                
    $cleanNodeIds substr($cleanNodeIds, -1);
                
    $cleanNodeIds explode(','$cleanNodeIds);
                
    $cleanNodeIds array_diff($cleanNodeIds$excludeNodes);
     

Share This Page