Welcome Guest, Not a member yet? Register   Sign In
Developing CI Based Forum - WIP
#11

[eluser]srpurdy[/eluser]
Here is the code example for the main display. So that what I explained above actually makes some sense. Wouldn't mind some feedback on this code. Smile

This is part of the frontend forum controller.

Code:
/*
This Function Extracts The Logged in Users Group ID Numbers into an array of valid user groups for that user.
*/
private function user_group()
  {
  $logged_in = $this->ion_auth->logged_in();
  $uid = 0;
  if($logged_in == true)
   {
   //Lets Get the current logged in users, user group. We will use this to compare with private permissions groups.
   $get_user_groups = $this->forum_model->user_group_logged_in($this->session->userdata['user_id']);
   $user_group_name = '';
   foreach($get_user_groups as $ug)
    {
    //We got a result
    $user_group_name[$uid] = $ug->group_id;
    $uid++;
    }
   }
  else
   {
   //if the user is not logged in. than we will just compare with a 0. (This should force permissions to false.)
   $user_group_name = '0';
   }
  return $user_group_name;
  }
  
/*
This function extracts forum user group access rights and constructs an array. This is where the magic happens. :)
*/
private function private_permissions()
  {
  $perm = 0;
  $logged_in = $this->ion_auth->logged_in();
  if($logged_in == true)
   {
   $user_group_name = $this->user_group();
  
   $private_permissions = $this->forum_model->get_all_permissions($user_group_name);
   if($private_permissions)
    {
    for($perm = 0; $perm <= count($private_permissions) -1; $perm++)
     {
     $private_group_name[$perm] = $private_permissions[$perm];
     }
    }
   else
    {
    $private_group_name[$perm] = '';
    }
   //test jig
   //print_r($data['private_group_name'][0]['forum_id']);
   //end test jig
   }
  else
   {
   $private_group_name[$perm] = '';
   }
  return $private_group_name;
  }
  
/*
This function extracts all sub forums within the database, and constructs an array we can use to display subforums.
*/
private function all_sub_forums()
  {
  $sub_forums = $this->forum_model->get_sub_forums_array();
  if($sub_forums)
   {
   for($sub = 0; $sub <= count($sub_forums) -1; $sub++)
    {
    $forum_sub_list[$sub] = $sub_forums[$sub];
    }
   }
  else
   {
   $forum_sub_list = '';
   }
  //test jig
  //print_r($forum_sub_list);
  //end test jig
  return $forum_sub_list;
  }
  
