group
[ class tree: group ] [ index: group ] [ all elements ]

Source for file group.inc.php

Documentation is available at group.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2009-08-26 19:19:41 +0200 (Mi, 26 Aug 2009) $
  5.      * @package            group
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/group.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_group extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.         }
  23.         /**
  24.          * @desc            Returns information on a group.
  25.          * @param    int        $group Group ID. If $group is ommited, the last known group (of the last member) is used.
  26.          * @return    array    Group Information
  27.          * @author            Matthias Reuter
  28.          * @sample
  29.          *  <code>
  30.          *  $ipbwi->group->info(5);
  31.          *  </code>
  32.          * @since            2.0
  33.          */
  34.         public function info($group=false){
  35.             if(!$group){
  36.                 // No Group? Return current group info
  37.                 $group $this->ipbwi->member->myInfo['member_group_id'];
  38.             }
  39.             // Check for cache - if exists don't bother getting it again
  40.             if($cache $this->ipbwi->cache->get('groupInfo'$group)){
  41.                 return $cache;
  42.             }else{
  43.                 // Return group info if group given
  44.                 $this->ipbwi->ips_wrapper->DB->query('SELECT g.* FROM '.$this->ipbwi->board['sql_tbl_prefix'].'groups g WHERE g_id="'.intval($group).'"');
  45.                 if($this->ipbwi->ips_wrapper->DB->getTotalRows()){
  46.                     $info $this->ipbwi->ips_wrapper->DB->fetch();
  47.                     $this->ipbwi->cache->save('groupInfo'$group$info);
  48.                     return $info;
  49.                 }else{
  50.                     return false;
  51.                 }
  52.             }
  53.         }
  54.         /**
  55.          * @desc            Changes Member group to delivered group-id.
  56.          * @param    int        $group Group ID
  57.          * @param    int        $member Member ID. If no Member-ID is delivered, the currently logged in member will moved.
  58.          * @param    array    $extra secondary Group-IDs
  59.          * @return    bool    true on success, otherwise false
  60.          * @author            Matthias Reuter
  61.          * @sample
  62.          *  <code>
  63.          *  $ipbwi->group->change(5);
  64.          *  $ipbwi->group->change(7,12,array(1,2,3,4));
  65.          *  </code>
  66.          * @since            2.0
  67.          */
  68.         public function change($group,$member=false,$extra=false){
  69.             if(!$member){
  70.                 $member $this->ipbwi->member->myInfo['member_id'];
  71.             }
  72.             if($extra){
  73.                 $sql_extra ', SET mgroup_others="'.implode(',',$extra).'"';
  74.             }else{
  75.                 $sql_extra '';
  76.             }
  77.             
  78.             $SQL 'UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET member_group_id="'.$group.'"'.$sql_extra.' WHERE member_id="'.intval($member).'"';
  79.  
  80.             if($this->ipbwi->ips_wrapper->DB->query($SQL)){
  81.                 $this->ipbwi->member->myInfo['member_group_id'$group;
  82.                 return true;
  83.             }else{
  84.                 return false;
  85.             }
  86.         }
  87.         /**
  88.          * @desc            Returns whether a member is in the specified group(s).
  89.          * @param    int        $group Group ID or array of groups-ids separated with comma: 2,5,7
  90.          * @param    int        $member Member ID to find
  91.          * @param    bool    $extra Include secondary groups to test against?
  92.          * @return    mixed    Whether member is in group(s)
  93.          * @author            Matthias Reuter
  94.          * @sample
  95.          *  <code>
  96.          *  $ipbwi->group->isInGroup(5);
  97.          *  $ipbwi->group->isInGroup(7,12,true);
  98.          *  </code>
  99.          * @since            2.0
  100.          */
  101.         function isInGroup($group$member false$extra true{
  102.             if (!is_array($group)) $group explode(','$group);
  103.             settype($group'array');
  104.             if ($member{
  105.                 $this->ipbwi->ips_wrapper->DB->query('SELECT member_group_id,mgroup_others FROM '.$this->ipbwi->board['sql_tbl_prefix'].'members WHERE member_id="'.$member.'"');
  106.                 if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  107.                     if(in_array($row['member_group_id']$group)){
  108.                         return true;
  109.                     }
  110.                     if($extra){
  111.                         $others explode(',',$row['mgroup_others']);
  112.                         foreach($others as $other){
  113.                             if(in_array($other,$group)){
  114.                                 return true;
  115.                             }
  116.                         }
  117.                     }
  118.                 }
  119.                 return false;
  120.             }else{
  121.                 if(in_array($this->ipbwi->member->myInfo['member_group_id']$group)){
  122.                     return true;
  123.                 }else{
  124.                     // START CHANGE
  125.                     $other explode(',',$this->ipbwi->member->myInfo['mgroup_others']);
  126.                     if(is_array($other)) {
  127.                         foreach($other as $v{
  128.                             if(in_array($v$group)) {
  129.                                 return true;
  130.                             }
  131.                         }
  132.                     }
  133.                     // END CHANGE
  134.                     return false;
  135.                 }
  136.             }
  137.         }
  138.     }
  139. ?>

Documentation generated on Sat, 23 Oct 2010 23:35:51 +0200 by phpDocumentor 1.4.3