diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-01-11 12:21:27 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-01-16 17:38:38 +0100 |
commit | c8e5f5a20c9e558efbd5e9c152f086ab72015ba3 (patch) | |
tree | 37f48d7eed97b1763785b41db949d07279d2116b /application | |
parent | 8fd7c6c2ab80240ab1d163c9a4134822c7524144 (diff) |
refactor service/file/history
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r-- | application/service/files.php | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/application/service/files.php b/application/service/files.php index 7b320078e..b4bf7b9ee 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -14,36 +14,13 @@ class files { static public function history($user) { $CI =& get_instance(); - $multipaste_items_grouped = array(); - $multipaste_items = array(); $fields = array("id", "filename", "mimetype", "date", "hash", "filesize"); - $items = $CI->db->select(implode(',', $fields)) ->from('files') ->where('user', $user) ->get()->result_array(); - $multipaste_items_query = $CI->db - ->select("m.url_id, f.filename, f.id, f.filesize, f.date, f.hash, f.mimetype") - ->from("multipaste m") - ->join("multipaste_file_map mfm", "m.multipaste_id = mfm.multipaste_id") - ->join("files f", "f.id = mfm.file_url_id") - ->where("m.user_id", $user) - ->get()->result_array(); - - foreach ($multipaste_items_query as $item) { - $key = $item["url_id"]; - unset($item["url_id"]); - $multipaste_items_grouped[$key][] = $item; - } - - foreach ($multipaste_items_grouped as $key => $items) { - $multipaste_info = $CI->db->get_where("multipaste", array("url_id" => $key))->row_array(); - $multipaste_info["items"] = $items; - $multipaste_items[] = $multipaste_info; - } - $total_size = $CI->db->query(" SELECT sum(filesize) sum FROM ( @@ -54,12 +31,39 @@ class files { ", array($user))->row_array(); $ret["items"] = $items; - $ret["multipaste_items"] = $multipaste_items; + $ret["multipaste_items"] = self::get_multipaste_history($user); $ret["total_size"] = $total_size["sum"]; return $ret; } + static private function get_multipaste_history($user) + { + $CI =& get_instance(); + $multipaste_items_grouped = array(); + $multipaste_items = array(); + + $query = $CI->db->get_where("multipaste", array("user_id" => $user))->result_array(); + $multipaste_info = array(); + foreach ($query as $item) { + $multipaste_info[$item["url_id"]] = $item; + } + + $multipaste_items_query = $CI->db + ->select("m.url_id, f.id") + ->from("multipaste m") + ->join("multipaste_file_map mfm", "m.multipaste_id = mfm.multipaste_id") + ->join("files f", "f.id = mfm.file_url_id") + ->where("m.user_id", $user) + ->get()->result_array(); + + foreach ($multipaste_items_query as $item) { + $multipaste_info[$item["url_id"]]["items"][$item["id"]] = array("id" => $item["id"]); + } + + return $multipaste_info; + } + static public function add_file($id, $file, $filename) { $CI =& get_instance(); |