$file_type / 1024 / 1024); } public function total_usage() { // Return the user's total usage in bytes. return ($this->fullsize + $this->resize + $this->thumb); } public function total_usage_mb() { // Return the user's total usage in megabytes. return (($this->total_usage()) / 1024 / 1024); } public function current_usage() { // Return the users relevant usage in bytes based on the use_all_sizes setting. if (module::get_var("quotas", "use_all_sizes") == true) { return $this->total_usage(); } else { return $this->fullsize; } } public function current_usage_mb() { // Return the users relevant usage in megabytes based on the use_all_sizes setting. return ($this->current_usage() / 1024 / 1024); } public function get_usage_limit() { // Returns a user's maximum limit in bytes. $user_groups = ORM::factory("group") ->join("groups_users", "groups_users.group_id", "groups.id") ->join("groups_quotas", "groups_quotas.group_id", "groups.id") ->select("groups.id") ->select("groups_quotas.storage_limit") ->where("groups_users.user_id", "=", $this->owner_id) ->order_by("groups_quotas.storage_limit", "DESC") ->find_all(1); if (!empty($user_groups)) { if ($user_groups[0]->storage_limit <= "0") { return 0; } else { return $user_groups[0]->storage_limit; } } return 0; } public function get_usage_limit_mb() { // Returns a user's maximum limit in megabytes. return ($this->get_usage_limit() / 1024 / 1024); } public function add_item($item) { // Adds an item's file size to the table. if ($item->is_album()) { return ; } $item_fullsize = 0; $item_resize = 0; $item_thumb = 0; if (file_exists($item->file_path())) { $item_fullsize = filesize($item->file_path()); } if (file_exists($item->thumb_path())) { $item_thumb = filesize($item->thumb_path()); } if (file_exists($item->resize_path())) { $item_resize = filesize($item->resize_path()); } $this->fullsize = $this->fullsize + $item_fullsize; $this->resize = $this->resize + $item_resize; $this->thumb = $this->thumb + $item_thumb; $this->save(); return ; } public function remove_item($item) { // Removes an item's file size from the table. if ($item->is_album()) { return ; } $item_fullsize = 0; $item_resize = 0; $item_thumb = 0; if (file_exists($item->file_path())) { $item_fullsize = filesize($item->file_path()); } if (file_exists($item->thumb_path())) { $item_thumb = filesize($item->thumb_path()); } if (file_exists($item->resize_path())) { $item_resize = filesize($item->resize_path()); } $this->fullsize = $this->fullsize - $item_fullsize; $this->resize = $this->resize - $item_resize; $this->thumb = $this->thumb - $item_thumb; $this->save(); return ; } }