Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
Prev Previous Post   Next Post Next
  #2  
Old 10-10-2013, 04:00 PM
ericbdev ericbdev is offline
 
Join Date: Jul 2013
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, i have a working solution:

Bare in mind, while I am not too much of a PHP novice, I am still learning OOP. I have also only been using vBulletin for about 3 weeks.

PHP Code:
public function getVisibileRelation($userID){
        
$userInfo $this->vb_auth->is_logged_in_as($userID);
// returns primary user group, and other member groups
        
if($userInfo['membergroupids'] != ''):
            
$memberGroupsStr $userInfo['usergroupid'].','.$userInfo['membergroupids'];
        else:
            
$memberGroupsStr $userInfo['usergroupid'];
        endif;

        
$allAttach = array();
        
$visNodeArrToStr = array();
        
$visNodeArr = array();

//Based on membergroups + usergroups, find category channels, where user has visible / editable permissions -- I will obviously need to revisit my forumpermissions column once I solidify my Channel / Category structure.

        
$visibleNodes $this->db->query("select permissionid, forumpermissions, TABLEPREFIX_permission.nodeid, TABLEPREFIX_node.title, TABLEPREFIX_channel.category from TABLEPREFIX_permission
            left join TABLEPREFIX_channel on (TABLEPREFIX_permission.nodeid = TABLEPREFIX_channel.nodeid)
            left join TABLEPREFIX_node on (TABLEPREFIX_node.nodeid = TABLEPREFIX_channel.nodeid)
            where (TABLEPREFIX_permission.groupid in (
$memberGroupsStr)) and (TABLEPREFIX_node.title is not null)  and (TABLEPREFIX_channel.category = 0) and (
            TABLEPREFIX_permission.forumpermissions = 569347 or
            TABLEPREFIX_permission.forumpermissions like '5%'
            )"
)->result_array();
            
//)
        
$visibleNodesQuery $this->db->last_query();

        
$allAttachments $this->db->query("select TABLEPREFIX_node.nodeid, TABLEPREFIX_node.userid, TABLEPREFIX_filedata.filedataid
            from TABLEPREFIX_node inner join TABLEPREFIX_attach on (TABLEPREFIX_node.nodeid = TABLEPREFIX_attach.nodeid )
            left join TABLEPREFIX_filedata on (TABLEPREFIX_attach.filedataid = TABLEPREFIX_filedata.filedataid)"
)->result_array();

        foreach (
$allAttachments as $row):
            
$allAttach[] = $row['nodeid'];
        endforeach;
        
$allAttachStr implode(',',$allAttach);

        foreach (
$visibleNodes as $row):
            
$visNodeArrToStr[] = $row['nodeid'];
            
$visNodeArr[] = array(
                
'nodeid' => $row['nodeid'],
                
'title' => $row['title']
            );
        endforeach;
        
$visNodeStr implode(',',$visNodeArrToStr);

//TABLEPREFIX_attach_keyword is a self made table where I assign keywords to uploaded documents
        
$visibleAttachments $this->db->query ("
        select  t1.nodeid as t1nodeid,      t2.nodeid as t2nodeid,      t3.nodeid as channelid,
        t4.nodeid as categoryid,      t5.nodeid AS postnodeid,      t6.nodeid AS attachNodeId,
        t5.userid,                  TABLEPREFIX_filedata.filedataid,    visible,
        username,                   counter,                    filename,
        dateline,                   keywords

        from TABLEPREFIX_node AS t1
        left join TABLEPREFIX_node AS t2 ON t2.parentid = t1.nodeid
        left join TABLEPREFIX_node AS t3 ON t3.parentid = t2.nodeid
        left join TABLEPREFIX_node AS t4 ON t4.parentid = t3.nodeid
        left join TABLEPREFIX_node AS t5 ON t5.parentid = t4.nodeid
        left join TABLEPREFIX_node AS t6 ON t6.parentid = t5.nodeid

            left join TABLEPREFIX_attach on (t6.nodeid = TABLEPREFIX_attach.nodeid )
            left join TABLEPREFIX_filedata on (TABLEPREFIX_attach.filedataid = TABLEPREFIX_filedata.filedataid)
            left join TABLEPREFIX_user on (TABLEPREFIX_user.userid = t6.userid )
            left join TABLEPREFIX_attach_keyword on (TABLEPREFIX_attach.filedataid = TABLEPREFIX_attach_keyword.filedataid)

            where (
                t1.nodeid in (
{$visNodeStr})  or
                t2.nodeid in (
{$visNodeStr}) or
                t3.nodeid in (
{$visNodeStr}) or
                t4.nodeid in (
{$visNodeStr}) or
                t5.nodeid in (
{$visNodeStr})
                )
            and
            t6.nodeid in (
{$allAttachStr})")->result_array();
        
$attachQuery $this->db->last_query();

        foreach(
$visibleAttachments as $row) {
            
$attachment[] = array(
                
'nodeid' => $row['attachNodeId'],
                
'userid' => $row['userid'],
                
'username' => $row['username'],
                
'filedataid'  => $row['filedataid'],
                
'visible'  => $row['visible'],
                
'counter'  => $row['counter'],
                
'dateline'  => date('l, F jS'$row['dateline']),
                
'filename'  => $row['filename'],
                
'keywords'  => $row['keywords']
            );
        }
        return 
$attachment;
    } 
It is definitly not stable, nor is it clean. I have thrown in some documentation, because this will not work out of the box for most people. I have a custom table I am referencing (_attach_keyword). Also, I am using the Code Igniter framework to assist with Queries (as well as other MVC aspects). This is the model I use to fetch visible files.

If anyone else is facing a similar situation, feel free to try and figure out my code. If you take out the join for _attach_keywords, it should work rather easily.
Reply With Quote
Благодарность от:
tbworld
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:10 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04268 seconds
  • Memory Usage 2,391KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (1)post_thanks_box_bit
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete