added RRD Stats Module
[PHP-P10.git] / Uplink / P10_Channel.class.php
index efe960de62b9f407f823241485cbcb766f099a49..bc8c152f690d086ca9dd36c634643296d14655d8 100644 (file)
@@ -46,10 +46,24 @@ class P10_Channel {
                return NULL;
        }
        
+       public static function getChannels() {
+               return self::$static_channels;
+       }
+       
+       public static function getChannelCount() {
+               return count(self::$static_channels);
+       }
+       
+       public static function recheckAllChannels() {
+               foreach(self::$static_channels as $channel) {
+                       $channel->checkChannel();
+               }
+       }       
        
        private $name;
        private $topic;
        private $modes;
+       private $create_time;
        private $users = array();
        const USERPRIV_OPED  = 0x0001;
        const USERPRIV_VOICE = 0x0002;
@@ -58,6 +72,7 @@ class P10_Channel {
        public function __construct($name) {
                $this->name = $name;
                $this->modes = new P10_ChannelModeSet($this);
+               $this->create_time = time();
                self::$static_channels[strtolower($name)] = $this;
        }
        
@@ -77,6 +92,14 @@ class P10_Channel {
                return $this->topic;
        }
        
+       public function setCreateTime($time) {
+               $this->create_time = $time;
+       }
+       
+       public function getCreateTime() {
+               return $this->create_time;
+       }
+       
        public function joinUser($user) {
                $this->users[$user->getNumeric()] = $user;
                $this->userPrivs[$user->getNumeric()] = 0;
@@ -89,11 +112,18 @@ class P10_Channel {
                $user->addChannel($this);
        }
        
+       private function checkChannel() {
+               if(count($this->users) == 0 && !$this->modes->hasMode('z')) {
+                       unset(self::$static_channels[strtolower($name)]); //drop empty channel
+               }
+       }
+       
        public function quitUser($user) {
                if(array_key_exists($user->getNumeric(), $this->users)) {
                        unset($this->users[$user->getNumeric()]);
                        unset($this->userPrivs[$user->getNumeric()]);
                        //$user->delChannel($this)  is not necessary because the user quits (the whole Object gets removed later)
+                       $this->checkChannel();
                } else {
                        trigger_error("Tried to quit a User from a Channel it is not joined.", E_USER_WARNING);
                }
@@ -104,6 +134,7 @@ class P10_Channel {
                        unset($this->users[$user->getNumeric()]);
                        unset($this->userPrivs[$user->getNumeric()]);
                        $user->delChannel($this);
+                       $this->checkChannel();
                } else {
                        trigger_error("Tried to part a User from a Channel it is not joined.", E_USER_WARNING);
                }
@@ -122,6 +153,10 @@ class P10_Channel {
                }
        }
        
+       public function getUsers() {
+               return $this->users;
+       }
+       
 }
 
 ?>
\ No newline at end of file