function index()
  {
  $private_group_name = $this->private_permissions();
  $data['forum_sub_list'] = $this->all_sub_forums();
  //Construct some view settings.
  $data['heading'] = 'Main Forum';
  $template_path = $this->config->item('template_page');
  $data['page'] = $template_path . '/forums/main_forum';
  $data['forum_categories'] = $this->forum_model->get_all_sections();
  
  //Create some ints we will need for arrays.
  $i = 0;
  $int_two = 0;
  $i_three = 0;
  $i_four = 0;
  $sub_per = 0;
  $sub = 0;
  
  //Start getting forums.
  foreach($data['forum_categories']->result() as $fc)
   {
   //Extract All Forums within each category
   $data['forum_list'][$i] = $this->forum_model->get_all_forums($fc->fcat_id);
   foreach($data['forum_list'][$i]->result() as $fl)
    {    
    //Lets get any subforms from each forum section.
    //$data['forum_sub_list'][$i_three] = $this->forum_model->get_sub_forums($fl->forum_id);
    if(!$data['forum_sub_list'])
     {
     $data['forum_sub_list'] = '';
     }
    else
     {
     //Check permissions on subforms.
     //foreach($data['forum_sub_list'][$i_three] as $fsl)
     for($sub = 0; $sub < count($data['forum_sub_list']); $sub++)
      {
      $sub_forum_id = $data['forum_sub_list'][$sub]['forum_id'];
      $logged_in = $this->ion_auth->logged_in();
      $data['group_sub_private_name'][$sub_per] = false;
      if($logged_in == true)
       {
       for($fperm = 0; $fperm <= count($private_group_name) -1; $fperm++)
        {
        if($sub_forum_id == @$private_group_name[$fperm]['forum_id'])
         {
         $current_private_group = $private_group_name[$fperm]['user_group_id'];
         $data['group_sub_private_name'][$sub_per] = true;
         }
        else
         {
         $data['group_sub_private_name'][$sub_per] = false;
         }
        if($data['group_sub_private_name'][$sub_per] == true)
         {
         break;
         }
        }
       }
      else
       {
       $data['group_sub_private_name'][$sub_per] = false;
       }
      $sub_per++;
      }
     }
    $forum_id = $fl->forum_id;
    $logged_in = $this->ion_auth->logged_in();
    $data['group_private_name'][$i_four] = false;
    if($logged_in == true)
     {
     for($fperm = 0; $fperm <= count($private_group_name) -1; $fperm++)
      {
      if($forum_id == @$private_group_name[$fperm]['forum_id'])
       {
       $current_private_group = $private_group_name[$fperm]['user_group_id'];
       $data['group_private_name'][$i_four] = true;
       }
      else
       {
       $data['group_private_name'][$i_four] = false;
       }
      if($data['group_private_name'][$i_four] == true)
       {
       break;
       }
      }
     }
    else
     {
     $data['group_private_name'][$i_four] = false;
     }
    $i_four++;
    }
   $i++;
   }
  
  //Okay we're ready to render our view.
  $this->load->vars($data);
  $this->load->view($this->_container_forum);
  }


Messages In This Thread
Developing CI Based Forum - WIP - by El Forum - 08-10-2012, 12:22 AM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 03:26 AM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 06:23 AM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 09:28 AM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 12:48 PM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 03:04 PM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 04:55 PM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 05:01 PM
Developing CI Based Forum - WIP - by El Forum - 08-11-2012, 05:21 PM
Developing CI Based Forum - WIP - by El Forum - 08-17-2012, 01:25 PM
Developing CI Based Forum - WIP - by El Forum - 08-17-2012, 05:23 PM
Developing CI Based Forum - WIP - by El Forum - 08-17-2012, 05:32 PM
Developing CI Based Forum - WIP - by El Forum - 08-17-2012, 05:41 PM
Developing CI Based Forum - WIP - by El Forum - 08-17-2012, 05:44 PM
Developing CI Based Forum - WIP - by El Forum - 08-18-2012, 07:39 AM
Developing CI Based Forum - WIP - by El Forum - 08-19-2012, 01:26 PM
Developing CI Based Forum - WIP - by El Forum - 12-29-2012, 06:03 AM
Developing CI Based Forum - WIP - by El Forum - 12-29-2012, 04:39 PM
Developing CI Based Forum - WIP - by El Forum - 12-30-2012, 07:11 AM
Developing CI Based Forum - WIP - by El Forum - 01-03-2013, 10:36 PM
Developing CI Based Forum - WIP - by El Forum - 01-04-2013, 05:05 AM
Developing CI Based Forum - WIP - by El Forum - 01-04-2013, 12:25 PM
Developing CI Based Forum - WIP - by El Forum - 01-07-2013, 01:20 AM
Developing CI Based Forum - WIP - by El Forum - 01-07-2013, 07:00 PM
Developing CI Based Forum - WIP - by El Forum - 01-14-2013, 06:03 AM
Developing CI Based Forum - WIP - by El Forum - 01-25-2013, 06:57 AM
Developing CI Based Forum - WIP - by El Forum - 01-28-2013, 04:29 PM
Developing CI Based Forum - WIP - by El Forum - 01-28-2013, 06:33 PM
Developing CI Based Forum - WIP - by El Forum - 01-29-2013, 06:22 PM
Developing CI Based Forum - WIP - by El Forum - 01-30-2013, 04:38 PM
Developing CI Based Forum - WIP - by El Forum - 02-04-2013, 06:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB